Test mixed pointers

This commit is contained in:
Andrea Marco Sartori 2023-03-21 17:33:52 +10:00
parent a6f037833c
commit 6e9c0996c4
2 changed files with 48 additions and 1 deletions

View File

@ -8,7 +8,6 @@ use Cerbero\JsonParser\Sources\Psr7Request;
use DirectoryIterator;
use Generator;
use Mockery;
use Pest\Expectation;
/**
* The dataset provider.
@ -278,6 +277,50 @@ final class Dataset
}
}
/**
* Retrieve the dataset to test mixed pointers
*
* @return Generator
*/
public static function forMixedPointers(): Generator
{
$json = fixture('json/complex_object.json');
$pointersList = [
[
'/name' => fn (string $name) => "name_{$name}",
],
[
'/id' => fn (string $id) => "id_{$id}",
'/type' => fn (string $type) => "type_{$type}",
],
];
$lazyPointers = [
[
'/batters/batter' => fn (Parser $batter) => $batter::class,
],
[
'/batters' => fn (Parser $batters) => $batters::class,
'/topping' => fn (Parser $topping) => $topping::class,
],
];
$expected = [
[
'name' => 'name_Cake',
'batter' => Parser::class,
],
[
'id' => 'id_0001',
'type' => 'type_donut',
'batters' => Parser::class,
'topping' => Parser::class,
],
];
foreach ($pointersList as $index => $pointers) {
yield [$json, $pointers, $lazyPointers[$index], $expected[$index]];
}
}
/**
* Retrieve the dataset to test syntax errors
*

View File

@ -39,3 +39,7 @@ it('lazy loads JSON from multiple lazy JSON pointers', function (string $json, a
it('lazy loads JSON recursively', function (string $json, string $pointer, array $keys, array $expected) {
expect(JsonParser::parse($json)->lazyPointer($pointer))->toLazyLoadRecursively($keys, $expected);
})->with(Dataset::forRecursiveLazyLoading());
it('mixes pointers and lazy pointers', function (string $json, array $pointers, array $lazyPointers, array $expected) {
expect(JsonParser::parse($json)->pointers($pointers)->lazyPointers($lazyPointers))->toParseTo($expected);
})->with(Dataset::forMixedPointers());