-
-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathRecursiveFilterTest.php
More file actions
45 lines (37 loc) · 1.12 KB
/
Copy pathRecursiveFilterTest.php
File metadata and controls
45 lines (37 loc) · 1.12 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
<?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\RecursiveFilter;
use Flow\JSONPath\JSONPathException;
use Flow\JSONPath\JSONPathToken;
use Flow\JSONPath\TokenType;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
#[CoversClass(RecursiveFilter::class)]
class RecursiveFilterTest extends TestCase
{
/**
* @throws JSONPathException
*/
public function testRecursesThroughNestedArraysAndObjects(): void
{
$token = new JSONPathToken(TokenType::Recursive, null);
$filter = new RecursiveFilter($token);
$nestedObject = (object)['inner' => ['value' => 3]];
$data = ['obj' => $nestedObject, 'scalar' => 1];
$result = $filter->filter($data);
self::assertSame($nestedObject, $result[0]['obj']);
self::assertSame(
[
['inner' => ['value' => 3]],
['value' => 3],
],
\array_slice($result, 1)
);
}
}