Skip to content

Commit

Permalink
ContainerAttributeResolverFactoryTest
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed Oct 26, 2023
1 parent e101145 commit bf468b3
Showing 1 changed file with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Hydrator\Tests\AttributeHandling\ResolverFactory;

use PHPUnit\Framework\TestCase;
use Yiisoft\Hydrator\AttributeHandling\Exception\AttributeResolverNonInstantiableException;
use Yiisoft\Hydrator\AttributeHandling\ResolverFactory\ContainerAttributeResolverFactory;
use Yiisoft\Hydrator\Tests\Support\Attribute\Counter;
use Yiisoft\Hydrator\Tests\Support\Attribute\CounterResolver;
use Yiisoft\Hydrator\Tests\Support\Attribute\CustomValue;
use Yiisoft\Test\Support\Container\SimpleContainer;

final class ContainerAttributeResolverFactoryTest extends TestCase
{
public function testBase(): void
{
$attribute = new Counter('test');
$resolver = new CounterResolver();
$container = new SimpleContainer([CounterResolver::class => $resolver]);
$factory = new ContainerAttributeResolverFactory($container);

$result = $factory->create($attribute);

$this->assertSame($resolver, $result);
}

public function testResolverIsAttributeItself(): void
{
$attribute = new CustomValue('test');
$container = new SimpleContainer();
$factory = new ContainerAttributeResolverFactory($container);

$result = $factory->create($attribute);

$this->assertSame($attribute, $result);
}

public function testResolverNotExists(): void
{
$attribute = new Counter('test');
$container = new SimpleContainer();
$factory = new ContainerAttributeResolverFactory($container);

$this->expectException(AttributeResolverNonInstantiableException::class);
$this->expectExceptionMessage('Class "' . CounterResolver::class . '" does not exist.');
$factory->create($attribute);
}
}

0 comments on commit bf468b3

Please sign in to comment.