-
-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathIndexesFilterTest.php
More file actions
60 lines (48 loc) · 1.41 KB
/
Copy pathIndexesFilterTest.php
File metadata and controls
60 lines (48 loc) · 1.41 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
<?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 Flow\JSONPath\Filters\IndexesFilter;
use Flow\JSONPath\JSONPathException;
use Flow\JSONPath\JSONPathToken;
use Flow\JSONPath\TokenType;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
#[CoversClass(IndexesFilter::class)]
class IndexesFilterTest extends TestCase
{
/**
* @throws JSONPathException
*/
public function testReturnsSliceAndExplicitIndexes(): void
{
$token = new JSONPathToken(TokenType::Indexes, [
['type' => 'slice', 'value' => ['start' => 1, 'end' => 3, 'step' => null]],
0,
]);
$filter = new IndexesFilter($token);
self::assertSame([2, 3, 1], $filter->filter([1, 2, 3, 4]));
}
/**
* @throws JSONPathException
*/
public function testSupportsQueryAndWildcard(): void
{
$token = new JSONPathToken(TokenType::Indexes, [
['type' => 'query', 'value' => '@.v>1'],
'*',
]);
$filter = new IndexesFilter($token);
$filter->setRootData([]);
$data = [
['v' => 1],
['v' => 2],
];
$result = $filter->filter($data);
self::assertSame([['v' => 2], ['v' => 1], ['v' => 2]], $result);
}
}