mirror of
https://github.com/cerbero90/json-parser.git
synced 2025-01-17 13:08:16 +01:00
Test mixed pointers
This commit is contained in:
parent
a6f037833c
commit
6e9c0996c4
@ -8,7 +8,6 @@ use Cerbero\JsonParser\Sources\Psr7Request;
|
|||||||
use DirectoryIterator;
|
use DirectoryIterator;
|
||||||
use Generator;
|
use Generator;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
use Pest\Expectation;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The dataset provider.
|
* 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
|
* Retrieve the dataset to test syntax errors
|
||||||
*
|
*
|
||||||
|
@ -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) {
|
it('lazy loads JSON recursively', function (string $json, string $pointer, array $keys, array $expected) {
|
||||||
expect(JsonParser::parse($json)->lazyPointer($pointer))->toLazyLoadRecursively($keys, $expected);
|
expect(JsonParser::parse($json)->lazyPointer($pointer))->toLazyLoadRecursively($keys, $expected);
|
||||||
})->with(Dataset::forRecursiveLazyLoading());
|
})->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());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user