Skip to content

Commit

Permalink
php8: address ReflectionParameter::getClass deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonFrings committed Oct 15, 2021
1 parent 6fe0751 commit 3011bbe
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 70 deletions.
85 changes: 15 additions & 70 deletions tests/FunctionCheckTypehintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ public function shouldAcceptFunctionStringCallbackWithTypehint()
/** @test */
public function shouldAcceptInvokableObjectCallbackWithTypehint()
{
$this->assertTrue(_checkTypehint(new TestCallbackWithTypehintClass(), new \InvalidArgumentException()));
$this->assertfalse(_checkTypehint(new TestCallbackWithTypehintClass(), new \Exception()));
$this->assertTrue(_checkTypehint(new CallbackWithTypehintClass(), new \InvalidArgumentException()));
$this->assertfalse(_checkTypehint(new CallbackWithTypehintClass(), new \Exception()));
}

/** @test */
public function shouldAcceptObjectMethodCallbackWithTypehint()
{
$this->assertTrue(_checkTypehint([new TestCallbackWithTypehintClass(), 'testCallback'], new \InvalidArgumentException()));
$this->assertfalse(_checkTypehint([new TestCallbackWithTypehintClass(), 'testCallback'], new \Exception()));
$this->assertTrue(_checkTypehint([new CallbackWithTypehintClass(), 'testCallback'], new \InvalidArgumentException()));
$this->assertfalse(_checkTypehint([new CallbackWithTypehintClass(), 'testCallback'], new \Exception()));
}

/** @test */
public function shouldAcceptStaticClassCallbackWithTypehint()
{
$this->assertTrue(_checkTypehint(['React\Promise\TestCallbackWithTypehintClass', 'testCallbackStatic'], new \InvalidArgumentException()));
$this->assertfalse(_checkTypehint(['React\Promise\TestCallbackWithTypehintClass', 'testCallbackStatic'], new \Exception()));
$this->assertTrue(_checkTypehint([new CallbackWithTypehintClass(), 'testCallbackStatic'], new \InvalidArgumentException()));
$this->assertfalse(_checkTypehint([new CallbackWithTypehintClass(), 'testCallbackStatic'], new \Exception()));
}

/**
Expand All @@ -60,8 +60,8 @@ public function shouldAcceptClosureCallbackWithUnionTypehint()
*/
public function shouldAcceptInvokableObjectCallbackWithUnionTypehint()
{
self::assertTrue(_checkTypehint(new TestCallbackWithUnionTypehintClass(), new InvalidArgumentException()));
self::assertFalse(_checkTypehint(new TestCallbackWithUnionTypehintClass(), new Exception()));
self::assertTrue(_checkTypehint(new CallbackWithUnionTypehintClass(), new \InvalidArgumentException()));
self::assertFalse(_checkTypehint(new CallbackWithUnionTypehintClass(), new \Exception()));
}

/**
Expand All @@ -70,8 +70,8 @@ public function shouldAcceptInvokableObjectCallbackWithUnionTypehint()
*/
public function shouldAcceptObjectMethodCallbackWithUnionTypehint()
{
self::assertTrue(_checkTypehint([new TestCallbackWithUnionTypehintClass(), 'testCallback'], new InvalidArgumentException()));
self::assertFalse(_checkTypehint([new TestCallbackWithUnionTypehintClass(), 'testCallback'], new Exception()));
self::assertTrue(_checkTypehint([new CallbackWithUnionTypehintClass(), 'testCallback'], new \InvalidArgumentException()));
self::assertFalse(_checkTypehint([new CallbackWithUnionTypehintClass(), 'testCallback'], new \Exception()));
}

/**
Expand All @@ -80,8 +80,8 @@ public function shouldAcceptObjectMethodCallbackWithUnionTypehint()
*/
public function shouldAcceptStaticClassCallbackWithUnionTypehint()
{
self::assertTrue(_checkTypehint([TestCallbackWithUnionTypehintClass::class, 'testCallbackStatic'], new InvalidArgumentException()));
self::assertFalse(_checkTypehint([TestCallbackWithUnionTypehintClass::class, 'testCallbackStatic'], new Exception()));
self::assertTrue(_checkTypehint(['React\Promise\CallbackWithUnionTypehintClass', 'testCallbackStatic'], new \InvalidArgumentException()));
self::assertFalse(_checkTypehint(['React\Promise\CallbackWithUnionTypehintClass', 'testCallbackStatic'], new \Exception()));
}

/** @test */
Expand All @@ -100,19 +100,19 @@ public function shouldAcceptFunctionStringCallbackWithoutTypehint()
/** @test */
public function shouldAcceptInvokableObjectCallbackWithoutTypehint()
{
$this->assertTrue(_checkTypehint(new TestCallbackWithoutTypehintClass(), new \InvalidArgumentException()));
$this->assertTrue(_checkTypehint(new CallbackWithoutTypehintClass(), new \InvalidArgumentException()));
}

/** @test */
public function shouldAcceptObjectMethodCallbackWithoutTypehint()
{
$this->assertTrue(_checkTypehint([new TestCallbackWithoutTypehintClass(), 'testCallback'], new \InvalidArgumentException()));
$this->assertTrue(_checkTypehint([new CallbackWithoutTypehintClass(), 'testCallback'], new \InvalidArgumentException()));
}

/** @test */
public function shouldAcceptStaticClassCallbackWithoutTypehint()
{
$this->assertTrue(_checkTypehint(['React\Promise\TestCallbackWithoutTypehintClass', 'testCallbackStatic'], new \InvalidArgumentException()));
$this->assertTrue(_checkTypehint(['React\Promise\CallbackWithoutTypehintClass', 'testCallbackStatic'], new \InvalidArgumentException()));
}
}

Expand All @@ -123,58 +123,3 @@ function testCallbackWithTypehint(\InvalidArgumentException $e)
function testCallbackWithoutTypehint()
{
}

class TestCallbackWithTypehintClass
{
public function __invoke(\InvalidArgumentException $e)
{

}

public function testCallback(\InvalidArgumentException $e)
{

}

public static function testCallbackStatic(\InvalidArgumentException $e)
{

}
}

if (defined('PHP_MAJOR_VERSION') && (PHP_MAJOR_VERSION >= 8)) {
eval(<<<EOT
namespace React\Promise;
class TestCallbackWithUnionTypehintClass
{
public function __invoke(\RuntimeException|\InvalidArgumentException \$e)
{
}
public function testCallback(\RuntimeException|\InvalidArgumentException \$e)
{
}
public static function testCallbackStatic(\RuntimeException|\InvalidArgumentException \$e)
{
}
}
EOT
);
}

class TestCallbackWithoutTypehintClass
{
public function __invoke()
{

}

public function testCallback()
{

}

public static function testCallbackStatic()
{

}
}
20 changes: 20 additions & 0 deletions tests/fixtures/CallbackWithTypehintClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace React\Promise;

use InvalidArgumentException;

class CallbackWithTypehintClass
{
public function __invoke(InvalidArgumentException $e)
{
}

public function testCallback(InvalidArgumentException $e)
{
}

public static function testCallbackStatic(InvalidArgumentException $e)
{
}
}
21 changes: 21 additions & 0 deletions tests/fixtures/CallbackWithUnionTypehintClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace React\Promise;

use InvalidArgumentException;
use RuntimeException;

class CallbackWithUnionTypehintClass
{
public function __invoke(RuntimeException|InvalidArgumentException $e)
{
}

public function testCallback(RuntimeException|InvalidArgumentException $e)
{
}

public static function testCallbackStatic(RuntimeException|InvalidArgumentException $e)
{
}
}
18 changes: 18 additions & 0 deletions tests/fixtures/CallbackWithoutTypehintClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace React\Promise;

class CallbackWithoutTypehintClass
{
public function __invoke()
{
}

public function testCallback()
{
}

public static function testCallbackStatic()
{
}
}

0 comments on commit 3011bbe

Please sign in to comment.