mirror of
https://github.com/danog/Valinor.git
synced 2025-01-10 06:38:24 +01:00
2d70efbfbb
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.
30 lines
680 B
PHP
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());
|
|
}
|
|
}
|