Valinor/tests/Unit/Definition/Repository/Cache/Compiler/ClassDefinitionCompilerTest.php
Romain Canon 2d70efbfbb feat: extract file watching feature in own cache implementation
When the application runs in a development environment, the cache
implementation should be decorated with `FileWatchingCache` to prevent
invalid cache entries states, which can result in the library not
behaving as expected (missing property value, callable with outdated
signature, …).

```php
$cache = new \CuyZ\Valinor\Cache\FileSystemCache('path/to/cache-dir');

if ($isApplicationInDevelopmentEnvironment) {
    $cache = new \CuyZ\Valinor\Cache\FileWatchingCache($cache);
}

(new \CuyZ\Valinor\MapperBuilder())
    ->withCache($cache)
    ->mapper()
    ->map(SomeClass::class, [/* … */]);
```

This behavior now forces to explicitly inject `FileWatchingCache`, when
it was done automatically before; but because it shouldn't be used in
a production environment, it will increase overall performance.
2022-05-23 20:28:02 +02:00

30 lines
680 B
PHP

<?php
declare(strict_types=1);
namespace CuyZ\Valinor\Tests\Unit\Definition\Repository\Cache\Compiler;
use AssertionError;
use CuyZ\Valinor\Definition\Repository\Cache\Compiler\ClassDefinitionCompiler;
use PHPUnit\Framework\TestCase;
use stdClass;
final class ClassDefinitionCompilerTest extends TestCase
{
private ClassDefinitionCompiler $compiler;
protected function setUp(): void
{
parent::setUp();
$this->compiler = new ClassDefinitionCompiler();
}
public function test_compile_wrong_type_fails_assertion(): void
{
$this->expectException(AssertionError::class);
$this->compiler->compile(new stdClass());
}
}