Skip to content

Commit 241d5b6

Browse files
cdosofteiSimonFrings
authored andcommitted
php8: address ReflectionParameter::getClass deprecation
1 parent b2a8948 commit 241d5b6

4 files changed

Lines changed: 78 additions & 70 deletions

File tree

tests/FunctionCheckTypehintTest.php

Lines changed: 19 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,29 @@ public function shouldAcceptClosureCallbackWithTypehint()
1717
/** @test */
1818
public function shouldAcceptFunctionStringCallbackWithTypehint()
1919
{
20-
self::assertTrue(_checkTypehint(new TestCallbackWithTypehintClass(), new InvalidArgumentException()));
21-
self::assertFalse(_checkTypehint(new TestCallbackWithTypehintClass(), new Exception()));
20+
self::assertTrue(_checkTypehint(new CallbackWithTypehintClass(), new InvalidArgumentException()));
21+
self::assertFalse(_checkTypehint(new CallbackWithTypehintClass(), new Exception()));
2222
}
2323

2424
/** @test */
2525
public function shouldAcceptInvokableObjectCallbackWithTypehint()
2626
{
27-
self::assertTrue(_checkTypehint(new TestCallbackWithTypehintClass(), new InvalidArgumentException()));
28-
self::assertFalse(_checkTypehint(new TestCallbackWithTypehintClass(), new Exception()));
27+
self::assertTrue(_checkTypehint(new CallbackWithTypehintClass(), new InvalidArgumentException()));
28+
self::assertFalse(_checkTypehint(new CallbackWithTypehintClass(), new Exception()));
2929
}
3030

3131
/** @test */
3232
public function shouldAcceptObjectMethodCallbackWithTypehint()
3333
{
34-
self::assertTrue(_checkTypehint([new TestCallbackWithTypehintClass(), 'testCallback'], new InvalidArgumentException()));
35-
self::assertFalse(_checkTypehint([new TestCallbackWithTypehintClass(), 'testCallback'], new Exception()));
34+
self::assertTrue(_checkTypehint([new CallbackWithTypehintClass(), 'testCallback'], new InvalidArgumentException()));
35+
self::assertFalse(_checkTypehint([new CallbackWithTypehintClass(), 'testCallback'], new Exception()));
3636
}
3737

3838
/** @test */
3939
public function shouldAcceptStaticClassCallbackWithTypehint()
4040
{
41-
self::assertTrue(_checkTypehint([TestCallbackWithTypehintClass::class, 'testCallbackStatic'], new InvalidArgumentException()));
42-
self::assertFalse(_checkTypehint([TestCallbackWithTypehintClass::class, 'testCallbackStatic'], new Exception()));
41+
self::assertTrue(_checkTypehint([CallbackWithTypehintClass::class, 'testCallbackStatic'], new InvalidArgumentException()));
42+
self::assertFalse(_checkTypehint([CallbackWithTypehintClass::class, 'testCallbackStatic'], new Exception()));
4343
}
4444

4545
/**
@@ -61,8 +61,8 @@ public function shouldAcceptClosureCallbackWithUnionTypehint()
6161
*/
6262
public function shouldAcceptInvokableObjectCallbackWithUnionTypehint()
6363
{
64-
self::assertTrue(_checkTypehint(new TestCallbackWithUnionTypehintClass(), new InvalidArgumentException()));
65-
self::assertFalse(_checkTypehint(new TestCallbackWithUnionTypehintClass(), new Exception()));
64+
self::assertTrue(_checkTypehint(new CallbackWithUnionTypehintClass(), new InvalidArgumentException()));
65+
self::assertFalse(_checkTypehint(new CallbackWithUnionTypehintClass(), new Exception()));
6666
}
6767

6868
/**
@@ -71,8 +71,8 @@ public function shouldAcceptInvokableObjectCallbackWithUnionTypehint()
7171
*/
7272
public function shouldAcceptObjectMethodCallbackWithUnionTypehint()
7373
{
74-
self::assertTrue(_checkTypehint([new TestCallbackWithUnionTypehintClass(), 'testCallback'], new InvalidArgumentException()));
75-
self::assertFalse(_checkTypehint([new TestCallbackWithUnionTypehintClass(), 'testCallback'], new Exception()));
74+
self::assertTrue(_checkTypehint([new CallbackWithUnionTypehintClass(), 'testCallback'], new InvalidArgumentException()));
75+
self::assertFalse(_checkTypehint([new CallbackWithUnionTypehintClass(), 'testCallback'], new Exception()));
7676
}
7777

7878
/**
@@ -81,11 +81,11 @@ public function shouldAcceptObjectMethodCallbackWithUnionTypehint()
8181
*/
8282
public function shouldAcceptStaticClassCallbackWithUnionTypehint()
8383
{
84-
self::assertTrue(_checkTypehint([TestCallbackWithUnionTypehintClass::class, 'testCallbackStatic'], new InvalidArgumentException()));
85-
self::assertFalse(_checkTypehint([TestCallbackWithUnionTypehintClass::class, 'testCallbackStatic'], new Exception()));
84+
self::assertTrue(_checkTypehint([CallbackWithUnionTypehintClass::class, 'testCallbackStatic'], new InvalidArgumentException()));
85+
self::assertFalse(_checkTypehint([CallbackWithUnionTypehintClass::class, 'testCallbackStatic'], new Exception()));
8686
}
8787

88-
/** @test */
88+
/** @test */
8989
public function shouldAcceptClosureCallbackWithoutTypehint()
9090
{
9191
self::assertTrue(_checkTypehint(function (InvalidArgumentException $e) {
@@ -95,25 +95,25 @@ public function shouldAcceptClosureCallbackWithoutTypehint()
9595
/** @test */
9696
public function shouldAcceptFunctionStringCallbackWithoutTypehint()
9797
{
98-
self::assertTrue(_checkTypehint(new TestCallbackWithoutTypehintClass(), new InvalidArgumentException()));
98+
self::assertTrue(_checkTypehint(new CallbackWithoutTypehintClass(), new InvalidArgumentException()));
9999
}
100100

101101
/** @test */
102102
public function shouldAcceptInvokableObjectCallbackWithoutTypehint()
103103
{
104-
self::assertTrue(_checkTypehint(new TestCallbackWithoutTypehintClass(), new InvalidArgumentException()));
104+
self::assertTrue(_checkTypehint(new CallbackWithoutTypehintClass(), new InvalidArgumentException()));
105105
}
106106

107107
/** @test */
108108
public function shouldAcceptObjectMethodCallbackWithoutTypehint()
109109
{
110-
self::assertTrue(_checkTypehint([new TestCallbackWithoutTypehintClass(), 'testCallback'], new InvalidArgumentException()));
110+
self::assertTrue(_checkTypehint([new CallbackWithoutTypehintClass(), 'testCallback'], new InvalidArgumentException()));
111111
}
112112

113113
/** @test */
114114
public function shouldAcceptStaticClassCallbackWithoutTypehint()
115115
{
116-
self::assertTrue(_checkTypehint([TestCallbackWithoutTypehintClass::class, 'testCallbackStatic'], new InvalidArgumentException()));
116+
self::assertTrue(_checkTypehint([CallbackWithoutTypehintClass::class, 'testCallbackStatic'], new InvalidArgumentException()));
117117
}
118118
}
119119

@@ -124,54 +124,3 @@ function testCallbackWithTypehint(InvalidArgumentException $e)
124124
function testCallbackWithoutTypehint()
125125
{
126126
}
127-
128-
class TestCallbackWithTypehintClass
129-
{
130-
public function __invoke(InvalidArgumentException $e)
131-
{
132-
}
133-
134-
public function testCallback(InvalidArgumentException $e)
135-
{
136-
}
137-
138-
public static function testCallbackStatic(InvalidArgumentException $e)
139-
{
140-
}
141-
}
142-
143-
if (defined('PHP_MAJOR_VERSION') && (PHP_MAJOR_VERSION >= 8)) {
144-
eval(<<<EOT
145-
namespace React\Promise;
146-
class TestCallbackWithUnionTypehintClass
147-
{
148-
public function __invoke(\RuntimeException|\InvalidArgumentException \$e)
149-
{
150-
}
151-
152-
public function testCallback(\RuntimeException|\InvalidArgumentException \$e)
153-
{
154-
}
155-
156-
public static function testCallbackStatic(\RuntimeException|\InvalidArgumentException \$e)
157-
{
158-
}
159-
}
160-
EOT
161-
);
162-
}
163-
164-
class TestCallbackWithoutTypehintClass
165-
{
166-
public function __invoke()
167-
{
168-
}
169-
170-
public function testCallback()
171-
{
172-
}
173-
174-
public static function testCallbackStatic()
175-
{
176-
}
177-
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace React\Promise;
4+
5+
use InvalidArgumentException;
6+
7+
class CallbackWithTypehintClass
8+
{
9+
public function __invoke(InvalidArgumentException $e)
10+
{
11+
}
12+
13+
public function testCallback(InvalidArgumentException $e)
14+
{
15+
}
16+
17+
public static function testCallbackStatic(InvalidArgumentException $e)
18+
{
19+
}
20+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace React\Promise;
4+
5+
use InvalidArgumentException;
6+
use RuntimeException;
7+
8+
class CallbackWithUnionTypehintClass
9+
{
10+
public function __invoke(RuntimeException|InvalidArgumentException $e)
11+
{
12+
}
13+
14+
public function testCallback(RuntimeException|InvalidArgumentException $e)
15+
{
16+
}
17+
18+
public static function testCallbackStatic(RuntimeException|InvalidArgumentException $e)
19+
{
20+
}
21+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace React\Promise;
4+
5+
class CallbackWithoutTypehintClass
6+
{
7+
public function __invoke()
8+
{
9+
}
10+
11+
public function testCallback()
12+
{
13+
}
14+
15+
public static function testCallbackStatic()
16+
{
17+
}
18+
}

0 commit comments

Comments
 (0)