diff --git a/.github/workflows/Test.yml b/.github/workflows/Test.yml
index 58a218d..d308b99 100644
--- a/.github/workflows/Test.yml
+++ b/.github/workflows/Test.yml
@@ -7,13 +7,13 @@ on:
- '**.php'
- 'composer.json'
branches:
- - 'main'
+ - 'oldphp'
pull_request:
paths:
- '**.php'
- 'composer.json'
branches:
- - 'main'
+ - 'oldphp'
workflow_dispatch:
jobs:
@@ -21,20 +21,18 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
- php: [ '7.1', '7.2', '7.3', '7.4', '8.0' ]
- continue-on-error: ${{ matrix.php == '8.0' }}
+ php: [ '5.4', '5.5', '5.6', '7.0' ]
name: PHP ${{ matrix.php }} Test
steps:
- name: Git checkout
- uses: actions/checkout@v2
+ uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: json
- coverage: pcov
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -47,14 +45,8 @@ jobs:
- name: Run phpcs
run: composer cs-check -- -v
- - name: Setup PCOV
- if: matrix.php == '7.1'
- run: |
- composer require pcov/clobber
- vendor/bin/pcov clobber
-
- name: Execute tests
run: composer test -- -v --coverage-clover=coverage.xml
- name: Run codecov
- uses: codecov/codecov-action@v1
+ uses: codecov/codecov-action@v3
diff --git a/.github/workflows/UpdateContributors.yml b/.github/workflows/UpdateContributors.yml
deleted file mode 100644
index 9d38b54..0000000
--- a/.github/workflows/UpdateContributors.yml
+++ /dev/null
@@ -1,18 +0,0 @@
----
-name: Update Contributors
-
-on: [ push, workflow_dispatch]
-
-jobs:
- Update:
- runs-on: ubuntu-latest
-
- steps:
- - name: Git checkout
- uses: actions/checkout@v2
-
- - uses: BobAnkh/add-contributors@master
- with:
- REPO_NAME: 'SoftCreatR/JSONPath'
- CONTRIBUTOR: '## Contributors ✨'
- ACCESS_TOKEN: ${{secrets.GITHUB_TOKEN}}
diff --git a/CHANGELOG.md b/CHANGELOG.md
deleted file mode 100644
index 1335909..0000000
--- a/CHANGELOG.md
+++ /dev/null
@@ -1,64 +0,0 @@
-# Changelog
-
-### 0.7.2
- - Fixed query/selector "Array Slice With Start Large Negative Number And Open End On Short Array" (#7)
- - Fixed query/selector "Union With Keys" (#22)
- - Fixed query/selector "Dot Notation After Union With Keys" (#15)
- - Fixed query/selector "Union With Keys After Array Slice" (#23)
- - Fixed query/selector "Union With Keys After Bracket Notation" (#24)
- - Fixed query/selector "Union With Keys On Object Without Key" (#25)
-
-### 0.7.1
- - Fixed issues with empty tokens (`['']` and `[""]`)
- - Fixed TypeError in AccessHelper::keyExists
- - Improved QueryTest
-
-### 0.7.0
-🔻 Breaking changes ahead:
-
- - Made JSONPath::__construct final
- - Added missing type hints
- - Partially reduced complexity
- - Performed some code optimizations
- - Updated composer.json for proper PHPUnit/PHP usage
- - Added support for regular expression operator (`=~`)
- - Added QueryTest to perform tests against all queries from https://cburgmer.github.io/json-path-comparison/
- - Switched Code Style from PSR-2 to PSR-12
-
-### 0.6.4
- - Removed unnecessary type casting, that caused problems under certain circumstances
- - Added support for `nin` operator
- - Added support for greater than or equal operator (`>=`)
- - Added support for less or equal operator (`<=`)
-
-### 0.6.3
- - Added support for `in` operator
- - Fixed evaluation on indexed object
-
-### 0.6.x
- - Dropped support for PHP < 7.1
- - Switched from (broken) PSR-0 to PSR-4
- - Updated PHPUnit to 8.5 / 9.4
- - Updated tests
- - Added missing PHPDoc blocks
- - Added return type hints
- - Moved from Travis to GitHub actions
- - Set `strict_types=1`
-
-### 0.5.0
- - Fixed the slice notation (e.g. [0:2:5] etc.). **Breaks code relying on the broken implementation**
-
-### 0.3.0
- - Added JSONPathToken class as value object
- - Lexer clean up and refactor
- - Updated the lexing and filtering of the recursive token ("..") to allow for a combination of recursion
- and filters, e.g. $..[?(@.type == 'suburb')].name
-
-### 0.2.1 - 0.2.5
- - Various bug fixes and clean up
-
-### 0.2.0
- - Added a heap of array access features for more creative iterating and chaining possibilities
-
-### 0.1.x
- - Init
diff --git a/README.md b/README.md
index 9ea8516..fec802e 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,6 @@
-# JSONPath for PHP 7.1+
+# JSONPath for PHP 5.4 - 7.0
-[](https://github.com/SoftCreatR/JSONPath/actions?query=workflow%3ATest)
-[](https://packagist.org/packages/softcreatr/jsonpath)
-[](./LICENSE)
-[](https://codecov.io/gh/SoftCreatR/JSONPath)
-[](https://codeclimate.com/github/SoftCreatR/JSONPath)
+[](https://github.com/SoftCreatR/JSONPath/blob/oldphp/.github/workflows/Test.yml) [](./LICENSE)
This is a [JSONPath](http://goessner.net/articles/JsonPath/) implementation for PHP based on Stefan Goessner's JSONPath script.
@@ -16,23 +12,15 @@ This project aims to be a clean and simple implementation with the following goa
- Expressions are parsed into tokens using code inspired by the Doctrine Lexer. The tokens are cached internally to avoid re-parsing the expressions.
- There is no `eval()` in use
- Any combination of objects/arrays/ArrayAccess-objects can be used as the data input which is great if you're de-serializing JSON in to objects or if you want to process your own data structures.
+
+🔻 **Please note, that this branch (based on JSONPath 0.7.2) is protected. There are no intentions to make any updates here. Please consider upgrading to PHP 7.1 or newer.**
## Installation
-**PHP 7.1+**
```bash
-composer require softcreatr/jsonpath
+composer require softcreatr/jsonpath:"^0.5 || ^0.7"
```
-**PHP < 7.1**
-
-Support for PHP < 7.1 has been dropped. However, legacy branches exist for PHP 5.6 and 7.0 and can be composer-installed as follows:
-
-* PHP 7.0: `"softcreatr/jsonpath": "dev-php-70"`
-* PHP 5.6: `"softcreatr/jsonpath": "dev-php-56"`
-
-🔻 Please note, that these legacy branches (based on JSONPath 0.6.2) are protected. There are no intentions to make any updates here. Please consider upgrading to PHP 7.1 or newer.
-
## JSONPath Examples
JSONPath | Result
@@ -69,6 +57,8 @@ Symbol | Description
## PHP Usage
+#### Using arrays
+
```php
use Flow\JSONPath\JSONPath;
@@ -79,11 +69,37 @@ $data = ['people' => [
['name' => 'Maximilian'],
]];
-print_r((new JSONPath($data))->find('$.people.*.name'), true);
-// $result[0] === 'Sascha'
-// $result[1] === 'Bianca'
-// $result[2] === 'Alexander'
-// $result[3] === 'Maximilian'
+print_r((new JSONPath($data))->find('$.people.*.name')->getData());
+
+/*
+Array
+(
+ [0] => Sascha
+ [1] => Bianca
+ [2] => Alexander
+ [3] => Maximilian
+)
+*/
+```
+
+#### Using objects
+
+```php
+use Flow\JSONPath\JSONPath;
+
+$data = json_decode('{"name":"Sascha Greuel","birthdate":"1987-12-16","city":"Gladbeck","country":"Germany"}', false);
+
+print_r((new JSONPath($data))->find('$')->getData()[0]);
+
+/*
+stdClass Object
+(
+ [name] => Sascha Greuel
+ [birthdate] => 1987-12-16
+ [city] => Gladbeck
+ [country] => Germany
+)
+*/
```
More examples can be found in the [Wiki](https://github.com/SoftCreatR/JSONPath/wiki/Queries)
@@ -102,7 +118,7 @@ not very predictable as:
```php
use Flow\JSONPath\JSONPath;
-$myObject = json_decode('{"name":"Sascha Greuel","birthdate":"1987-12-16","city":"Gladbeck","country":"Germany"}', false);
+$myObject = (new Foo())->get('bar');
$jsonPath = new JSONPath($myObject, JSONPath::ALLOW_MAGIC);
```
@@ -137,39 +153,6 @@ So here are the types of query expressions that are supported:
Other / Similar implementations can be found in the [Wiki](https://github.com/SoftCreatR/JSONPath/wiki/Other-Implementations).
-## Changelog
-
-A list of changes can be found in the [CHANGELOG.md](CHANGELOG.md) file.
-
## License
[MIT](LICENSE)
-
-## Contributors ✨
-
-
-
diff --git a/composer.json b/composer.json
index 446fd65..3d6449f 100644
--- a/composer.json
+++ b/composer.json
@@ -1,7 +1,7 @@
{
"name": "softcreatr/jsonpath",
"description": "JSONPath implementation for parsing, searching and flattening arrays",
- "version": "0.7.2",
+ "version": "0.5.1",
"license": "MIT",
"authors": [
{
@@ -18,17 +18,17 @@
}
],
"require": {
- "php": ">=7.1",
+ "php": ">=5.4,<7.1",
"ext-json": "*"
},
"replace": {
"flow/jsonpath": "*"
},
"conflict": {
- "phpunit/phpunit": "<7.0 || >= 10.0"
+ "phpunit/phpunit": "<4.0,>=7.0"
},
"require-dev": {
- "phpunit/phpunit": ">=7.0",
+ "phpunit/phpunit": "^4.0 || ^5.7 || ^6.5",
"roave/security-advisories": "dev-master",
"squizlabs/php_codesniffer": "^3.5"
},
@@ -42,6 +42,9 @@
}
},
"autoload-dev": {
+ "files": [
+ "tests/bootstrap.php"
+ ],
"psr-4": {
"Flow\\JSONPath\\Test\\": "tests/"
}
diff --git a/phpcs.xml b/phpcs.xml
index 63d7bf8..3f6eaf5 100644
--- a/phpcs.xml
+++ b/phpcs.xml
@@ -1,20 +1,17 @@
-
+
-
-
src
tests
-
-
+
+
+
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 3e39278..aa4b9f3 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,17 +1,14 @@
-
+
- ./tests
+ tests
+
- ./src/
+ src
diff --git a/src/AccessHelper.php b/src/AccessHelper.php
index 2aeaa75..51c81ad 100644
--- a/src/AccessHelper.php
+++ b/src/AccessHelper.php
@@ -6,30 +6,18 @@
* @license https://github.com/SoftCreatR/JSONPath/blob/main/LICENSE MIT License
*/
-declare(strict_types=1);
-
namespace Flow\JSONPath;
use ArrayAccess;
-use function abs;
-use function array_key_exists;
-use function array_keys;
-use function array_slice;
-use function array_values;
-use function get_object_vars;
-use function is_array;
-use function is_int;
-use function is_object;
-use function method_exists;
-use function property_exists;
-
class AccessHelper
{
/**
* @param array|ArrayAccess $collection
+ *
+ * @return array
*/
- public static function collectionKeys($collection): array
+ public static function collectionKeys($collection)
{
if (is_object($collection)) {
return array_keys(get_object_vars($collection));
@@ -40,16 +28,22 @@ public static function collectionKeys($collection): array
/**
* @param array|ArrayAccess $collection
+ *
+ * @return bool
*/
- public static function isCollectionType($collection): bool
+ public static function isCollectionType($collection)
{
return is_array($collection) || is_object($collection);
}
/**
* @param array|ArrayAccess $collection
+ * @param mixed $key
+ * @param bool $magicIsAllowed
+ *
+ * @return bool
*/
- public static function keyExists($collection, $key, bool $magicIsAllowed = false): bool
+ public static function keyExists($collection, $key, $magicIsAllowed = false)
{
if ($magicIsAllowed && is_object($collection) && method_exists($collection, '__get')) {
return true;
@@ -71,12 +65,16 @@ public static function keyExists($collection, $key, bool $magicIsAllowed = false
}
/**
- * @todo Optimize conditions
- *
* @param array|ArrayAccess $collection
+ * @param mixed $key
+ * @param bool $magicIsAllowed
+ *
+ * @return mixed|null
* @noinspection NotOptimalIfConditionsInspection
+ *
+ * @todo Optimize conditions
*/
- public static function getValue($collection, $key, bool $magicIsAllowed = false)
+ public static function getValue($collection, $key, $magicIsAllowed = false)
{
$return = null;
@@ -108,6 +106,7 @@ public static function getValue($collection, $key, bool $magicIsAllowed = false)
* Written this way to handle instances ArrayAccess or Traversable objects
*
* @param array|ArrayAccess $collection
+ * @param mixed $key
*
* @return mixed|null
*/
@@ -141,6 +140,10 @@ private static function getValueByIndex($collection, $key)
/**
* @param array|ArrayAccess $collection
+ * @param mixed $key
+ * @param mixed $value
+ *
+ * @return mixed
*/
public static function setValue(&$collection, $key, $value)
{
@@ -153,8 +156,9 @@ public static function setValue(&$collection, $key, $value)
/**
* @param array|ArrayAccess $collection
+ * @param mixed $key
*/
- public static function unsetValue(&$collection, $key): void
+ public static function unsetValue(&$collection, $key)
{
if (is_object($collection) && !$collection instanceof ArrayAccess) {
unset($collection->$key);
@@ -167,8 +171,10 @@ public static function unsetValue(&$collection, $key): void
* @param array|ArrayAccess $collection
*
* @throws JSONPathException
+ *
+ * @return array|ArrayAccess
*/
- public static function arrayValues($collection): array
+ public static function arrayValues($collection)
{
if (is_array($collection)) {
return array_values($collection);
diff --git a/src/Filters/AbstractFilter.php b/src/Filters/AbstractFilter.php
index 42a7698..0eb949b 100644
--- a/src/Filters/AbstractFilter.php
+++ b/src/Filters/AbstractFilter.php
@@ -6,12 +6,11 @@
* @license https://github.com/SoftCreatR/JSONPath/blob/main/LICENSE MIT License
*/
-declare(strict_types=1);
-
namespace Flow\JSONPath\Filters;
use ArrayAccess;
-use Flow\JSONPath\{JSONPath, JSONPathToken};
+use Flow\JSONPath\JSONPath;
+use Flow\JSONPath\JSONPathToken;
abstract class AbstractFilter
{
@@ -26,6 +25,7 @@ abstract class AbstractFilter
protected $magicIsAllowed = false;
/**
+ * @param JSONPathToken $token
* @param int|bool $options
*/
public function __construct(JSONPathToken $token, $options = false)
@@ -37,5 +37,5 @@ public function __construct(JSONPathToken $token, $options = false)
/**
* @param array|ArrayAccess $collection
*/
- abstract public function filter($collection): array;
+ abstract public function filter($collection);
}
diff --git a/src/Filters/IndexFilter.php b/src/Filters/IndexFilter.php
index 15599ff..4bb9562 100644
--- a/src/Filters/IndexFilter.php
+++ b/src/Filters/IndexFilter.php
@@ -6,11 +6,10 @@
* @license https://github.com/SoftCreatR/JSONPath/blob/main/LICENSE MIT License
*/
-declare(strict_types=1);
-
namespace Flow\JSONPath\Filters;
-use Flow\JSONPath\{AccessHelper, JSONPathException};
+use Flow\JSONPath\AccessHelper;
+use Flow\JSONPath\JSONPathException;
class IndexFilter extends AbstractFilter
{
@@ -19,7 +18,7 @@ class IndexFilter extends AbstractFilter
*
* @throws JSONPathException
*/
- public function filter($collection): array
+ public function filter($collection)
{
if (is_array($this->token->value)) {
$result = [];
diff --git a/src/Filters/IndexesFilter.php b/src/Filters/IndexesFilter.php
index 6cc3e59..bb27392 100644
--- a/src/Filters/IndexesFilter.php
+++ b/src/Filters/IndexesFilter.php
@@ -6,8 +6,6 @@
* @license https://github.com/SoftCreatR/JSONPath/blob/main/LICENSE MIT License
*/
-declare(strict_types=1);
-
namespace Flow\JSONPath\Filters;
use Flow\JSONPath\AccessHelper;
@@ -17,7 +15,7 @@ class IndexesFilter extends AbstractFilter
/**
* @inheritDoc
*/
- public function filter($collection): array
+ public function filter($collection)
{
$return = [];
diff --git a/src/Filters/QueryMatchFilter.php b/src/Filters/QueryMatchFilter.php
index b1f69c4..89e3438 100644
--- a/src/Filters/QueryMatchFilter.php
+++ b/src/Filters/QueryMatchFilter.php
@@ -6,26 +6,14 @@
* @license https://github.com/SoftCreatR/JSONPath/blob/main/LICENSE MIT License
*/
-declare(strict_types=1);
-
namespace Flow\JSONPath\Filters;
use Flow\JSONPath\AccessHelper;
use RuntimeException;
-use function explode;
-use function in_array;
-use function is_array;
-use function is_string;
-use function preg_match;
-use function preg_replace;
-use function strpos;
-use function strtolower;
-use function substr;
-
class QueryMatchFilter extends AbstractFilter
{
- protected const MATCH_QUERY_OPERATORS = '
+ const MATCH_QUERY_OPERATORS = '
@(\.(?[^\s<>!=]+)|\[["\']?(?.*?)["\']?\])
(\s*(?==|=~|=|<>|!==|!=|>=|<=|>|<|in|!in|nin)\s*(?.+))?
';
@@ -33,7 +21,7 @@ class QueryMatchFilter extends AbstractFilter
/**
* @inheritDoc
*/
- public function filter($collection): array
+ public function filter($collection)
{
preg_match('/^' . static::MATCH_QUERY_OPERATORS . '$/x', $this->token->value, $matches);
@@ -47,8 +35,8 @@ public function filter($collection): array
throw new RuntimeException('Malformed filter query: key was not set');
}
- $operator = $matches['operator'] ?? null;
- $comparisonValue = $matches['comparisonValue'] ?? null;
+ $operator = isset($matches['operator']) ? $matches['operator'] : null;
+ $comparisonValue = isset($matches['comparisonValue']) ? $matches['comparisonValue'] : null;
if (is_string($comparisonValue)) {
if (strpos($comparisonValue, "[") === 0 && substr($comparisonValue, -1) === "]") {
diff --git a/src/Filters/QueryResultFilter.php b/src/Filters/QueryResultFilter.php
index 418de96..2026acf 100644
--- a/src/Filters/QueryResultFilter.php
+++ b/src/Filters/QueryResultFilter.php
@@ -6,14 +6,10 @@
* @license https://github.com/SoftCreatR/JSONPath/blob/main/LICENSE MIT License
*/
-declare(strict_types=1);
-
namespace Flow\JSONPath\Filters;
-use Flow\JSONPath\{AccessHelper, JSONPathException};
-
-use function count;
-use function preg_match;
+use Flow\JSONPath\AccessHelper;
+use Flow\JSONPath\JSONPathException;
class QueryResultFilter extends AbstractFilter
{
@@ -22,7 +18,7 @@ class QueryResultFilter extends AbstractFilter
*
* @throws JSONPathException
*/
- public function filter($collection): array
+ public function filter($collection)
{
preg_match('/@\.(?\w+)\s*(?[-+*\/])\s*(?\d+)/', $this->token->value, $matches);
diff --git a/src/Filters/RecursiveFilter.php b/src/Filters/RecursiveFilter.php
index 800da0e..9930f47 100644
--- a/src/Filters/RecursiveFilter.php
+++ b/src/Filters/RecursiveFilter.php
@@ -6,12 +6,11 @@
* @license https://github.com/SoftCreatR/JSONPath/blob/main/LICENSE MIT License
*/
-declare(strict_types=1);
-
namespace Flow\JSONPath\Filters;
-use Flow\JSONPath\{AccessHelper, JSONPathException};
use ArrayAccess;
+use Flow\JSONPath\AccessHelper;
+use Flow\JSONPath\JSONPathException;
class RecursiveFilter extends AbstractFilter
{
@@ -20,7 +19,7 @@ class RecursiveFilter extends AbstractFilter
*
* @throws JSONPathException
*/
- public function filter($collection): array
+ public function filter($collection)
{
$result = [];
@@ -30,11 +29,12 @@ public function filter($collection): array
}
/**
+ * @param array $result
* @param array|ArrayAccess $data
*
* @throws JSONPathException
*/
- private function recurse(array &$result, $data): void
+ private function recurse(array &$result, $data)
{
$result[] = $data;
diff --git a/src/Filters/SliceFilter.php b/src/Filters/SliceFilter.php
index 0e05a82..e70c1f0 100644
--- a/src/Filters/SliceFilter.php
+++ b/src/Filters/SliceFilter.php
@@ -6,20 +6,16 @@
* @license https://github.com/SoftCreatR/JSONPath/blob/main/LICENSE MIT License
*/
-declare(strict_types=1);
-
namespace Flow\JSONPath\Filters;
use Flow\JSONPath\AccessHelper;
-use function count;
-
class SliceFilter extends AbstractFilter
{
/**
* @inheritDoc
*/
- public function filter($collection): array
+ public function filter($collection)
{
$length = count($collection);
$start = $this->token->value['start'];
diff --git a/src/JSONPath.php b/src/JSONPath.php
index f57f102..4b5ead9 100644
--- a/src/JSONPath.php
+++ b/src/JSONPath.php
@@ -6,8 +6,6 @@
* @license https://github.com/SoftCreatR/JSONPath/blob/main/LICENSE MIT License
*/
-declare(strict_types=1);
-
namespace Flow\JSONPath;
use ArrayAccess;
@@ -15,20 +13,9 @@
use Iterator;
use JsonSerializable;
-use function array_merge;
-use function count;
-use function crc32;
-use function current;
-use function end;
-use function key;
-use function next;
-use function reset;
-
-use const E_USER_DEPRECATED;
-
class JSONPath implements ArrayAccess, Iterator, JsonSerializable, Countable
{
- public const ALLOW_MAGIC = true;
+ const ALLOW_MAGIC = true;
/**
* @var array
@@ -47,8 +34,9 @@ class JSONPath implements ArrayAccess, Iterator, JsonSerializable, Countable
/**
* @param array|ArrayAccess $data
+ * @param bool $options
*/
- final public function __construct($data = [], bool $options = false)
+ final public function __construct($data = [], $options = false)
{
$this->data = $data;
$this->options = $options;
@@ -57,11 +45,13 @@ final public function __construct($data = [], bool $options = false)
/**
* Evaluate an expression
*
+ * @param string $expression
+ *
* @throws JSONPathException
*
* @return static
*/
- public function find(string $expression): self
+ public function find($expression)
{
$tokens = $this->parseTokens($expression);
$collectionData = [$this->data];
@@ -78,7 +68,7 @@ public function find(string $expression): self
}
if (!empty($filteredDataList)) {
- $collectionData = array_merge(...$filteredDataList);
+ $collectionData = call_user_func_array('array_merge', $filteredDataList);
} else {
$collectionData = [];
}
@@ -98,7 +88,7 @@ public function first()
return null;
}
- $value = $this->data[$keys[0]] ?? null;
+ $value = isset($this->data[$keys[0]]) ? $this->data[$keys[0]] : null;
return AccessHelper::isCollectionType($value) ? new static($value, $this->options) : $value;
}
@@ -154,9 +144,13 @@ public function lastKey()
}
/**
+ * @param $expression
+ *
* @throws JSONPathException
+ *
+ * @return array|mixed
*/
- public function parseTokens(string $expression): array
+ public function parseTokens($expression)
{
$cacheKey = crc32($expression);
@@ -172,7 +166,7 @@ public function parseTokens(string $expression): array
return $tokens;
}
- public function getData(): array
+ public function getData()
{
return $this->data;
}
@@ -180,7 +174,7 @@ public function getData(): array
/**
* @deprecated Please use getData() instead
*/
- public function data(): array
+ public function data()
{
trigger_error(
'Calling JSONPath::data() is deprecated, please use JSONPath::getData() instead.',
@@ -191,6 +185,8 @@ public function data(): array
}
/**
+ * @param $key
+ *
* @return mixed|null
* @noinspection MagicMethodsValidityInspection
*/
@@ -202,7 +198,7 @@ public function __get($key)
/**
* @inheritDoc
*/
- public function offsetExists($offset): bool
+ public function offsetExists($offset)
{
return AccessHelper::keyExists($this->data, $offset);
}
@@ -222,7 +218,7 @@ public function offsetGet($offset)
/**
* @inheritDoc
*/
- public function offsetSet($offset, $value): void
+ public function offsetSet($offset, $value)
{
if ($offset === null) {
$this->data[] = $value;
@@ -234,7 +230,7 @@ public function offsetSet($offset, $value): void
/**
* @inheritDoc
*/
- public function offsetUnset($offset): void
+ public function offsetUnset($offset)
{
AccessHelper::unsetValue($this->data, $offset);
}
@@ -242,7 +238,7 @@ public function offsetUnset($offset): void
/**
* @inheritDoc
*/
- public function jsonSerialize(): array
+ public function jsonSerialize()
{
return $this->getData();
}
@@ -260,7 +256,7 @@ public function current()
/**
* @inheritDoc
*/
- public function next(): void
+ public function next()
{
next($this->data);
}
@@ -276,7 +272,7 @@ public function key()
/**
* @inheritDoc
*/
- public function valid(): bool
+ public function valid()
{
return key($this->data) !== null;
}
@@ -284,7 +280,7 @@ public function valid(): bool
/**
* @inheritDoc
*/
- public function rewind(): void
+ public function rewind()
{
reset($this->data);
}
@@ -292,7 +288,7 @@ public function rewind(): void
/**
* @inheritDoc
*/
- public function count(): int
+ public function count()
{
return count($this->data);
}
diff --git a/src/JSONPathException.php b/src/JSONPathException.php
index 3a5cb33..834a906 100644
--- a/src/JSONPathException.php
+++ b/src/JSONPathException.php
@@ -6,8 +6,6 @@
* @license https://github.com/SoftCreatR/JSONPath/blob/main/LICENSE MIT License
*/
-declare(strict_types=1);
-
namespace Flow\JSONPath;
use Exception;
diff --git a/src/JSONPathLexer.php b/src/JSONPathLexer.php
index 7ba52b6..a48686a 100644
--- a/src/JSONPathLexer.php
+++ b/src/JSONPathLexer.php
@@ -6,30 +6,21 @@
* @license https://github.com/SoftCreatR/JSONPath/blob/main/LICENSE MIT License
*/
-declare(strict_types=1);
-
namespace Flow\JSONPath;
-use function explode;
-use function in_array;
-use function preg_match;
-use function strlen;
-use function substr;
-use function trim;
-
class JSONPathLexer
{
/*
* Match within bracket groups
* Matches are whitespace insensitive
*/
- public const MATCH_INDEX = '(?!\-)[\-\w]+ | \*'; // Eg. foo or 40f35757-2563-4790-b0b1-caa904be455f
- public const MATCH_INDEXES = '\s* -?\d+ [-?\d,\s]+'; // Eg. 0,1,2
- public const MATCH_SLICE = '[-\d:]+ | :'; // Eg. [0:2:1]
- public const MATCH_QUERY_RESULT = '\s* \( .+? \) \s*'; // Eg. ?(@.length - 1)
- public const MATCH_QUERY_MATCH = '\s* \?\(.+?\) \s*'; // Eg. ?(@.foo = "bar")
- public const MATCH_INDEX_IN_SINGLE_QUOTES = '\s* \' (.+?)? \' \s*'; // Eg. 'bar'
- public const MATCH_INDEX_IN_DOUBLE_QUOTES = '\s* " (.+?)? " \s*'; // Eg. "bar"
+ const MATCH_INDEX = '(?!\-)[\-\w]+ | \*'; // Eg. foo or 40f35757-2563-4790-b0b1-caa904be455f
+ const MATCH_INDEXES = '\s* -?\d+ [-?\d,\s]+'; // Eg. 0,1,2
+ const MATCH_SLICE = '[-\d:]+ | :'; // Eg. [0:2:1]
+ const MATCH_QUERY_RESULT = '\s* \( .+? \) \s*'; // Eg. ?(@.length - 1)
+ const MATCH_QUERY_MATCH = '\s* \?\(.+?\) \s*'; // Eg. ?(@.foo = "bar")
+ const MATCH_INDEX_IN_SINGLE_QUOTES = '\s* \' (.+?)? \' \s*'; // Eg. 'bar'
+ const MATCH_INDEX_IN_DOUBLE_QUOTES = '\s* " (.+?)? " \s*'; // Eg. "bar"
/**
* The expression being lexed.
@@ -45,7 +36,10 @@ class JSONPathLexer
*/
protected $expressionLength = 0;
- public function __construct(string $expression)
+ /**
+ * @param string $expression
+ */
+ public function __construct($expression)
{
$expression = trim($expression);
$len = strlen($expression);
@@ -68,8 +62,10 @@ public function __construct(string $expression)
/**
* @throws JSONPathException
+ *
+ * @return array
*/
- public function parseExpressionTokens(): array
+ public function parseExpressionTokens()
{
$dotIndexDepth = 0;
$squareBracketDepth = 0;
@@ -143,28 +139,45 @@ public function parseExpressionTokens(): array
return $tokens;
}
- protected function lookAhead(int $pos, int $forward = 1): ?string
+ /**
+ * @param int $pos
+ * @param int $forward
+ *
+ * @return string|null
+ */
+ protected function lookAhead($pos, $forward = 1)
{
- return $this->expression[$pos + $forward] ?? null;
+ return isset($this->expression[$pos + $forward]) ? $this->expression[$pos + $forward] : null;
}
- protected function atEnd(int $pos): bool
+ /**
+ * @param int $pos
+ *
+ * @return bool
+ */
+ protected function atEnd($pos)
{
return $pos === $this->expressionLength;
}
/**
* @throws JSONPathException
+ *
+ * @return array
*/
- public function parseExpression(): array
+ public function parseExpression()
{
return $this->parseExpressionTokens();
}
/**
+ * @param string $value
+ *
* @throws JSONPathException
+ *
+ * @return JSONPathToken
*/
- protected function createToken(string $value): JSONPathToken
+ protected function createToken($value)
{
// The IDE doesn't like, what we do with $value, so let's
// move it to a separate variable, to get rid of any IDE warnings
diff --git a/src/JSONPathToken.php b/src/JSONPathToken.php
index b63056b..31a128c 100644
--- a/src/JSONPathToken.php
+++ b/src/JSONPathToken.php
@@ -6,37 +6,37 @@
* @license https://github.com/SoftCreatR/JSONPath/blob/main/LICENSE MIT License
*/
-declare(strict_types=1);
-
namespace Flow\JSONPath;
-use function class_exists;
-use function in_array;
-use function ucfirst;
-
class JSONPathToken
{
/*
* Tokens
*/
- public const T_INDEX = 'index';
- public const T_RECURSIVE = 'recursive';
- public const T_QUERY_RESULT = 'queryResult';
- public const T_QUERY_MATCH = 'queryMatch';
- public const T_SLICE = 'slice';
- public const T_INDEXES = 'indexes';
+ const T_INDEX = 'index';
+ const T_RECURSIVE = 'recursive';
+ const T_QUERY_RESULT = 'queryResult';
+ const T_QUERY_MATCH = 'queryMatch';
+ const T_SLICE = 'slice';
+ const T_INDEXES = 'indexes';
/**
* @var string
*/
public $type;
+ /**
+ * @var mixed
+ */
public $value;
/**
+ * @param string $type
+ * @param mixed $value
+ *
* @throws JSONPathException
*/
- public function __construct(string $type, $value)
+ public function __construct($type, $value)
{
$this->validateType($type);
@@ -45,16 +45,18 @@ public function __construct(string $type, $value)
}
/**
+ * @param string $type
+ *
* @throws JSONPathException
*/
- public function validateType(string $type): void
+ public function validateType($type)
{
if (!in_array($type, static::getTypes(), true)) {
throw new JSONPathException('Invalid token: ' . $type);
}
}
- public static function getTypes(): array
+ public static function getTypes()
{
return [
static::T_INDEX,
@@ -67,9 +69,13 @@ public static function getTypes(): array
}
/**
+ * @param bool $options
+ *
* @throws JSONPathException
+ *
+ * @return mixed
*/
- public function buildFilter(bool $options)
+ public function buildFilter($options)
{
$filterClass = 'Flow\\JSONPath\\Filters\\' . ucfirst($this->type) . 'Filter';
diff --git a/tests/JSONPathArrayAccessTest.php b/tests/JSONPathArrayAccessTest.php
index 599ba6b..7877f89 100644
--- a/tests/JSONPathArrayAccessTest.php
+++ b/tests/JSONPathArrayAccessTest.php
@@ -6,17 +6,11 @@
* @license https://github.com/SoftCreatR/JSONPath/blob/main/LICENSE MIT License
*/
-declare(strict_types=1);
-
namespace Flow\JSONPath\Test;
use Exception;
use Flow\JSONPath\JSONPath;
use Flow\JSONPath\Test\Traits\TestDataTrait;
-use PHPUnit\Framework\TestCase;
-
-use function is_array;
-use function random_int;
class JSONPathArrayAccessTest extends TestCase
{
@@ -25,7 +19,7 @@ class JSONPathArrayAccessTest extends TestCase
/**
* @throws Exception
*/
- public function testChaining(): void
+ public function testChaining()
{
$jsonPath = (new JSONPath($this->getData('conferences')));
@@ -53,7 +47,7 @@ public function testChaining(): void
/**
* @throws Exception
*/
- public function testIterating(): void
+ public function testIterating()
{
$data = $this->getData('conferences');
@@ -77,9 +71,9 @@ public function testIterating(): void
/**
* @throws Exception
*/
- public function testDifferentStylesOfAccess(): void
+ public function testDifferentStylesOfAccess()
{
- $data = (new JSONPath($this->getData('conferences', random_int(0, 1))));
+ $data = (new JSONPath($this->getData('conferences', mt_rand(0, 1))));
self::assertArrayHasKey('conferences', $data);
diff --git a/tests/JSONPathDashedIndexTest.php b/tests/JSONPathDashedIndexTest.php
index dd89dc7..58cffa9 100644
--- a/tests/JSONPathDashedIndexTest.php
+++ b/tests/JSONPathDashedIndexTest.php
@@ -6,19 +6,17 @@
* @license https://github.com/SoftCreatR/JSONPath/blob/main/LICENSE MIT License
*/
-declare(strict_types=1);
-
namespace Flow\JSONPath\Test;
-use Flow\JSONPath\{JSONPath, JSONPathException};
-use PHPUnit\Framework\TestCase;
+use Flow\JSONPath\JSONPath;
+use Flow\JSONPath\JSONPathException;
class JSONPathDashedIndexTest extends TestCase
{
/**
* @return array[]
*/
- public function indexDataProvider(): array
+ public function indexDataProvider()
{
return [
[
@@ -37,9 +35,13 @@ public function indexDataProvider(): array
/**
* @dataProvider indexDataProvider
*
+ * @param string $path
+ * @param array $data
+ * @param array $expected
+ *
* @throws JSONPathException
*/
- public function testSlice(string $path, array $data, array $expected): void
+ public function testSlice($path, array $data, array $expected)
{
$results = (new JSONPath($data))
->find($path);
diff --git a/tests/JSONPathLexerTest.php b/tests/JSONPathLexerTest.php
index c9478db..cb72173 100644
--- a/tests/JSONPathLexerTest.php
+++ b/tests/JSONPathLexerTest.php
@@ -6,19 +6,19 @@
* @license https://github.com/SoftCreatR/JSONPath/blob/main/LICENSE MIT License
*/
-declare(strict_types=1);
-
namespace Flow\JSONPath\Test;
-use Flow\JSONPath\{JSONPathException, JSONPathLexer, JSONPathToken};
-use PHPUnit\Framework\TestCase;
+use Flow\JSONPath\JSONPathException;
+use Flow\JSONPath\JSONPathLexer;
+use Flow\JSONPath\JSONPathToken;
+use PHPUnit\Framework\Exception as PHPUnit_Framework_Exception;
class JSONPathLexerTest extends TestCase
{
/**
* @throws JSONPathException
*/
- public function testIndexWildcard(): void
+ public function testIndexWildcard()
{
$tokens = (new JSONPathLexer('.*'))
->parseExpression();
@@ -30,7 +30,7 @@ public function testIndexWildcard(): void
/**
* @throws JSONPathException
*/
- public function testIndexSimple(): void
+ public function testIndexSimple()
{
$tokens = (new JSONPathLexer('.foo'))
->parseExpression();
@@ -42,7 +42,7 @@ public function testIndexSimple(): void
/**
* @throws JSONPathException
*/
- public function testIndexRecursive(): void
+ public function testIndexRecursive()
{
$tokens = (new JSONPathLexer('..teams.*'))
->parseExpression();
@@ -59,7 +59,7 @@ public function testIndexRecursive(): void
/**
* @throws JSONPathException
*/
- public function testIndexComplex(): void
+ public function testIndexComplex()
{
$tokens = (new JSONPathLexer('["\'b.^*_"]'))
->parseExpression();
@@ -70,10 +70,11 @@ public function testIndexComplex(): void
/**
* @throws JSONPathException
+ * @throws PHPUnit_Framework_Exception
*/
- public function testIndexBadlyFormed(): void
+ public function testIndexBadlyFormed()
{
- $this->expectException(JSONPathException::class);
+ $this->expectException('Flow\JSONPath\JSONPathException');
$this->expectExceptionMessage('Unable to parse token hello* in expression: .hello*');
(new JSONPathLexer('.hello*'))
@@ -83,7 +84,7 @@ public function testIndexBadlyFormed(): void
/**
* @throws JSONPathException
*/
- public function testIndexInteger(): void
+ public function testIndexInteger()
{
$tokens = (new JSONPathLexer('[0]'))
->parseExpression();
@@ -95,7 +96,7 @@ public function testIndexInteger(): void
/**
* @throws JSONPathException
*/
- public function testIndexIntegerAfterDotNotation(): void
+ public function testIndexIntegerAfterDotNotation()
{
$tokens = (new JSONPathLexer('.books[0]'))
->parseExpression();
@@ -109,7 +110,7 @@ public function testIndexIntegerAfterDotNotation(): void
/**
* @throws JSONPathException
*/
- public function testIndexWord(): void
+ public function testIndexWord()
{
$tokens = (new JSONPathLexer('["foo$-/\'"]'))
->parseExpression();
@@ -121,7 +122,7 @@ public function testIndexWord(): void
/**
* @throws JSONPathException
*/
- public function testIndexWordWithWhitespace(): void
+ public function testIndexWordWithWhitespace()
{
$tokens = (new JSONPathLexer('[ "foo$-/\'" ]'))
->parseExpression();
@@ -133,7 +134,7 @@ public function testIndexWordWithWhitespace(): void
/**
* @throws JSONPathException
*/
- public function testSliceSimple(): void
+ public function testSliceSimple()
{
$tokens = (new JSONPathLexer('[0:1:2]'))
->parseExpression();
@@ -145,7 +146,7 @@ public function testSliceSimple(): void
/**
* @throws JSONPathException
*/
- public function testIndexNegativeIndex(): void
+ public function testIndexNegativeIndex()
{
$tokens = (new JSONPathLexer('[-1]'))
->parseExpression();
@@ -157,7 +158,7 @@ public function testIndexNegativeIndex(): void
/**
* @throws JSONPathException
*/
- public function testSliceAllNull(): void
+ public function testSliceAllNull()
{
$tokens = (new JSONPathLexer('[:]'))
->parseExpression();
@@ -169,7 +170,7 @@ public function testSliceAllNull(): void
/**
* @throws JSONPathException
*/
- public function testQueryResultSimple(): void
+ public function testQueryResultSimple()
{
$tokens = (new JSONPathLexer('[(@.foo + 2)]'))
->parseExpression();
@@ -181,7 +182,7 @@ public function testQueryResultSimple(): void
/**
* @throws JSONPathException
*/
- public function testQueryMatchSimple(): void
+ public function testQueryMatchSimple()
{
$tokens = (new JSONPathLexer('[?(@.foo < \'bar\')]'))
->parseExpression();
@@ -193,7 +194,7 @@ public function testQueryMatchSimple(): void
/**
* @throws JSONPathException
*/
- public function testQueryMatchNotEqualTO(): void
+ public function testQueryMatchNotEqualTO()
{
$tokens = (new JSONPathLexer('[?(@.foo != \'bar\')]'))
->parseExpression();
@@ -205,7 +206,7 @@ public function testQueryMatchNotEqualTO(): void
/**
* @throws JSONPathException
*/
- public function testQueryMatchBrackets(): void
+ public function testQueryMatchBrackets()
{
$tokens = (new JSONPathLexer("[?(@['@language']='en')]"))
->parseExpression();
@@ -217,7 +218,7 @@ public function testQueryMatchBrackets(): void
/**
* @throws JSONPathException
*/
- public function testRecursiveSimple(): void
+ public function testRecursiveSimple()
{
$tokens = (new JSONPathLexer('..foo'))
->parseExpression();
@@ -231,7 +232,7 @@ public function testRecursiveSimple(): void
/**
* @throws JSONPathException
*/
- public function testRecursiveWildcard(): void
+ public function testRecursiveWildcard()
{
$tokens = (new JSONPathLexer('..*'))
->parseExpression();
@@ -244,10 +245,11 @@ public function testRecursiveWildcard(): void
/**
* @throws JSONPathException
+ * @throws PHPUnit_Framework_Exception
*/
- public function testRecursiveBadlyFormed(): void
+ public function testRecursiveBadlyFormed()
{
- $this->expectException(JSONPathException::class);
+ $this->expectException('Flow\JSONPath\JSONPathException');
$this->expectExceptionMessage('Unable to parse token ba^r in expression: ..ba^r');
(new JSONPathLexer('..ba^r'))
@@ -257,7 +259,7 @@ public function testRecursiveBadlyFormed(): void
/**
* @throws JSONPathException
*/
- public function testIndexesSimple(): void
+ public function testIndexesSimple()
{
$tokens = (new JSONPathLexer('[1,2,3]'))
->parseExpression();
@@ -269,7 +271,7 @@ public function testIndexesSimple(): void
/**
* @throws JSONPathException
*/
- public function testIndexesWhitespace(): void
+ public function testIndexesWhitespace()
{
$tokens = (new JSONPathLexer('[ 1,2 , 3]'))
->parseExpression();
diff --git a/tests/JSONPathSliceAccessTest.php b/tests/JSONPathSliceAccessTest.php
index d5a7203..017a6cd 100644
--- a/tests/JSONPathSliceAccessTest.php
+++ b/tests/JSONPathSliceAccessTest.php
@@ -6,16 +6,14 @@
* @license https://github.com/SoftCreatR/JSONPath/blob/main/LICENSE MIT License
*/
-declare(strict_types=1);
-
namespace Flow\JSONPath\Test;
-use Flow\JSONPath\{JSONPath, JSONPathException};
-use PHPUnit\Framework\TestCase;
+use Flow\JSONPath\JSONPath;
+use Flow\JSONPath\JSONPathException;
class JSONPathSliceAccessTest extends TestCase
{
- public function sliceDataProvider(): array
+ public function sliceDataProvider()
{
return [
[
@@ -79,9 +77,13 @@ public function sliceDataProvider(): array
/**
* @dataProvider sliceDataProvider
*
+ * @param string $path
+ * @param array $data
+ * @param array $expected
+ *
* @throws JSONPathException
*/
- public function testSlice(string $path, array $data, array $expected): void
+ public function testSlice($path, array $data, array $expected)
{
$result = (new JSONPath($data))
->find($path);
diff --git a/tests/JSONPathTest.php b/tests/JSONPathTest.php
index 435337b..1eb5d31 100644
--- a/tests/JSONPathTest.php
+++ b/tests/JSONPathTest.php
@@ -6,17 +6,11 @@
* @license https://github.com/SoftCreatR/JSONPath/blob/main/LICENSE MIT License
*/
-declare(strict_types=1);
-
namespace Flow\JSONPath\Test;
-use Flow\JSONPath\{JSONPath, JSONPathException};
+use Flow\JSONPath\JSONPath;
+use Flow\JSONPath\JSONPathException;
use Flow\JSONPath\Test\Traits\TestDataTrait;
-use PHPUnit\Framework\TestCase;
-
-use function is_object;
-use function json_decode;
-use function json_encode;
class JSONPathTest extends TestCase
{
@@ -27,7 +21,7 @@ class JSONPathTest extends TestCase
*
* @throws JSONPathException
*/
- public function testChildOperators(): void
+ public function testChildOperators()
{
$result = (new JSONPath($this->getData('example')))
->find('$.store.books[0].title');
@@ -38,7 +32,7 @@ public function testChildOperators(): void
/**
* @throws JSONPathException
*/
- public function testIndexesObject(): void
+ public function testIndexesObject()
{
$result = (new JSONPath($this->getData('indexed-object')))
->find('$.store.books[3].title');
@@ -51,7 +45,7 @@ public function testIndexesObject(): void
*
* @throws JSONPathException
*/
- public function testChildOperatorsAlt(): void
+ public function testChildOperatorsAlt()
{
$result = (new JSONPath($this->getData('example')))
->find("$['store']['books'][0]['title']");
@@ -64,7 +58,7 @@ public function testChildOperatorsAlt(): void
*
* @throws JSONPathException
*/
- public function testFilterSliceA(): void
+ public function testFilterSliceA()
{
// Copy all items... similar to a wildcard
$result = (new JSONPath($this->getData('example')))
@@ -82,7 +76,7 @@ public function testFilterSliceA(): void
*
* @throws JSONPathException
*/
- public function testFilterSlicePositiveEndIndexes(): void
+ public function testFilterSlicePositiveEndIndexes()
{
$jsonPath = (new JSONPath(['first', 'second', 'third', 'fourth', 'fifth']));
@@ -125,7 +119,7 @@ public function testFilterSlicePositiveEndIndexes(): void
/**
* @throws JSONPathException
*/
- public function testFilterSliceNegativeStartIndexes(): void
+ public function testFilterSliceNegativeStartIndexes()
{
$result = (new JSONPath(['first', 'second', 'third', 'fourth', 'fifth']))
->find('$[-2:]');
@@ -149,7 +143,7 @@ public function testFilterSliceNegativeStartIndexes(): void
*
* @throws JSONPathException
*/
- public function testFilterSliceNegativeEndIndexes(): void
+ public function testFilterSliceNegativeEndIndexes()
{
$jsonPath = (new JSONPath(['first', 'second', 'third', 'fourth', 'fifth']));
@@ -170,7 +164,7 @@ public function testFilterSliceNegativeEndIndexes(): void
*
* @throws JSONPathException
*/
- public function testFilterSliceNegativeStartAndEndIndexes(): void
+ public function testFilterSliceNegativeStartAndEndIndexes()
{
$jsonPath = (new JSONPath(['first', 'second', 'third', 'fourth', 'fifth']));
@@ -191,7 +185,7 @@ public function testFilterSliceNegativeStartAndEndIndexes(): void
*
* @throws JSONPathException
*/
- public function testFilterSliceNegativeStartAndPositiveEnd(): void
+ public function testFilterSliceNegativeStartAndPositiveEnd()
{
$result = (new JSONPath(['first', 'second', 'third', 'fourth', 'fifth']))
->find('$[-2:2]');
@@ -202,7 +196,7 @@ public function testFilterSliceNegativeStartAndPositiveEnd(): void
/**
* @throws JSONPathException
*/
- public function testFilterSliceStepBy2(): void
+ public function testFilterSliceStepBy2()
{
$result = (new JSONPath(['first', 'second', 'third', 'fourth', 'fifth']))
->find('$[0:4:2]');
@@ -216,7 +210,7 @@ public function testFilterSliceStepBy2(): void
*
* @throws JSONPathException
*/
- public function testFilterLastIndex(): void
+ public function testFilterLastIndex()
{
$result = (new JSONPath(['first', 'second', 'third', 'fourth', 'fifth']))
->find('$[-1]');
@@ -230,7 +224,7 @@ public function testFilterLastIndex(): void
*
* @throws JSONPathException
*/
- public function testFilterSliceG(): void
+ public function testFilterSliceG()
{
// Fetch up to the second index
$result = (new JSONPath(['first', 'second', 'third', 'fourth', 'fifth']))
@@ -246,7 +240,7 @@ public function testFilterSliceG(): void
*
* @throws JSONPathException
*/
- public function testChildQuery(): void
+ public function testChildQuery()
{
$result = (new JSONPath($this->getData('example')))
->find('$.store.books[(@.length-1)].title');
@@ -260,7 +254,7 @@ public function testChildQuery(): void
*
* @throws JSONPathException
*/
- public function testQueryMatchLessThan(): void
+ public function testQueryMatchLessThan()
{
$result = (new JSONPath($this->getData('example')))
->find('$.store.books[?(@.price < 10)].title');
@@ -274,7 +268,7 @@ public function testQueryMatchLessThan(): void
*
* @throws JSONPathException
*/
- public function testQueryMatchMoreThan(): void
+ public function testQueryMatchMoreThan()
{
$result = (new JSONPath($this->getData('example')))
->find('$.store.books[?(@.price > 10)].title');
@@ -288,7 +282,7 @@ public function testQueryMatchMoreThan(): void
*
* @throws JSONPathException
*/
- public function testQueryMatchLessOrEqual(): void
+ public function testQueryMatchLessOrEqual()
{
$result = (new JSONPath($this->getData('example')))
->find('$.store.books[?(@.price <= 12.99)].title');
@@ -302,7 +296,7 @@ public function testQueryMatchLessOrEqual(): void
*
* @throws JSONPathException
*/
- public function testQueryMatchEqualOrMore(): void
+ public function testQueryMatchEqualOrMore()
{
$result = (new JSONPath($this->getData('example')))
->find('$.store.books[?(@.price >= 12.99)].title');
@@ -316,7 +310,7 @@ public function testQueryMatchEqualOrMore(): void
*
* @throws JSONPathException
*/
- public function testQueryMatchEquals(): void
+ public function testQueryMatchEquals()
{
$result = (new JSONPath($this->getData('example')))
->find('$..books[?(@.author == "J. R. R. Tolkien")].title');
@@ -330,7 +324,7 @@ public function testQueryMatchEquals(): void
*
* @throws JSONPathException
*/
- public function testQueryMatchEqualsWithUnquotedInteger(): void
+ public function testQueryMatchEqualsWithUnquotedInteger()
{
$results = (new JSONPath($this->getData('simple-integers')))
->find('$..features[?(@.value = 1)]');
@@ -345,7 +339,7 @@ public function testQueryMatchEqualsWithUnquotedInteger(): void
*
* @throws JSONPathException
*/
- public function testQueryMatchNotEqualsTo(): void
+ public function testQueryMatchNotEqualsTo()
{
$jsonPath = (new JSONPath($this->getData('example')));
@@ -374,7 +368,7 @@ public function testQueryMatchNotEqualsTo(): void
*
* @throws JSONPathException
*/
- public function testQueryMatchWithRegexCaseSensitive(): void
+ public function testQueryMatchWithRegexCaseSensitive()
{
$jsonPath = (new JSONPath($this->getData('example')));
@@ -397,7 +391,7 @@ public function testQueryMatchWithRegexCaseSensitive(): void
*
* @throws JSONPathException
*/
- public function testQueryMatchWithInvalidRegex(): void
+ public function testQueryMatchWithInvalidRegex()
{
$result = (new JSONPath($this->getData('example')))
->find('$..books[?(@.author =~ "J. R. R. Tolkien")].title');
@@ -411,7 +405,7 @@ public function testQueryMatchWithInvalidRegex(): void
*
* @throws JSONPathException
*/
- public function testQueryMatchIn(): void
+ public function testQueryMatchIn()
{
$results = (new JSONPath($this->getData('example')))
->find('$..books[?(@.author in ["J. R. R. Tolkien", "Nigel Rees"])].title');
@@ -425,7 +419,7 @@ public function testQueryMatchIn(): void
*
* @throws JSONPathException
*/
- public function testQueryMatchNin(): void
+ public function testQueryMatchNin()
{
$results = (new JSONPath($this->getData('example')))
->find('$..books[?(@.author nin ["J. R. R. Tolkien", "Nigel Rees"])].title');
@@ -439,7 +433,7 @@ public function testQueryMatchNin(): void
*
* @throws JSONPathException
*/
- public function testQueryMatchNotIn(): void
+ public function testQueryMatchNotIn()
{
$results = (new JSONPath($this->getData('example')))
->find('$..books[?(@.author !in ["J. R. R. Tolkien", "Nigel Rees"])].title');
@@ -452,7 +446,7 @@ public function testQueryMatchNotIn(): void
*
* @throws JSONPathException
*/
- public function testWildcardAltNotation(): void
+ public function testWildcardAltNotation()
{
$results = (new JSONPath($this->getData('example')))
->find('$.store.books[*].author');
@@ -465,7 +459,7 @@ public function testWildcardAltNotation(): void
*
* @throws JSONPathException
*/
- public function testRecursiveChildSearch(): void
+ public function testRecursiveChildSearch()
{
$result = (new JSONPath($this->getData('example')))
->find('$..author');
@@ -480,7 +474,7 @@ public function testRecursiveChildSearch(): void
*
* @throws JSONPathException
*/
- public function testWildCard(): void
+ public function testWildCard()
{
$result = (new JSONPath($this->getData('example')))
->find('$.store.*');
@@ -504,7 +498,7 @@ public function testWildCard(): void
*
* @throws JSONPathException
*/
- public function testRecursiveChildSearchAlt(): void
+ public function testRecursiveChildSearchAlt()
{
$result = (new JSONPath($this->getData('example')))
->find('$.store..price');
@@ -518,7 +512,7 @@ public function testRecursiveChildSearchAlt(): void
*
* @throws JSONPathException
*/
- public function testRecursiveChildSearchWithChildIndex(): void
+ public function testRecursiveChildSearchWithChildIndex()
{
$result = (new JSONPath($this->getData('example')))
->find('$..books[2].title');
@@ -531,7 +525,7 @@ public function testRecursiveChildSearchWithChildIndex(): void
*
* @throws JSONPathException
*/
- public function testRecursiveChildSearchWithChildQuery(): void
+ public function testRecursiveChildSearchWithChildQuery()
{
$result = (new JSONPath($this->getData('example')))
->find('$..books[(@.length-1)].title');
@@ -545,7 +539,7 @@ public function testRecursiveChildSearchWithChildQuery(): void
*
* @throws JSONPathException
*/
- public function testRecursiveChildSearchWithSliceFilter(): void
+ public function testRecursiveChildSearchWithSliceFilter()
{
$result = (new JSONPath($this->getData('example')))
->find('$..books[-1:].title');
@@ -559,7 +553,7 @@ public function testRecursiveChildSearchWithSliceFilter(): void
*
* @throws JSONPathException
*/
- public function testRecursiveWithQueryMatch(): void
+ public function testRecursiveWithQueryMatch()
{
$result = (new JSONPath($this->getData('example')))
->find('$..books[?(@.isbn)].isbn');
@@ -573,7 +567,7 @@ public function testRecursiveWithQueryMatch(): void
*
* @throws JSONPathException
*/
- public function testRecursiveWithQueryMatchWithDots(): void
+ public function testRecursiveWithQueryMatchWithDots()
{
$result = (new JSONPath($this->getData('with-dots')))
->find(".data.tokens[?(@.Employee.FirstName)]");
@@ -588,7 +582,7 @@ public function testRecursiveWithQueryMatchWithDots(): void
*
* @throws JSONPathException
*/
- public function testRecursiveWithWildcard(): void
+ public function testRecursiveWithWildcard()
{
$result = (new JSONPath($this->getData('example')))
->find('$..*');
@@ -603,7 +597,7 @@ public function testRecursiveWithWildcard(): void
*
* @throws JSONPathException
*/
- public function testSimpleArrayAccess(): void
+ public function testSimpleArrayAccess()
{
$result = (new JSONPath(['title' => 'test title']))
->find('title');
@@ -614,7 +608,7 @@ public function testSimpleArrayAccess(): void
/**
* @throws JSONPathException
*/
- public function testFilteringOnNoneArrays(): void
+ public function testFilteringOnNoneArrays()
{
$result = (new JSONPath(['foo' => 'asdf']))
->find('$.foo.bar');
@@ -625,7 +619,7 @@ public function testFilteringOnNoneArrays(): void
/**
* @throws JSONPathException
*/
- public function testMagicMethods(): void
+ public function testMagicMethods()
{
$fooClass = new JSONPathTestClass();
$results = (new JSONPath($fooClass, JSONPath::ALLOW_MAGIC))->find('$.foo');
@@ -636,7 +630,7 @@ public function testMagicMethods(): void
/**
* @throws JSONPathException
*/
- public function testMatchWithComplexSquareBrackets(): void
+ public function testMatchWithComplexSquareBrackets()
{
$result = (new JSONPath($this->getData('extra')))
->find("$['http://www.w3.org/2000/01/rdf-schema#label'][?(@['@language']='en')]['@language']");
@@ -647,7 +641,7 @@ public function testMatchWithComplexSquareBrackets(): void
/**
* @throws JSONPathException
*/
- public function testQueryMatchWithRecursive(): void
+ public function testQueryMatchWithRecursive()
{
$result = (new JSONPath($this->getData('locations')))
->find("..[?(@.type == 'suburb')].name");
@@ -658,7 +652,7 @@ public function testQueryMatchWithRecursive(): void
/**
* @throws JSONPathException
*/
- public function testFirst(): void
+ public function testFirst()
{
$result = (new JSONPath($this->getData('extra')))
->find("$['http://www.w3.org/2000/01/rdf-schema#label'].*");
@@ -669,7 +663,7 @@ public function testFirst(): void
/**
* @throws JSONPathException
*/
- public function testLast(): void
+ public function testLast()
{
$result = (new JSONPath($this->getData('extra')))
->find("$['http://www.w3.org/2000/01/rdf-schema#label'].*");
@@ -680,7 +674,7 @@ public function testLast(): void
/**
* @throws JSONPathException
*/
- public function testSlashesInIndex(): void
+ public function testSlashesInIndex()
{
$result = (new JSONPath($this->getData('with-slashes')))
->find("$['mediatypes']['image/png']");
@@ -691,7 +685,7 @@ public function testSlashesInIndex(): void
/**
* @throws JSONPathException
*/
- public function testUnionWithKeys(): void
+ public function testUnionWithKeys()
{
$result = (new JSONPath(
[
@@ -706,7 +700,7 @@ public function testUnionWithKeys(): void
/**
* @throws JSONPathException
*/
- public function testCyrillicText(): void
+ public function testCyrillicText()
{
$jsonPath = (new JSONPath(["трололо" => 1]));
@@ -721,7 +715,7 @@ public function testCyrillicText(): void
self::assertEquals([1], $result->getData());
}
- public function testOffsetUnset(): void
+ public function testOffsetUnset()
{
$jsonIterator = new JSONPath(
[
@@ -740,7 +734,7 @@ public function testOffsetUnset(): void
self::assertEquals("B", $first['name']);
}
- public function testFirstKey(): void
+ public function testFirstKey()
{
// Array test for array
$firstKey = (new JSONPath(['a' => 'A', 'b', 'B']))->firstKey();
@@ -753,7 +747,7 @@ public function testFirstKey(): void
self::assertEquals('a', $firstKey);
}
- public function testLastKey(): void
+ public function testLastKey()
{
// Array test for array
$lastKey = (new JSONPath(['a' => 'A', 'b' => 'B', 'c' => 'C']))->lastKey();
@@ -771,7 +765,7 @@ public function testLastKey(): void
*
* @throws JSONPathException
*/
- public function testTrailingComma(): void
+ public function testTrailingComma()
{
$result = (new JSONPath($this->getData('example')))
->find("$..books[0,1,2,]");
@@ -784,7 +778,7 @@ public function testTrailingComma(): void
*
* @throws JSONPathException
*/
- public function testNegativeIndex(): void
+ public function testNegativeIndex()
{
$result = (new JSONPath($this->getData('example')))
->find('$..books[-2]');
@@ -795,7 +789,7 @@ public function testNegativeIndex(): void
/**
* @throws JSONPathException
*/
- public function testQueryAccessWithNumericalIndexes(): void
+ public function testQueryAccessWithNumericalIndexes()
{
$result = (new JSONPath($this->getData('numerical-indexes-object')))
->find("$.result.list[?(@.o == \"11.51000\")]");
diff --git a/tests/JSONPathTestClass.php b/tests/JSONPathTestClass.php
index 91cc90e..241c3bf 100644
--- a/tests/JSONPathTestClass.php
+++ b/tests/JSONPathTestClass.php
@@ -6,8 +6,6 @@
* @license https://github.com/SoftCreatR/JSONPath/blob/main/LICENSE MIT License
*/
-declare(strict_types=1);
-
namespace Flow\JSONPath\Test;
class JSONPathTestClass
@@ -22,9 +20,11 @@ class JSONPathTestClass
/**
* @param $key
* @noinspection MagicMethodsValidityInspection
+ *
+ * @return string|null
*/
- public function __get($key): ?string
+ public function __get($key)
{
- return $this->attributes[$key] ?? null;
+ return isset($this->attributes[$key]) ? $this->attributes[$key] : null;
}
}
diff --git a/tests/QueryTest.php b/tests/QueryTest.php
index 6d72965..fd0cc0b 100644
--- a/tests/QueryTest.php
+++ b/tests/QueryTest.php
@@ -6,18 +6,12 @@
* @license https://github.com/SoftCreatR/JSONPath/blob/main/LICENSE MIT License
*/
-declare(strict_types=1);
-
namespace Flow\JSONPath\Test;
-use Flow\JSONPath\{JSONPath, JSONPathException};
-use PHPUnit\Framework\{ExpectationFailedException, TestCase};
-
-use function fwrite;
-use function json_decode;
-use function json_encode;
-
-use const STDERR;
+use Flow\JSONPath\JSONPath;
+use Flow\JSONPath\JSONPathException;
+use PHPUnit\Framework\ExpectationFailedException;
+use RuntimeException;
class QueryTest extends TestCase
{
@@ -30,14 +24,20 @@ class QueryTest extends TestCase
*
* @see https://cburgmer.github.io/json-path-comparison
* @dataProvider queryDataProvider
+ *
+ * @param string $id
+ * @param string $selector
+ * @param string $data
+ * @param string $consensus
+ * @param false|bool $skip
*/
public function testQueries(
- string $id,
- string $selector,
- string $data,
- string $consensus,
- bool $skip = false
- ): void {
+ $id,
+ $selector,
+ $data,
+ $consensus,
+ $skip = false
+ ) {
$results = null;
$query = ucwords(str_replace('_', ' ', $id));
$url = sprintf('https://cburgmer.github.io/json-path-comparison/results/%s', $id);
@@ -68,10 +68,10 @@ public function testQueries(
// assert in these cases. There might be still some false positives
// (e.g. multidimensional comparisons), but that's okay, I guess. Maybe,
// we can also find a way around that in the future.
- $results = json_decode($results, true);
- $consensus = json_decode($consensus, true);
-
- self::assertEqualsCanonicalizing($consensus, $results);
+ self::assertEqualsCanonicalizing(
+ json_decode($consensus, true),
+ json_decode($results, true)
+ );
} catch (ExpectationFailedException $f) {
$e = $e->getComparisonFailure();
@@ -83,6 +83,8 @@ public function testQueries(
fwrite(STDERR, "==========================\n");
fwrite(STDERR, "Query: {$query}\n\n{$e->getMessage()}\n");
fwrite(STDERR, "==========================\n\n");
+ } catch (RuntimeException $e) {
+ // ignore
}
}
@@ -106,7 +108,7 @@ public function testQueries(
*
* @return string[]
*/
- public function queryDataProvider(): array
+ public function queryDataProvider()
{
return [
[ // data set #0
@@ -146,24 +148,24 @@ public function queryDataProvider(): array
'["third","forth","fifth"]',
true, // skip
],
- [ // data set #6
+ [ // data set #6 - unknown consensus, fallback to Proposal A
'array_slice_with_large_number_for_end_and_negative_step',
'$[2:-113667776004:-1]',
'["first","second","third","forth","fifth"]',
- '' // unknown consensus
+ '["third","second","first"]'
],
[ // data set #7
'array_slice_with_large_number_for_start',
'$[-113667776004:2]',
'["first","second","third","forth","fifth"]',
- '', // unknown consensus,
+ '["first","second"]',
true, // skip
],
- [ // data set #8
+ [ // data set #8 - unknown consensus, fallback to Proposal A
'array_slice_with_large_number_for_start_end_negative_step',
'$[113667776004:2:-1]',
'["first","second","third","forth","fifth"]',
- '' // unknown consensus
+ '["fifth","forth"]'
],
[ // data set #9
'array_slice_with_negative_start_and_end_and_range_of_-1',
@@ -201,30 +203,30 @@ public function queryDataProvider(): array
'[2,"a",4,5,100,"nice"]',
'[4]'
],
- [ // data set #15
+ [ // data set #15 - unknown consensus, fallback to Proposal A
'array_slice_with_negative_step',
'$[3:0:-2]',
'["first","second","third","forth","fifth"]',
- '' // unknown consensus
+ '["forth","second"]'
],
- [ // data set #16
+ [ // data set #16 - unknown consensus, fallback to Proposal A
'array_slice_with_negative_step_and_start_greater_than_end',
'$[0:3:-2]',
'["first","second","third","forth","fifth"]',
- '', // unknown consensus,
+ '[]',
true, // skip
],
- [ // data set #17
+ [ // data set #17 - unknown consensus, fallback to Proposal A
'array_slice_with_negative_step_on_partially_overlapping_array',
'$[7:3:-1]',
'["first","second","third","forth","fifth"]',
- '' // unknown consensus
+ '["fifth"]'
],
- [ // data set #18
+ [ // data set #18 - unknown consensus, fallback to Proposal A
'array_slice_with_negative_step_only',
'$[::-2]',
'["first","second","third","forth","fifth"]',
- '', // unknown consensus,
+ '["fifth","third","first"]',
true, // skip
],
[ // data set #19
@@ -233,11 +235,11 @@ public function queryDataProvider(): array
'["first","second","third","forth","fifth"]',
'["second","third","forth","fifth"]'
],
- [ // data set #20
+ [ // data set #20 - unknown consensus, fallback to Proposal A
'array_slice_with_open_end_and_negative_step',
'$[3::-1]',
'["first","second","third","forth","fifth"]',
- '', // unknown consensus,
+ '["forth","third","second","first"]',
true, // skip
],
[ // data set #21
@@ -258,17 +260,17 @@ public function queryDataProvider(): array
'["first","second"]',
'["first","second"]'
],
- [ // data set #24
+ [ // data set #24 - unknown consensus, fallback to Proposal A
'array_slice_with_open_start_and_end_on_object',
'$[:]',
'{":":42,"more":"string"}',
- '' // unknown consensus
+ '[]'
],
- [ // data set #25
+ [ // data set #25 - unknown consensus, fallback to Proposal A
'array_slice_with_open_start_and_negative_step',
'$[:2:-1]',
'["first","second","third","forth","fifth"]',
- '', // unknown consensus,
+ '["fifth","forth"]',
true, // skip
],
[ // data set #26
@@ -331,11 +333,11 @@ public function queryDataProvider(): array
'["first","second","third","forth","fifth"]',
'["first","third"]'
],
- [ // data set #36
+ [ // data set #36 - unknown consensus
'array_slice_with_step_0',
'$[0:3:0]',
'["first","second","third","forth","fifth"]',
- '' // unknown consensus
+ ''
],
[ // data set #37
'array_slice_with_step_1',
@@ -403,11 +405,11 @@ public function queryDataProvider(): array
'{"key":"value"}',
'["value"]'
],
- [ // data set #48
+ [ // data set #48 - unknown consensus
'bracket_notation_with_empty_path',
'$[]',
'{"":42,"\'\'":123,"\\"\\"":222}',
- '' // unknown consensus
+ ''
],
[ // data set #49
'bracket_notation_with_empty_string',
@@ -457,11 +459,11 @@ public function queryDataProvider(): array
'[[1],[2,3]]',
'[3]'
],
- [ // data set #57
+ [ // data set #57 - unknown consensus, fallback to Proposal A
'bracket_notation_with_number_on_object',
'$[0]',
'{"0":"value"}',
- '' // unknown consensus
+ '[]'
],
[ // data set #58
'bracket_notation_with_number_on_short_array',
@@ -469,11 +471,11 @@ public function queryDataProvider(): array
'["one element"]',
'[]'
],
- [ // data set #59
+ [ // data set #59 - unknown consensus, fallback to Proposal A
'bracket_notation_with_number_on_string',
'$[0]',
'"Hello World"',
- '' // unknown consensus
+ '[]'
],
[ // data set #60
'bracket_notation_with_quoted_array_slice_literal',
@@ -511,17 +513,17 @@ public function queryDataProvider(): array
'{"\\"":"value","another":"entry"}',
'["value"]'
],
- [ // data set #66
+ [ // data set #66 - unknown consensus, fallback to Proposal A
'bracket_notation_with_quoted_escaped_backslash',
'$[\'\\\\\']',
'{"\\\\":"value"}',
- '' // unknown consensus
+ '["value"]'
],
- [ // data set #67
+ [ // data set #67 - unknown consensus, fallback to Proposal A
'bracket_notation_with_quoted_escaped_single_quote',
'$[\'\\\'\']',
'{"\'":"value"}',
- '' // unknown consensus
+ '["value"]'
],
[ // data set #68
'bracket_notation_with_quoted_number_on_object',
@@ -535,17 +537,17 @@ public function queryDataProvider(): array
'{"$":"value","another":"entry"}',
'["value"]'
],
- [ // data set #70
+ [ // data set #70 - unknown consensus, fallback to Proposal A
'bracket_notation_with_quoted_special_characters_combined',
'$[\':@."$,*\\\'\\\\\']',
'{":@.\\"$,*\'\\\\":42}',
- '' // unknown consensus
+ '[42]'
],
- [ // data set #71
+ [ // data set #71 - unknown consensus
'bracket_notation_with_quoted_string_and_unescaped_single_quote',
'$[\'single\'quote\']',
'{"single\'quote":"value"}',
- '' // unknown consensus
+ ''
],
[ // data set #72
'bracket_notation_with_quoted_union_literal',
@@ -559,11 +561,11 @@ public function queryDataProvider(): array
'{"*":"value","another":"entry"}',
'["value"]'
],
- [ // data set #74
+ [ // data set #74 - unknown consensus, fallback to Proposal A
'bracket_notation_with_quoted_wildcard_literal_on_object_without_key',
'$[\'*\']',
'{"another":"entry"}',
- '' // unknown consensus
+ '[]'
],
[ // data set #75
'bracket_notation_with_string_including_dot_wildcard',
@@ -571,18 +573,18 @@ public function queryDataProvider(): array
'{"nice":42,"ni.*":1,"mice":100}',
'[1]'
],
- [ // data set #76
+ [ // data set #76 - unknown consensus
'bracket_notation_with_two_literals_separated_by_dot',
'$[\'two\'.\'some\']',
'{"one":{"key":"value"},"two":{"some":"more","key":"other value"},"two.some":"42","two\'.\'some":"43' .
'"}',
- '' // unknown consensus
+ ''
],
- [ // data set #77
+ [ // data set #77 - unknown consensus
'bracket_notation_with_two_literals_separated_by_dot_without_quotes',
'$[two.some]',
'{"one":{"key":"value"},"two":{"some":"more","key":"other value"},"two.some":"42"}',
- '' // unknown consensus
+ ''
],
[ // data set #78
'bracket_notation_with_wildcard_after_array_slice',
@@ -632,29 +634,29 @@ public function queryDataProvider(): array
'{"some":"string","int":42,"object":{"key":"value"},"array":[0,1]}',
'["string",42,[0,1],{"key":"value"}]'
],
- [ // data set #86
+ [ // data set #86 - unknown consensus
'bracket_notation_without_quotes',
'$[key]',
'{"key":"value"}',
- '' // unknown consensus
+ ''
],
- [ // data set #87
+ [ // data set #87 - unknown consensus
'dot_bracket_notation',
'$.[\'key\']',
'{"key":"value","other":{"key":[{"key":42}]}}',
- '' // unknown consensus
+ ''
],
- [ // data set #88
+ [ // data set #88 - unknown consensus
'dot_bracket_notation_with_double_quotes',
'$.["key"]',
'{"key":"value","other":{"key":[{"key":42}]}}',
- '' // unknown consensus
+ ''
],
- [ // data set #89
+ [ // data set #89 - unknown consensus
'dot_bracket_notation_without_quotes',
'$.[key]',
'{"key":"value","other":{"key":[{"key":42}]}}',
- '' // unknown consensus
+ ''
],
[ // data set #90
'dot_notation',
@@ -770,24 +772,24 @@ public function queryDataProvider(): array
'{"key-dash":"value"}',
'["value"]'
],
- [ // data set #108
+ [ // data set #108 - unknown consensus
'dot_notation_with_double_quotes',
'$."key"',
'{"key":"value","\\"key\\"":42}',
- '' // unknown consensus
+ ''
],
- [ // data set #109
+ [ // data set #109 - unknown consensus
'dot_notation_with_double_quotes_after_recursive_descent',
'$.."key"',
'{"object":{"key":"value","\\"key\\"":100,"array":[{"key":"something","\\"key\\"":0},{"key":{"key":"' .
'russian dolls"},"\\"key\\"":{"\\"key\\"":99}}]},"key":"top","\\"key\\"":42}',
- '' // unknown consensus
+ ''
],
- [ // data set #110
+ [ // data set #110 - unknown consensus
'dot_notation_with_empty_path',
'$.',
'{"key":42,"":9001,"\'\'":"nice"}',
- '' // unknown consensus
+ ''
],
[ // data set #111
'dot_notation_with_key_named_in',
@@ -819,11 +821,11 @@ public function queryDataProvider(): array
'{"true":"value"}',
'["value"]'
],
- [ // data set #116
+ [ // data set #116 - unknown consensus, fallback to Proposal A
'dot_notation_with_key_root_literal',
'$.$',
'{"$":"value"}',
- '' // unknown consensus
+ '["value"]'
],
[ // data set #117
'dot_notation_with_non_ASCII_key',
@@ -831,17 +833,17 @@ public function queryDataProvider(): array
'{"\\u5c6c\\u6027":"value"}',
'["value"]'
],
- [ // data set #118
+ [ // data set #118 - unknown consensus, fallback to Proposal A
'dot_notation_with_number',
'$.2',
'["first","second","third","forth","fifth"]',
- '' // unknown consensus
+ '[]'
],
- [ // data set #119
+ [ // data set #119 - unknown consensus, fallback to Proposal A
'dot_notation_with_number_-1',
'$.-1',
'["first","second","third","forth","fifth"]',
- '' // unknown consensus
+ '[]'
],
[ // data set #120
'dot_notation_with_number_on_object',
@@ -849,24 +851,24 @@ public function queryDataProvider(): array
'{"a":"first","2":"second","b":"third"}',
'["second"]'
],
- [ // data set #121
+ [ // data set #121 - unknown consensus
'dot_notation_with_single_quotes',
'$.\'key\'',
'{"key":"value","\'key\'":42}',
- '' // unknown consensus
+ ''
],
- [ // data set #122
+ [ // data set #122 - unknown consensus
'dot_notation_with_single_quotes_after_recursive_descent',
'$..\'key\'',
'{"object":{"key":"value","\'key\'":100,"array":[{"key":"something","\'key\'":0},{"key":{"key":"russ' .
'ian dolls"},"\'key\'":{"\'key\'":99}}]},"key":"top","\'key\'":42}',
- '' // unknown consensus
+ ''
],
- [ // data set #123
+ [ // data set #123 - unknown consensus
'dot_notation_with_single_quotes_and_dot',
'$.\'some.key\'',
'{"some.key":42,"some":{"key":"value"},"\'some.key\'":43}',
- '' // unknown consensus
+ ''
],
[ // data set #124
'dot_notation_with_wildcard_after_dot_notation_after_dot_notation_with_wildcard',
@@ -922,76 +924,76 @@ public function queryDataProvider(): array
'{"some":"string","int":42,"object":{"key":"value"},"array":[0,1]}',
'["string",42,[0,1],{"key":"value"}]'
],
- [ // data set #133
+ [ // data set #133 - unknown consensus
'dot_notation_without_root',
'key',
'{"key":"value"}',
- '' // unknown consensus
+ ''
],
- [ // data set #134
+ [ // data set #134 - unknown consensus, fallback to Proposal A
'filter_expression_after_dot_notation_with_wildcard_after_recursive_descent',
'$..*[?(@.id>2)]',
'[{"complext":{"one":[{"name":"first","id":1},{"name":"next","id":2},{"name":"another","id":3},{"nam' .
'e":"more","id":4}],"more":{"name":"next to last","id":5}}},{"name":"last","id":6}]',
- '' // unknown consensus
+ '[{"id":3,"name":"another"},{"id":4,"name":"more"},{"id":5,"name":"next to last"}]'
],
- [ // data set #135
+ [ // data set #135 - unknown consensus, fallback to Proposal A
'filter_expression_after_recursive_descent',
'$..[?(@.id==2)]',
'{"id":2,"more":[{"id":2},{"more":{"id":2}},{"id":{"id":2}},[{"id":2}]]}',
- '' // unknown consensus
+ '[{"id":2},{"id":2},{"id":2},{"id":2}]'
],
- [ // data set #136
+ [ // data set #136 - unknown consensus, fallback to Proposal A
'filter_expression_on_object',
'$[?(@.key)]',
'{"key":42,"another":{"key":1}}',
- '' // unknown consensus
+ '[{"key":1}]'
],
- [ // data set #137
+ [ // data set #137 - unknown consensus
'filter_expression_with_addition',
'$[?(@.key+50==100)]',
'[{"key":60},{"key":50},{"key":10},{"key":-50},{"key+50":100}]',
- '' // unknown consensus
+ ''
],
- [ // data set #138
+ [ // data set #138 - unknown consensus, fallback to Proposal A
'filter_expression_with_boolean_and_operator',
'$[?(@.key>42 && @.key<44)]',
'[{"key":42},{"key":43},{"key":44}]',
- '' // unknown consensus
+ '[{"key":43}]'
],
- [ // data set #139
+ [ // data set #139 - unknown consensus
'filter_expression_with_boolean_and_operator_and_value_false',
'$[?(@.key>0 && false)]',
'[{"key":1},{"key":3},{"key":"nice"},{"key":true},{"key":null},{"key":false},{"key":{}},{"key":[]},{' .
'"key":-1},{"key":0},{"key":""}]',
- '' // unknown consensus
+ ''
],
- [ // data set #140
+ [ // data set #140 - unknown consensus
'filter_expression_with_boolean_and_operator_and_value_true',
'$[?(@.key>0 && true)]',
'[{"key":1},{"key":3},{"key":"nice"},{"key":true},{"key":null},{"key":false},{"key":{}},{"key":[]},{' .
'"key":-1},{"key":0},{"key":""}]',
- '' // unknown consensus
+ ''
],
- [ // data set #141
+ [ // data set #141 - unknown consensus, fallback to Proposal A
'filter_expression_with_boolean_or_operator',
'$[?(@.key>43 || @.key<43)]',
'[{"key":42},{"key":43},{"key":44}]',
- '' // unknown consensus
+ '[{"key":42},{"key":44}]'
],
- [ // data set #142
+ [ // data set #142 - unknown consensus
'filter_expression_with_boolean_or_operator_and_value_false',
'$[?(@.key>0 || false)]',
'[{"key":1},{"key":3},{"key":"nice"},{"key":true},{"key":null},{"key":false},{"key":{}},{"key":[]},{' .
'"key":-1},{"key":0},{"key":""}]',
- '' // unknown consensus
+ ''
],
- [ // data set #143
+ [ // data set #143 - unknown consensus
'filter_expression_with_boolean_or_operator_and_value_true',
'$[?(@.key>0 || true)]',
'[{"key":1},{"key":3},{"key":"nice"},{"key":true},{"key":null},{"key":false},{"key":{}},{"key":[]},{' .
'"key":-1},{"key":0},{"key":""}]',
- '' // unknown consensus
+ ''
],
[ // data set #144
'filter_expression_with_bracket_notation',
@@ -1006,11 +1008,11 @@ public function queryDataProvider(): array
'[{"@key":0},{"@key":42},{"key":42},{"@key":43},{"some":"value"}]',
'[{"@key":42}]'
],
- [ // data set #146
+ [ // data set #146 - unknown consensus, fallback to Proposal A
'filter_expression_with_bracket_notation_with_-1',
'$[?(@[-1]==2)]',
'[[2,3],["a"],[0,2],[2]]',
- '' // unknown consensus
+ '[[0,2],[2]]'
],
[ // data set #147
'filter_expression_with_bracket_notation_with_number',
@@ -1018,142 +1020,142 @@ public function queryDataProvider(): array
'[["a","b"],["x","y"]]',
'[["a","b"]]'
],
- [ // data set #148
+ [ // data set #148 - unknown consensus, fallback to Proposal A
'filter_expression_with_bracket_notation_with_number_on_object',
'$[?(@[1]==\'b\')]',
'{"1":["a","b"],"2":["x","y"]}',
- '' // unknown consensus
+ '[["a","b"]]'
],
- [ // data set #149
+ [ // data set #149 - unknown consensus, fallback to Proposal A
'filter_expression_with_current_object',
'$[?(@)]',
'["some value",null,"value",0,1,-1,"",[],{},false,true]',
- '' // unknown consensus
+ '["some value",null,"value",0,1,-1,"",[],{},false,true]'
],
- [ // data set #150
+ [ // data set #150 - unknown consensus, fallback to Proposal A
'filter_expression_with_different_grouped_operators',
'$[?(@.a && (@.b || @.c))]',
'[{"a":true},{"a":true,"b":true},{"a":true,"b":true,"c":true},{"b":true,"c":true},{"a":true,"c":true' .
'},{"c":true},{"b":true}]',
- '' // unknown consensus
+ '[{"a":true,"b":true},{"a":true,"b":true,"c":true},{"a":true,"c":true}]'
],
- [ // data set #151
+ [ // data set #151 - unknown consensus
'filter_expression_with_different_ungrouped_operators',
'$[?(@.a && @.b || @.c)]',
'[{"a":true,"b":true},{"a":true,"b":true,"c":true},{"b":true,"c":true},{"a":true,"c":true},{"a":true' .
'},{"b":true},{"c":true},{"d":true},{}]',
- '' // unknown consensus
+ ''
],
- [ // data set #152
+ [ // data set #152 - unknown consensus
'filter_expression_with_division',
'$[?(@.key/10==5)]',
'[{"key":60},{"key":50},{"key":10},{"key":-50},{"key\\/10":5}]',
- '' // unknown consensus
+ ''
],
- [ // data set #153
+ [ // data set #153 - unknown consensus
'filter_expression_with_empty_expression',
'$[?()]',
'[1,{"key":42},"value",null]',
- '' // unknown consensus
+ ''
],
- [ // data set #154
+ [ // data set #154 - unknown consensus, fallback to Proposal A
'filter_expression_with_equals',
'$[?(@.key==42)]',
'[{"key":0},{"key":42},{"key":-1},{"key":1},{"key":41},{"key":43},{"key":42.0001},{"key":41.9999},{"' .
'key":100},{"key":"some"},{"key":"42"},{"key":null},{"key":420},{"key":""},{"key":{}},{"key":[]},{"k' .
'ey":[42]},{"key":{"key":42}},{"key":{"some":42}},{"some":"value"}]',
- '' // unknown consensus
+ '[{"key":42}]'
],
- [ // data set #155
+ [ // data set #155 - unknown consensus
'filter_expression_with_equals_array',
'$[?(@.d==["v1","v2"])]',
'[{"d":["v1","v2"]},{"d":["a","b"]},{"d":"v1"},{"d":"v2"},{"d":{}},{"d":[]},{"d":null},{"d":-1},{"d"' .
':0},{"d":1},{"d":"[\'v1\',\'v2\']"},{"d":"[\'v1\', \'v2\']"},{"d":"v1,v2"},{"d":"[\\"v1\\", \\"v2\\' .
'"]"},{"d":"[\\"v1\\",\\"v2\\"]"}]',
- '' // unknown consensus
+ ''
],
- [ // data set #156
+ [ // data set #156 - unknown consensus
'filter_expression_with_equals_array_for_array_slice_with_range_1',
'$[?(@[0:1]==[1])]',
'[[1,2,3],[1],[2,3],1,2]',
- '' // unknown consensus
+ ''
],
- [ // data set #157
+ [ // data set #157 - unknown consensus
'filter_expression_with_equals_array_for_dot_notation_with_star',
'$[?(@.*==[1,2])]',
'[[1,2],[2,3],[1],[2],[1,2,3],1,2,3]',
- '' // unknown consensus
+ ''
],
- [ // data set #158
+ [ // data set #158 - unknown consensus
'filter_expression_with_equals_array_with_single_quotes',
'$[?(@.d==[\'v1\',\'v2\'])]',
'[{"d":["v1","v2"]},{"d":["a","b"]},{"d":"v1"},{"d":"v2"},{"d":{}},{"d":[]},{"d":null},{"d":-1},{"d"' .
':0},{"d":1},{"d":"[\'v1\',\'v2\']"},{"d":"[\'v1\', \'v2\']"},{"d":"v1,v2"},{"d":"[\\"v1\\", \\"v2\\' .
'"]"},{"d":"[\\"v1\\",\\"v2\\"]"}]',
- '' // unknown consensus
+ ''
],
- [ // data set #159
+ [ // data set #159 - unknown consensus
'filter_expression_with_equals_boolean_expression_value',
'$[?((@.key<44)==false)]',
'[{"key":42},{"key":43},{"key":44}]',
- '' // unknown consensus
+ ''
],
- [ // data set #160
+ [ // data set #160 - unknown consensus, fallback to Proposal A
'filter_expression_with_equals_false',
'$[?(@.key==false)]',
'[{"some":"some value"},{"key":true},{"key":false},{"key":null},{"key":"value"},{"key":""},{"key":0}' .
',{"key":1},{"key":-1},{"key":42},{"key":{}},{"key":[]}]',
- '' // unknown consensus
+ '[{"key":false}]'
],
- [ // data set #161
+ [ // data set #161 - unknown consensus, fallback to Proposal A
'filter_expression_with_equals_null',
'$[?(@.key==null)]',
'[{"some":"some value"},{"key":true},{"key":false},{"key":null},{"key":"value"},{"key":""},{"key":0}' .
',{"key":1},{"key":-1},{"key":42},{"key":{}},{"key":[]}]',
- '' // unknown consensus
+ '[{"key":null}]'
],
- [ // data set #162
+ [ // data set #162 - unknown consensus
'filter_expression_with_equals_number_for_array_slice_with_range_1',
'$[?(@[0:1]==1)]',
'[[1,2,3],[1],[2,3],1,2]',
- '' // unknown consensus
+ ''
],
- [ // data set #163
+ [ // data set #163 - unknown consensus
'filter_expression_with_equals_number_for_bracket_notation_with_star',
'$[?(@[*]==2)]',
'[[1,2],[2,3],[1],[2],[1,2,3],1,2,3]',
- '' // unknown consensus
+ ''
],
- [ // data set #164
+ [ // data set #164 - unknown consensus
'filter_expression_with_equals_number_for_dot_notation_with_star',
'$[?(@.*==2)]',
'[[1,2],[2,3],[1],[2],[1,2,3],1,2,3]',
- '' // unknown consensus
+ ''
],
- [ // data set #165
+ [ // data set #165 - unknown consensus, fallback to Proposal A
'filter_expression_with_equals_number_with_fraction',
'$[?(@.key==-0.123e2)]',
'[{"key":-12.3},{"key":-0.123},{"key":-12},{"key":12.3},{"key":2},{"key":"-0.123e2"}]',
- '' // unknown consensus
+ '[{"key":-12.3}]'
],
- [ // data set #166
+ [ // data set #166 - unknown consensus
'filter_expression_with_equals_number_with_leading_zeros',
'$[?(@.key==010)]',
'[{"key":"010"},{"key":"10"},{"key":10},{"key":0},{"key":8}]',
- '' // unknown consensus
+ ''
],
- [ // data set #167
+ [ // data set #167 - unknown consensus
'filter_expression_with_equals_object',
'$[?(@.d=={"k":"v"})]',
'[{"d":{"k":"v"}},{"d":{"a":"b"}},{"d":"k"},{"d":"v"},{"d":{}},{"d":[]},{"d":null},{"d":-1},{"d":0},' .
'{"d":1},{"d":"[object Object]"},{"d":"{\\"k\\": \\"v\\"}"},{"d":"{\\"k\\":\\"v\\"}"},"v"]',
- '' // unknown consensus
+ ''
],
- [ // data set #168
+ [ // data set #168 - unknown consensus, fallback to Proposal A
'filter_expression_with_equals_on_array_of_numbers',
'$[?(@==42)]',
'[0,42,-1,41,43,42.0001,41.9999,null,100]',
- '' // unknown consensus
+ '[42]'
],
[ // data set #169
'filter_expression_with_equals_on_array_without_match',
@@ -1161,26 +1163,26 @@ public function queryDataProvider(): array
'[{"key":42}]',
'[]'
],
- [ // data set #170
+ [ // data set #170 - unknown consensus, fallback to Proposal A
'filter_expression_with_equals_on_object',
'$[?(@.key==42)]',
'{"a":{"key":0},"b":{"key":42},"c":{"key":-1},"d":{"key":41},"e":{"key":43},"f":{"key":42.0001},"g":' .
'{"key":41.9999},"h":{"key":100},"i":{"some":"value"}}',
- '' // unknown consensus
+ '[{"key":42}]'
],
- [ // data set #171
+ [ // data set #171 - unknown consensus, fallback to Proposal A
'filter_expression_with_equals_on_object_with_key_matching_query',
'$[?(@.id==2)]',
'{"id":2}',
- '' // unknown consensus
+ '[]'
],
- [ // data set #172
+ [ // data set #172 - unknown consensus, fallback to Proposal A
'filter_expression_with_equals_string',
'$[?(@.key=="value")]',
'[{"key":"some"},{"key":"value"},{"key":null},{"key":0},{"key":1},{"key":-1},{"key":""},{"key":{}},{' .
'"key":[]},{"key":"valuemore"},{"key":"morevalue"},{"key":["value"]},{"key":{"some":"value"}},{"key"' .
':{"key":"value"}},{"some":"value"}]',
- '' // unknown consensus
+ '[{"key":"value"}]'
],
[ // data set #173
'filter_expression_with_equals_string_with_current_object_literal',
@@ -1200,120 +1202,124 @@ public function queryDataProvider(): array
'[{"key":"some"},{"key":"value"}]',
'[{"key":"value"}]'
],
- [ // data set #176
+ [ // data set #176 - unknown consensus, fallback to Proposal A
'filter_expression_with_equals_true',
'$[?(@.key==true)]',
'[{"some":"some value"},{"key":true},{"key":false},{"key":null},{"key":"value"},{"key":""},{"key":0}' .
',{"key":1},{"key":-1},{"key":42},{"key":{}},{"key":[]}]',
- '' // unknown consensus
+ '[{"key":true}]'
],
- [ // data set #177
+ [ // data set #177 - unknown consensus, fallback to Proposal A
'filter_expression_with_equals_with_root_reference',
'$.items[?(@.key==$.value)]',
'{"value":42,"items":[{"key":10},{"key":42},{"key":50}]}',
- '' // unknown consensus
+ '[{"key":42}]'
],
- [ // data set #178
+ [ // data set #178 - unknown consensus, fallback to Proposal A
'filter_expression_with_greater_than',
'$[?(@.key>42)]',
'[{"key":0},{"key":42},{"key":-1},{"key":41},{"key":43},{"key":42.0001},{"key":41.9999},{"key":100},' .
'{"key":"43"},{"key":"42"},{"key":"41"},{"key":"value"},{"some":"value"}]',
- '' // unknown consensus
+ '[{"key":43},{"key":42.0001},{"key":100}]'
],
- [ // data set #179
+ [ // data set #179 - unknown consensus, fallback to Proposal A
'filter_expression_with_greater_than_or_equal',
'$[?(@.key>=42)]',
'[{"key":0},{"key":42},{"key":-1},{"key":41},{"key":43},{"key":42.0001},{"key":41.9999},{"key":100},' .
'{"key":"43"},{"key":"42"},{"key":"41"},{"key":"value"},{"some":"value"}]',
- '' // unknown consensus
+ '[{"key":42},{"key":43},{"key":42.0001},{"key":100}]'
],
- [ // data set #180
+ [ // data set #180 - unknown consensus
'filter_expression_with_in_array_of_values',
'$[?(@.d in [2, 3])]',
'[{"d":1},{"d":2},{"d":1},{"d":3},{"d":4}]',
- '' // unknown consensus
+ ''
],
- [ // data set #181
+ [ // data set #181 - unknown consensus
'filter_expression_with_in_current_object',
'$[?(2 in @.d)]',
'[{"d":[1,2,3]},{"d":[2]},{"d":[1]},{"d":[3,4]},{"d":[4,2]}]',
- '' // unknown consensus
+ ''
],
- [ // data set #182
+ [ // data set #182 - unknown consensus, fallback to Proposal A
'filter_expression_with_less_than',
'$[?(@.key<42)]',
'[{"key":0},{"key":42},{"key":-1},{"key":41},{"key":43},{"key":42.0001},{"key":41.9999},{"key":100},' .
'{"key":"43"},{"key":"42"},{"key":"41"},{"key":"value"},{"some":"value"}]',
- '' // unknown consensus
+ '[{"key":0},{"key":-1},{"key":41},{"key":41.9999}]'
],
- [ // data set #183
+ [ // data set #183 - unknown consensus, fallback to Proposal A
'filter_expression_with_less_than_or_equal',
'$[?(@.key<=42)]',
'[{"key":0},{"key":42},{"key":-1},{"key":41},{"key":43},{"key":42.0001},{"key":41.9999},{"key":100},' .
'{"key":"43"},{"key":"42"},{"key":"41"},{"key":"value"},{"some":"value"}]',
- '' // unknown consensus
+ '[{"key":0},{"key":42},{"key":-1},{"key":41},{"key":41.9999}]'
],
- [ // data set #184
+ [ // data set #184 - unknown consensus
'filter_expression_with_multiplication',
'$[?(@.key*2==100)]',
'[{"key":60},{"key":50},{"key":10},{"key":-50},{"key*2":100}]',
- '' // unknown consensus
+ ''
],
- [ // data set #185
+ [ // data set #185 - unknown consensus, fallback to Proposal A
'filter_expression_with_negation_and_equals',
'$[?(!(@.key==42))]',
'[{"key":0},{"key":42},{"key":-1},{"key":41},{"key":43},{"key":42.0001},{"key":41.9999},{"key":100},' .
'{"key":"43"},{"key":"42"},{"key":"41"},{"key":"value"},{"some":"value"}]',
- '' // unknown consensus
+ '[{"key":0},{"key":-1},{"key":41},{"key":43},{"key":42.0001},{"key":41.9999},{"key":100},{"key":"43"' .
+ '},{"key":"42"},{"key":"41"},{"key":"value"},{"some":"value"}]'
],
- [ // data set #186
+ [ // data set #186 - unknown consensus, fallback to Proposal A
'filter_expression_with_negation_and_less_than',
'$[?(!(@.key<42))]',
'[{"key":0},{"key":42},{"key":-1},{"key":41},{"key":43},{"key":42.0001},{"key":41.9999},{"key":100},' .
'{"key":"43"},{"key":"42"},{"key":"41"},{"key":"value"},{"some":"value"}]',
- '' // unknown consensus
+ '[{"key":42},{"key":43},{"key":42.0001},{"key":100},{"key":"43"},{"key":"42"},{"key":"41"},{"key":"v' .
+ 'alue"},{"some":"value"}]'
],
- [ // data set #187
+ [ // data set #187 - unknown consensus, fallback to Proposal A
'filter_expression_with_not_equals',
'$[?(@.key!=42)]',
'[{"key":0},{"key":42},{"key":-1},{"key":1},{"key":41},{"key":43},{"key":42.0001},{"key":41.9999},{"' .
'key":100},{"key":"some"},{"key":"42"},{"key":null},{"key":420},{"key":""},{"key":{}},{"key":[]},{"k' .
'ey":[42]},{"key":{"key":42}},{"key":{"some":42}},{"some":"value"}]',
- '' // unknown consensus
+ '[{"key":0},{"key":-1},{"key":1},{"key":41},{"key":43},{"key":42.0001},{"key":41.9999},{"key":100},{' .
+ '"key":"some"},{"key":"42"},{"key":null},{"key":420},{"key":""},{"key":{}},{"key":[]},{"key":[42]},{' .
+ '"key":{"key":42}},{"key":{"some":42}},{"some":"value"}]'
],
- [ // data set #188
+ [ // data set #188 - unknown consensus
'filter_expression_with_regular_expression',
'$[?(@.name=~/hello.*/)]',
'[{"name":"hullo world"},{"name":"hello world"},{"name":"yes hello world"},{"name":"HELLO WORLD"},{"' .
'name":"good bye"}]',
- '' // unknown consensus
+ ''
],
- [ // data set #189
+ [ // data set #189 - unknown consensus
'filter_expression_with_set_wise_comparison_to_scalar',
'$[?(@[*]>=4)]',
'[[1,2],[3,4],[5,6]]',
- '' // unknown consensus
+ ''
],
- [ // data set #190
+ [ // data set #190 - unknown consensus
'filter_expression_with_set_wise_comparison_to_set',
'$.x[?(@[*]>=$.y[*])]',
'{"x":[[1,2],[3,4],[5,6]],"y":[3,4,5]}',
- '' // unknown consensus
+ ''
],
- [ // data set #191
+ [ // data set #191 - unknown consensus
'filter_expression_with_single_equal',
'$[?(@.key=42)]',
'[{"key":0},{"key":42},{"key":-1},{"key":1},{"key":41},{"key":43},{"key":42.0001},{"key":41.9999},{"' .
'key":100},{"key":"some"},{"key":"42"},{"key":null},{"key":420},{"key":""},{"key":{}},{"key":[]},{"k' .
'ey":[42]},{"key":{"key":42}},{"key":{"some":42}},{"some":"value"}]',
- '' // unknown consensus
+ ''
],
- [ // data set #192
+ [ // data set #192 - unknown consensus
'filter_expression_with_subfilter',
'$[?(@.a[?(@.price>10)])]',
'[{"a":[{"price":1},{"price":3}]},{"a":[{"price":11}]},{"a":[{"price":8},{"price":12},{"price":3}]},' .
'{"a":[]}]',
- '' // unknown consensus
+ ''
],
[ // data set #193
'filter_expression_with_subpaths',
@@ -1321,102 +1327,103 @@ public function queryDataProvider(): array
'[{"address":{"city":"Berlin"}},{"address":{"city":"London"}}]',
'[{"address":{"city":"Berlin"}}]'
],
- [ // data set #194
+ [ // data set #194 - unknown consensus, fallback to Proposal A
'filter_expression_with_subtraction',
'$[?(@.key-50==-100)]',
'[{"key":60},{"key":50},{"key":10},{"key":-50},{"key-50":-100}]',
- '' // unknown consensus
+ '[{"key-50":-100}]'
],
- [ // data set #195
+ [ // data set #195 - unknown consensus, fallback to Proposal A
'filter_expression_with_tautological_comparison',
'$[?(1==1)]',
'[1,3,"nice",true,null,false,{},[],-1,0,""]',
- '' // unknown consensus
+ '[1,3,"nice",true,null,false,{},[],-1,0,""]'
],
- [ // data set #196
+ [ // data set #196 - unknown consensus
'filter_expression_with_triple_equal',
'$[?(@.key===42)]',
'[{"key":0},{"key":42},{"key":-1},{"key":1},{"key":41},{"key":43},{"key":42.0001},{"key":41.9999},{"' .
'key":100},{"key":"some"},{"key":"42"},{"key":null},{"key":420},{"key":""},{"key":{}},{"key":[]},{"k' .
'ey":[42]},{"key":{"key":42}},{"key":{"some":42}},{"some":"value"}]',
- '' // unknown consensus
+ ''
],
- [ // data set #197
+ [ // data set #197 - unknown consensus, fallback to Proposal A
'filter_expression_with_value',
'$[?(@.key)]',
'[{"some":"some value"},{"key":true},{"key":false},{"key":null},{"key":"value"},{"key":""},{"key":0}' .
',{"key":1},{"key":-1},{"key":42},{"key":{}},{"key":[]}]',
- '' // unknown consensus
+ '[{"key":true},{"key":false},{"key":null},{"key":"value"},{"key":""},{"key":0},{"key":1},{"key":-1},' .
+ '{"key":42},{"key":{}},{"key":[]}]'
],
- [ // data set #198
+ [ // data set #198 - unknown consensus, fallback to Proposal A
'filter_expression_with_value_after_dot_notation_with_wildcard_on_array_of_objects',
'$.*[?(@.key)]',
'[{"some":"some value"},{"key":"value"}]',
- '' // unknown consensus
+ '[]'
],
- [ // data set #199
+ [ // data set #199 - unknown consensus, fallback to Proposal A
'filter_expression_with_value_after_recursive_descent',
'$..[?(@.id)]',
'{"id":2,"more":[{"id":2},{"more":{"id":2}},{"id":{"id":2}},[{"id":2}]]}',
- '' // unknown consensus
+ '[{"id":2},{"id":2},{"id":2},{"id":2},{"id":{"id":2}}]'
],
- [ // data set #200
+ [ // data set #200 - unknown consensus
'filter_expression_with_value_false',
'$[?(false)]',
'[1,3,"nice",true,null,false,{},[],-1,0,""]',
- '' // unknown consensus
+ ''
],
- [ // data set #201
+ [ // data set #201 - unknown consensus
'filter_expression_with_value_from_recursive_descent',
'$[?(@..child)]',
'[{"key":[{"child":1},{"child":2}]},{"key":[{"child":2}]},{"key":[{}]},{"key":[{"something":42}]},{}' .
']',
- '' // unknown consensus
+ ''
],
- [ // data set #202
+ [ // data set #202 - unknown consensus
'filter_expression_with_value_null',
'$[?(null)]',
'[1,3,"nice",true,null,false,{},[],-1,0,""]',
- '' // unknown consensus
+ ''
],
- [ // data set #203
+ [ // data set #203 - unknown consensus
'filter_expression_with_value_true',
'$[?(true)]',
'[1,3,"nice",true,null,false,{},[],-1,0,""]',
- '' // unknown consensus
+ ''
],
- [ // data set #204
+ [ // data set #204 - unknown consensus
'filter_expression_without_parens',
'$[?@.key==42]',
'[{"key":0},{"key":42},{"key":-1},{"key":1},{"key":41},{"key":43},{"key":42.0001},{"key":41.9999},{"' .
'key":100},{"key":"some"},{"key":"42"},{"key":null},{"key":420},{"key":""},{"key":{}},{"key":[]},{"k' .
'ey":[42]},{"key":{"key":42}},{"key":{"some":42}},{"some":"value"}]',
- '' // unknown consensus
+ ''
],
- [ // data set #205
+ [ // data set #205 - unknown consensus, fallback to Proposal A
'filter_expression_without_value',
'$[?(!@.key)]',
'[{"some":"some value"},{"key":true},{"key":false},{"key":null},{"key":"value"},{"key":""},{"key":0}' .
',{"key":1},{"key":-1},{"key":42},{"key":{}},{"key":[]}]',
- '' // unknown consensus
+ '[{"some":"some value"}]'
],
- [ // data set #206
+ [ // data set #206 - unknown consensus
'parens_notation',
'$(key,more)',
'{"key":1,"some":2,"more":3}',
- '' // unknown consensus
+ ''
],
- [ // data set #207
+ [ // data set #207 - unknown consensus
'recursive_descent',
'$..',
'[{"a":{"b":"c"}},[0,1]]',
- '' // unknown consensus
+ ''
],
- [ // data set #208
+ [ // data set #208 - unknown consensus
'recursive_descent_after_dot_notation',
'$.key..',
'{"some key":"value","key":{"complex":"string","primitives":[0,1]}}',
- '' // unknown consensus
+ ''
],
[ // data set #209
'root',
@@ -1442,11 +1449,11 @@ public function queryDataProvider(): array
'true',
'[true]'
],
- [ // data set #213
+ [ // data set #213 - unknown consensus
'script_expression',
'$[(@.length-1)]',
'["first","second","third","forth","fifth"]',
- '' // unknown consensus
+ ''
],
[ // data set #214
'union',
@@ -1454,11 +1461,11 @@ public function queryDataProvider(): array
'["first","second","third"]',
'["first","second"]'
],
- [ // data set #215
+ [ // data set #215 - unknown consensus, fallback to Proposal A
'union_with_filter',
'$[?(@.key<3),?(@.key>6)]',
'[{"key":1},{"key":8},{"key":3},{"key":10},{"key":7},{"key":2},{"key":6},{"key":4}]',
- '' // unknown consensus
+ '[{"key":1},{"key":2},{"key":8},{"key":10},{"key":7}]'
],
[ // data set #216
'union_with_keys',
@@ -1478,18 +1485,18 @@ public function queryDataProvider(): array
'[{"c":"cc1","d":"dd1","e":"ee1"},{"c":"cc2","d":"dd2","e":"ee2"}]',
'["cc1","dd1"]'
],
- [ // data set #219
+ [ // data set #219 - unknown consensus, fallback to Proposal A
'union_with_keys_after_dot_notation_with_wildcard',
'$.*[\'c\',\'d\']',
'[{"c":"cc1","d":"dd1","e":"ee1"},{"c":"cc2","d":"dd2","e":"ee2"}]',
- '' // unknown consensus
+ '["cc1","dd1","cc2","dd2"]'
],
- [ // data set #220
+ [ // data set #220 - unknown consensus, fallback to Proposal A
'union_with_keys_after_recursive_descent',
'$..[\'c\',\'d\']',
'[{"c":"cc1","d":"dd1","e":"ee1"},{"c":"cc2","child":{"d":"dd2"}},{"c":"cc3"},{"d":"dd4"},{"child":{' .
'"c":"cc5"}}]',
- '' // unknown consensus
+ '["cc1","cc2","cc3","cc5","dd1","dd2","dd4"]'
],
[ // data set #221
'union_with_keys_on_object_without_key',
@@ -1503,17 +1510,17 @@ public function queryDataProvider(): array
'[1,2,3,4,5]',
'[5,2]'
],
- [ // data set #223
+ [ // data set #223 - unknown consensus, fallback to Proposal A
'union_with_repeated_matches_after_dot_notation_with_wildcard',
'$.*[0,:5]',
'{"a":["string",null,true],"b":[false,"string",5.4]}',
- '' // unknown consensus
+ '["string","string",null,true,false,false,"string",5.4]'
],
- [ // data set #224
+ [ // data set #224 - unknown consensus, fallback to Proposal A
'union_with_slice_and_number',
'$[1:3,4]',
'[1,2,3,4,5]',
- '' // unknown consensus
+ '[2,3,5]'
],
[ // data set #225
'union_with_spaces',
@@ -1521,12 +1528,12 @@ public function queryDataProvider(): array
'["first","second","third"]',
'["first","second"]'
],
- [ // data set #226
+ [ // data set #226 - unknown consensus, fallback to Proposal A
'union_with_wildcard_and_number',
'$[*,1]',
'["first","second","third","forth","fifth"]',
- '' // unknown consensus
- ]
+ '["first","second","third","forth","fifth","second"]'
+ ],
];
}
}
diff --git a/tests/TestCase.php b/tests/TestCase.php
new file mode 100644
index 0000000..0c8de49
--- /dev/null
+++ b/tests/TestCase.php
@@ -0,0 +1,138 @@
+expectedException = $exception;
+ $this->setExpectedException($exception);
+ }
+
+ /**
+ * @param string $class
+ * @param null|string $message
+ * @param null|int|string $code
+ *
+ * @return void
+ */
+ public function setExpectedException($class, $message = null, $code = null)
+ {
+ if (is_callable('parent::' . __FUNCTION__)) {
+ parent::setExpectedException($class, $message, $code);
+ return;
+ }
+ if (is_callable('parent::expectException')) {
+ $this->expectException($class);
+ }
+ if (null !== $message && is_callable('parent::expectExceptionMessage')) {
+ $this->expectExceptionMessage($message);
+ }
+ if (null !== $code && is_callable('parent::expectExceptionCode')) {
+ $this->expectExceptionCode($code);
+ }
+ }
+
+ /**
+ * @param string $message
+ *
+ * @return void
+ * @throws PHPUnit_Framework_Exception
+ *
+ */
+ public function expectExceptionMessage($message)
+ {
+ if (is_callable('parent::' . __FUNCTION__)) {
+ parent::expectExceptionMessage($message);
+
+ return;
+ }
+
+ if (null === $this->expectedException) {
+ throw new BadMethodCallException('Hmm this is message without class *gg* - reflection?');
+ }
+
+ $this->expectedExceptionMessage = $message;
+ $this->setExpectedException($this->expectedException, $message);
+ }
+
+ /**
+ * @param int|string $code
+ *
+ * @return void
+ * @throws PHPUnit_Framework_Exception
+ *
+ */
+ public function expectExceptionCode($code)
+ {
+ if (is_callable('parent::' . __FUNCTION__)) {
+ parent::expectExceptionCode($code);
+
+ return;
+ }
+
+ if (null === $this->expectedException) {
+ throw new BadMethodCallException('No exception expected');
+ }
+
+ $this->setExpectedException($this->expectedException, $this->expectedExceptionMessage, $code);
+ }
+}
diff --git a/tests/Traits/TestDataTrait.php b/tests/Traits/TestDataTrait.php
index 07026d9..f9ad964 100644
--- a/tests/Traits/TestDataTrait.php
+++ b/tests/Traits/TestDataTrait.php
@@ -6,8 +6,6 @@
* @license https://github.com/SoftCreatR/JSONPath/blob/main/LICENSE MIT License
*/
-declare(strict_types=1);
-
namespace Flow\JSONPath\Test\Traits;
use ArrayAccess;
@@ -18,13 +16,14 @@ trait TestDataTrait
/**
* Returns decoded JSON from a given file either as array or object.
*
+ * @param string $type
* @param bool|int $asArray
*
* @return array|ArrayAccess|null
*/
- protected function getData(string $type, $asArray = true)
+ private function getData($type, $asArray = true)
{
- $filePath = sprintf('%s/data/%s.json', dirname(__DIR__, 1), $type);
+ $filePath = sprintf('%s/data/%s.json', dirname(__DIR__), $type);
if (!file_exists($filePath)) {
throw new RuntimeException("File {$filePath} does not exist.");
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
new file mode 100644
index 0000000..86ba8a4
--- /dev/null
+++ b/tests/bootstrap.php
@@ -0,0 +1,15 @@
+