Skip to content

Commit d5646e4

Browse files
committed
Updated tests
1 parent edad2e1 commit d5646e4

File tree

3 files changed

+39
-27
lines changed

3 files changed

+39
-27
lines changed

tests/JSONPathArrayAccessTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,23 @@ class JSONPathArrayAccessTest extends TestCase
2727
*/
2828
public function testChaining(): void
2929
{
30-
$data = $this->getData('conferences');
30+
$jsonPath = (new JSONPath($this->getData('conferences')));
3131

32-
$teams = (new JSONPath($data))
32+
$teams = $jsonPath
3333
->find('.conferences.*')
3434
->find('..teams.*');
3535

3636
self::assertEquals('Dodger', $teams[0]['name']);
3737
self::assertEquals('Mets', $teams[1]['name']);
3838

39-
$teams = (new JSONPath($data))
39+
$teams = $jsonPath
4040
->find('.conferences.*')
4141
->find('..teams.*');
4242

4343
self::assertEquals('Dodger', $teams[0]['name']);
4444
self::assertEquals('Mets', $teams[1]['name']);
4545

46-
$teams = (new JSONPath($data))
46+
$teams = $jsonPath
4747
->find('.conferences..teams.*');
4848

4949
self::assertEquals('Dodger', $teams[0]['name']);

tests/JSONPathDashedIndexTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
class JSONPathDashedIndexTest extends TestCase
1717
{
18+
/**
19+
* @return array[]
20+
*/
1821
public function indexDataProvider(): array
1922
{
2023
return [

tests/JSONPathTest.php

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -337,19 +337,21 @@ public function testQueryMatchEqualsWithUnquotedInteger(): void
337337
*/
338338
public function testQueryMatchNotEqualsTo(): void
339339
{
340-
$results = (new JSONPath($this->getData('example')))
340+
$jsonPath = (new JSONPath($this->getData('example')));
341+
342+
$results = $jsonPath
341343
->find('$..books[?(@.author != "J. R. R. Tolkien")].title');
342344

343345
self::assertcount(3, $results);
344346
self::assertEquals(['Sayings of the Century', 'Sword of Honour', 'Moby Dick'], $results->getData());
345347

346-
$results = (new JSONPath($this->getData('example')))
348+
$results = $jsonPath
347349
->find('$..books[?(@.author !== "J. R. R. Tolkien")].title');
348350

349351
self::assertcount(3, $results);
350352
self::assertEquals(['Sayings of the Century', 'Sword of Honour', 'Moby Dick'], $results->getData());
351353

352-
$results = (new JSONPath($this->getData('example')))
354+
$results = $jsonPath
353355
->find('$..books[?(@.author <> "J. R. R. Tolkien")].title');
354356

355357
self::assertcount(3, $results);
@@ -364,17 +366,19 @@ public function testQueryMatchNotEqualsTo(): void
364366
*/
365367
public function testQueryMatchWithRegexCaseSensitive(): void
366368
{
367-
$result = (new JSONPath($this->getData('example')))
369+
$jsonPath = (new JSONPath($this->getData('example')));
370+
371+
$results = $jsonPath
368372
->find('$..books[?(@.author =~ /nigel ree?s/i)].title');
369373

370-
self::assertcount(1, $result);
371-
self::assertEquals(['Sayings of the Century'], $result->getData());
374+
self::assertcount(1, $results);
375+
self::assertEquals(['Sayings of the Century'], $results->getData());
372376

373-
$result = (new JSONPath($this->getData('example')))
377+
$results = $jsonPath
374378
->find('$..books[?(@.title =~ /^(Say|The).*/)].title');
375379

376-
self::assertcount(2, $result);
377-
self::assertEquals(['Sayings of the Century', 'The Lord of the Rings'], $result->getData());
380+
self::assertcount(2, $results);
381+
self::assertEquals(['Sayings of the Century', 'The Lord of the Rings'], $results->getData());
378382
}
379383

380384
/**
@@ -602,8 +606,7 @@ public function testSimpleArrayAccess(): void
602606
*/
603607
public function testFilteringOnNoneArrays(): void
604608
{
605-
$data = ['foo' => 'asdf'];
606-
$result = (new JSONPath($data))
609+
$result = (new JSONPath(['foo' => 'asdf']))
607610
->find('$.foo.bar');
608611

609612
self::assertEquals([], $result->getData());
@@ -636,8 +639,7 @@ public function testMatchWithComplexSquareBrackets(): void
636639
*/
637640
public function testQueryMatchWithRecursive(): void
638641
{
639-
$locations = $this->getData('locations');
640-
$result = (new JSONPath($locations))
642+
$result = (new JSONPath($this->getData('locations')))
641643
->find("..[?(@.type == 'suburb')].name");
642644

643645
self::assertEquals(["Rosebank"], $result->getData());
@@ -681,12 +683,14 @@ public function testSlashesInIndex(): void
681683
*/
682684
public function testCyrillicText(): void
683685
{
684-
$result = (new JSONPath(["трололо" => 1]))
686+
$jsonPath = (new JSONPath(["трололо" => 1]));
687+
688+
$result = $jsonPath
685689
->find("$['трололо']");
686690

687691
self::assertEquals([1], $result->getData());
688692

689-
$result = (new JSONPath(["трололо" => 1]))
693+
$result = $jsonPath
690694
->find("$.трололо");
691695

692696
self::assertEquals([1], $result->getData());
@@ -697,14 +701,19 @@ public function testCyrillicText(): void
697701
*/
698702
public function testOffsetUnset(): void
699703
{
700-
$data = [
701-
"route" => [
702-
["name" => "A", "type" => "type of A"],
703-
["name" => "B", "type" => "type of B"],
704-
],
705-
];
706-
$data = json_encode($data);
707-
$jsonIterator = new JSONPath(json_decode($data, false));
704+
$jsonIterator = new JSONPath(
705+
json_decode(
706+
json_encode(
707+
[
708+
"route" => [
709+
["name" => "A", "type" => "type of A"],
710+
["name" => "B", "type" => "type of B"],
711+
],
712+
]
713+
),
714+
false
715+
)
716+
);
708717

709718
/** @var JSONPath $route */
710719
$route = $jsonIterator->offsetGet('route');

0 commit comments

Comments
 (0)