1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
<?php declare(strict_types=1);
namespace Invoker\Test\ParameterResolver;
use Invoker\ParameterResolver\TypeHintResolver;
use PHPUnit\Framework\TestCase;
class TypeHintResolverTest extends TestCase
{
private const FIXTURE = TypeHintResolverFixture::class;
/** @var TypeHintResolver */
private $resolver;
public function setUp(): void
{
$this->resolver = new TypeHintResolver;
}
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_resolve_parameter_with_typehint()
{
$callable = function (TypeHintResolverFixture $foo, self $bar) {
};
$reflection = new \ReflectionFunction($callable);
$fixture = new TypeHintResolverFixture;
$parameters = $this->resolver->getParameters(
$reflection,
[self::FIXTURE => $fixture, self::class => $this],
[]
);
$this->assertCount(2, $parameters);
$this->assertSame($fixture, $parameters[0]);
$this->assertSame($this, $parameters[1]);
}
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_skip_parameter_if_provided_parameters_do_not_contain_typehint()
{
$callable = function (TypeHintResolverFixture $foo) {
};
$reflection = new \ReflectionFunction($callable);
$parameters = $this->resolver->getParameters($reflection, [], []);
$this->assertCount(0, $parameters);
}
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_skip_parameter_if_already_resolved()
{
$callable = function (TypeHintResolverFixture $foo) {
};
$reflection = new \ReflectionFunction($callable);
$fixture = new TypeHintResolverFixture;
$resolvedParameters = ['first param value'];
$parameters = $this->resolver->getParameters($reflection, [self::FIXTURE => $fixture], $resolvedParameters);
$this->assertSame($resolvedParameters, $parameters);
}
}
class TypeHintResolverFixture
{
}
|