-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIndexTest.php
More file actions
118 lines (102 loc) · 2.33 KB
/
IndexTest.php
File metadata and controls
118 lines (102 loc) · 2.33 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
declare(strict_types=1);
require_once 'utils.php';
$book1 = (object) [
'category' => 'reference',
'author' => 'Nigel Rees',
'title' => 'Sayings of the Century',
'price' => 8.95,
];
$book2 = (object) [
'category' => 'fiction',
'author' => 'Evelyn Waugh',
'title' => 'Sword of Honour',
'price' => 12.99,
];
$book3 = (object) [
'category' => 'fiction',
'author' => 'Herman Melville',
'title' => 'Moby Dick',
'isbn' => '0-553-21311-3',
'price' => 8.99,
];
$book4 = (object) [
'category' => 'fiction',
'author' => 'J. R. R. Tolkien',
'title' => 'The Lord of the Rings',
'isbn' => '0-395-19395-8',
'price' => 22.99,
];
$json = (object) [
'store' => (object) [
'book' => [$book1, $book2, $book3, $book4],
'bicycle' => (object) [
'color' => 'red',
'price' => 19.95,
],
],
];
// https://goessner.net/articles/JsonPath/index.html#e2
describe('Stefan Goessner JsonPath implementation', function () use (
$json,
$book1,
$book2,
$book3,
$book4
) {
it('child operator', function () use ($json) {
test_json_path($json, '$.store.bicycle.color', ['red']);
});
it('recursive descent', function () use (
$json,
$book1,
$book2,
$book3,
$book4
) {
test_json_path($json, '$..author', [
$book1->author,
$book2->author,
$book3->author,
$book4->author,
]);
});
it('wildcard', function () use ($json, $book1, $book2, $book3, $book4) {
test_json_path($json, '$.store.book.*', [
$book1,
$book2,
$book3,
$book4,
]);
});
it('subscript operator', function () use ($json, $book3) {
test_json_path($json, '$..book[2]', [$book3]);
});
it('array slice operator borrowed from ES4', function () use (
$json,
$book2,
$book3
) {
test_json_path($json, '$..book[1:3]', [$book2, $book3]);
});
it('array slice operator with slice', function () use (
$json,
$book1,
$book3
) {
test_json_path($json, '$..book[0:3:2]', [$book1, $book3]);
});
it('array slice operator with end', function () use (
$json,
$book1,
$book2
) {
test_json_path($json, '$..book[:2]', [$book1, $book2]);
});
it('applies a filter expression', function () use ($json, $book3, $book4) {
test_json_path($json, '$..book[?(@.isbn)]', [$book3, $book4]);
});
it('applies a script expression', function () use ($json, $book1, $book3) {
test_json_path($json, '$..book[?(@.price<10)]', [$book1, $book3]);
});
});