-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPathSegmentsTest.php
More file actions
49 lines (40 loc) · 1.03 KB
/
PathSegmentsTest.php
File metadata and controls
49 lines (40 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
declare(strict_types=1);
use Loilo\JsonPath\JsonPath;
$book_1 = [
'category' => 'reference',
'author' => 'Nigel Rees',
'title' => 'Sayings of the Century',
'price' => 8.95,
];
$book_2 = [
'category' => 'fiction',
'author' => 'Evelyn Waugh',
'title' => 'Sword of Honour',
'price' => 12.99,
];
$json = [
'store' => [
'book' => [$book_1, $book_2],
],
];
it(
'should return path segments as arrays of strings and numbers',
function () use ($json) {
$path = new JsonPath("$.store.book[*].author");
$path_segments_list = array_map(
fn($result) => $result->segments,
$path->path_segments($json),
);
expect($path_segments_list[0])->toEqual(['store', 'book', 0, 'author']);
expect($path_segments_list[1])->toEqual(['store', 'book', 1, 'author']);
},
);
it('should return empty segments for root segment', function () use ($json) {
$path = new JsonPath("$");
$path_segments_list = array_map(
fn($result) => $result->segments,
$path->path_segments($json),
);
expect($path_segments_list[0])->toEqual([]);
});