Skip to content

Commit 44635e3

Browse files
committed
Query property isPath covered with tests
1 parent 41beb2c commit 44635e3

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

tests/Parser/TranslationSchemeTest.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,39 @@
77
use Remorhaz\JSON\Path\Processor\Processor;
88
use Remorhaz\JSON\Path\Query\QueryFactory;
99

10+
/**
11+
* @covers \Remorhaz\JSON\Path\Parser\TranslationScheme
12+
* @todo Maybe it's better to test in isolation, checking the resulting AST.
13+
*/
1014
class TranslationSchemeTest extends TestCase
1115
{
1216

17+
/**
18+
* @param string $path
19+
* @param bool $expectedValue
20+
* @dataProvider providerIsPath
21+
*/
22+
public function testIsPathProperty_GivenQueryParsed_ContainsMatchingValue(string $path, bool $expectedValue): void
23+
{
24+
$query = QueryFactory::create()->createQuery($path);
25+
26+
self::assertSame($expectedValue, $query->getProperties()->isPath());
27+
}
28+
29+
public function providerIsPath(): array
30+
{
31+
return [
32+
'Dot-notation star' => ['$.*', true],
33+
'Dot-notation property' => ['$.a', true],
34+
'Double-dot-notation star' => ['$..*', true],
35+
'Double-dot-notation property' => ['$..a', true],
36+
'Aggregate function' => ['$.length()', false],
37+
'Filter by absolute property' => ['$.a[?($.b)]', true],
38+
'Filter by relative property' => ['$.a[?(@.b)]', true],
39+
'Filter by aggregate function' => ['$.a[?(@.b.length() > 1)]', true],
40+
];
41+
}
42+
1343
/**
1444
* Because of the scheme complexity it's more convenient to test it in full integration.
1545
*
@@ -18,8 +48,6 @@ class TranslationSchemeTest extends TestCase
1848
* @param array $expectedValue
1949
* @param bool $isDefinite
2050
* @dataProvider providerParser
21-
* @covers \Remorhaz\JSON\Path\Parser\TranslationScheme
22-
* @todo Maybe it's better to test in isolation, checking the resulting AST.
2351
*/
2452
public function testAllMethods_AssembledWithParser_QueryWorksAsExpected(
2553
$json,
@@ -33,7 +61,7 @@ public function testAllMethods_AssembledWithParser_QueryWorksAsExpected(
3361

3462
$result = Processor::create()->select(
3563
$query,
36-
(new NodeValueFactory)->createValue($json)
64+
NodeValueFactory::create()->createValue($json)
3765
);
3866

3967
self::assertEquals($expectedValue, $result->encode());

0 commit comments

Comments
 (0)