mirror of
https://github.com/danog/Valinor.git
synced 2024-11-26 20:24:40 +01:00
69ad3f4777
The cache implementation that was previously injected in the mapper builder must now be manually injected. This gives better control on when the cache should be enabled, especially depending on which environment the application is running. The library provides a cache implementation out of the box, which saves cache entries into the file system. It is also possible to use any PSR-16 compliant implementation, as long as it is capable of caching the entries handled by the library. ```php $cache = new \CuyZ\Valinor\Cache\FileSystemCache('path/to/cache-dir'); (new \CuyZ\Valinor\MapperBuilder()) ->withCache($cache) ->mapper() ->map(SomeClass::class, [/* … */]); ```
48 lines
1.1 KiB
PHP
48 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace CuyZ\Valinor\Tests\Integration;
|
|
|
|
use CuyZ\Valinor\Mapper\MappingError;
|
|
use CuyZ\Valinor\Mapper\Tree\Node;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use function implode;
|
|
use function iterator_to_array;
|
|
|
|
abstract class IntegrationTest extends TestCase
|
|
{
|
|
/**
|
|
* @return never-return
|
|
*/
|
|
protected function mappingFail(MappingError $error)
|
|
{
|
|
$errorFinder = static function (Node $node, callable $errorFinder) {
|
|
if ($node->isValid()) {
|
|
return;
|
|
}
|
|
|
|
$errors = [];
|
|
|
|
foreach ($node->messages() as $message) {
|
|
if ($message->isError()) {
|
|
$errors[] = (string)$message;
|
|
}
|
|
}
|
|
|
|
if (count($errors) > 0) {
|
|
yield $node->path() => "{$node->path()}: " . implode(' / ', $errors);
|
|
}
|
|
|
|
foreach ($node->children() as $child) {
|
|
yield from $errorFinder($child, $errorFinder);
|
|
}
|
|
};
|
|
|
|
$list = iterator_to_array($errorFinder($error->node(), $errorFinder));
|
|
|
|
self::fail(implode(' — ', $list));
|
|
}
|
|
}
|