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
|
<?php
declare(strict_types=1);
namespace DI\Test\UnitTest\Definition\Resolver;
use DI\Definition\Definition;
use DI\Definition\Resolver\ResolverDispatcher;
use DI\Definition\StringDefinition;
use DI\Definition\ValueDefinition;
use DI\Proxy\ProxyFactory;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
/**
* @covers \DI\Definition\Resolver\ResolverDispatcher
*/
#[\PHPUnit\Framework\Attributes\CoversClass(\DI\Definition\Resolver\ResolverDispatcher::class)]
class ResolverDispatcherTest extends TestCase
{
private ResolverDispatcher $resolver;
public function setUp(): void
{
$this->markTestSkipped('Requires mnapoli/phpunit-easymock');
$container = $this->easyMock(ContainerInterface::class);
$proxyFactory = $this->easyMock(ProxyFactory::class);
$this->resolver = new ResolverDispatcher($container, $proxyFactory);
}
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_resolve_using_sub_resolvers()
{
$this->assertEquals('foo', $this->resolver->resolve(new ValueDefinition('foo')));
$this->assertEquals('bar', $this->resolver->resolve(new StringDefinition('bar')));
}
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_test_if_resolvable_using_sub_resolvers()
{
$this->assertTrue($this->resolver->isResolvable(new ValueDefinition('value')));
$this->assertTrue($this->resolver->isResolvable(new StringDefinition('value')));
}
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_throw_if_non_handled_definition()
{
$this->expectException('RuntimeException');
$this->expectExceptionMessage('No definition resolver was configured for definition of type');
$this->resolver->resolve($this->easyMock(Definition::class));
}
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_resolve_definitions()
{
$definition = new ValueDefinition('bar');
$this->assertTrue($this->resolver->isResolvable($definition));
$this->assertEquals('bar', $this->resolver->resolve($definition));
}
}
|