Valinor/tests/Unit/Definition/Repository/Cache/CacheClassDefinitionRepositoryTest.php
Romain Canon 7869cbd09c refactor: remove unnecessary ClassSignature
This abstraction layer was not useful, so it is removed to simplify the
API around `ClassDefinition`.

A new method `ClassDefinition::type()` is also added, giving access to
the `ClassType` instance when working with a class definition.
2022-01-25 18:32:28 +01:00

42 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace CuyZ\Valinor\Tests\Unit\Definition\Repository\Cache;
use CuyZ\Valinor\Definition\Repository\Cache\CacheClassDefinitionRepository;
use CuyZ\Valinor\Tests\Fake\Cache\FakeCache;
use CuyZ\Valinor\Tests\Fake\Definition\Repository\FakeClassDefinitionRepository;
use CuyZ\Valinor\Type\Types\ClassType;
use DateTime;
use PHPUnit\Framework\TestCase;
use stdClass;
final class CacheClassDefinitionRepositoryTest extends TestCase
{
private CacheClassDefinitionRepository $repository;
protected function setUp(): void
{
parent::setUp();
$this->repository = new CacheClassDefinitionRepository(
new FakeClassDefinitionRepository(),
new FakeCache()
);
}
public function test_class_is_saved_in_cache(): void
{
$typeA = new ClassType(stdClass::class);
$typeB = new ClassType(DateTime::class);
$classA = $this->repository->for($typeA);
$classB = $this->repository->for($typeA);
$classC = $this->repository->for($typeB);
self::assertSame($classA, $classB);
self::assertNotSame($classA, $classC);
}
}