2022-05-22 20:43:01 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace CuyZ\Valinor\Tests\Integration\Cache;
|
|
|
|
|
|
|
|
use CuyZ\Valinor\Cache\FileSystemCache;
|
2022-05-23 00:21:38 +02:00
|
|
|
use CuyZ\Valinor\Cache\FileWatchingCache;
|
2022-05-22 20:43:01 +02:00
|
|
|
use CuyZ\Valinor\MapperBuilder;
|
|
|
|
use CuyZ\Valinor\Tests\Integration\IntegrationTest;
|
|
|
|
use CuyZ\Valinor\Tests\Integration\Mapping\Fixture\SimpleObject;
|
|
|
|
use org\bovigo\vfs\vfsStream;
|
|
|
|
|
|
|
|
use function strtoupper;
|
|
|
|
|
|
|
|
final class CacheInjectionTest extends IntegrationTest
|
|
|
|
{
|
|
|
|
public function test_cache_entries_are_written_during_mapping(): void
|
|
|
|
{
|
|
|
|
$files = vfsStream::setup('cache-dir');
|
|
|
|
|
|
|
|
$cache = new FileSystemCache($files->url());
|
2022-05-23 00:21:38 +02:00
|
|
|
$cache = new FileWatchingCache($cache);
|
2022-05-22 20:43:01 +02:00
|
|
|
|
|
|
|
self::assertFalse($files->hasChildren());
|
|
|
|
|
|
|
|
$object = (new MapperBuilder())
|
|
|
|
->withCache($cache)
|
|
|
|
// The cache should be able to cache function definitions…
|
|
|
|
->alter(fn (string $value): string => strtoupper($value))
|
|
|
|
->mapper()
|
|
|
|
// …as well as class definitions.
|
|
|
|
->map(SimpleObject::class, 'foo');
|
|
|
|
|
|
|
|
self::assertSame('FOO', $object->value);
|
|
|
|
|
|
|
|
self::assertTrue($files->hasChildren());
|
|
|
|
}
|
|
|
|
}
|