-
-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathJSONPathIntegrationTest.php
More file actions
59 lines (47 loc) · 1.46 KB
/
JSONPathIntegrationTest.php
File metadata and controls
59 lines (47 loc) · 1.46 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
<?php
/**
* JSONPath implementation for PHP.
*
* @license https://github.com/SoftCreatR/JSONPath/blob/main/LICENSE MIT License
*/
declare(strict_types=1);
namespace Flow\JSONPath\Test;
use ArrayObject;
use Flow\JSONPath\JSONPath;
use Flow\JSONPath\JSONPathException;
use PHPUnit\Framework\TestCase;
class JSONPathIntegrationTest extends TestCase
{
/**
* @throws JSONPathException
*/
public function testArrayObjectTraversal(): void
{
$data = new ArrayObject([
'items' => new ArrayObject([
['name' => 'keep', 'active' => true],
['name' => 'skip', 'active' => false],
]),
]);
$result = new JSONPath($data)->find('$.items[?(@.active==true)]')->getData();
self::assertSame([['name' => 'keep', 'active' => true]], $result);
}
/**
* @throws JSONPathException
*/
public function testDashedIndexIsParsedWithoutQuotes(): void
{
$data = ['data' => ['dash-key' => 42, 'other' => 1]];
$result = new JSONPath($data)->find('$.data[dash-key]')->getData();
self::assertSame([42], $result);
}
/**
* @throws JSONPathException
*/
public function testSlicesResolveViaPublicApi(): void
{
$path = new JSONPath(['values' => [0, 1, 2, 3, 4]]);
self::assertSame([1, 2, 3], $path->find('$.values[1:-1]')->getData());
self::assertSame([4, 3], $path->find('$.values[-1:-3:-1]')->getData());
}
}