Skip to content

Commit 74a2d70

Browse files
committed
Update
1 parent 3e3c8ac commit 74a2d70

File tree

6 files changed

+39
-34
lines changed

6 files changed

+39
-34
lines changed

.github/workflows/Test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ name: Test
33

44
on:
55
push:
6+
tags-ignore:
7+
- '**'
68
paths:
79
- '*.php'
810
- 'composer.json'

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
JSONPath ![Test](https://github.com/SoftCreatR/JSONPath/workflows/Test/badge.svg)
1+
JSONPath ![Test](https://github.com/SoftCreatR/JSONPath/workflows/Test/badge.svg?branch=main)
22
=============
33

44
This is a [JSONPath](http://goessner.net/articles/JsonPath/) implementation for PHP based on Stefan Goessner's JSONPath script.
@@ -106,7 +106,7 @@ So here are the types of query expressions that are supported:
106106
Known issues
107107
------
108108

109-
- This project has not implemented multiple string indexes eg. `$[name,year]` or `$["name","year"]`. I have no ETA on that feature and it would require some re-writing of the parser that uses a very basic regex implementation.
109+
- This project has not implemented multiple string indexes e.g. `$[name,year]` or `$["name","year"]`. I have no ETA on that feature, and it would require some re-writing of the parser that uses a very basic regex implementation.
110110

111111
Similar projects
112112
----------------
@@ -119,8 +119,7 @@ Similar projects
119119

120120
The [Hash](http://book.cakephp.org/2.0/en/core-utility-libraries/hash.html) utility from CakePHP does some similar things
121121

122-
The original JsonPath implementations is available at [http://code.google.com/p/jsonpath]() and re-hosted for composer
123-
here [Peekmo/JsonPath](https://github.com/Peekmo/JsonPath).
122+
The original JsonPath implementations is available at [http://code.google.com/p/jsonpath]() and re-hosted for composer here [Peekmo/JsonPath](https://github.com/Peekmo/JsonPath).
124123

125124
[ObjectPath](http://objectpath.org) ([https://github.com/adriank/ObjectPath]()) appears to be a Python/JS implementation with a new name and extra features.
126125

@@ -135,15 +134,16 @@ Changelog
135134
- Added missing PHPDoc blocks
136135
- Added return type hints
137136
- Moved from Travis to GitHub actions
137+
- Set `strict_types=1`
138138

139139
### 0.5.0
140-
- Fixed the slice notation (eg. [0:2:5] etc.). **Breaks code relying on the broken implementation**
140+
- Fixed the slice notation (e.g. [0:2:5] etc.). **Breaks code relying on the broken implementation**
141141

142142
### 0.3.0
143143
- Added JSONPathToken class as value object
144144
- Lexer clean up and refactor
145145
- Updated the lexing and filtering of the recursive token ("..") to allow for a combination of recursion
146-
and filters, eg. $..[?(@.type == 'suburb')].name
146+
and filters, e.g. $..[?(@.type == 'suburb')].name
147147

148148
### 0.2.1 - 0.2.5
149149
- Various bug fixes and clean up

phpunit.xml.dist

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
3+
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
44
bootstrap="vendor/autoload.php"
5-
beStrictAboutOutputDuringTests="true"
6-
beStrictAboutTodoAnnotatedTests="true"
7-
verbose="true">
5+
colors="true"
6+
>
87
<testsuites>
9-
<testsuite name="default">
10-
<directory>tests</directory>
8+
<testsuite name="Unit">
9+
<directory suffix="Test.php">./tests</directory>
1110
</testsuite>
1211
</testsuites>
13-
14-
<filter>
15-
<whitelist processUncoveredFilesFromWhitelist="true">
16-
<directory suffix=".php">src</directory>
17-
</whitelist>
18-
</filter>
12+
<coverage processUncoveredFiles="true">
13+
<include>
14+
<directory suffix=".php">./src</directory>
15+
</include>
16+
</coverage>
1917
</phpunit>

tests/JSONPathArrayAccessTest.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Exception;
1313
use PHPUnit\Framework\TestCase;
1414
use Flow\JSONPath\JSONPath;
15+
use function json_decode;
1516
use function random_int;
1617

1718
class JSONPathArrayAccessTest extends TestCase
@@ -22,7 +23,6 @@ class JSONPathArrayAccessTest extends TestCase
2223
public function testChaining(): void
2324
{
2425
$data = $this->exampleData(random_int(0, 1));
25-
2626
$conferences = (new JSONPath($data))->find('.conferences.*');
2727
$teams = $conferences->find('..teams.*');
2828

@@ -46,9 +46,7 @@ public function testChaining(): void
4646
public function testIterating(): void
4747
{
4848
$data = $this->exampleData(random_int(0, 1));
49-
5049
$conferences = (new JSONPath($data))->find('.conferences.*');
51-
5250
$names = [];
5351

5452
foreach ($conferences as $conference) {
@@ -67,11 +65,17 @@ public function testIterating(): void
6765
*/
6866
public function testDifferentStylesOfAccess(): void
6967
{
70-
$data = $this->exampleData(random_int(0, 1));
68+
$data = (new JSONPath($this->exampleData(random_int(0, 1))));
69+
70+
self::assertArrayHasKey('conferences', $data);
7171

72-
$firstConference = (new JSONPath($data))->conferences[0];
72+
$conferences = $data->__get('conferences')->getData();
7373

74-
self::assertEquals('Western Conference', $firstConference->name);
74+
if (is_array($conferences[0])) {
75+
self::assertEquals('Western Conference', $conferences[0]['name']);
76+
} else {
77+
self::assertEquals('Western Conference', $conferences[0]->name);
78+
}
7579
}
7680

7781
/**
@@ -131,6 +135,6 @@ public function exampleData(int $asArray = 1)
131135
]
132136
}';
133137

134-
return \json_decode($json, $asArray === 1);
138+
return json_decode($json, $asArray === 1);
135139
}
136140
}

tests/JSONPathDashedIndexTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ public function indexDataProvider(): array
4949

5050
/**
5151
* @dataProvider indexDataProvider
52-
* @param $path
53-
* @param $data
54-
* @param $expected
52+
* @param string $path
53+
* @param array $data
54+
* @param array $expected
5555
* @throws Exception
5656
*/
57-
public function testSlice($path, $data, $expected): void
57+
public function testSlice(string $path, array $data, array $expected): void
5858
{
5959
$jsonPath = new JSONPath($data);
6060
$result = $jsonPath->find($path)->getData();

tests/JSONPathSliceAccessTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,14 @@ public function sliceDataProvider(): array
218218
];
219219
}
220220

221-
/** @dataProvider sliceDataProvider
222-
* @param $path
223-
* @param $data
224-
* @param $expected
221+
/**
222+
* @dataProvider sliceDataProvider
223+
* @param string $path
224+
* @param array $data
225+
* @param array $expected
225226
* @throws Exception
226227
*/
227-
public function testSlice($path, $data, $expected): void
228+
public function testSlice(string $path, array $data, array $expected): void
228229
{
229230
$jsonPath = new JSONPath($data);
230231
$result = $jsonPath->find($path)->getData();

0 commit comments

Comments
 (0)