├── .build-scripts ├── compile-coverage.sh ├── compile.sh └── show-errors.sh ├── .clang-format ├── .github ├── dependabot.yml └── workflows │ ├── build.yml │ ├── clang_format_lint.yml │ ├── code_coverage.yml │ └── windows.yml ├── .gitignore ├── LICENSE ├── Makefile.frag ├── Makefile.gcov ├── README.md ├── benchmark.png ├── composer.json ├── config.m4 ├── config.w32 ├── jsonpath.c ├── jsonpath.php ├── jsonpath.stub.php ├── jsonpath_arginfo.h ├── package.xml ├── php_jsonpath.h ├── pre-commit ├── src └── jsonpath │ ├── exceptions.c │ ├── exceptions.h │ ├── interpreter.c │ ├── interpreter.h │ ├── lexer.c │ ├── lexer.h │ ├── parser.c │ └── parser.h ├── tests ├── 001.phpt ├── 002.phpt ├── 003.phpt ├── 004.phpt ├── 005.phpt ├── 006.phpt ├── 007.phpt ├── 008.phpt ├── 009.phpt ├── 010.phpt ├── 011.phpt ├── 012.phpt ├── 013.phpt ├── 014.phpt ├── 015.phpt ├── 016.phpt ├── 017.phpt ├── 018.phpt ├── 019.phpt ├── 020.phpt ├── 021.phpt ├── 022.phpt ├── 023.phpt ├── 024.phpt ├── 025.phpt ├── 026.phpt ├── bounds_checks │ ├── 002.phpt │ ├── 003.phpt │ └── 004.phpt ├── comparison_array_slice │ ├── 001.phpt │ ├── 002.phpt │ ├── 003.phpt │ ├── 004.phpt │ ├── 005.phpt │ ├── 006.phpt │ ├── 007.phpt │ ├── 008.phpt │ ├── 009.phpt │ ├── 010.phpt │ ├── 011.phpt │ ├── 012.phpt │ ├── 013.phpt │ ├── 014.phpt │ ├── 015.phpt │ ├── 016.phpt │ ├── 017.phpt │ ├── 018.phpt │ ├── 019.phpt │ ├── 020.phpt │ ├── 021.phpt │ ├── 022.phpt │ ├── 023.phpt │ ├── 024.phpt │ ├── 025.phpt │ ├── 026.phpt │ ├── 027.phpt │ ├── 028.phpt │ ├── 029.phpt │ ├── 030.phpt │ ├── 031.phpt │ ├── 032.phpt │ ├── 033.phpt │ ├── 034.phpt │ ├── 035.phpt │ ├── 036.phpt │ ├── 037.phpt │ ├── 038.phpt │ ├── 039.phpt │ ├── 040.phpt │ ├── 041.phpt │ └── 042.phpt ├── comparison_bracket_notation │ ├── 001.phpt │ ├── 002.phpt │ ├── 003.phpt │ ├── 004.phpt │ ├── 005.phpt │ ├── 006.phpt │ ├── 007.phpt │ ├── 008.phpt │ ├── 009.phpt │ ├── 010.phpt │ ├── 011.phpt │ ├── 012.phpt │ ├── 013.phpt │ ├── 014.phpt │ ├── 015.phpt │ ├── 016.phpt │ ├── 017.phpt │ ├── 018.phpt │ ├── 019.phpt │ ├── 020.phpt │ ├── 021.phpt │ ├── 022.phpt │ ├── 023.phpt │ ├── 024.phpt │ ├── 025.phpt │ ├── 026.phpt │ ├── 027.phpt │ ├── 028.phpt │ ├── 029.phpt │ ├── 030.phpt │ ├── 031.phpt │ ├── 032.phpt │ ├── 033.phpt │ ├── 034.phpt │ ├── 035.phpt │ ├── 036.phpt │ ├── 037.phpt │ ├── 038.phpt │ ├── 039.phpt │ ├── 040.phpt │ ├── 041.phpt │ ├── 042.phpt │ ├── 043.phpt │ ├── 044.phpt │ ├── 045.phpt │ └── 046.phpt ├── comparison_dot_notation │ ├── 001.phpt │ ├── 002.phpt │ ├── 003.phpt │ ├── 004.phpt │ ├── 005.phpt │ ├── 006.phpt │ ├── 007.phpt │ ├── 008.phpt │ ├── 009.phpt │ ├── 010.phpt │ ├── 011.phpt │ ├── 012.phpt │ ├── 013.phpt │ ├── 014.phpt │ ├── 015.phpt │ ├── 016.phpt │ ├── 017.phpt │ ├── 018.phpt │ ├── 019.phpt │ ├── 020.phpt │ ├── 021.phpt │ ├── 022.phpt │ ├── 023.phpt │ ├── 024.phpt │ ├── 025.phpt │ ├── 026.phpt │ ├── 027.phpt │ ├── 028.phpt │ ├── 029.phpt │ ├── 030.phpt │ ├── 031.phpt │ ├── 032.phpt │ ├── 033.phpt │ ├── 034.phpt │ ├── 035.phpt │ ├── 036.phpt │ ├── 037.phpt │ ├── 038.phpt │ ├── 039.phpt │ ├── 040.phpt │ ├── 041.phpt │ ├── 042.phpt │ ├── 043.phpt │ ├── 044.phpt │ ├── 045.phpt │ ├── 046.phpt │ ├── 047.phpt │ ├── 048.phpt │ ├── 049.phpt │ └── 050.phpt ├── comparison_filter │ ├── 001.phpt │ ├── 002.phpt │ ├── 003.phpt │ ├── 004.phpt │ ├── 005.phpt │ ├── 006.phpt │ ├── 007.phpt │ ├── 008.phpt │ ├── 009.phpt │ ├── 010.phpt │ ├── 011.phpt │ ├── 012.phpt │ ├── 013.phpt │ ├── 014.phpt │ ├── 015.phpt │ ├── 016.phpt │ ├── 017.phpt │ ├── 018.phpt │ ├── 019.phpt │ ├── 020.phpt │ ├── 021.phpt │ ├── 022.phpt │ ├── 023.phpt │ ├── 024.phpt │ ├── 025.phpt │ ├── 026.phpt │ ├── 027.phpt │ ├── 028.phpt │ ├── 029.phpt │ ├── 030.phpt │ ├── 031.phpt │ ├── 032.phpt │ ├── 033.phpt │ ├── 034.phpt │ ├── 035.phpt │ ├── 036.phpt │ ├── 037.phpt │ ├── 038.phpt │ ├── 039.phpt │ ├── 040.phpt │ ├── 041.phpt │ ├── 042.phpt │ ├── 043.phpt │ ├── 044.phpt │ ├── 045.phpt │ ├── 046.phpt │ ├── 047.phpt │ ├── 048.phpt │ ├── 049.phpt │ ├── 050.phpt │ ├── 051.phpt │ ├── 052.phpt │ ├── 053.phpt │ ├── 054.phpt │ ├── 055.phpt │ ├── 056.phpt │ ├── 057.phpt │ ├── 058.phpt │ ├── 059.phpt │ ├── 060.phpt │ ├── 061.phpt │ ├── 062.phpt │ ├── 063.phpt │ ├── 064.phpt │ ├── 065.phpt │ ├── 066.phpt │ ├── 067.phpt │ ├── 068.phpt │ ├── 069.phpt │ ├── 070.phpt │ ├── 071.phpt │ ├── 072.phpt │ ├── 073.phpt │ ├── 074.phpt │ └── 075.phpt ├── comparison_misc │ ├── 001.phpt │ ├── 002.phpt │ └── 003.phpt ├── comparison_recursive_descent │ ├── 001.phpt │ └── 002.phpt ├── comparison_root │ ├── 001.phpt │ ├── 002.phpt │ ├── 003.phpt │ └── 004.phpt ├── comparison_union │ ├── 001.phpt │ ├── 002.phpt │ ├── 003.phpt │ ├── 004.phpt │ ├── 005.phpt │ ├── 006.phpt │ ├── 007.phpt │ ├── 008.phpt │ ├── 009.phpt │ ├── 010.phpt │ ├── 011.phpt │ ├── 012.phpt │ ├── 013.phpt │ ├── 014.phpt │ └── 015.phpt ├── expressions │ ├── 001.phpt │ ├── 002.phpt │ └── 003.phpt ├── extension_info │ ├── 001.phpt │ ├── 002.phpt │ └── 003.phpt ├── isset │ ├── 001.phpt │ ├── 002.phpt │ └── 003.phpt ├── issue_27 │ └── 001.phpt ├── issues │ ├── 00143.phpt │ ├── 00145.phpt │ ├── 00146-1.phpt │ ├── 00146-2.phpt │ ├── 00156.phpt │ ├── 00158.phpt │ └── 00164.phpt ├── lex_errs │ ├── 001.phpt │ ├── 002.phpt │ ├── 004.phpt │ └── 005.phpt ├── parse_errs │ ├── 001.phpt │ └── 002.phpt ├── references │ ├── 001.phpt │ ├── 002.phpt │ ├── 003.phpt │ ├── 004.phpt │ ├── 005.phpt │ └── 006.phpt ├── regex │ ├── 001.phpt │ ├── 002.phpt │ ├── 003.phpt │ └── 004.phpt └── utils │ └── sort_recursively.php └── tools └── build-packagexml.php /.build-scripts/compile-coverage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | phpize 3 | ./configure --enable-jsonpath --enable-code-coverage 4 | make 5 | -------------------------------------------------------------------------------- /.build-scripts/compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | phpize 3 | ./configure --enable-jsonpath 4 | make 5 | -------------------------------------------------------------------------------- /.build-scripts/show-errors.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | for i in tests/*.diff tests/*/*.diff; do 4 | echo "==========================================================================" 5 | echo $i 6 | echo "--------------------------------------------------------------------------" 7 | cat $i 8 | echo "==========================================================================" 9 | echo 10 | done 11 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | # Maintain dependencies for GitHub Actions 4 | - package-ecosystem: "github-actions" 5 | directory: "/" 6 | schedule: 7 | interval: weekly 8 | open-pull-requests-limit: 5 9 | -------------------------------------------------------------------------------- /.github/workflows/clang_format_lint.yml: -------------------------------------------------------------------------------- 1 | name: Run lint check with clang-format 2 | 3 | on: 4 | push: 5 | 6 | jobs: 7 | build: 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - name: Checkout jsonpath 12 | uses: actions/checkout@v4 13 | 14 | - name: Perform linting 15 | uses: DoozyX/clang-format-lint-action@v0.20 16 | with: 17 | source: './jsonpath.c ./php_jsonpath.h ./src/jsonpath' 18 | extensions: 'c,h' 19 | clangFormatVersion: 12 20 | -------------------------------------------------------------------------------- /.github/workflows/windows.yml: -------------------------------------------------------------------------------- 1 | name: Build and test on Windows 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | release: 8 | types: [ created ] 9 | 10 | jobs: 11 | tests: 12 | runs-on: windows-2022 13 | name: Build and test 14 | defaults: 15 | run: 16 | shell: cmd 17 | strategy: 18 | matrix: 19 | version: [ "8.0", "8.1", "8.2", "8.3", "8.4" ] 20 | arch: [ "x64" ] 21 | ts: [ "ts" ] 22 | steps: 23 | - name: Checkout jsonpath 24 | uses: actions/checkout@v4 25 | 26 | - name: Setup PHP 27 | id: setup-php 28 | uses: php/setup-php-sdk@v0.10 29 | with: 30 | version: ${{matrix.version}} 31 | arch: ${{matrix.arch}} 32 | ts: ${{matrix.ts}} 33 | cache: true 34 | 35 | - name: Enable Developer Command Prompt 36 | uses: ilammy/msvc-dev-cmd@v1 37 | with: 38 | arch: ${{matrix.arch}} 39 | toolset: ${{steps.setup-php.outputs.toolset}} 40 | 41 | - name: Run phpize for jsonpath 42 | run: phpize 43 | 44 | - name: Run configure for jsonpath 45 | run: configure --enable-jsonpath --with-prefix=${{steps.setup-php.outputs.prefix}} 46 | 47 | - name: Compile jsonpath 48 | run: nmake 49 | 50 | - name: Run jsonpath tests 51 | run: nmake test TESTS="-j2 --show-diff -g FAIL,BORK,WARN,LEAK tests" 52 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Build 2 | .deps 3 | *.dep 4 | *.lo 5 | *.la 6 | .libs 7 | acinclude.m4 8 | aclocal.m4 9 | autom4te.cache 10 | build 11 | config.guess 12 | config.h 13 | config.h.in 14 | config.log 15 | config.nice 16 | config.status 17 | config.sub 18 | configure 19 | configure.ac 20 | configure.in 21 | include 22 | install-sh 23 | libtool 24 | ltmain.sh 25 | Makefile 26 | Makefile.fragments 27 | Makefile.global 28 | Makefile.objects 29 | missing 30 | mkinstalldirs 31 | modules 32 | 33 | # Project 34 | .idea/ 35 | 36 | # Tests 37 | run-tests.php 38 | tests/*/*.diff 39 | tests/*/*.out 40 | tests/*/*.php 41 | tests/*/*.exp 42 | tests/*/*.log 43 | tests/*/*.sh 44 | !tests/utils/*.php 45 | 46 | # Code coverage 47 | jsonpath_lcov.info 48 | lcov_html/ 49 | -------------------------------------------------------------------------------- /Makefile.frag: -------------------------------------------------------------------------------- 1 | format_files=jsonpath.c \ 2 | php_jsonpath.h \ 3 | src/jsonpath/*.{c,h} \ 4 | 5 | findphp: 6 | @echo $(PHP_EXECUTABLE) 7 | 8 | format-check: 9 | @clang-format --dry-run -Werror $(format_files) 10 | 11 | format-code: 12 | @clang-format -i $(format_files) 13 | 14 | lint-code: 15 | @cppcheck --enable=all --error-exitcode=1 --std=c89 --suppress=missingInclude $(format_files) 16 | 17 | release: php_$(PHP_PECL_EXTENSION).h 18 | @php ./tools/build-packagexml.php 19 | 20 | setup-pre-commit: 21 | @ln -s ../../pre-commit .git/hooks 22 | 23 | -------------------------------------------------------------------------------- /Makefile.gcov: -------------------------------------------------------------------------------- 1 | # 2 | # GCOV 3 | # 4 | 5 | LTP = lcov 6 | LTP_GENHTML = genhtml 7 | 8 | lcov: lcov-html 9 | 10 | jsonpath_lcov.info: 11 | @echo "Generating lcov data for $@" 12 | $(LTP) --capture --no-external --directory . --output-file $@ 13 | 14 | lcov-html: jsonpath_lcov.info 15 | @echo "Generating lcov HTML" 16 | $(LTP_GENHTML) --legend --output-directory lcov_html/ --title "JSONPath PHP extension code coverage" jsonpath_lcov.info 17 | 18 | lcov-summary: jsonpath_lcov.info 19 | $(LTP) --summary jsonpath_lcov.info 20 | 21 | lcov-clean: 22 | rm -f jsonpath_lcov.info 23 | rm -rf lcov_html/ 24 | 25 | lcov-clean-data: 26 | @find . -name \*.gcda -o -name \*.da -o -name \*.bbg? | xargs rm -f 27 | 28 | gcovr-html: 29 | @echo "Generating gcovr HTML" 30 | @rm -rf gcovr_html/ 31 | @mkdir gcovr_html 32 | gcovr -sr . -o gcovr_html/index.html --html --html-details 33 | 34 | gcovr-xml: 35 | @echo "Generating gcovr XML" 36 | @rm -f gcovr.xml 37 | gcovr -sr . -o gcovr.xml --xml 38 | 39 | .PHONY: gcovr-html lcov-html jsonpath_lcov.info 40 | -------------------------------------------------------------------------------- /benchmark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supermetrics-public/pecl-jsonpath/1a85a9f5a57a2db7860076d9eed8bdc4a7e83997/benchmark.png -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "supermetrics/jsonpath", 3 | "type": "php-ext", 4 | "license": "PHP-3.01", 5 | "description": "Extract data from a decoded JSON document using the versatile JSONPath query language", 6 | "require": { 7 | "php": ">=8.0,<8.5" 8 | }, 9 | "php-ext": { 10 | "extension-name": "jsonpath", 11 | "priority": 80, 12 | "configure-options": [ 13 | { 14 | "name": "enable-jsonpath", 15 | "description": "Whether to enable JSONPath support", 16 | "needs-value": false 17 | }, 18 | { 19 | "name": "enable-code-coverage", 20 | "description": "Whether to enable code coverage (relevant for extension development only!)", 21 | "needs-value": false 22 | } 23 | ] 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /config.w32: -------------------------------------------------------------------------------- 1 | ARG_ENABLE('jsonpath', 'enable JSONPath support', 'no'); 2 | 3 | if (PHP_JSONPATH != 'no') { 4 | AC_DEFINE('HAVE_JSONPATH', 1, 'JSONPath support enabled') 5 | EXTENSION('jsonpath', 'jsonpath.c', null, '/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1'); 6 | ADD_SOURCES(configure_module_dirname + '/src/jsonpath', 'exceptions.c lexer.c parser.c interpreter.c', 'jsonpath'); 7 | } 8 | -------------------------------------------------------------------------------- /jsonpath.php: -------------------------------------------------------------------------------- 1 | "; 3 | 4 | if(!extension_loaded('jsonpath')) { 5 | dl('jsonpath.' . PHP_SHLIB_SUFFIX); 6 | } 7 | $module = 'jsonpath'; 8 | $functions = get_extension_funcs($module); 9 | echo "Functions available in the test extension:$br\n"; 10 | foreach($functions as $func) { 11 | echo $func."$br\n"; 12 | } 13 | echo "$br\n"; 14 | $function = 'confirm_' . $module . '_compiled'; 15 | if (extension_loaded($module)) { 16 | $str = $function($module); 17 | } else { 18 | $str = "Module $module is not compiled into PHP"; 19 | } 20 | echo "$str\n"; 21 | ?> 22 | -------------------------------------------------------------------------------- /jsonpath.stub.php: -------------------------------------------------------------------------------- 1 | 4 | 5 | #include "ext/spl/spl_exceptions.h" 6 | #include "zend_exceptions.h" 7 | 8 | extern zend_class_entry *jsonpath_exception_ce; 9 | 10 | void throw_jsonpath_exception(const char *msg, ...) { 11 | va_list args; 12 | char *formatted_msg = NULL; 13 | 14 | va_start(args, msg); 15 | zend_vspprintf(&formatted_msg, 0, msg, args); 16 | zend_throw_exception(jsonpath_exception_ce, formatted_msg, 0); 17 | efree(formatted_msg); 18 | va_end(args); 19 | } 20 | -------------------------------------------------------------------------------- /src/jsonpath/exceptions.h: -------------------------------------------------------------------------------- 1 | #ifndef JSONPATH_EXCEPTIONS_H 2 | #define JSONPATH_EXCEPTIONS_H 1 3 | 4 | void throw_jsonpath_exception(const char* msg, ...); 5 | 6 | #endif /* JSONPATH_EXCEPTIONS_H */ 7 | -------------------------------------------------------------------------------- /src/jsonpath/interpreter.h: -------------------------------------------------------------------------------- 1 | #ifndef INTERPRETER_H 2 | #define INTERPRETER_H 1 3 | 4 | #include "parser.h" 5 | #include "php.h" 6 | 7 | void eval_ast(zval* arr_head, zval* arr_cur, struct ast_node* tok, zval* return_value); 8 | 9 | #endif /* INTERPRETER_H */ -------------------------------------------------------------------------------- /tests/003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test typical use cases 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 1234, 12 | 'name' => 'just a name', 13 | 'source' => null, 14 | 'source2' => array( 15 | 'child1' => null 16 | ) 17 | ); 18 | 19 | echo "Assertion 1\n"; 20 | var_dump($jsonPath->find($obj, '$.source.id')); 21 | echo "Assertion 2\n"; 22 | var_dump($jsonPath->find($obj, '$.source2.child1.id')); 23 | --EXPECT-- 24 | Assertion 1 25 | bool(false) 26 | Assertion 2 27 | bool(false) 28 | -------------------------------------------------------------------------------- /tests/005.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Ensure no segfault if filtering on object instead of array 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | array( 12 | 'val' => 0 13 | ) 14 | ); 15 | 16 | 17 | var_dump($jsonPath->find($obj, '$.test[?(@.vals == 0)]')); 18 | --EXPECT-- 19 | bool(false) 20 | -------------------------------------------------------------------------------- /tests/006.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Ensure no "Array to string conversion" notice when selecting non-scalar 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | array( 12 | array( 13 | 'val' => array(1) 14 | ) 15 | ) 16 | ); 17 | 18 | 19 | var_dump($jsonPath->find($obj, '$.test[?(@.val == 0)]')); 20 | --EXPECT-- 21 | bool(false) 22 | -------------------------------------------------------------------------------- /tests/007.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Testing <= operator 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | array( 12 | array ( 13 | 'id' => 1, 14 | 'val' => 10, 15 | 'val_str' => "table" 16 | ), 17 | ) 18 | ); 19 | 20 | var_dump($jsonPath->find($obj, '$.test[?(@.val <= 11)]')); 21 | --EXPECT-- 22 | array(1) { 23 | [0]=> 24 | array(3) { 25 | ["id"]=> 26 | int(1) 27 | ["val"]=> 28 | int(10) 29 | ["val_str"]=> 30 | string(5) "table" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/008.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Testing <= operator 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | array( 12 | array ( 13 | 'id' => 1, 14 | 'val' => 11, 15 | 'val_str' => "table" 16 | ), 17 | ) 18 | ); 19 | 20 | var_dump($jsonPath->find($obj, '$.test[?(@.val <= 11)]')); 21 | --EXPECT-- 22 | array(1) { 23 | [0]=> 24 | array(3) { 25 | ["id"]=> 26 | int(1) 27 | ["val"]=> 28 | int(11) 29 | ["val_str"]=> 30 | string(5) "table" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/009.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Testing <= operator 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | array( 12 | array ( 13 | 'id' => 1, 14 | 'val' => 12, 15 | 'val_str' => "table" 16 | ), 17 | ) 18 | ); 19 | 20 | var_dump($jsonPath->find($obj, '$.test[?(@.val <= 11)]')); 21 | --EXPECT-- 22 | bool(false) 23 | -------------------------------------------------------------------------------- /tests/010.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Testing >= operator 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | array( 12 | array ( 13 | 'id' => 1, 14 | 'val' => 12, 15 | 'val_str' => "table" 16 | ), 17 | ) 18 | ); 19 | 20 | var_dump($jsonPath->find($obj, '$.test[?(@.val >= 11)]')); 21 | --EXPECT-- 22 | array(1) { 23 | [0]=> 24 | array(3) { 25 | ["id"]=> 26 | int(1) 27 | ["val"]=> 28 | int(12) 29 | ["val_str"]=> 30 | string(5) "table" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/011.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Testing >= operator 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | array( 12 | array ( 13 | 'id' => 1, 14 | 'val' => 11, 15 | 'val_str' => "table" 16 | ), 17 | ) 18 | ); 19 | 20 | var_dump($jsonPath->find($obj, '$.test[?(@.val >= 11)]')); 21 | --EXPECT-- 22 | array(1) { 23 | [0]=> 24 | array(3) { 25 | ["id"]=> 26 | int(1) 27 | ["val"]=> 28 | int(11) 29 | ["val_str"]=> 30 | string(5) "table" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/012.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Testing >= operator 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | array( 12 | array ( 13 | 'id' => 1, 14 | 'val' => 10, 15 | 'val_str' => "table" 16 | ), 17 | ) 18 | ); 19 | 20 | var_dump($jsonPath->find($obj, '$.test[?(@.val >= 11)]')); 21 | --EXPECT-- 22 | bool(false) 23 | -------------------------------------------------------------------------------- /tests/013.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Testing != operator 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | array( 12 | array ( 13 | 'id' => 1, 14 | 'val' => 10, 15 | 'val_str' => "table" 16 | ), 17 | ) 18 | ); 19 | 20 | var_dump($jsonPath->find($obj, '$.test[?(@.val != 10)]')); 21 | --EXPECT-- 22 | bool(false) 23 | -------------------------------------------------------------------------------- /tests/014.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Testing != operator 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | array( 12 | array ( 13 | 'id' => 1, 14 | 'val' => 11, 15 | 'val_str' => "table" 16 | ), 17 | ) 18 | ); 19 | 20 | var_dump($jsonPath->find($obj, '$.test[?(@.val != 12)]')); 21 | --EXPECT-- 22 | array(1) { 23 | [0]=> 24 | array(3) { 25 | ["id"]=> 26 | int(1) 27 | ["val"]=> 28 | int(11) 29 | ["val_str"]=> 30 | string(5) "table" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/015.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with strings as start, end, and step 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 12 | 'soggy', 13 | 'minor', 14 | 'elated', 15 | 'unnatural', 16 | 'grubby', 17 | 'fabulous', 18 | 'parsimonious', 19 | 'cheerful', 20 | 'unadvised', 21 | 'simplistic', 22 | ], 23 | ]; 24 | 25 | $jsonPath = new \JsonPath\JsonPath(); 26 | $result = $jsonPath->find($data, "$.words['first':'last':'two']"); 27 | 28 | var_dump($result); 29 | ?> 30 | --EXPECTF-- 31 | Fatal error: Uncaught JsonPath\JsonPathException: Expected slice separator `:` or integer, got LEX_LITERAL in slice union filter in %s 32 | Stack trace: 33 | %s 34 | %s 35 | %s 36 | -------------------------------------------------------------------------------- /tests/016.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with unquoted strings as start, end, and step 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 12 | 'soggy', 13 | 'minor', 14 | 'elated', 15 | 'unnatural', 16 | 'grubby', 17 | 'fabulous', 18 | 'parsimonious', 19 | 'cheerful', 20 | 'unadvised', 21 | 'simplistic', 22 | ], 23 | ]; 24 | 25 | $jsonPath = new \JsonPath\JsonPath(); 26 | $result = $jsonPath->find($data, "$.words[first:last:two]"); 27 | 28 | var_dump($result); 29 | ?> 30 | --EXPECTF-- 31 | Fatal error: Uncaught JsonPath\JsonPathException: Unrecognized token `l` at position 14 in %s 32 | Stack trace: 33 | %s 34 | %s 35 | %s 36 | -------------------------------------------------------------------------------- /tests/017.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with mix of unquoted string and numbers as start, end, and step 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 12 | 'soggy', 13 | 'minor', 14 | 'elated', 15 | 'unnatural', 16 | 'grubby', 17 | 'fabulous', 18 | 'parsimonious', 19 | 'cheerful', 20 | 'unadvised', 21 | 'simplistic', 22 | ], 23 | ]; 24 | 25 | $jsonPath = new \JsonPath\JsonPath(); 26 | $result = $jsonPath->find($data, "$.words[first:-1:2]"); 27 | 28 | var_dump($result); 29 | ?> 30 | --EXPECTF-- 31 | Fatal error: Uncaught JsonPath\JsonPathException: Unexpected filter element in %s 32 | Stack trace: 33 | %s 34 | %s 35 | %s 36 | -------------------------------------------------------------------------------- /tests/018.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with wildcard as end 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 12 | 'soggy', 13 | 'minor', 14 | 'elated', 15 | 'unnatural', 16 | 'grubby', 17 | 'fabulous', 18 | 'parsimonious', 19 | 'cheerful', 20 | 'unadvised', 21 | 'simplistic', 22 | ], 23 | ]; 24 | 25 | $jsonPath = new \JsonPath\JsonPath(); 26 | $result = $jsonPath->find($data, "$.words[0:*:2]"); 27 | 28 | var_dump($result); 29 | ?> 30 | --EXPECTF-- 31 | Fatal error: Uncaught JsonPath\JsonPathException: Unrecognized token `*` at position 10 in %s 32 | Stack trace: 33 | %s 34 | %s 35 | %s 36 | -------------------------------------------------------------------------------- /tests/019.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test broken boolean as right-hand operand 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 12 | [ 13 | 'isAdjective' => true, 14 | 'value' => 'soggy', 15 | ], 16 | [ 17 | 'isAdjective' => true, 18 | 'value' => 'minor', 19 | ], 20 | [ 21 | 'isAdjective' => true, 22 | 'value' => 'elated', 23 | ], 24 | [ 25 | 'isAdjective' => true, 26 | 'value' => 'unnatural', 27 | ], 28 | [ 29 | 'isAdjective' => true, 30 | 'value' => 'grubby', 31 | ], 32 | ], 33 | ]; 34 | 35 | $jsonPath = new \JsonPath\JsonPath(); 36 | $result = $jsonPath->find($data, "$.words[?(@.isAdjective == truse)]"); 37 | 38 | var_dump($result); 39 | ?> 40 | --EXPECTF-- 41 | Fatal error: Uncaught JsonPath\JsonPathException: Expected `true` or `false` for boolean token in %s 42 | Stack trace: 43 | %s 44 | %s 45 | %s 46 | -------------------------------------------------------------------------------- /tests/020.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test broken boolean as left-hand operand 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 12 | [ 13 | 'isAdjective' => true, 14 | 'value' => 'soggy', 15 | ], 16 | [ 17 | 'isAdjective' => true, 18 | 'value' => 'minor', 19 | ], 20 | [ 21 | 'isAdjective' => true, 22 | 'value' => 'elated', 23 | ], 24 | [ 25 | 'isAdjective' => true, 26 | 'value' => 'unnatural', 27 | ], 28 | [ 29 | 'isAdjective' => true, 30 | 'value' => 'grubby', 31 | ], 32 | ], 33 | ]; 34 | 35 | $jsonPath = new \JsonPath\JsonPath(); 36 | $result = $jsonPath->find($data, "$.words[?(falsue == @.isAdjective)]"); 37 | 38 | var_dump($result); 39 | ?> 40 | --EXPECTF-- 41 | Fatal error: Uncaught JsonPath\JsonPathException: Expected `true` or `false` for boolean token in %s 42 | Stack trace: 43 | %s 44 | %s 45 | %s 46 | -------------------------------------------------------------------------------- /tests/021.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot selector with misplaced current node operator 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 12 | [ 13 | 'type' => 'adjective', 14 | 'value' => 'soggy', 15 | ], 16 | [ 17 | 'type' => 'adjective', 18 | 'value' => 'minor', 19 | ], 20 | [ 21 | 'type' => 'adjective', 22 | 'value' => 'elated', 23 | ], 24 | [ 25 | 'type' => 'adjective', 26 | 'value' => 'unnatural', 27 | ], 28 | [ 29 | 'type' => 'adjective', 30 | 'value' => 'grubby', 31 | ], 32 | ], 33 | ]; 34 | 35 | $jsonPath = new \JsonPath\JsonPath(); 36 | $result = $jsonPath->find($data, "$.words.@"); 37 | 38 | var_dump($result); 39 | ?> 40 | --EXPECTF-- 41 | Fatal error: Uncaught JsonPath\JsonPathException: Expecting child node, filter, expression, or recursive node in %s 42 | Stack trace: 43 | %s 44 | %s 45 | %s 46 | -------------------------------------------------------------------------------- /tests/022.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with unsupported operand (int array) 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 11 | "100", 12 | "200", 13 | ], 14 | ], 15 | [ 16 | "d" => [ 17 | "a", 18 | "b", 19 | ], 20 | ], 21 | [ 22 | "d" => "v1", 23 | ], 24 | [ 25 | "d" => "v2", 26 | ], 27 | [ 28 | "d" => [ 29 | ], 30 | ], 31 | [ 32 | "d" => [ 33 | ], 34 | ], 35 | [ 36 | "d" => null, 37 | ], 38 | [ 39 | "d" => -1, 40 | ], 41 | [ 42 | "d" => 0, 43 | ], 44 | [ 45 | "d" => 1, 46 | ], 47 | [ 48 | "d" => "['v1','v2']", 49 | ], 50 | [ 51 | "d" => "['v1', 'v2']", 52 | ], 53 | [ 54 | "d" => "v1,v2", 55 | ], 56 | [ 57 | "d" => "[\"v1\", \"v2\"]", 58 | ], 59 | [ 60 | "d" => "[\"v1\",\"v2\"]", 61 | ], 62 | ]; 63 | 64 | $jsonPath = new \JsonPath\JsonPath(); 65 | $result = $jsonPath->find($data, '$[?(@.d==[100,200])]'); 66 | 67 | var_dump($result); 68 | ?> 69 | --EXPECTF-- 70 | Fatal error: Uncaught JsonPath\JsonPathException: Unsupported expression operand in %s 71 | Stack trace: 72 | %s 73 | %s 74 | %s -------------------------------------------------------------------------------- /tests/023.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with regular expression that contains escaped slash 3 | --SKIPIF-- 4 | 5 | --INI-- 6 | pcre.jit=0 7 | --FILE-- 8 | "hello world", 13 | ], 14 | [ 15 | "name" => "yes hello/ world", 16 | ], 17 | [ 18 | "name" => "HELLO WORLD", 19 | ], 20 | [ 21 | "name" => "good bye", 22 | ], 23 | ]; 24 | 25 | $jsonPath = new \JsonPath\JsonPath(); 26 | $result = $jsonPath->find($data, "$[?(@.name=~/hello\/.*/)]"); 27 | 28 | var_dump($result); 29 | ?> 30 | --EXPECT-- 31 | array(1) { 32 | [0]=> 33 | array(1) { 34 | ["name"]=> 35 | string(16) "yes hello/ world" 36 | } 37 | } -------------------------------------------------------------------------------- /tests/bounds_checks/002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Ensure queries that contain more than LEX_TOK_ARR_LEN tokens safely fail 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find([], '$.1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.52.53.54.55.56.57.58.59.60.61.62.63.64.65')); 16 | } catch (JsonPathException $e) { 17 | echo get_class($e) . ": " . $e->getMessage(); 18 | } 19 | --EXPECT-- 20 | JsonPath\JsonPathException: The query is too long, token count exceeds maximum amount (64) 21 | -------------------------------------------------------------------------------- /tests/bounds_checks/003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with overflowing values for start, end, and stop 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 12 | 'soggy', 13 | 'minor', 14 | 'elated', 15 | 'unnatural', 16 | 'grubby', 17 | 'fabulous', 18 | 'parsimonious', 19 | 'cheerful', 20 | 'unadvised', 21 | 'simplistic', 22 | ], 23 | ]; 24 | 25 | $jsonPath = new \JsonPath\JsonPath(); 26 | $result = $jsonPath->find($data, "$.words[9223372036854775808:9223372036854775809:9223372036854775810]"); 27 | 28 | var_dump($result); 29 | ?> 30 | --EXPECTF-- 31 | Fatal error: Uncaught JsonPath\JsonPathException: Unable to parse filter index value in %s 32 | Stack trace: 33 | %s 34 | %s 35 | %s 36 | -------------------------------------------------------------------------------- /tests/bounds_checks/004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter with overflowing operand 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 12 | [ 13 | 'occurrences' => 647812, 14 | 'value' => 'soggy', 15 | ], 16 | [ 17 | 'occurrences' => 214216781, 18 | 'value' => 'minor', 19 | ], 20 | [ 21 | 'occurrences' => 1426, 22 | 'value' => 'elated', 23 | ], 24 | [ 25 | 'occurrences' => 126781, 26 | 'value' => 'unnatural', 27 | ], 28 | [ 29 | 'occurrences' => 972840012, 30 | 'value' => 'grubby', 31 | ], 32 | ], 33 | ]; 34 | 35 | $jsonPath = new \JsonPath\JsonPath(); 36 | $result = $jsonPath->find($data, "$.words[?($.occurrences > 9223372036854775808)]"); 37 | 38 | var_dump($result); 39 | ?> 40 | --EXPECTF-- 41 | Fatal error: Uncaught JsonPath\JsonPathException: Unable to parse numeric in %s 42 | Stack trace: 43 | %s 44 | %s 45 | %s 46 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[1:3]'); 18 | 19 | var_dump($result); 20 | ?> 21 | --EXPECT-- 22 | array(2) { 23 | [0]=> 24 | string(6) "second" 25 | [1]=> 26 | string(5) "third" 27 | } 28 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice on exact match 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[0:5]'); 18 | 19 | var_dump($result); 20 | ?> 21 | --EXPECT-- 22 | array(5) { 23 | [0]=> 24 | string(5) "first" 25 | [1]=> 26 | string(6) "second" 27 | [2]=> 28 | string(5) "third" 29 | [3]=> 30 | string(5) "forth" 31 | [4]=> 32 | string(5) "fifth" 33 | } 34 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice on non overlapping array 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[7:10]'); 16 | 17 | var_dump($result); 18 | ?> 19 | --EXPECT-- 20 | bool(false) 21 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice on object 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 42, 10 | "more" => "string", 11 | "a" => 1, 12 | "b" => 2, 13 | "c" => 3, 14 | "1:3" => "nice", 15 | ]; 16 | 17 | $jsonPath = new \JsonPath\JsonPath(); 18 | $result = $jsonPath->find($data, '$[1:3]'); 19 | 20 | var_dump($result); 21 | ?> 22 | --EXPECT-- 23 | bool(false) 24 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/005.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice on partially overlapping array 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[1:10]'); 16 | 17 | var_dump($result); 18 | ?> 19 | --EXPECT-- 20 | array(2) { 21 | [0]=> 22 | string(6) "second" 23 | [1]=> 24 | string(5) "third" 25 | } 26 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/006.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with large number for end 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[2:113667776004]'); 18 | 19 | var_dump($result); 20 | ?> 21 | --EXPECT-- 22 | array(3) { 23 | [0]=> 24 | string(5) "third" 25 | [1]=> 26 | string(5) "forth" 27 | [2]=> 28 | string(5) "fifth" 29 | } 30 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/007.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with large number for end and negative step 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[2:-113667776004:-1]'); 18 | 19 | var_dump($result); 20 | ?> 21 | --EXPECT-- 22 | array(3) { 23 | [0]=> 24 | string(5) "third" 25 | [1]=> 26 | string(6) "second" 27 | [2]=> 28 | string(5) "first" 29 | } 30 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/008.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with large number for start 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[-113667776004:2]'); 18 | 19 | var_dump($result); 20 | ?> 21 | --EXPECT-- 22 | array(2) { 23 | [0]=> 24 | string(5) "first" 25 | [1]=> 26 | string(6) "second" 27 | } 28 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/009.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with large number for start end negative step 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[113667776004:2:-1]'); 18 | 19 | var_dump($result); 20 | ?> 21 | --EXPECT-- 22 | array(2) { 23 | [0]=> 24 | string(5) "fifth" 25 | [1]=> 26 | string(5) "forth" 27 | } 28 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/010.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with negative start and end and range of -1 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[-4:-5]'); 19 | 20 | var_dump($result); 21 | ?> 22 | --EXPECT-- 23 | bool(false) 24 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/011.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with negative start and end and range of 0 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[-4:-4]'); 19 | 20 | var_dump($result); 21 | ?> 22 | --EXPECT-- 23 | bool(false) 24 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/012.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with negative start and end and range of 1 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[-4:-3]'); 19 | 20 | var_dump($result); 21 | ?> 22 | --EXPECT-- 23 | array(1) { 24 | [0]=> 25 | int(4) 26 | } 27 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/013.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with negative start and positive end and range of -1 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[-4:1]'); 19 | 20 | var_dump($result); 21 | ?> 22 | --EXPECT-- 23 | bool(false) 24 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/014.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with negative start and positive end and range of 0 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[-4:2]'); 19 | 20 | var_dump($result); 21 | ?> 22 | --EXPECT-- 23 | bool(false) 24 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/015.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with negative start and positive end and range of 1 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[-4:3]'); 19 | 20 | var_dump($result); 21 | ?> 22 | --EXPECT-- 23 | array(1) { 24 | [0]=> 25 | int(4) 26 | } 27 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/016.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with negative step 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[3:0:-2]'); 18 | 19 | var_dump($result); 20 | ?> 21 | --EXPECT-- 22 | array(2) { 23 | [0]=> 24 | string(5) "forth" 25 | [1]=> 26 | string(6) "second" 27 | } 28 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/017.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with negative step on partially overlapping array 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[7:3:-1]'); 18 | 19 | var_dump($result); 20 | ?> 21 | --EXPECT-- 22 | array(1) { 23 | [0]=> 24 | string(5) "fifth" 25 | } 26 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/018.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with negative step and start greater than end 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[0:3:-2]'); 18 | 19 | var_dump($result); 20 | ?> 21 | --EXPECT-- 22 | bool(false) 23 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/019.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with negative step only 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[::-2]'); 18 | 19 | var_dump($result); 20 | ?> 21 | --EXPECT-- 22 | array(3) { 23 | [0]=> 24 | string(5) "fifth" 25 | [1]=> 26 | string(5) "third" 27 | [2]=> 28 | string(5) "first" 29 | } 30 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/020.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with open end 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[1:]'); 18 | 19 | var_dump($result); 20 | ?> 21 | --EXPECT-- 22 | array(4) { 23 | [0]=> 24 | string(6) "second" 25 | [1]=> 26 | string(5) "third" 27 | [2]=> 28 | string(5) "forth" 29 | [3]=> 30 | string(5) "fifth" 31 | } 32 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/021.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with open end and negative step 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[3::-1]'); 18 | 19 | var_dump($result); 20 | ?> 21 | --EXPECT-- 22 | array(4) { 23 | [0]=> 24 | string(5) "forth" 25 | [1]=> 26 | string(5) "third" 27 | [2]=> 28 | string(6) "second" 29 | [3]=> 30 | string(5) "first" 31 | } 32 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/022.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with open start 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[:2]'); 18 | 19 | var_dump($result); 20 | ?> 21 | --EXPECT-- 22 | array(2) { 23 | [0]=> 24 | string(5) "first" 25 | [1]=> 26 | string(6) "second" 27 | } 28 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/023.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with open start and end 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[:]'); 15 | 16 | var_dump($result); 17 | ?> 18 | --EXPECT-- 19 | array(2) { 20 | [0]=> 21 | string(5) "first" 22 | [1]=> 23 | string(6) "second" 24 | } 25 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/024.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with open start and end on object 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 42, 10 | "more" => "string", 11 | ]; 12 | 13 | $jsonPath = new \JsonPath\JsonPath(); 14 | $result = $jsonPath->find($data, '$[:]'); 15 | 16 | var_dump($result); 17 | ?> 18 | --EXPECT-- 19 | bool(false) 20 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/025.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with open start and end and step empty 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[::]'); 15 | 16 | var_dump($result); 17 | ?> 18 | --EXPECT-- 19 | array(2) { 20 | [0]=> 21 | string(5) "first" 22 | [1]=> 23 | string(6) "second" 24 | } 25 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/026.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with open start and negative step 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[:2:-1]'); 18 | 19 | var_dump($result); 20 | ?> 21 | --EXPECT-- 22 | array(2) { 23 | [0]=> 24 | string(5) "fifth" 25 | [1]=> 26 | string(5) "forth" 27 | } 28 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/027.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with positive start and negative end and range of -1 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[3:-4]'); 19 | 20 | var_dump($result); 21 | ?> 22 | --EXPECT-- 23 | bool(false) 24 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/028.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with positive start and negative end and range of 0 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[3:-3]'); 19 | 20 | var_dump($result); 21 | ?> 22 | --EXPECT-- 23 | bool(false) 24 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/029.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with positive start and negative end and range of 1 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[3:-2]'); 19 | 20 | var_dump($result); 21 | ?> 22 | --EXPECT-- 23 | array(1) { 24 | [0]=> 25 | int(5) 26 | } 27 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/030.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with range of -1 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[2:1]'); 17 | 18 | var_dump($result); 19 | ?> 20 | --EXPECT-- 21 | bool(false) 22 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/031.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with range of 0 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[0:0]'); 15 | 16 | var_dump($result); 17 | ?> 18 | --EXPECT-- 19 | bool(false) 20 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/032.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with range of 1 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[0:1]'); 15 | 16 | var_dump($result); 17 | ?> 18 | --EXPECT-- 19 | array(1) { 20 | [0]=> 21 | string(5) "first" 22 | } 23 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/033.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with start -1 and open end 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[-1:]'); 16 | 17 | var_dump($result); 18 | ?> 19 | --EXPECT-- 20 | array(1) { 21 | [0]=> 22 | string(5) "third" 23 | } 24 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/034.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with start -2 and open end 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[-2:]'); 16 | 17 | var_dump($result); 18 | ?> 19 | --EXPECT-- 20 | array(2) { 21 | [0]=> 22 | string(6) "second" 23 | [1]=> 24 | string(5) "third" 25 | } 26 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/035.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with start large negative number and open end on short array 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[-4:]'); 16 | 17 | var_dump($result); 18 | ?> 19 | --EXPECT-- 20 | array(3) { 21 | [0]=> 22 | string(5) "first" 23 | [1]=> 24 | string(6) "second" 25 | [2]=> 26 | string(5) "third" 27 | } 28 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/036.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with step 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[0:3:2]'); 18 | 19 | var_dump($result); 20 | ?> 21 | --EXPECT-- 22 | array(2) { 23 | [0]=> 24 | string(5) "first" 25 | [1]=> 26 | string(5) "third" 27 | } 28 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/037.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with step 0 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[0:3:0]'); 18 | 19 | var_dump($result); 20 | ?> 21 | --EXPECT-- 22 | bool(false) 23 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/038.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with step 1 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[0:3:1]'); 18 | 19 | var_dump($result); 20 | ?> 21 | --EXPECT-- 22 | array(3) { 23 | [0]=> 24 | string(5) "first" 25 | [1]=> 26 | string(6) "second" 27 | [2]=> 28 | string(5) "third" 29 | } 30 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/039.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with step and leading zeros 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[010:024:010]'); 39 | 40 | var_dump($result); 41 | ?> 42 | --EXPECT-- 43 | array(2) { 44 | [0]=> 45 | int(10) 46 | [1]=> 47 | int(20) 48 | } 49 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/040.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with step but end not aligned 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[0:4:2]'); 18 | 19 | var_dump($result); 20 | ?> 21 | --EXPECT-- 22 | array(2) { 23 | [0]=> 24 | string(5) "first" 25 | [1]=> 26 | string(5) "third" 27 | } 28 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/041.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with step empty 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[1:3:]'); 18 | 19 | var_dump($result); 20 | ?> 21 | --EXPECT-- 22 | array(2) { 23 | [0]=> 24 | string(6) "second" 25 | [1]=> 26 | string(5) "third" 27 | } 28 | -------------------------------------------------------------------------------- /tests/comparison_array_slice/042.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice with step empty 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[::2]'); 18 | 19 | var_dump($result); 20 | ?> 21 | --EXPECT-- 22 | array(3) { 23 | [0]=> 24 | string(5) "first" 25 | [1]=> 26 | string(5) "third" 27 | [2]=> 28 | string(5) "fifth" 29 | } 30 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | ]; 11 | 12 | $jsonPath = new \JsonPath\JsonPath(); 13 | $result = $jsonPath->find($data, "$['key']"); 14 | 15 | var_dump($result); 16 | ?> 17 | --EXPECT-- 18 | array(1) { 19 | [0]=> 20 | string(5) "value" 21 | } 22 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation on object without key 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | ]; 11 | 12 | $jsonPath = new \JsonPath\JsonPath(); 13 | $result = $jsonPath->find($data, "$['missing']"); 14 | 15 | var_dump($result); 16 | ?> 17 | --EXPECT-- 18 | bool(false) 19 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation after recursive descent 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 13 | "first nested", 14 | [ 15 | "more" => [ 16 | [ 17 | "nested" => [ 18 | "deepest", 19 | "second", 20 | ], 21 | ], 22 | [ 23 | "more", 24 | "values", 25 | ], 26 | ], 27 | ], 28 | ], 29 | ], 30 | ]; 31 | 32 | $jsonPath = new \JsonPath\JsonPath(); 33 | $result = $jsonPath->find($data, '$..[0]'); 34 | sortRecursively($result); 35 | 36 | var_dump($result); 37 | ?> 38 | --EXPECT-- 39 | array(5) { 40 | [0]=> 41 | array(1) { 42 | ["nested"]=> 43 | array(2) { 44 | [0]=> 45 | string(7) "deepest" 46 | [1]=> 47 | string(6) "second" 48 | } 49 | } 50 | [1]=> 51 | string(7) "deepest" 52 | [2]=> 53 | string(5) "first" 54 | [3]=> 55 | string(12) "first nested" 56 | [4]=> 57 | string(4) "more" 58 | } 59 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with NFC path on NFD key 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 42, 10 | ]; 11 | 12 | $jsonPath = new \JsonPath\JsonPath(); 13 | $result = $jsonPath->find($data, "$['ü']"); 14 | 15 | var_dump($result); 16 | ?> 17 | --EXPECT-- 18 | bool(false) 19 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/005.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with dot 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 10 | "key" => "value", 11 | ], 12 | "two" => [ 13 | "some" => "more", 14 | "key" => "other value", 15 | ], 16 | "two.some" => 42, 17 | ]; 18 | 19 | $jsonPath = new \JsonPath\JsonPath(); 20 | $result = $jsonPath->find($data, "$['two.some']"); 21 | 22 | var_dump($result); 23 | ?> 24 | --EXPECT-- 25 | array(1) { 26 | [0]=> 27 | int(42) 28 | } 29 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/006.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with double quotes 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | ]; 11 | 12 | $jsonPath = new \JsonPath\JsonPath(); 13 | $result = $jsonPath->find($data, '$["key"]'); 14 | 15 | var_dump($result); 16 | ?> 17 | --EXPECT-- 18 | array(1) { 19 | [0]=> 20 | string(5) "value" 21 | } 22 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/007.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with empty path 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 42, 10 | "''" => 123, 11 | "\"\"" => 222, 12 | ]; 13 | 14 | $jsonPath = new \JsonPath\JsonPath(); 15 | $result = $jsonPath->find($data, '$[]'); 16 | 17 | var_dump($result); 18 | ?> 19 | --EXPECTF-- 20 | Fatal error: Uncaught JsonPath\JsonPathException: Filter must not be empty in %s007.php:%d 21 | Stack trace: 22 | %s 23 | %s 24 | %s 25 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/008.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with empty string 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 42, 10 | "''" => 123, 11 | "\"\"" => 222, 12 | ]; 13 | 14 | $jsonPath = new \JsonPath\JsonPath(); 15 | $result = $jsonPath->find($data, "$['']"); 16 | 17 | var_dump($result); 18 | ?> 19 | --EXPECT-- 20 | array(1) { 21 | [0]=> 22 | int(42) 23 | } 24 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/009.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with empty string doubled quoted 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 42, 10 | "''" => 123, 11 | "\"\"" => 222, 12 | ]; 13 | 14 | $jsonPath = new \JsonPath\JsonPath(); 15 | $result = $jsonPath->find($data, '$[""]'); 16 | 17 | var_dump($result); 18 | ?> 19 | --EXPECT-- 20 | array(1) { 21 | [0]=> 22 | int(42) 23 | } 24 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/010.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with negative number on short array 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[-2]'); 14 | 15 | var_dump($result); 16 | ?> 17 | --EXPECT-- 18 | bool(false) 19 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/011.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with number 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[2]'); 18 | 19 | var_dump($result); 20 | ?> 21 | --EXPECT-- 22 | array(1) { 23 | [0]=> 24 | string(5) "third" 25 | } 26 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/012.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with number on object 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | ]; 11 | 12 | $jsonPath = new \JsonPath\JsonPath(); 13 | $result = $jsonPath->find($data, '$[0]'); 14 | 15 | var_dump($result); 16 | ?> 17 | --EXPECT-- 18 | array(1) { 19 | [0]=> 20 | string(5) "value" 21 | } 22 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/013.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with number on short array 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[1]'); 14 | 15 | var_dump($result); 16 | ?> 17 | --EXPECT-- 18 | bool(false) 19 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/014.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with number on string 3 | --SKIPIF-- 4 | 5 | 6 | --FILE-- 7 | find($data, '$[0]'); 13 | 14 | var_dump($result); 15 | ?> 16 | --EXPECTF-- 17 | Fatal error: Uncaught TypeError: JsonPath\JsonPath::find(): Argument #1 ($data) must be of type array, string given in %s014.php:%d 18 | Stack trace: 19 | %s 20 | %s 21 | %s 22 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/015.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with number after dot notation with wildcard on nested arrays with different length 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$.*[1]'); 20 | 21 | var_dump($result); 22 | ?> 23 | --EXPECT-- 24 | array(1) { 25 | [0]=> 26 | int(3) 27 | } 28 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/016.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with number -1 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[-1]'); 16 | 17 | var_dump($result); 18 | ?> 19 | --EXPECT-- 20 | array(1) { 21 | [0]=> 22 | string(5) "third" 23 | } 24 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/017.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with number -1 on empty array 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[-1]'); 12 | 13 | var_dump($result); 14 | ?> 15 | --EXPECT-- 16 | bool(false) 17 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/018.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with number 0 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, '$[0]'); 18 | 19 | var_dump($result); 20 | ?> 21 | --EXPECT-- 22 | array(1) { 23 | [0]=> 24 | string(5) "first" 25 | } 26 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/019.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with quoted array slice literal 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | "another" => "entry", 11 | ]; 12 | 13 | $jsonPath = new \JsonPath\JsonPath(); 14 | $result = $jsonPath->find($data, "$[':']"); 15 | 16 | var_dump($result); 17 | ?> 18 | --EXPECT-- 19 | array(1) { 20 | [0]=> 21 | string(5) "value" 22 | } 23 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/020.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with quoted closing bracket literal 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 42, 10 | ]; 11 | 12 | $jsonPath = new \JsonPath\JsonPath(); 13 | $result = $jsonPath->find($data, "$[']']"); 14 | 15 | var_dump($result); 16 | ?> 17 | --EXPECT-- 18 | array(1) { 19 | [0]=> 20 | int(42) 21 | } 22 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/021.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with quoted current object literal 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | "another" => "entry", 11 | ]; 12 | 13 | $jsonPath = new \JsonPath\JsonPath(); 14 | $result = $jsonPath->find($data, "$['@']"); 15 | 16 | var_dump($result); 17 | ?> 18 | --EXPECT-- 19 | array(1) { 20 | [0]=> 21 | string(5) "value" 22 | } 23 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/022.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with quoted dot literal 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | "another" => "entry", 11 | ]; 12 | 13 | $jsonPath = new \JsonPath\JsonPath(); 14 | $result = $jsonPath->find($data, "$['.']"); 15 | 16 | var_dump($result); 17 | ?> 18 | --EXPECT-- 19 | array(1) { 20 | [0]=> 21 | string(5) "value" 22 | } 23 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/023.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with quoted dot wildcard 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 42, 10 | ".*" => 1, 11 | "" => 10, 12 | ]; 13 | 14 | $jsonPath = new \JsonPath\JsonPath(); 15 | $result = $jsonPath->find($data, "$['.*']"); 16 | 17 | var_dump($result); 18 | ?> 19 | --EXPECT-- 20 | array(1) { 21 | [0]=> 22 | int(1) 23 | } 24 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/024.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with quoted double quote literal 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | "another" => "entry", 11 | ]; 12 | 13 | $jsonPath = new \JsonPath\JsonPath(); 14 | $result = $jsonPath->find($data, "$['\"']"); 15 | 16 | var_dump($result); 17 | ?> 18 | --EXPECT-- 19 | array(1) { 20 | [0]=> 21 | string(5) "value" 22 | } 23 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/025.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with quoted escaped backslash 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | ]; 11 | 12 | $jsonPath = new \JsonPath\JsonPath(); 13 | $result = $jsonPath->find($data, "$['\\\\']"); 14 | 15 | var_dump($result); 16 | ?> 17 | --EXPECT-- 18 | array(1) { 19 | [0]=> 20 | string(5) "value" 21 | } 22 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/026.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with quoted escaped single quote 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | ]; 11 | 12 | $jsonPath = new \JsonPath\JsonPath(); 13 | $result = $jsonPath->find($data, "$['\\'']"); 14 | 15 | var_dump($result); 16 | ?> 17 | --EXPECT-- 18 | array(1) { 19 | [0]=> 20 | string(5) "value" 21 | } 22 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/027.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with quoted number on object 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | ]; 11 | 12 | $jsonPath = new \JsonPath\JsonPath(); 13 | $result = $jsonPath->find($data, "$['0']"); 14 | 15 | var_dump($result); 16 | ?> 17 | --EXPECT-- 18 | array(1) { 19 | [0]=> 20 | string(5) "value" 21 | } 22 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/028.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with quoted root literal 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | "another" => "entry", 11 | ]; 12 | 13 | $jsonPath = new \JsonPath\JsonPath(); 14 | $result = $jsonPath->find($data, "$['$']"); 15 | 16 | var_dump($result); 17 | ?> 18 | --EXPECT-- 19 | array(1) { 20 | [0]=> 21 | string(5) "value" 22 | } 23 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/029.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with quoted special characters combined 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 42, 10 | ]; 11 | 12 | $jsonPath = new \JsonPath\JsonPath(); 13 | $result = $jsonPath->find($data, "$[':@.\"$,*\'\\\\']"); 14 | 15 | var_dump($result); 16 | ?> 17 | --EXPECT-- 18 | array(1) { 19 | [0]=> 20 | int(42) 21 | } 22 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/030.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with quoted string and unescaped single quote 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | ]; 11 | 12 | $jsonPath = new \JsonPath\JsonPath(); 13 | $result = $jsonPath->find($data, "$['single'quote']"); 14 | 15 | var_dump($result); 16 | ?> 17 | --EXPECTF-- 18 | Fatal error: Uncaught JsonPath\JsonPathException: Unrecognized token `q` at position 10 in %s 19 | Stack trace: 20 | %s 21 | %s 22 | %s -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/031.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with quoted union literal 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | "another" => "entry", 11 | ]; 12 | 13 | $jsonPath = new \JsonPath\JsonPath(); 14 | $result = $jsonPath->find($data, "$[',']"); 15 | 16 | var_dump($result); 17 | ?> 18 | --EXPECT-- 19 | array(1) { 20 | [0]=> 21 | string(5) "value" 22 | } 23 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/032.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with quoted wildcard literal 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | "another" => "entry", 11 | ]; 12 | 13 | $jsonPath = new \JsonPath\JsonPath(); 14 | $result = $jsonPath->find($data, "$['*']"); 15 | 16 | var_dump($result); 17 | ?> 18 | --EXPECT-- 19 | array(1) { 20 | [0]=> 21 | string(5) "value" 22 | } 23 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/033.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with quoted wildcard literal on object without key 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "entry", 10 | ]; 11 | 12 | $jsonPath = new \JsonPath\JsonPath(); 13 | $result = $jsonPath->find($data, "$['*']"); 14 | 15 | var_dump($result); 16 | ?> 17 | --EXPECT-- 18 | bool(false) 19 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/034.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with spaces 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 1, 10 | "a" => 2, 11 | " a " => 3, 12 | "a " => 4, 13 | " 'a' " => 5, 14 | " 'a" => 6, 15 | "a' " => 7, 16 | " \"a\" " => 8, 17 | "\"a\"" => 9, 18 | ]; 19 | 20 | $jsonPath = new \JsonPath\JsonPath(); 21 | $result = $jsonPath->find($data, "$[ 'a' ]"); 22 | 23 | var_dump($result); 24 | ?> 25 | --EXPECT-- 26 | array(1) { 27 | [0]=> 28 | int(2) 29 | } 30 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/035.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with string including dot wildcard 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 42, 10 | "ni.*" => 1, 11 | "mice" => 100, 12 | ]; 13 | 14 | $jsonPath = new \JsonPath\JsonPath(); 15 | $result = $jsonPath->find($data, "$['ni.*']"); 16 | 17 | var_dump($result); 18 | ?> 19 | --EXPECT-- 20 | array(1) { 21 | [0]=> 22 | int(1) 23 | } 24 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/036.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with two literals separated by dot 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 10 | "key" => "value", 11 | ], 12 | "two" => [ 13 | "some" => "more", 14 | "key" => "other value", 15 | ], 16 | "two.some" => "42", 17 | "two'.'some" => "43", 18 | ]; 19 | 20 | $jsonPath = new \JsonPath\JsonPath(); 21 | $result = $jsonPath->find($data, "$['two'.'some']"); 22 | 23 | var_dump($result); 24 | ?> 25 | --EXPECTF-- 26 | Fatal error: Uncaught JsonPath\JsonPathException: Quoted node names must use the bracket notation `[` at position 8 in %s 27 | Stack trace: 28 | %s 29 | %s 30 | %s 31 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/037.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with two literals separated by dot without quotes 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 10 | "key" => "value", 11 | ], 12 | "two" => [ 13 | "some" => "more", 14 | "key" => "other value", 15 | ], 16 | "two.some" => "42", 17 | ]; 18 | 19 | $jsonPath = new \JsonPath\JsonPath(); 20 | $result = $jsonPath->find($data, "$[two.some]"); 21 | 22 | var_dump($result); 23 | ?> 24 | --EXPECTF-- 25 | Fatal error: Uncaught JsonPath\JsonPathException: Unexpected filter element in %s 26 | Stack trace: 27 | %s 28 | %s 29 | %s -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/038.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with wildcard on array 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 13 | ], 14 | [ 15 | 0, 16 | 1, 17 | ], 18 | ]; 19 | 20 | $jsonPath = new \JsonPath\JsonPath(); 21 | $result = $jsonPath->find($data, "$[*]"); 22 | 23 | var_dump($result); 24 | ?> 25 | --EXPECT-- 26 | array(4) { 27 | [0]=> 28 | string(6) "string" 29 | [1]=> 30 | int(42) 31 | [2]=> 32 | array(1) { 33 | ["key"]=> 34 | string(5) "value" 35 | } 36 | [3]=> 37 | array(2) { 38 | [0]=> 39 | int(0) 40 | [1]=> 41 | int(1) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/039.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with wildcard on empty array 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, "$[*]"); 12 | 13 | var_dump($result); 14 | ?> 15 | --EXPECT-- 16 | bool(false) 17 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/040.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with wildcard on empty object 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, "$[*]"); 12 | 13 | var_dump($result); 14 | ?> 15 | --EXPECT-- 16 | bool(false) 17 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/041.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with wildcard on null value array 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, "$[*]"); 16 | 17 | var_dump($result); 18 | ?> 19 | --EXPECT-- 20 | array(3) { 21 | [0]=> 22 | int(40) 23 | [1]=> 24 | NULL 25 | [2]=> 26 | int(42) 27 | } 28 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/042.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with wildcard on object 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "string", 10 | "int" => 42, 11 | "object" => [ 12 | "key" => "value", 13 | ], 14 | "array" => [ 15 | 0, 16 | 1, 17 | ], 18 | ]; 19 | 20 | $jsonPath = new \JsonPath\JsonPath(); 21 | $result = $jsonPath->find($data, "$[*]"); 22 | 23 | var_dump($result); 24 | ?> 25 | --EXPECT-- 26 | array(4) { 27 | [0]=> 28 | string(6) "string" 29 | [1]=> 30 | int(42) 31 | [2]=> 32 | array(1) { 33 | ["key"]=> 34 | string(5) "value" 35 | } 36 | [3]=> 37 | array(2) { 38 | [0]=> 39 | int(0) 40 | [1]=> 41 | int(1) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/043.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with wildcard after array slice 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, "$[0:2][*]"); 25 | 26 | var_dump($result); 27 | ?> 28 | --EXPECT-- 29 | array(4) { 30 | [0]=> 31 | int(1) 32 | [1]=> 33 | int(2) 34 | [2]=> 35 | string(1) "a" 36 | [3]=> 37 | string(1) "b" 38 | } 39 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/044.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with wildcard after dot notation after bracket notation with wildcard 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 11 | 42, 12 | ], 13 | ], 14 | ]; 15 | 16 | $jsonPath = new \JsonPath\JsonPath(); 17 | $result = $jsonPath->find($data, "$[*].bar[*]"); 18 | 19 | var_dump($result); 20 | ?> 21 | --EXPECT-- 22 | array(1) { 23 | [0]=> 24 | int(42) 25 | } 26 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/045.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation with wildcard after dot notation after bracket notation with wildcard 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | "another key" => [ 11 | "complex" => "string", 12 | "primitives" => [ 13 | 0, 14 | 1, 15 | ], 16 | ], 17 | ]; 18 | 19 | $jsonPath = new \JsonPath\JsonPath(); 20 | $result = $jsonPath->find($data, "$..[*]"); 21 | 22 | var_dump($result); 23 | ?> 24 | --EXPECT-- 25 | array(6) { 26 | [0]=> 27 | string(5) "value" 28 | [1]=> 29 | array(2) { 30 | ["complex"]=> 31 | string(6) "string" 32 | ["primitives"]=> 33 | array(2) { 34 | [0]=> 35 | int(0) 36 | [1]=> 37 | int(1) 38 | } 39 | } 40 | [2]=> 41 | string(6) "string" 42 | [3]=> 43 | array(2) { 44 | [0]=> 45 | int(0) 46 | [1]=> 47 | int(1) 48 | } 49 | [4]=> 50 | int(0) 51 | [5]=> 52 | int(1) 53 | } 54 | -------------------------------------------------------------------------------- /tests/comparison_bracket_notation/046.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation without quotes 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | ]; 11 | 12 | $jsonPath = new \JsonPath\JsonPath(); 13 | $result = $jsonPath->find($data, "$[key]"); 14 | 15 | var_dump($result); 16 | ?> 17 | --EXPECTF-- 18 | Fatal error: Uncaught JsonPath\JsonPathException: Unrecognized token `k` at position 2 in %s 19 | Stack trace: 20 | %s 21 | %s 22 | %s -------------------------------------------------------------------------------- /tests/comparison_dot_notation/001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot bracket notation 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | "other" => [ 11 | "key" => [ 12 | "key" => 42, 13 | ], 14 | ], 15 | ]; 16 | 17 | $jsonPath = new \JsonPath\JsonPath(); 18 | $result = $jsonPath->find($data, "$.['key']"); 19 | 20 | var_dump($result); 21 | ?> 22 | --EXPECT-- 23 | array(1) { 24 | [0]=> 25 | string(5) "value" 26 | } 27 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot bracket notation with double quotes 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | "other" => [ 11 | "key" => [ 12 | "key" => 42, 13 | ], 14 | ], 15 | ]; 16 | 17 | $jsonPath = new \JsonPath\JsonPath(); 18 | $result = $jsonPath->find($data, '$.["key"]'); 19 | 20 | var_dump($result); 21 | ?> 22 | --EXPECT-- 23 | array(1) { 24 | [0]=> 25 | string(5) "value" 26 | } 27 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot bracket notation without quotes 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | "other" => [ 11 | "key" => [ 12 | "key" => 42, 13 | ], 14 | ], 15 | ]; 16 | 17 | $jsonPath = new \JsonPath\JsonPath(); 18 | $result = $jsonPath->find($data, "$.[key]"); 19 | 20 | var_dump($result); 21 | ?> 22 | --EXPECTF-- 23 | Fatal error: Uncaught JsonPath\JsonPathException: Unrecognized token `k` at position 3 in %s 24 | Stack trace: 25 | %s 26 | %s 27 | %s -------------------------------------------------------------------------------- /tests/comparison_dot_notation/004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | ]; 11 | 12 | $jsonPath = new \JsonPath\JsonPath(); 13 | $result = $jsonPath->find($data, "$.key"); 14 | 15 | var_dump($result); 16 | ?> 17 | --EXPECT-- 18 | array(1) { 19 | [0]=> 20 | string(5) "value" 21 | } 22 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/005.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation on array 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, "$.key"); 15 | 16 | var_dump($result); 17 | ?> 18 | --EXPECT-- 19 | bool(false) 20 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/006.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation on array value 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 10 | "first", 11 | "second", 12 | ], 13 | ]; 14 | 15 | $jsonPath = new \JsonPath\JsonPath(); 16 | $result = $jsonPath->find($data, "$.key"); 17 | 18 | var_dump($result); 19 | ?> 20 | --EXPECT-- 21 | array(1) { 22 | [0]=> 23 | array(2) { 24 | [0]=> 25 | string(5) "first" 26 | [1]=> 27 | string(6) "second" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/007.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation on array with containing object matching key 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 2, 11 | ], 12 | ]; 13 | 14 | $jsonPath = new \JsonPath\JsonPath(); 15 | $result = $jsonPath->find($data, "$.id"); 16 | 17 | var_dump($result); 18 | ?> 19 | --EXPECT-- 20 | bool(false) 21 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/008.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation on empty object value 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [], 10 | ]; 11 | 12 | $jsonPath = new \JsonPath\JsonPath(); 13 | $result = $jsonPath->find($data, "$.key"); 14 | 15 | var_dump($result); 16 | ?> 17 | --EXPECT-- 18 | array(1) { 19 | [0]=> 20 | array(0) { 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/009.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation on null value 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | null, 10 | ]; 11 | 12 | $jsonPath = new \JsonPath\JsonPath(); 13 | $result = $jsonPath->find($data, "$.key"); 14 | 15 | var_dump($result); 16 | ?> 17 | --EXPECT-- 18 | array(1) { 19 | [0]=> 20 | NULL 21 | } 22 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/010.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation on object without key 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | ]; 11 | 12 | $jsonPath = new \JsonPath\JsonPath(); 13 | $result = $jsonPath->find($data, "$.missing"); 14 | 15 | var_dump($result); 16 | ?> 17 | --EXPECT-- 18 | bool(false) 19 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/011.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation after array slice 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "ey", 11 | ], 12 | [ 13 | "key" => "bee", 14 | ], 15 | [ 16 | "key" => "see", 17 | ], 18 | ]; 19 | 20 | $jsonPath = new \JsonPath\JsonPath(); 21 | $result = $jsonPath->find($data, "$[0:2].key"); 22 | 23 | var_dump($result); 24 | ?> 25 | --EXPECT-- 26 | array(2) { 27 | [0]=> 28 | string(2) "ey" 29 | [1]=> 30 | string(3) "bee" 31 | } 32 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/012.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation after bracket notation after recursive descent 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 11 | [ 12 | "key" => "some value", 13 | ], 14 | [ 15 | "key" => 42, 16 | ], 17 | ], 18 | "kk" => [ 19 | [ 20 | [ 21 | "key" => 100, 22 | ], 23 | [ 24 | "key" => 200, 25 | ], 26 | [ 27 | "key" => 300, 28 | ], 29 | [ 30 | [ 31 | "key" => 400, 32 | ], 33 | [ 34 | "key" => 500, 35 | ], 36 | [ 37 | "key" => 600, 38 | ], 39 | ], 40 | ], 41 | ], 42 | "key" => [ 43 | 0, 44 | 1, 45 | ], 46 | ]; 47 | 48 | $jsonPath = new \JsonPath\JsonPath(); 49 | $result = $jsonPath->find($data, "$..[1].key"); 50 | sortRecursively($result); 51 | 52 | var_dump($result); 53 | ?> 54 | --EXPECT-- 55 | array(3) { 56 | [0]=> 57 | int(42) 58 | [1]=> 59 | int(200) 60 | [2]=> 61 | int(500) 62 | } 63 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/013.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation after bracket notation with wildcard 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 1, 11 | ], 12 | [ 13 | "a" => 1, 14 | ], 15 | ]; 16 | 17 | $jsonPath = new \JsonPath\JsonPath(); 18 | $result = $jsonPath->find($data, "$[*].a"); 19 | 20 | var_dump($result); 21 | ?> 22 | --EXPECT-- 23 | array(2) { 24 | [0]=> 25 | int(1) 26 | [1]=> 27 | int(1) 28 | } 29 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/014.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation after bracket notation with wildcard on one matching 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 1, 11 | ], 12 | ]; 13 | 14 | $jsonPath = new \JsonPath\JsonPath(); 15 | $result = $jsonPath->find($data, "$[*].a"); 16 | 17 | var_dump($result); 18 | ?> 19 | --EXPECT-- 20 | array(1) { 21 | [0]=> 22 | int(1) 23 | } 24 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/015.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation after bracket notation with wildcard on some matching 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 1, 11 | ], 12 | [ 13 | "b" => 1, 14 | ], 15 | ]; 16 | 17 | $jsonPath = new \JsonPath\JsonPath(); 18 | $result = $jsonPath->find($data, "$[*].a"); 19 | 20 | var_dump($result); 21 | ?> 22 | --EXPECT-- 23 | array(1) { 24 | [0]=> 25 | int(1) 26 | } 27 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/016.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation after filter expression 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 42, 11 | "name" => "forty-two", 12 | ], 13 | [ 14 | "id" => 1, 15 | "name" => "one", 16 | ], 17 | ]; 18 | 19 | $jsonPath = new \JsonPath\JsonPath(); 20 | $result = $jsonPath->find($data, "$[?(@.id==42)].name"); 21 | 22 | var_dump($result); 23 | ?> 24 | --EXPECT-- 25 | array(1) { 26 | [0]=> 27 | string(9) "forty-two" 28 | } 29 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/017.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation after recursive descent 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 11 | "key" => "value", 12 | "array" => [ 13 | [ 14 | "key" => "something", 15 | ], 16 | [ 17 | "key" => [ 18 | "key" => "russian dolls", 19 | ], 20 | ], 21 | ], 22 | ], 23 | "key" => "top", 24 | ]; 25 | 26 | $jsonPath = new \JsonPath\JsonPath(); 27 | $result = $jsonPath->find($data, "$..key"); 28 | sortRecursively($result); 29 | 30 | var_dump($result); 31 | ?> 32 | --EXPECT-- 33 | array(5) { 34 | [0]=> 35 | array(1) { 36 | ["key"]=> 37 | string(13) "russian dolls" 38 | } 39 | [1]=> 40 | string(13) "russian dolls" 41 | [2]=> 42 | string(9) "something" 43 | [3]=> 44 | string(3) "top" 45 | [4]=> 46 | string(5) "value" 47 | } 48 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/019.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation after union 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "ey", 11 | ], 12 | [ 13 | "key" => "bee", 14 | ], 15 | [ 16 | "key" => "see", 17 | ], 18 | ]; 19 | 20 | $jsonPath = new \JsonPath\JsonPath(); 21 | $result = $jsonPath->find($data, "$[0,2].key"); 22 | 23 | var_dump($result); 24 | ?> 25 | --EXPECT-- 26 | array(2) { 27 | [0]=> 28 | string(2) "ey" 29 | [1]=> 30 | string(3) "see" 31 | } 32 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/020.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation after union with keys 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 10 | "key" => "value", 11 | ], 12 | "two" => [ 13 | "k" => "v", 14 | ], 15 | "three" => [ 16 | "some" => "more", 17 | "key" => "other value", 18 | ], 19 | ]; 20 | 21 | $jsonPath = new \JsonPath\JsonPath(); 22 | $result = $jsonPath->find($data, "$['one','three'].key"); 23 | 24 | var_dump($result); 25 | ?> 26 | --EXPECT-- 27 | array(2) { 28 | [0]=> 29 | string(5) "value" 30 | [1]=> 31 | string(11) "other value" 32 | } -------------------------------------------------------------------------------- /tests/comparison_dot_notation/021.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation with dash 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | ]; 11 | 12 | $jsonPath = new \JsonPath\JsonPath(); 13 | $result = $jsonPath->find($data, "$.key-dash"); 14 | 15 | var_dump($result); 16 | ?> 17 | --EXPECT-- 18 | array(1) { 19 | [0]=> 20 | string(5) "value" 21 | } 22 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/022.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation with double quotes 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | "\"key\"" => 42, 11 | ]; 12 | 13 | $jsonPath = new \JsonPath\JsonPath(); 14 | $result = $jsonPath->find($data, '$."key"'); 15 | 16 | var_dump($result); 17 | ?> 18 | --EXPECTF-- 19 | Fatal error: Uncaught JsonPath\JsonPathException: Quoted node names must use the bracket notation `[` at position 2 in %s 20 | Stack trace: 21 | %s 22 | %s 23 | %s 24 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/023.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation with double quotes after recursive descent 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 10 | "key" => "value", 11 | "\"key\"" => 42, 12 | "array" => [ 13 | [ 14 | "key" => "something", 15 | "\"key\"" => 0, 16 | ], 17 | [ 18 | "key" => [ 19 | "key" => "russian dolls", 20 | ], 21 | "\"key\"" => [ 22 | "\"key\"" => 99, 23 | ], 24 | ], 25 | ], 26 | ], 27 | "key" => "top", 28 | "\"key\"" => 42, 29 | ]; 30 | 31 | $jsonPath = new \JsonPath\JsonPath(); 32 | $result = $jsonPath->find($data, '$.."key"'); 33 | 34 | var_dump($result); 35 | ?> 36 | --EXPECTF-- 37 | Fatal error: Uncaught JsonPath\JsonPathException: Quoted node names must use the bracket notation `[` at position 3 in %s 38 | Stack trace: 39 | %s 40 | %s 41 | %s -------------------------------------------------------------------------------- /tests/comparison_dot_notation/024.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation with empty path 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 42, 10 | "" => 9001, 11 | "''" => "nice", 12 | ]; 13 | 14 | $jsonPath = new \JsonPath\JsonPath(); 15 | $result = $jsonPath->find($data, "$."); 16 | 17 | var_dump($result); 18 | ?> 19 | --EXPECTF-- 20 | Fatal error: Uncaught JsonPath\JsonPathException: Dot selector `.` must be followed by a node name or wildcard at position 1 in %s 21 | Stack trace: 22 | %s 23 | %s 24 | %s 25 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/025.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation with key named in 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | ]; 11 | 12 | $jsonPath = new \JsonPath\JsonPath(); 13 | $result = $jsonPath->find($data, "$.in"); 14 | 15 | var_dump($result); 16 | ?> 17 | --EXPECT-- 18 | array(1) { 19 | [0]=> 20 | string(5) "value" 21 | } 22 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/026.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation with key named length 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | ]; 11 | 12 | $jsonPath = new \JsonPath\JsonPath(); 13 | $result = $jsonPath->find($data, "$.length"); 14 | 15 | var_dump($result); 16 | ?> 17 | --EXPECT-- 18 | array(1) { 19 | [0]=> 20 | string(5) "value" 21 | } 22 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/027.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation with key named length on array 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, "$.length"); 16 | 17 | var_dump($result); 18 | ?> 19 | --EXPECT-- 20 | bool(false) 21 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/028.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation with key named null 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | ]; 11 | 12 | $jsonPath = new \JsonPath\JsonPath(); 13 | $result = $jsonPath->find($data, "$.null"); 14 | 15 | var_dump($result); 16 | ?> 17 | --EXPECT-- 18 | array(1) { 19 | [0]=> 20 | string(5) "value" 21 | } 22 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/029.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation with key named true 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | ]; 11 | 12 | $jsonPath = new \JsonPath\JsonPath(); 13 | $result = $jsonPath->find($data, "$.true"); 14 | 15 | var_dump($result); 16 | ?> 17 | --EXPECT-- 18 | array(1) { 19 | [0]=> 20 | string(5) "value" 21 | } 22 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/030.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation with key root literal 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | ]; 11 | 12 | $jsonPath = new \JsonPath\JsonPath(); 13 | $result = $jsonPath->find($data, "$.$"); 14 | 15 | var_dump($result); 16 | ?> 17 | --EXPECTF-- 18 | Fatal error: Uncaught JsonPath\JsonPathException: Unexpected root `$` in node name, use bracket notation for node names with special characters in %s 19 | Stack trace: 20 | %s 21 | %s 22 | %s 23 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/031.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation with non ASCII key 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | ]; 11 | 12 | $jsonPath = new \JsonPath\JsonPath(); 13 | $result = $jsonPath->find($data, "$.屬性"); 14 | 15 | var_dump($result); 16 | ?> 17 | --EXPECT-- 18 | array(1) { 19 | [0]=> 20 | string(5) "value" 21 | } 22 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/032.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation with number 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, "$.2"); 18 | 19 | var_dump($result); 20 | ?> 21 | --EXPECT-- 22 | array(1) { 23 | [0]=> 24 | string(5) "third" 25 | } -------------------------------------------------------------------------------- /tests/comparison_dot_notation/033.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation with number on object 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "first", 10 | "2" => "second", 11 | "c" => "third", 12 | ]; 13 | 14 | $jsonPath = new \JsonPath\JsonPath(); 15 | $result = $jsonPath->find($data, "$.2"); 16 | 17 | var_dump($result); 18 | ?> 19 | --EXPECT-- 20 | array(1) { 21 | [0]=> 22 | string(6) "second" 23 | } -------------------------------------------------------------------------------- /tests/comparison_dot_notation/034.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation with number -1 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, "$.-1"); 18 | 19 | var_dump($result); 20 | ?> 21 | --EXPECT-- 22 | bool(false) 23 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/035.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation with single quotes 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | "'key'" => 42, 11 | ]; 12 | 13 | $jsonPath = new \JsonPath\JsonPath(); 14 | $result = $jsonPath->find($data, "$.'key'"); 15 | 16 | var_dump($result); 17 | ?> 18 | --EXPECTF-- 19 | Fatal error: Uncaught JsonPath\JsonPathException: Quoted node names must use the bracket notation `[` at position 2 in %s 20 | Stack trace: 21 | %s 22 | %s 23 | %s 24 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/036.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation with single quotes after recursive descent 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 10 | "key" => "value", 11 | "'key'" => 42, 12 | "array" => [ 13 | [ 14 | "key" => "something", 15 | "'key'" => 0, 16 | ], 17 | [ 18 | "key" => [ 19 | "key" => "russian dolls", 20 | ], 21 | "'key'" => [ 22 | "'key'" => 99, 23 | ], 24 | ], 25 | ], 26 | ], 27 | "key" => "top", 28 | "'key'" => 42, 29 | ]; 30 | 31 | $jsonPath = new \JsonPath\JsonPath(); 32 | $result = $jsonPath->find($data, "$..'key'"); 33 | 34 | var_dump($result); 35 | ?> 36 | --EXPECTF-- 37 | Fatal error: Uncaught JsonPath\JsonPathException: Quoted node names must use the bracket notation `[` at position 3 in %s 38 | Stack trace: 39 | %s 40 | %s 41 | %s -------------------------------------------------------------------------------- /tests/comparison_dot_notation/037.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation with single quotes and dot 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 42, 10 | "some" => [ 11 | "key" => "value", 12 | ], 13 | "'some.key'" => 43, 14 | ]; 15 | 16 | $jsonPath = new \JsonPath\JsonPath(); 17 | $result = $jsonPath->find($data, "$.'some.key'"); 18 | 19 | var_dump($result); 20 | ?> 21 | --EXPECTF-- 22 | Fatal error: Uncaught JsonPath\JsonPathException: Quoted node names must use the bracket notation `[` at position 2 in %s 23 | Stack trace: 24 | %s 25 | %s 26 | %s 27 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/038.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation with space padded key 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 1, 10 | "a" => 2, 11 | " a " => 3, 12 | "" => 4, 13 | ]; 14 | 15 | $jsonPath = new \JsonPath\JsonPath(); 16 | $result = $jsonPath->find($data, "$. a"); 17 | 18 | var_dump($result); 19 | ?> 20 | --EXPECTF-- 21 | Fatal error: Uncaught JsonPath\JsonPathException: Unexpected whitespace at position 2 in %s 22 | Stack trace: 23 | %s 24 | %s 25 | %s 26 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/039.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation with wildcard on array 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 13 | ], 14 | [ 15 | 0, 16 | 1, 17 | ], 18 | ]; 19 | 20 | $jsonPath = new \JsonPath\JsonPath(); 21 | $result = $jsonPath->find($data, "$.*"); 22 | 23 | var_dump($result); 24 | ?> 25 | --EXPECT-- 26 | array(4) { 27 | [0]=> 28 | string(6) "string" 29 | [1]=> 30 | int(42) 31 | [2]=> 32 | array(1) { 33 | ["key"]=> 34 | string(5) "value" 35 | } 36 | [3]=> 37 | array(2) { 38 | [0]=> 39 | int(0) 40 | [1]=> 41 | int(1) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/040.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation with wildcard on empty array 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, "$.*"); 12 | 13 | var_dump($result); 14 | ?> 15 | --EXPECT-- 16 | bool(false) 17 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/041.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation with wildcard on empty object 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, "$.*"); 12 | 13 | var_dump($result); 14 | ?> 15 | --EXPECT-- 16 | bool(false) 17 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/042.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation with wildcard on object 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "string", 11 | "int" => 42, 12 | "object" => [ 13 | "key" => "value", 14 | ], 15 | "array" => [ 16 | 0, 17 | 1, 18 | ], 19 | ]; 20 | 21 | $jsonPath = new \JsonPath\JsonPath(); 22 | $result = $jsonPath->find($data, "$.*"); 23 | sortRecursively($result); 24 | 25 | var_dump($result); 26 | ?> 27 | --EXPECT-- 28 | array(4) { 29 | [0]=> 30 | array(1) { 31 | ["key"]=> 32 | string(5) "value" 33 | } 34 | [1]=> 35 | array(2) { 36 | [0]=> 37 | int(0) 38 | [1]=> 39 | int(1) 40 | } 41 | [2]=> 42 | int(42) 43 | [3]=> 44 | string(6) "string" 45 | } 46 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/043.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation with wildcard after dot notation after dot notation with wildcard 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 11 | 42, 12 | ], 13 | ] 14 | ]; 15 | 16 | $jsonPath = new \JsonPath\JsonPath(); 17 | $result = $jsonPath->find($data, "$.*.bar.*"); 18 | 19 | var_dump($result); 20 | ?> 21 | --EXPECT-- 22 | array(1) { 23 | [0]=> 24 | int(42) 25 | } 26 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/044.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation with wildcard after dot notation with wildcard on nested arrays 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, "$.*.*"); 23 | 24 | var_dump($result); 25 | ?> 26 | --EXPECT-- 27 | array(6) { 28 | [0]=> 29 | int(1) 30 | [1]=> 31 | int(2) 32 | [2]=> 33 | int(3) 34 | [3]=> 35 | int(4) 36 | [4]=> 37 | int(5) 38 | [5]=> 39 | int(6) 40 | } 41 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/045.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation with wildcard after recursive descent 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 11 | "another key" => [ 12 | "complex" => "string", 13 | "primitives" => [ 14 | 0, 15 | 1, 16 | ], 17 | ], 18 | ]; 19 | 20 | $jsonPath = new \JsonPath\JsonPath(); 21 | $result = $jsonPath->find($data, "$..*"); 22 | sortRecursively($result); 23 | 24 | var_dump($result); 25 | ?> 26 | --EXPECT-- 27 | array(6) { 28 | [0]=> 29 | array(2) { 30 | [0]=> 31 | int(0) 32 | [1]=> 33 | int(1) 34 | } 35 | [1]=> 36 | array(2) { 37 | ["primitives"]=> 38 | array(2) { 39 | [0]=> 40 | int(0) 41 | [1]=> 42 | int(1) 43 | } 44 | ["complex"]=> 45 | string(6) "string" 46 | } 47 | [2]=> 48 | int(0) 49 | [3]=> 50 | int(1) 51 | [4]=> 52 | string(6) "string" 53 | [5]=> 54 | string(5) "value" 55 | } 56 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/046.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation with wildcard after recursive descent on null value array 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, "$..*"); 17 | sortRecursively($result); 18 | 19 | var_dump($result); 20 | ?> 21 | --EXPECT-- 22 | array(3) { 23 | [0]=> 24 | NULL 25 | [1]=> 26 | int(40) 27 | [2]=> 28 | int(42) 29 | } 30 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/047.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation with wildcard after recursive descent on scalar 3 | --SKIPIF-- 4 | 5 | 6 | --FILE-- 7 | find($data, "$..*"); 13 | 14 | var_dump($result); 15 | ?> 16 | --EXPECTF-- 17 | Fatal error: Uncaught TypeError: JsonPath\JsonPath::find(): Argument #1 ($data) must be of type array, int given in %s047.php:%d 18 | Stack trace: 19 | %s 20 | %s 21 | %s 22 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/048.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation without dot 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 1, 10 | "\$a" => 2, 11 | ]; 12 | 13 | $jsonPath = new \JsonPath\JsonPath(); 14 | $result = $jsonPath->find($data, "\$a"); 15 | 16 | var_dump($result); 17 | ?> 18 | --EXPECTF-- 19 | Fatal error: Uncaught JsonPath\JsonPathException: Unrecognized token `a` at position 1 in %s 20 | Stack trace: 21 | %s 22 | %s 23 | %s 24 | -------------------------------------------------------------------------------- /tests/comparison_dot_notation/049.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation without root 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | ]; 11 | 12 | $jsonPath = new \JsonPath\JsonPath(); 13 | $result = $jsonPath->find($data, ".key"); 14 | 15 | var_dump($result); 16 | ?> 17 | --EXPECTF-- 18 | Fatal error: Uncaught JsonPath\JsonPathException: JSONPath must start with a root operator `$` in %s 19 | Stack trace: 20 | %s 21 | %s 22 | %s -------------------------------------------------------------------------------- /tests/comparison_dot_notation/050.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation without root and dot 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | ]; 11 | 12 | $jsonPath = new \JsonPath\JsonPath(); 13 | $result = $jsonPath->find($data, "key"); 14 | 15 | var_dump($result); 16 | ?> 17 | --EXPECTF-- 18 | Fatal error: Uncaught JsonPath\JsonPathException: Unrecognized token `k` at position 0 in %s 19 | Stack trace: 20 | %s 21 | %s 22 | %s -------------------------------------------------------------------------------- /tests/comparison_filter/001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression on object 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 42, 10 | "another" => [ 11 | "key" => 1, 12 | ], 13 | ]; 14 | 15 | $jsonPath = new \JsonPath\JsonPath(); 16 | $result = $jsonPath->find($data, "$[?(@.key)]"); 17 | 18 | var_dump($result); 19 | ?> 20 | --EXPECT-- 21 | array(1) { 22 | [0]=> 23 | array(1) { 24 | ["key"]=> 25 | int(1) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/comparison_filter/003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression after recursive descent 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 2, 11 | "more" => [ 12 | [ 13 | "id" => 2, 14 | ], 15 | [ 16 | "more" => [ 17 | "id" => 2, 18 | ], 19 | ], 20 | [ 21 | "id" => [ 22 | "id" => 2, 23 | ], 24 | ], 25 | [ 26 | [ 27 | "id" => 2, 28 | ], 29 | ], 30 | ], 31 | ]; 32 | 33 | $jsonPath = new \JsonPath\JsonPath(); 34 | $result = $jsonPath->find($data, "$..[?(@.id==2)]"); 35 | sortRecursively($result); 36 | 37 | var_dump($result); 38 | ?> 39 | --EXPECT-- 40 | array(4) { 41 | [0]=> 42 | array(1) { 43 | ["id"]=> 44 | int(2) 45 | } 46 | [1]=> 47 | array(1) { 48 | ["id"]=> 49 | int(2) 50 | } 51 | [2]=> 52 | array(1) { 53 | ["id"]=> 54 | int(2) 55 | } 56 | [3]=> 57 | array(1) { 58 | ["id"]=> 59 | int(2) 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /tests/comparison_filter/004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with addition 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 60, 11 | ], 12 | [ 13 | "key" => 50, 14 | ], 15 | [ 16 | "key" => 10, 17 | ], 18 | [ 19 | "key" => -50, 20 | ], 21 | [ 22 | "key+50" => 100, 23 | ], 24 | ]; 25 | 26 | $jsonPath = new \JsonPath\JsonPath(); 27 | $result = $jsonPath->find($data, "$[?(@.key+50==100)]"); 28 | 29 | var_dump($result); 30 | ?> 31 | --EXPECTF-- 32 | Fatal error: Uncaught JsonPath\JsonPathException: Unrecognized token `+` at position 9 in %s 33 | Stack trace: 34 | %s 35 | %s 36 | %s -------------------------------------------------------------------------------- /tests/comparison_filter/005.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with boolean and operator 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 42, 11 | ], 12 | [ 13 | "key" => 43, 14 | ], 15 | [ 16 | "key" => 44, 17 | ], 18 | ]; 19 | 20 | $jsonPath = new \JsonPath\JsonPath(); 21 | $result = $jsonPath->find($data, "$[?(@.key>42 && @.key<44)]"); 22 | 23 | var_dump($result); 24 | ?> 25 | --EXPECT-- 26 | array(1) { 27 | [0]=> 28 | array(1) { 29 | ["key"]=> 30 | int(43) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/comparison_filter/006.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with boolean and operator and value false 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 1, 11 | ], 12 | [ 13 | "key" => 3, 14 | ], 15 | [ 16 | "key" => "nice", 17 | ], 18 | [ 19 | "key" => true, 20 | ], 21 | [ 22 | "key" => null, 23 | ], 24 | [ 25 | "key" => false, 26 | ], 27 | [ 28 | "key" => [], 29 | ], 30 | [ 31 | "key" => [], 32 | ], 33 | [ 34 | "key" => -1, 35 | ], 36 | [ 37 | "key" => 0, 38 | ], 39 | [ 40 | "key" => "", 41 | ], 42 | ]; 43 | 44 | $jsonPath = new \JsonPath\JsonPath(); 45 | $result = $jsonPath->find($data, "$[?(@.key>0 && false)]"); 46 | 47 | var_dump($result); 48 | ?> 49 | --EXPECT-- 50 | bool(false) 51 | -------------------------------------------------------------------------------- /tests/comparison_filter/007.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with boolean and operator and value true 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 1, 11 | ], 12 | [ 13 | "key" => 3, 14 | ], 15 | [ 16 | "key" => "nice", 17 | ], 18 | [ 19 | "key" => true, 20 | ], 21 | [ 22 | "key" => null, 23 | ], 24 | [ 25 | "key" => false, 26 | ], 27 | [ 28 | "key" => [], 29 | ], 30 | [ 31 | "key" => [], 32 | ], 33 | [ 34 | "key" => -1, 35 | ], 36 | [ 37 | "key" => 0, 38 | ], 39 | [ 40 | "key" => "", 41 | ], 42 | ]; 43 | 44 | $jsonPath = new \JsonPath\JsonPath(); 45 | $result = $jsonPath->find($data, "$[?(@.key>0 && true)]"); 46 | 47 | var_dump($result); 48 | ?> 49 | --EXPECT-- 50 | array(2) { 51 | [0]=> 52 | array(1) { 53 | ["key"]=> 54 | int(1) 55 | } 56 | [1]=> 57 | array(1) { 58 | ["key"]=> 59 | int(3) 60 | } 61 | } -------------------------------------------------------------------------------- /tests/comparison_filter/008.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with boolean or operator 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 42, 11 | ], 12 | [ 13 | "key" => 43, 14 | ], 15 | [ 16 | "key" => 44, 17 | ], 18 | ]; 19 | 20 | $jsonPath = new \JsonPath\JsonPath(); 21 | $result = $jsonPath->find($data, "$[?(@.key>43 || @.key<43)]"); 22 | 23 | var_dump($result); 24 | ?> 25 | --EXPECT-- 26 | array(2) { 27 | [0]=> 28 | array(1) { 29 | ["key"]=> 30 | int(42) 31 | } 32 | [1]=> 33 | array(1) { 34 | ["key"]=> 35 | int(44) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tests/comparison_filter/009.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with boolean or operator and value false 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 1, 11 | ], 12 | [ 13 | "key" => 3, 14 | ], 15 | [ 16 | "key" => "nice", 17 | ], 18 | [ 19 | "key" => true, 20 | ], 21 | [ 22 | "key" => null, 23 | ], 24 | [ 25 | "key" => false, 26 | ], 27 | [ 28 | "key" => [], 29 | ], 30 | [ 31 | "key" => [], 32 | ], 33 | [ 34 | "key" => -1, 35 | ], 36 | [ 37 | "key" => 0, 38 | ], 39 | [ 40 | "key" => "", 41 | ], 42 | ]; 43 | 44 | $jsonPath = new \JsonPath\JsonPath(); 45 | $result = $jsonPath->find($data, "$[?(@.key>0 || false)]"); 46 | 47 | var_dump($result); 48 | ?> 49 | --EXPECT-- 50 | array(2) { 51 | [0]=> 52 | array(1) { 53 | ["key"]=> 54 | int(1) 55 | } 56 | [1]=> 57 | array(1) { 58 | ["key"]=> 59 | int(3) 60 | } 61 | } -------------------------------------------------------------------------------- /tests/comparison_filter/011.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with bracket notation 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 0, 11 | ], 12 | [ 13 | "key" => 42, 14 | ], 15 | [ 16 | "key" => -1, 17 | ], 18 | [ 19 | "key" => 41, 20 | ], 21 | [ 22 | "key" => 43, 23 | ], 24 | [ 25 | "key" => 42.0001, 26 | ], 27 | [ 28 | "key" => 41.9999, 29 | ], 30 | [ 31 | "key" => 100, 32 | ], 33 | [ 34 | "some" => "value", 35 | ], 36 | ]; 37 | 38 | $jsonPath = new \JsonPath\JsonPath(); 39 | $result = $jsonPath->find($data, "$[?(@['key']==42)]"); 40 | 41 | var_dump($result); 42 | ?> 43 | --EXPECT-- 44 | array(1) { 45 | [0]=> 46 | array(1) { 47 | ["key"]=> 48 | int(42) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /tests/comparison_filter/012.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with bracket notation and current object literal 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 0, 11 | ], 12 | [ 13 | "@key" => 42, 14 | ], 15 | [ 16 | "key" => 42, 17 | ], 18 | [ 19 | "@key" => 43, 20 | ], 21 | [ 22 | "some" => "value", 23 | ], 24 | ]; 25 | 26 | $jsonPath = new \JsonPath\JsonPath(); 27 | $result = $jsonPath->find($data, "$[?(@['@key']==42)]"); 28 | 29 | var_dump($result); 30 | ?> 31 | --EXPECT-- 32 | array(1) { 33 | [0]=> 34 | array(1) { 35 | ["@key"]=> 36 | int(42) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tests/comparison_filter/013.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with bracket notation with -1 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, "$[?(@[-1]==2)]"); 27 | 28 | var_dump($result); 29 | ?> 30 | --EXPECT-- 31 | array(2) { 32 | [0]=> 33 | array(2) { 34 | [0]=> 35 | int(0) 36 | [1]=> 37 | int(2) 38 | } 39 | [1]=> 40 | array(1) { 41 | [0]=> 42 | int(2) 43 | } 44 | } -------------------------------------------------------------------------------- /tests/comparison_filter/014.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with bracket notation with number 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, "$[?(@[1]=='b')]"); 21 | 22 | var_dump($result); 23 | ?> 24 | --EXPECT-- 25 | array(1) { 26 | [0]=> 27 | array(2) { 28 | [0]=> 29 | string(1) "a" 30 | [1]=> 31 | string(1) "b" 32 | } 33 | } -------------------------------------------------------------------------------- /tests/comparison_filter/015.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with bracket notation with number on object 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 10 | "a", 11 | "b", 12 | ], 13 | "2" => [ 14 | "x", 15 | "y", 16 | ], 17 | ]; 18 | 19 | $jsonPath = new \JsonPath\JsonPath(); 20 | $result = $jsonPath->find($data, "$[?(@[1]=='b')]"); 21 | 22 | var_dump($result); 23 | ?> 24 | --EXPECT-- 25 | array(1) { 26 | [0]=> 27 | array(2) { 28 | [0]=> 29 | string(1) "a" 30 | [1]=> 31 | string(1) "b" 32 | } 33 | } -------------------------------------------------------------------------------- /tests/comparison_filter/016.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with current object 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, "$[?(@)]"); 24 | 25 | var_dump($result); 26 | ?> 27 | --EXPECT-- 28 | array(11) { 29 | [0]=> 30 | string(10) "some value" 31 | [1]=> 32 | NULL 33 | [2]=> 34 | string(5) "value" 35 | [3]=> 36 | int(0) 37 | [4]=> 38 | int(1) 39 | [5]=> 40 | int(-1) 41 | [6]=> 42 | string(0) "" 43 | [7]=> 44 | array(0) { 45 | } 46 | [8]=> 47 | array(0) { 48 | } 49 | [9]=> 50 | bool(false) 51 | [10]=> 52 | bool(true) 53 | } -------------------------------------------------------------------------------- /tests/comparison_filter/017.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with different grouped operators 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | true, 11 | ], 12 | [ 13 | "a" => true, 14 | "b" => true, 15 | ], 16 | [ 17 | "a" => true, 18 | "b" => true, 19 | "c" => true, 20 | ], 21 | [ 22 | "b" => true, 23 | "c" => true, 24 | ], 25 | [ 26 | "a" => true, 27 | "c" => true, 28 | ], 29 | [ 30 | "c" => true, 31 | ], 32 | [ 33 | "b" => true, 34 | ], 35 | ]; 36 | 37 | $jsonPath = new \JsonPath\JsonPath(); 38 | $result = $jsonPath->find($data, "$[?(@.a && (@.b || @.c))]"); 39 | 40 | var_dump($result); 41 | ?> 42 | --EXPECT-- 43 | array(3) { 44 | [0]=> 45 | array(2) { 46 | ["a"]=> 47 | bool(true) 48 | ["b"]=> 49 | bool(true) 50 | } 51 | [1]=> 52 | array(3) { 53 | ["a"]=> 54 | bool(true) 55 | ["b"]=> 56 | bool(true) 57 | ["c"]=> 58 | bool(true) 59 | } 60 | [2]=> 61 | array(2) { 62 | ["a"]=> 63 | bool(true) 64 | ["c"]=> 65 | bool(true) 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /tests/comparison_filter/019.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with division 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 60, 11 | ], 12 | [ 13 | "key" => 50, 14 | ], 15 | [ 16 | "key" => 10, 17 | ], 18 | [ 19 | "key" => -50, 20 | ], 21 | [ 22 | "key/10" => 5, 23 | ], 24 | ]; 25 | 26 | $jsonPath = new \JsonPath\JsonPath(); 27 | $result = $jsonPath->find($data, "$[?(@.key/10==5)]"); 28 | 29 | var_dump($result); 30 | ?> 31 | --EXPECTF-- 32 | Fatal error: Uncaught JsonPath\JsonPathException: Missing closing regex / at position 9 in %s 33 | Stack trace: 34 | %s 35 | %s 36 | %s -------------------------------------------------------------------------------- /tests/comparison_filter/020.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with dot notation with dash 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 11 | ], 12 | ]; 13 | 14 | $jsonPath = new \JsonPath\JsonPath(); 15 | $result = $jsonPath->find($data, "$[?(@.key-dash == 'value')]"); 16 | 17 | var_dump($result); 18 | ?> 19 | --EXPECT-- 20 | array(1) { 21 | [0]=> 22 | array(1) { 23 | ["key-dash"]=> 24 | string(5) "value" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/comparison_filter/021.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with dot notation with number 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "first", 12 | "2" => "second", 13 | "b" => "third", 14 | ], 15 | ]; 16 | 17 | $jsonPath = new \JsonPath\JsonPath(); 18 | $result = $jsonPath->find($data, "$[?(@.2 == 'second')]"); 19 | sortRecursively($result); 20 | 21 | var_dump($result); 22 | ?> 23 | --EXPECT-- 24 | array(1) { 25 | [0]=> 26 | array(3) { 27 | ["a"]=> 28 | string(5) "first" 29 | [2]=> 30 | string(6) "second" 31 | ["b"]=> 32 | string(5) "third" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tests/comparison_filter/022.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with empty expression 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 42, 12 | ], 13 | "value", 14 | null, 15 | ]; 16 | 17 | $jsonPath = new \JsonPath\JsonPath(); 18 | $result = $jsonPath->find($data, "$[?()]"); 19 | 20 | var_dump($result); 21 | ?> 22 | --EXPECTF-- 23 | Fatal error: Uncaught JsonPath\JsonPathException: Expecting child node, filter, expression, or recursive node in %s 24 | Stack trace: 25 | %s 26 | %s 27 | %s -------------------------------------------------------------------------------- /tests/comparison_filter/024.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with equals on array of numbers 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, "$[?(@==42)]"); 22 | 23 | var_dump($result); 24 | ?> 25 | --EXPECT-- 26 | array(1) { 27 | [0]=> 28 | int(42) 29 | } -------------------------------------------------------------------------------- /tests/comparison_filter/025.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with equals on array without match 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 42, 11 | ] 12 | ]; 13 | 14 | $jsonPath = new \JsonPath\JsonPath(); 15 | $result = $jsonPath->find($data, "$[?(@.key==43)]"); 16 | 17 | var_dump($result); 18 | ?> 19 | --EXPECT-- 20 | bool(false) 21 | -------------------------------------------------------------------------------- /tests/comparison_filter/026.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with equals on object 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 10 | "key" => 0, 11 | ], 12 | "b" => [ 13 | "key" => 42, 14 | ], 15 | "c" => [ 16 | "key" => -1, 17 | ], 18 | "d" => [ 19 | "key" => 41, 20 | ], 21 | "e" => [ 22 | "key" => 43, 23 | ], 24 | "f" => [ 25 | "key" => 42.0001, 26 | ], 27 | "g" => [ 28 | "key" => 41.9999, 29 | ], 30 | "h" => [ 31 | "key" => 100, 32 | ], 33 | "i" => [ 34 | "some" => "value", 35 | ], 36 | ]; 37 | 38 | $jsonPath = new \JsonPath\JsonPath(); 39 | $result = $jsonPath->find($data, "$[?(@.key==42)]"); 40 | 41 | var_dump($result); 42 | ?> 43 | --EXPECT-- 44 | array(1) { 45 | [0]=> 46 | array(1) { 47 | ["key"]=> 48 | int(42) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /tests/comparison_filter/027.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with equals on object with key matching query 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 2, 10 | ]; 11 | 12 | $jsonPath = new \JsonPath\JsonPath(); 13 | $result = $jsonPath->find($data, "$[?(@.id==2)]"); 14 | 15 | var_dump($result); 16 | ?> 17 | --EXPECT-- 18 | bool(false) 19 | -------------------------------------------------------------------------------- /tests/comparison_filter/028.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with equals array 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 11 | "v1", 12 | "v2", 13 | ], 14 | ], 15 | [ 16 | "d" => [ 17 | "a", 18 | "b", 19 | ], 20 | ], 21 | [ 22 | "d" => "v1", 23 | ], 24 | [ 25 | "d" => "v2", 26 | ], 27 | [ 28 | "d" => [ 29 | ], 30 | ], 31 | [ 32 | "d" => [ 33 | ], 34 | ], 35 | [ 36 | "d" => null, 37 | ], 38 | [ 39 | "d" => -1, 40 | ], 41 | [ 42 | "d" => 0, 43 | ], 44 | [ 45 | "d" => 1, 46 | ], 47 | [ 48 | "d" => "['v1','v2']", 49 | ], 50 | [ 51 | "d" => "['v1', 'v2']", 52 | ], 53 | [ 54 | "d" => "v1,v2", 55 | ], 56 | [ 57 | "d" => "[\"v1\", \"v2\"]", 58 | ], 59 | [ 60 | "d" => "[\"v1\",\"v2\"]", 61 | ], 62 | ]; 63 | 64 | $jsonPath = new \JsonPath\JsonPath(); 65 | $result = $jsonPath->find($data, '$[?(@.d==["v1","v2"])]'); 66 | 67 | var_dump($result); 68 | ?> 69 | --EXPECT-- 70 | array(1) { 71 | [0]=> 72 | array(1) { 73 | ["d"]=> 74 | array(2) { 75 | [0]=> 76 | string(2) "v1" 77 | [1]=> 78 | string(2) "v2" 79 | } 80 | } 81 | } -------------------------------------------------------------------------------- /tests/comparison_filter/029.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with equals array for array slice with range 1 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, "$[?(@[0:1]==[1])]"); 27 | 28 | var_dump($result); 29 | ?> 30 | --EXPECTF-- 31 | Fatal error: Uncaught JsonPath\JsonPathException: Unsupported expression operand in %s 32 | Stack trace: 33 | %s 34 | %s 35 | %s -------------------------------------------------------------------------------- /tests/comparison_filter/030.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with equals array for dot notation with star 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, "$[?(@.*==[1,2])]"); 35 | 36 | var_dump($result); 37 | ?> 38 | --EXPECTF-- 39 | Fatal error: Uncaught JsonPath\JsonPathException: Unsupported expression operand in %s 40 | Stack trace: 41 | %s 42 | %s 43 | %s -------------------------------------------------------------------------------- /tests/comparison_filter/031.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with equals array with single quotes 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 11 | "v1", 12 | "v2", 13 | ], 14 | ], 15 | [ 16 | "d" => [ 17 | "a", 18 | "b", 19 | ], 20 | ], 21 | [ 22 | "d" => "v1", 23 | ], 24 | [ 25 | "d" => "v2", 26 | ], 27 | [ 28 | "d" => [ 29 | ], 30 | ], 31 | [ 32 | "d" => [ 33 | ], 34 | ], 35 | [ 36 | "d" => null, 37 | ], 38 | [ 39 | "d" => -1, 40 | ], 41 | [ 42 | "d" => 0, 43 | ], 44 | [ 45 | "d" => 1, 46 | ], 47 | [ 48 | "d" => "['v1','v2']", 49 | ], 50 | [ 51 | "d" => "['v1', 'v2']", 52 | ], 53 | [ 54 | "d" => "v1,v2", 55 | ], 56 | [ 57 | "d" => "[\"v1\", \"v2\"]", 58 | ], 59 | [ 60 | "d" => "[\"v1\",\"v2\"]", 61 | ], 62 | ]; 63 | 64 | $jsonPath = new \JsonPath\JsonPath(); 65 | $result = $jsonPath->find($data, "$[?(@.d==['v1','v2'])]"); 66 | 67 | var_dump($result); 68 | ?> 69 | --EXPECT-- 70 | array(1) { 71 | [0]=> 72 | array(1) { 73 | ["d"]=> 74 | array(2) { 75 | [0]=> 76 | string(2) "v1" 77 | [1]=> 78 | string(2) "v2" 79 | } 80 | } 81 | } -------------------------------------------------------------------------------- /tests/comparison_filter/032.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with equals boolean expression value 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 42, 11 | ], 12 | [ 13 | "key" => 43, 14 | ], 15 | [ 16 | "key" => 44, 17 | ], 18 | ]; 19 | 20 | $jsonPath = new \JsonPath\JsonPath(); 21 | $result = $jsonPath->find($data, "$[?((@.key<44)==false)]"); 22 | 23 | var_dump($result); 24 | ?> 25 | --EXPECT-- 26 | array(1) { 27 | [0]=> 28 | array(1) { 29 | ["key"]=> 30 | int(44) 31 | } 32 | } -------------------------------------------------------------------------------- /tests/comparison_filter/033.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with equals false 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "some value", 11 | ], 12 | [ 13 | "key" => true, 14 | ], 15 | [ 16 | "key" => false, 17 | ], 18 | [ 19 | "key" => null, 20 | ], 21 | [ 22 | "key" => "value", 23 | ], 24 | [ 25 | "key" => "", 26 | ], 27 | [ 28 | "key" => 0, 29 | ], 30 | [ 31 | "key" => 1, 32 | ], 33 | [ 34 | "key" => -1, 35 | ], 36 | [ 37 | "key" => "42", 38 | ], 39 | [ 40 | "key" => [], 41 | ], 42 | [ 43 | "key" => [], 44 | ], 45 | ]; 46 | 47 | $jsonPath = new \JsonPath\JsonPath(); 48 | $result = $jsonPath->find($data, "$[?(@.key==false)]"); 49 | 50 | var_dump($result); 51 | ?> 52 | --EXPECT-- 53 | array(1) { 54 | [0]=> 55 | array(1) { 56 | ["key"]=> 57 | bool(false) 58 | } 59 | } -------------------------------------------------------------------------------- /tests/comparison_filter/034.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with equals null 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "some value", 11 | ], 12 | [ 13 | "key" => true, 14 | ], 15 | [ 16 | "key" => false, 17 | ], 18 | [ 19 | "key" => null, 20 | ], 21 | [ 22 | "key" => "value", 23 | ], 24 | [ 25 | "key" => "", 26 | ], 27 | [ 28 | "key" => 0, 29 | ], 30 | [ 31 | "key" => 1, 32 | ], 33 | [ 34 | "key" => -1, 35 | ], 36 | [ 37 | "key" => "42", 38 | ], 39 | [ 40 | "key" => [], 41 | ], 42 | [ 43 | "key" => [], 44 | ], 45 | ]; 46 | 47 | $jsonPath = new \JsonPath\JsonPath(); 48 | $result = $jsonPath->find($data, "$[?(@.key==null)]"); 49 | 50 | var_dump($result); 51 | ?> 52 | --EXPECT-- 53 | array(1) { 54 | [0]=> 55 | array(1) { 56 | ["key"]=> 57 | NULL 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /tests/comparison_filter/035.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with equals number for array slice with range 1 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, "$[?(@[0:1]==1)]"); 27 | 28 | var_dump($result); 29 | ?> 30 | --EXPECT-- 31 | array(2) { 32 | [0]=> 33 | array(3) { 34 | [0]=> 35 | int(1) 36 | [1]=> 37 | int(2) 38 | [2]=> 39 | int(3) 40 | } 41 | [1]=> 42 | array(1) { 43 | [0]=> 44 | int(1) 45 | } 46 | } -------------------------------------------------------------------------------- /tests/comparison_filter/036.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with equals number for bracket notation with star 3 | --SKIPIF-- 4 | 5 | --DESCRIPTION-- 6 | This test case is allowed by the grammar but is semantically ambiguous. When 7 | an expression operand resolves to a non-scalar value, the first element in the 8 | set is used for comparison. In this case, the following comparisons are made: 9 | 10 | 1 == 2 11 | 2 == 2 12 | 1 == 2 13 | 2 == 2 14 | 1 == 2 15 | --FILE-- 16 | find($data, "$[?(@[*]==2)]"); 45 | 46 | var_dump($result); 47 | ?> 48 | --EXPECT-- 49 | array(2) { 50 | [0]=> 51 | array(2) { 52 | [0]=> 53 | int(2) 54 | [1]=> 55 | int(3) 56 | } 57 | [1]=> 58 | array(1) { 59 | [0]=> 60 | int(2) 61 | } 62 | } -------------------------------------------------------------------------------- /tests/comparison_filter/037.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with equals number for dot notation with star 3 | --SKIPIF-- 4 | 5 | --DESCRIPTION-- 6 | This test case is allowed by the grammar but is semantically ambiguous. When 7 | an expression operand resolves to a non-scalar value, the first element in the 8 | set is used for comparison. In this case, the following comparisons are made: 9 | 10 | 1 == 2 11 | 2 == 2 12 | 1 == 2 13 | 2 == 2 14 | 1 == 2 15 | --FILE-- 16 | find($data, "$[?(@.*==2)]"); 45 | 46 | var_dump($result); 47 | ?> 48 | --EXPECT-- 49 | array(2) { 50 | [0]=> 51 | array(2) { 52 | [0]=> 53 | int(2) 54 | [1]=> 55 | int(3) 56 | } 57 | [1]=> 58 | array(1) { 59 | [0]=> 60 | int(2) 61 | } 62 | } -------------------------------------------------------------------------------- /tests/comparison_filter/038.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with equals number with fraction 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | -12.3, 11 | ], 12 | [ 13 | "key" => -0.123, 14 | ], 15 | [ 16 | "key" => -12, 17 | ], 18 | [ 19 | "key" => 12.3, 20 | ], 21 | [ 22 | "key" => 2, 23 | ], 24 | [ 25 | "key" => "-0.123e2", 26 | ], 27 | ]; 28 | 29 | $jsonPath = new \JsonPath\JsonPath(); 30 | $result = $jsonPath->find($data, "$[?(@.key==-0.123e2)]"); 31 | 32 | var_dump($result); 33 | ?> 34 | --EXPECT-- 35 | array(1) { 36 | [0]=> 37 | array(1) { 38 | ["key"]=> 39 | float(-12.3) 40 | } 41 | } -------------------------------------------------------------------------------- /tests/comparison_filter/039.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with equals number with leading zeros 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "010", 11 | ], 12 | [ 13 | "key" => "10", 14 | ], 15 | [ 16 | "key" => 10, 17 | ], 18 | [ 19 | "key" => 0, 20 | ], 21 | [ 22 | "key" => 8, 23 | ], 24 | ]; 25 | 26 | $jsonPath = new \JsonPath\JsonPath(); 27 | $result = $jsonPath->find($data, "$[?(@.key==010)]"); 28 | 29 | var_dump($result); 30 | ?> 31 | --EXPECT-- 32 | array(1) { 33 | [0]=> 34 | array(1) { 35 | ["key"]=> 36 | int(10) 37 | } 38 | } -------------------------------------------------------------------------------- /tests/comparison_filter/041.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with equals string 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "some", 11 | ], 12 | [ 13 | "key" => "value", 14 | ], 15 | [ 16 | "key" => null, 17 | ], 18 | [ 19 | "key" => 0, 20 | ], 21 | [ 22 | "key" => 1, 23 | ], 24 | [ 25 | "key" => -1, 26 | ], 27 | [ 28 | "key" => "", 29 | ], 30 | [ 31 | "key" => [], 32 | ], 33 | [ 34 | "key" => [], 35 | ], 36 | [ 37 | "key" => "valuemore", 38 | ], 39 | [ 40 | "key" => "morevalue", 41 | ], 42 | [ 43 | "key" => [ 44 | "value", 45 | ], 46 | ], 47 | [ 48 | "key" => [ 49 | "some" => "value", 50 | ], 51 | ], 52 | [ 53 | "key" => [ 54 | "key" => "value", 55 | ], 56 | ], 57 | [ 58 | "some" => "value", 59 | ], 60 | ]; 61 | 62 | $jsonPath = new \JsonPath\JsonPath(); 63 | $result = $jsonPath->find($data, "$[?(@.key==\"value\")]"); 64 | 65 | var_dump($result); 66 | ?> 67 | --EXPECT-- 68 | array(1) { 69 | [0]=> 70 | array(1) { 71 | ["key"]=> 72 | string(5) "value" 73 | } 74 | } -------------------------------------------------------------------------------- /tests/comparison_filter/042.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with equals string with current object literal 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "some", 11 | ], 12 | [ 13 | "key" => "value", 14 | ], 15 | [ 16 | "key" => "hi@example.com", 17 | ], 18 | ]; 19 | 20 | $jsonPath = new \JsonPath\JsonPath(); 21 | $result = $jsonPath->find($data, "$[?(@.key==\"hi@example.com\")]"); 22 | 23 | var_dump($result); 24 | ?> 25 | --EXPECT-- 26 | array(1) { 27 | [0]=> 28 | array(1) { 29 | ["key"]=> 30 | string(14) "hi@example.com" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/comparison_filter/043.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with equals string with dot literal 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "some", 11 | ], 12 | [ 13 | "key" => "value", 14 | ], 15 | [ 16 | "key" => "some.value", 17 | ], 18 | ]; 19 | 20 | $jsonPath = new \JsonPath\JsonPath(); 21 | $result = $jsonPath->find($data, "$[?(@.key==\"some.value\")]"); 22 | 23 | var_dump($result); 24 | ?> 25 | --EXPECT-- 26 | array(1) { 27 | [0]=> 28 | array(1) { 29 | ["key"]=> 30 | string(10) "some.value" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/comparison_filter/044.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with equals string with single quotes 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "some", 11 | ], 12 | [ 13 | "key" => "value", 14 | ], 15 | ]; 16 | 17 | $jsonPath = new \JsonPath\JsonPath(); 18 | $result = $jsonPath->find($data, "$[?(@.key=='value')]"); 19 | 20 | var_dump($result); 21 | ?> 22 | --EXPECT-- 23 | array(1) { 24 | [0]=> 25 | array(1) { 26 | ["key"]=> 27 | string(5) "value" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/comparison_filter/045.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with equals true 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 11 | ], 12 | [ 13 | "key" => true, 14 | ], 15 | [ 16 | "key" => false, 17 | ], 18 | [ 19 | "key" => null, 20 | ], 21 | [ 22 | "key" => "value", 23 | ], 24 | [ 25 | "key" => "", 26 | ], 27 | [ 28 | "key" => 0, 29 | ], 30 | [ 31 | "key" => 1, 32 | ], 33 | [ 34 | "key" => -1, 35 | ], 36 | [ 37 | "key" => 42, 38 | ], 39 | [ 40 | "key" => [], 41 | ], 42 | [ 43 | "key" => [], 44 | ], 45 | ]; 46 | 47 | $jsonPath = new \JsonPath\JsonPath(); 48 | $result = $jsonPath->find($data, "$[?(@.key==true)]"); 49 | 50 | var_dump($result); 51 | ?> 52 | --EXPECT-- 53 | array(1) { 54 | [0]=> 55 | array(1) { 56 | ["key"]=> 57 | bool(true) 58 | } 59 | } -------------------------------------------------------------------------------- /tests/comparison_filter/046.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with equals with root reference 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 42, 10 | "items" => [ 11 | [ 12 | "key" => 10, 13 | ], 14 | [ 15 | "key" => 42, 16 | ], 17 | [ 18 | "key" => 50, 19 | ], 20 | ], 21 | ]; 22 | 23 | $jsonPath = new \JsonPath\JsonPath(); 24 | $result = $jsonPath->find($data, "$.items[?(@.key==$.value)]"); 25 | 26 | var_dump($result); 27 | ?> 28 | --EXPECT-- 29 | array(1) { 30 | [0]=> 31 | array(1) { 32 | ["key"]=> 33 | int(42) 34 | } 35 | } -------------------------------------------------------------------------------- /tests/comparison_filter/047.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with greater than 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 0, 11 | ], 12 | [ 13 | "key" => 42, 14 | ], 15 | [ 16 | "key" => -1, 17 | ], 18 | [ 19 | "key" => 41, 20 | ], 21 | [ 22 | "key" => 43, 23 | ], 24 | [ 25 | "key" => 42.0001, 26 | ], 27 | [ 28 | "key" => 41.9999, 29 | ], 30 | [ 31 | "key" => 100, 32 | ], 33 | [ 34 | "key" => "43", 35 | ], 36 | [ 37 | "key" => "42", 38 | ], 39 | [ 40 | "key" => "41", 41 | ], 42 | [ 43 | "key" => "value", 44 | ], 45 | [ 46 | "some" => "value", 47 | ], 48 | ]; 49 | 50 | $jsonPath = new \JsonPath\JsonPath(); 51 | $result = $jsonPath->find($data, "$[?(@.key>42)]"); 52 | 53 | var_dump($result); 54 | ?> 55 | --EXPECT-- 56 | array(4) { 57 | [0]=> 58 | array(1) { 59 | ["key"]=> 60 | int(43) 61 | } 62 | [1]=> 63 | array(1) { 64 | ["key"]=> 65 | float(42.0001) 66 | } 67 | [2]=> 68 | array(1) { 69 | ["key"]=> 70 | int(100) 71 | } 72 | [3]=> 73 | array(1) { 74 | ["key"]=> 75 | string(2) "43" 76 | } 77 | } -------------------------------------------------------------------------------- /tests/comparison_filter/049.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with in array of values 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 1, 11 | ], 12 | [ 13 | "d" => 2, 14 | ], 15 | [ 16 | "d" => 1, 17 | ], 18 | [ 19 | "d" => 3, 20 | ], 21 | [ 22 | "d" => 4, 23 | ], 24 | ]; 25 | 26 | $jsonPath = new \JsonPath\JsonPath(); 27 | $result = $jsonPath->find($data, "$[?(@.d in [2, 3])]"); 28 | 29 | var_dump($result); 30 | ?> 31 | --EXPECTF-- 32 | Fatal error: Uncaught JsonPath\JsonPathException: Unrecognized token `i` at position 8 in %s 33 | Stack trace: 34 | %s 35 | %s 36 | %s -------------------------------------------------------------------------------- /tests/comparison_filter/050.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with in current object 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 11 | 1, 12 | 2, 13 | 3, 14 | ], 15 | ], 16 | [ 17 | "d" => [ 18 | 2, 19 | ], 20 | ], 21 | [ 22 | "d" => [ 23 | 1, 24 | ], 25 | ], 26 | [ 27 | "d" => [ 28 | 3, 29 | 4, 30 | ], 31 | ], 32 | [ 33 | "d" => [ 34 | 4, 35 | 2, 36 | ], 37 | ], 38 | ]; 39 | 40 | $jsonPath = new \JsonPath\JsonPath(); 41 | $result = $jsonPath->find($data, "$[?(2 in @.d)]"); 42 | 43 | var_dump($result); 44 | ?> 45 | --EXPECTF-- 46 | Fatal error: Uncaught JsonPath\JsonPathException: Unrecognized token `i` at position 6 in %s 47 | Stack trace: 48 | %s 49 | %s 50 | %s -------------------------------------------------------------------------------- /tests/comparison_filter/051.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with less than 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 0, 11 | ], 12 | [ 13 | "key" => 42, 14 | ], 15 | [ 16 | "key" => -1, 17 | ], 18 | [ 19 | "key" => 41, 20 | ], 21 | [ 22 | "key" => 43, 23 | ], 24 | [ 25 | "key" => 42.0001, 26 | ], 27 | [ 28 | "key" => 41.9999, 29 | ], 30 | [ 31 | "key" => 100, 32 | ], 33 | [ 34 | "key" => "43", 35 | ], 36 | [ 37 | "key" => "42", 38 | ], 39 | [ 40 | "key" => "41", 41 | ], 42 | [ 43 | "key" => "value", 44 | ], 45 | [ 46 | "some" => "value", 47 | ], 48 | ]; 49 | 50 | $jsonPath = new \JsonPath\JsonPath(); 51 | $result = $jsonPath->find($data, "$[?(@.key<42)]"); 52 | 53 | var_dump($result); 54 | ?> 55 | --EXPECT-- 56 | array(5) { 57 | [0]=> 58 | array(1) { 59 | ["key"]=> 60 | int(0) 61 | } 62 | [1]=> 63 | array(1) { 64 | ["key"]=> 65 | int(-1) 66 | } 67 | [2]=> 68 | array(1) { 69 | ["key"]=> 70 | int(41) 71 | } 72 | [3]=> 73 | array(1) { 74 | ["key"]=> 75 | float(41.9999) 76 | } 77 | [4]=> 78 | array(1) { 79 | ["key"]=> 80 | string(2) "41" 81 | } 82 | } -------------------------------------------------------------------------------- /tests/comparison_filter/053.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with multiplication 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 60, 11 | ], 12 | [ 13 | "key" => 50, 14 | ], 15 | [ 16 | "key" => 10, 17 | ], 18 | [ 19 | "key" => -50, 20 | ], 21 | [ 22 | "key*2" => 100, 23 | ], 24 | ]; 25 | 26 | $jsonPath = new \JsonPath\JsonPath(); 27 | $result = $jsonPath->find($data, "$[?(@.key*2==100)]"); 28 | 29 | var_dump($result); 30 | ?> 31 | --EXPECTF-- 32 | Fatal error: Uncaught JsonPath\JsonPathException: Unrecognized token `*` at position 9 in %s 33 | Stack trace: 34 | %s 35 | %s 36 | %s 37 | -------------------------------------------------------------------------------- /tests/comparison_filter/057.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with regular expression 3 | --SKIPIF-- 4 | 5 | --INI-- 6 | pcre.jit=0 7 | --FILE-- 8 | "hullo world", 13 | ], 14 | [ 15 | "name" => "hello world", 16 | ], 17 | [ 18 | "name" => "yes hello world", 19 | ], 20 | [ 21 | "name" => "HELLO WORLD", 22 | ], 23 | [ 24 | "name" => "good bye", 25 | ], 26 | ]; 27 | 28 | $jsonPath = new \JsonPath\JsonPath(); 29 | $result = $jsonPath->find($data, "$[?(@.name=~/hello.*/)]"); 30 | 31 | var_dump($result); 32 | ?> 33 | --EXPECT-- 34 | array(2) { 35 | [0]=> 36 | array(1) { 37 | ["name"]=> 38 | string(11) "hello world" 39 | } 40 | [1]=> 41 | array(1) { 42 | ["name"]=> 43 | string(15) "yes hello world" 44 | } 45 | } -------------------------------------------------------------------------------- /tests/comparison_filter/058.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with regular expression from member 3 | --SKIPIF-- 4 | 5 | --DESCRIPTION-- 6 | JSONPath node selectors are not interpolated within regex patterns. 7 | --INI-- 8 | pcre.jit=0 9 | --FILE-- 10 | "hullo world", 15 | ], 16 | [ 17 | "name" => "hello world", 18 | ], 19 | [ 20 | "name" => "yes hello world", 21 | ], 22 | [ 23 | "name" => "HELLO WORLD", 24 | ], 25 | [ 26 | "name" => "good bye", 27 | ], 28 | [ 29 | "pattern" => "hello.*", 30 | ], 31 | ]; 32 | 33 | $jsonPath = new \JsonPath\JsonPath(); 34 | $result = $jsonPath->find($data, "$[?(@.name=~/@.pattern/)]"); 35 | 36 | var_dump($result); 37 | ?> 38 | --EXPECT-- 39 | bool(false) -------------------------------------------------------------------------------- /tests/comparison_filter/059.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with set wise comparison to scalar 3 | --SKIPIF-- 4 | 5 | --DESCRIPTION-- 6 | This test case is allowed by the grammar but is semantically ambiguous. When 7 | an expression operand resolves to a non-scalar value, the first element in the 8 | set is used for comparison. In this case, the following comparisons are made: 9 | 10 | 1 >= 4 11 | 3 >= 4 12 | 5 >= 4 13 | --FILE-- 14 | find($data, "$[?(@[*]>=4)]"); 33 | 34 | var_dump($result); 35 | ?> 36 | --EXPECT-- 37 | array(1) { 38 | [0]=> 39 | array(2) { 40 | [0]=> 41 | int(5) 42 | [1]=> 43 | int(6) 44 | } 45 | } -------------------------------------------------------------------------------- /tests/comparison_filter/060.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with set wise comparison to set 3 | --SKIPIF-- 4 | 5 | --DESCRIPTION-- 6 | This test case is allowed by the grammar but is semantically ambiguous. When 7 | an expression operand resolves to a non-scalar value, the first element in the 8 | set is used for comparison. In this case, the following comparisons are made: 9 | 10 | 1 >= 3 11 | 3 >= 3 12 | 5 >= 3 13 | --FILE-- 14 | [ 18 | [ 19 | 1, 20 | 2, 21 | ], 22 | [ 23 | 3, 24 | 4, 25 | ], 26 | [ 27 | 5, 28 | 6, 29 | ], 30 | ], 31 | "y" => [ 32 | 3, 33 | 4, 34 | 5, 35 | ], 36 | ]; 37 | 38 | $jsonPath = new \JsonPath\JsonPath(); 39 | $result = $jsonPath->find($data, "$.x[?(@[*]>=$.y[*])]"); 40 | 41 | var_dump($result); 42 | ?> 43 | --EXPECT-- 44 | array(2) { 45 | [0]=> 46 | array(2) { 47 | [0]=> 48 | int(3) 49 | [1]=> 50 | int(4) 51 | } 52 | [1]=> 53 | array(2) { 54 | [0]=> 55 | int(5) 56 | [1]=> 57 | int(6) 58 | } 59 | } -------------------------------------------------------------------------------- /tests/comparison_filter/063.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with subpaths 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 11 | "city" => "Berlin", 12 | ], 13 | ], 14 | [ 15 | "address" => [ 16 | "city" => "London", 17 | ], 18 | ], 19 | ]; 20 | 21 | $jsonPath = new \JsonPath\JsonPath(); 22 | $result = $jsonPath->find($data, "$[?(@.address.city=='Berlin')]"); 23 | 24 | var_dump($result); 25 | ?> 26 | --EXPECT-- 27 | array(1) { 28 | [0]=> 29 | array(1) { 30 | ["address"]=> 31 | array(1) { 32 | ["city"]=> 33 | string(6) "Berlin" 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/comparison_filter/064.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with subtraction 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 60, 11 | ], 12 | [ 13 | "key" => 50, 14 | ], 15 | [ 16 | "key" => 10, 17 | ], 18 | [ 19 | "key" => -50, 20 | ], 21 | [ 22 | "key-50" => -100, 23 | ], 24 | ]; 25 | 26 | $jsonPath = new \JsonPath\JsonPath(); 27 | $result = $jsonPath->find($data, "$[?(@.key-50==-100)]"); 28 | 29 | var_dump($result); 30 | ?> 31 | --EXPECT-- 32 | array(1) { 33 | [0]=> 34 | array(1) { 35 | ["key-50"]=> 36 | int(-100) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tests/comparison_filter/065.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with tautological comparison 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, "$[?(1==1)]"); 24 | 25 | var_dump($result); 26 | ?> 27 | --EXPECT-- 28 | array(11) { 29 | [0]=> 30 | int(1) 31 | [1]=> 32 | int(3) 33 | [2]=> 34 | string(4) "nice" 35 | [3]=> 36 | bool(true) 37 | [4]=> 38 | NULL 39 | [5]=> 40 | bool(false) 41 | [6]=> 42 | array(0) { 43 | } 44 | [7]=> 45 | array(0) { 46 | } 47 | [8]=> 48 | int(-1) 49 | [9]=> 50 | int(0) 51 | [10]=> 52 | string(0) "" 53 | } 54 | -------------------------------------------------------------------------------- /tests/comparison_filter/068.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with value after dot notation with wildcard on array of objects 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "some value", 11 | ], 12 | [ 13 | "key" => "value", 14 | ], 15 | ]; 16 | 17 | $jsonPath = new \JsonPath\JsonPath(); 18 | $result = $jsonPath->find($data, "$.*[?(@.key)]"); 19 | 20 | var_dump($result); 21 | ?> 22 | --EXPECT-- 23 | bool(false) 24 | -------------------------------------------------------------------------------- /tests/comparison_filter/069.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with value after recursive descent 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 2, 11 | "more" => [ 12 | [ 13 | "id" => 2, 14 | ], 15 | [ 16 | "more" => [ 17 | "id" => 2, 18 | ], 19 | ], 20 | [ 21 | "id" => [ 22 | "id" => 2, 23 | ], 24 | ], 25 | [ 26 | [ 27 | "id" => 2, 28 | ], 29 | ], 30 | ], 31 | ]; 32 | 33 | $jsonPath = new \JsonPath\JsonPath(); 34 | $result = $jsonPath->find($data, "$..[?(@.id)]"); 35 | sortRecursively($result); 36 | 37 | var_dump($result); 38 | ?> 39 | --EXPECT-- 40 | array(5) { 41 | [0]=> 42 | array(1) { 43 | ["id"]=> 44 | int(2) 45 | } 46 | [1]=> 47 | array(1) { 48 | ["id"]=> 49 | int(2) 50 | } 51 | [2]=> 52 | array(1) { 53 | ["id"]=> 54 | int(2) 55 | } 56 | [3]=> 57 | array(1) { 58 | ["id"]=> 59 | int(2) 60 | } 61 | [4]=> 62 | array(1) { 63 | ["id"]=> 64 | array(1) { 65 | ["id"]=> 66 | int(2) 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tests/comparison_filter/070.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with value false 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, "$[?(false)]"); 24 | 25 | var_dump($result); 26 | ?> 27 | --EXPECTF-- 28 | Fatal error: Uncaught JsonPath\JsonPathException: Invalid expression. in %s 29 | Stack trace: 30 | %s 31 | %s 32 | %s 33 | -------------------------------------------------------------------------------- /tests/comparison_filter/071.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with value from recursive descent 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 11 | [ 12 | "child" => 1, 13 | ], 14 | [ 15 | "child" => 2, 16 | ], 17 | ], 18 | ], 19 | [ 20 | "key" => [ 21 | [ 22 | "child" => 2, 23 | ], 24 | ], 25 | ], 26 | [ 27 | "key" => [ 28 | [], 29 | ], 30 | ], 31 | [ 32 | "key" => [ 33 | [ 34 | "something" => 42, 35 | ], 36 | ], 37 | ], 38 | [], 39 | ]; 40 | 41 | $jsonPath = new \JsonPath\JsonPath(); 42 | $result = $jsonPath->find($data, "$[?(@..child)]"); 43 | 44 | var_dump($result); 45 | ?> 46 | --EXPECT-- 47 | array(2) { 48 | [0]=> 49 | array(1) { 50 | ["key"]=> 51 | array(2) { 52 | [0]=> 53 | array(1) { 54 | ["child"]=> 55 | int(1) 56 | } 57 | [1]=> 58 | array(1) { 59 | ["child"]=> 60 | int(2) 61 | } 62 | } 63 | } 64 | [1]=> 65 | array(1) { 66 | ["key"]=> 67 | array(1) { 68 | [0]=> 69 | array(1) { 70 | ["child"]=> 71 | int(2) 72 | } 73 | } 74 | } 75 | } -------------------------------------------------------------------------------- /tests/comparison_filter/072.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with value null 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, "$[?(null)]"); 24 | 25 | var_dump($result); 26 | ?> 27 | --EXPECTF-- 28 | Fatal error: Uncaught JsonPath\JsonPathException: Invalid expression. in %s 29 | Stack trace: 30 | %s 31 | %s 32 | %s -------------------------------------------------------------------------------- /tests/comparison_filter/073.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with value true 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, "$[?(true)]"); 24 | 25 | var_dump($result); 26 | ?> 27 | --EXPECTF-- 28 | Fatal error: Uncaught JsonPath\JsonPathException: Invalid expression. in %s 29 | Stack trace: 30 | %s 31 | %s 32 | %s 33 | -------------------------------------------------------------------------------- /tests/comparison_filter/075.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression without value 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "some value", 11 | ], 12 | [ 13 | "key" => true, 14 | ], 15 | [ 16 | "key" => false, 17 | ], 18 | [ 19 | "key" => null, 20 | ], 21 | [ 22 | "key" => "value", 23 | ], 24 | [ 25 | "key" => "", 26 | ], 27 | [ 28 | "key" => 0, 29 | ], 30 | [ 31 | "key" => 1, 32 | ], 33 | [ 34 | "key" => -1, 35 | ], 36 | [ 37 | "key" => 42, 38 | ], 39 | [ 40 | "key" => [], 41 | ], 42 | [ 43 | "key" => [], 44 | ], 45 | ]; 46 | 47 | $jsonPath = new \JsonPath\JsonPath(); 48 | $result = $jsonPath->find($data, "$[?(!@.key)]"); 49 | 50 | var_dump($result); 51 | ?> 52 | --EXPECT-- 53 | array(1) { 54 | [0]=> 55 | array(1) { 56 | ["some"]=> 57 | string(10) "some value" 58 | } 59 | } -------------------------------------------------------------------------------- /tests/comparison_misc/001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test empty 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 42, 10 | "" => 21, 11 | ]; 12 | 13 | $jsonPath = new \JsonPath\JsonPath(); 14 | $result = $jsonPath->find($data, ""); 15 | 16 | var_dump($result); 17 | ?> 18 | --EXPECTF-- 19 | Fatal error: Uncaught JsonPath\JsonPathException: JSONPath must start with a root operator `$` in %s 20 | Stack trace: 21 | %s 22 | %s 23 | %s -------------------------------------------------------------------------------- /tests/comparison_misc/002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test parens notation 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 1, 10 | "some" => 2, 11 | "more" => 3, 12 | ]; 13 | 14 | $jsonPath = new \JsonPath\JsonPath(); 15 | $result = $jsonPath->find($data, "$(key,more)"); 16 | 17 | var_dump($result); 18 | ?> 19 | --EXPECTF-- 20 | Fatal error: Uncaught JsonPath\JsonPathException: Unrecognized token `k` at position 2 in %s 21 | Stack trace: 22 | %s 23 | %s 24 | %s -------------------------------------------------------------------------------- /tests/comparison_misc/003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test script expression 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, "$[(@.length-1)]"); 18 | 19 | var_dump($result); 20 | ?> 21 | --EXPECTF-- 22 | Fatal error: Uncaught JsonPath\JsonPathException: Unexpected filter element in %s 23 | Stack trace: 24 | %s 25 | %s 26 | %s -------------------------------------------------------------------------------- /tests/comparison_recursive_descent/001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test recursive descent 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 11 | "b" => "c", 12 | ], 13 | ], 14 | [ 15 | 0, 16 | 1, 17 | ], 18 | ]; 19 | 20 | $jsonPath = new \JsonPath\JsonPath(); 21 | $result = $jsonPath->find($data, "$.."); 22 | 23 | var_dump($result); 24 | ?> 25 | --EXPECTF-- 26 | Fatal error: Uncaught JsonPath\JsonPathException: Recursive descent operator `..` must be followed by a child selector, filter or wildcard at position 3 in %s 27 | Stack trace: 28 | %s 29 | %s 30 | %s -------------------------------------------------------------------------------- /tests/comparison_recursive_descent/002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test recursive descent after dot notation 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | "key" => [ 11 | "complex" => "string", 12 | "primitives" => [ 13 | 0, 14 | 1, 15 | ], 16 | ], 17 | ]; 18 | 19 | $jsonPath = new \JsonPath\JsonPath(); 20 | $result = $jsonPath->find($data, "$.key.."); 21 | 22 | var_dump($result); 23 | ?> 24 | --EXPECTF-- 25 | Fatal error: Uncaught JsonPath\JsonPathException: Recursive descent operator `..` must be followed by a child selector, filter or wildcard at position 7 in %s 26 | Stack trace: 27 | %s 28 | %s 29 | %s -------------------------------------------------------------------------------- /tests/comparison_root/001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test root 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 11 | "another key" => [ 12 | "complex" => [ 13 | "a", 14 | 1, 15 | ], 16 | ], 17 | ]; 18 | 19 | $jsonPath = new \JsonPath\JsonPath(); 20 | $result = $jsonPath->find($data, "$"); 21 | sortRecursively($result); 22 | 23 | var_dump($result); 24 | ?> 25 | --EXPECT-- 26 | array(1) { 27 | [0]=> 28 | array(2) { 29 | ["another key"]=> 30 | array(1) { 31 | ["complex"]=> 32 | array(2) { 33 | [0]=> 34 | int(1) 35 | [1]=> 36 | string(1) "a" 37 | } 38 | } 39 | ["key"]=> 40 | string(5) "value" 41 | } 42 | } -------------------------------------------------------------------------------- /tests/comparison_root/002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test root on scalar 3 | --SKIPIF-- 4 | 5 | 6 | --FILE-- 7 | find($data, "$"); 13 | 14 | var_dump($result); 15 | ?> 16 | --EXPECTF-- 17 | Fatal error: Uncaught TypeError: JsonPath\JsonPath::find(): Argument #1 ($data) must be of type array, int given in %s002.php:%d 18 | Stack trace: 19 | %s 20 | %s 21 | %s 22 | -------------------------------------------------------------------------------- /tests/comparison_root/003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test root on scalar false 3 | --SKIPIF-- 4 | 5 | 6 | --FILE-- 7 | find($data, "$"); 13 | 14 | var_dump($result); 15 | ?> 16 | --EXPECTF-- 17 | Fatal error: Uncaught TypeError: JsonPath\JsonPath::find(): Argument #1 ($data) must be of type array, %s given in %s003.php:%d 18 | Stack trace: 19 | %s 20 | %s 21 | %s 22 | -------------------------------------------------------------------------------- /tests/comparison_root/004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test root on scalar true 3 | --SKIPIF-- 4 | 5 | 6 | --FILE-- 7 | find($data, "$"); 13 | 14 | var_dump($result); 15 | ?> 16 | --EXPECTF-- 17 | Fatal error: Uncaught TypeError: JsonPath\JsonPath::find(): Argument #1 ($data) must be of type array, %s given in %s004.php:%d 18 | Stack trace: 19 | %s 20 | %s 21 | %s 22 | -------------------------------------------------------------------------------- /tests/comparison_union/001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test union 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, "$[0,1]"); 16 | 17 | var_dump($result); 18 | ?> 19 | --EXPECT-- 20 | array(2) { 21 | [0]=> 22 | string(5) "first" 23 | [1]=> 24 | string(6) "second" 25 | } 26 | -------------------------------------------------------------------------------- /tests/comparison_union/002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test union with duplication from array 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, "$[0,0]"); 14 | 15 | var_dump($result); 16 | ?> 17 | --EXPECT-- 18 | array(2) { 19 | [0]=> 20 | string(1) "a" 21 | [1]=> 22 | string(1) "a" 23 | } 24 | -------------------------------------------------------------------------------- /tests/comparison_union/003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test union with duplication from object 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 1, 10 | ]; 11 | 12 | $jsonPath = new \JsonPath\JsonPath(); 13 | $result = $jsonPath->find($data, "$['a','a']"); 14 | 15 | var_dump($result); 16 | ?> 17 | --EXPECT-- 18 | array(2) { 19 | [0]=> 20 | int(1) 21 | [1]=> 22 | int(1) 23 | } -------------------------------------------------------------------------------- /tests/comparison_union/004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test union with filter 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 1, 11 | ], 12 | [ 13 | "key" => 8, 14 | ], 15 | [ 16 | "key" => 3, 17 | ], 18 | [ 19 | "key" => 10, 20 | ], 21 | [ 22 | "key" => 7, 23 | ], 24 | [ 25 | "key" => 2, 26 | ], 27 | [ 28 | "key" => 6, 29 | ], 30 | [ 31 | "key" => 4, 32 | ], 33 | ]; 34 | 35 | $jsonPath = new \JsonPath\JsonPath(); 36 | $result = $jsonPath->find($data, "$[?(@.key<3),?(@.key>6)]"); 37 | 38 | var_dump($result); 39 | ?> 40 | --EXPECTF-- 41 | Fatal error: Uncaught JsonPath\JsonPathException: Unrecognized token `?` at position 13 in %s 42 | Stack trace: 43 | %s 44 | %s 45 | %s 46 | -------------------------------------------------------------------------------- /tests/comparison_union/005.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test union with keys 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | "another" => "entry", 11 | ]; 12 | 13 | $jsonPath = new \JsonPath\JsonPath(); 14 | $result = $jsonPath->find($data, "$['key','another']"); 15 | 16 | var_dump($result); 17 | ?> 18 | --EXPECT-- 19 | array(2) { 20 | [0]=> 21 | string(5) "value" 22 | [1]=> 23 | string(5) "entry" 24 | } -------------------------------------------------------------------------------- /tests/comparison_union/006.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test union with keys on object without key 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "value", 10 | "another" => "entry", 11 | ]; 12 | 13 | $jsonPath = new \JsonPath\JsonPath(); 14 | $result = $jsonPath->find($data, "$['missing','key']"); 15 | 16 | var_dump($result); 17 | ?> 18 | --EXPECT-- 19 | array(1) { 20 | [0]=> 21 | string(5) "value" 22 | } -------------------------------------------------------------------------------- /tests/comparison_union/007.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test union with keys after array slice 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "cc1", 11 | "d" => "dd1", 12 | "e" => "ee1", 13 | ], 14 | [ 15 | "c" => "cc2", 16 | "d" => "dd2", 17 | "e" => "ee2", 18 | ], 19 | ]; 20 | 21 | $jsonPath = new \JsonPath\JsonPath(); 22 | $result = $jsonPath->find($data, "$[:]['c','d']"); 23 | 24 | var_dump($result); 25 | ?> 26 | --EXPECT-- 27 | array(4) { 28 | [0]=> 29 | string(3) "cc1" 30 | [1]=> 31 | string(3) "dd1" 32 | [2]=> 33 | string(3) "cc2" 34 | [3]=> 35 | string(3) "dd2" 36 | } -------------------------------------------------------------------------------- /tests/comparison_union/008.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test union with keys after bracket notation 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "cc1", 11 | "d" => "dd1", 12 | "e" => "ee1", 13 | ], 14 | [ 15 | "c" => "cc2", 16 | "d" => "dd2", 17 | "e" => "ee2", 18 | ], 19 | ]; 20 | 21 | $jsonPath = new \JsonPath\JsonPath(); 22 | $result = $jsonPath->find($data, "$[0]['c','d']"); 23 | 24 | var_dump($result); 25 | ?> 26 | --EXPECT-- 27 | array(2) { 28 | [0]=> 29 | string(3) "cc1" 30 | [1]=> 31 | string(3) "dd1" 32 | } -------------------------------------------------------------------------------- /tests/comparison_union/009.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test union with keys after dot notation with wildcard 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "cc1", 11 | "d" => "dd1", 12 | "e" => "ee1", 13 | ], 14 | [ 15 | "c" => "cc2", 16 | "d" => "dd2", 17 | "e" => "ee2", 18 | ], 19 | ]; 20 | 21 | $jsonPath = new \JsonPath\JsonPath(); 22 | $result = $jsonPath->find($data, "$.*['c','d']"); 23 | 24 | var_dump($result); 25 | ?> 26 | --EXPECT-- 27 | array(4) { 28 | [0]=> 29 | string(3) "cc1" 30 | [1]=> 31 | string(3) "dd1" 32 | [2]=> 33 | string(3) "cc2" 34 | [3]=> 35 | string(3) "dd2" 36 | } -------------------------------------------------------------------------------- /tests/comparison_union/010.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test union with keys after recursive descent 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "cc1", 12 | "d" => "dd1", 13 | "e" => "ee1", 14 | ], 15 | [ 16 | "c" => "cc2", 17 | "child" => [ 18 | "d" => "dd2", 19 | ], 20 | ], 21 | [ 22 | "c" => "cc3", 23 | ], 24 | [ 25 | "d" => "dd4", 26 | ], 27 | [ 28 | "child" => [ 29 | "c" => "cc5", 30 | ], 31 | ], 32 | ]; 33 | 34 | $jsonPath = new \JsonPath\JsonPath(); 35 | $result = $jsonPath->find($data, "$..['c','d']"); 36 | sortRecursively($result); 37 | 38 | var_dump($result); 39 | ?> 40 | --EXPECT-- 41 | array(7) { 42 | [0]=> 43 | string(3) "cc1" 44 | [1]=> 45 | string(3) "cc2" 46 | [2]=> 47 | string(3) "cc3" 48 | [3]=> 49 | string(3) "cc5" 50 | [4]=> 51 | string(3) "dd1" 52 | [5]=> 53 | string(3) "dd2" 54 | [6]=> 55 | string(3) "dd4" 56 | } -------------------------------------------------------------------------------- /tests/comparison_union/011.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test union with numbers in decreasing order 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, "$[4,1]"); 18 | 19 | var_dump($result); 20 | ?> 21 | --EXPECT-- 22 | array(2) { 23 | [0]=> 24 | int(5) 25 | [1]=> 26 | int(2) 27 | } 28 | -------------------------------------------------------------------------------- /tests/comparison_union/012.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test union with repeated matches after dot notation with wildcard 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 10 | "string", 11 | null, 12 | true, 13 | ], 14 | "b" => [ 15 | false, 16 | "string", 17 | 5.4, 18 | ], 19 | ]; 20 | 21 | $jsonPath = new \JsonPath\JsonPath(); 22 | $result = $jsonPath->find($data, "$.*[0,:5]"); 23 | 24 | var_dump($result); 25 | ?> 26 | --EXPECTF-- 27 | Fatal error: Uncaught JsonPath\JsonPathException: Expected integer, got LEX_SLICE in index union filter in %s 28 | Stack trace: 29 | %s 30 | %s 31 | %s -------------------------------------------------------------------------------- /tests/comparison_union/013.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test union with slice and number 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, "$[1:3,4]"); 18 | 19 | var_dump($result); 20 | ?> 21 | --EXPECTF-- 22 | Fatal error: Uncaught JsonPath\JsonPathException: Expected slice separator `:` or integer, got LEX_CHILD_SEP in slice union filter in %s 23 | Stack trace: 24 | %s 25 | %s 26 | %s -------------------------------------------------------------------------------- /tests/comparison_union/014.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test union with spaces 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, "$[ 0 , 1 ]"); 16 | 17 | var_dump($result); 18 | ?> 19 | --EXPECT-- 20 | array(2) { 21 | [0]=> 22 | string(5) "first" 23 | [1]=> 24 | string(6) "second" 25 | } 26 | -------------------------------------------------------------------------------- /tests/comparison_union/015.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test union with wildcard and number 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find($data, "$[*,1]"); 18 | 19 | var_dump($result); 20 | ?> 21 | --EXPECTF-- 22 | Fatal error: Uncaught JsonPath\JsonPathException: Wildcard filter contains an invalid character, expected `]` at position 3 in %s 23 | Stack trace: 24 | %s 25 | %s 26 | %s 27 | -------------------------------------------------------------------------------- /tests/expressions/001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Ensure order of operations are enforced 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 12 | [ 13 | "a" => "true", 14 | "b" => "false", 15 | "c" => "false" 16 | ] 17 | ] 18 | ]; 19 | 20 | echo "Without parentheses\n"; 21 | var_dump($jsonPath->find($obj, '$.test[?(@.a == "true" || @.b == "true" && @.c == "true")]')); 22 | echo "With parentheses\n"; 23 | var_dump($jsonPath->find($obj, '$.test[?((@.a == "true" || @.b == "true") && @.c == "true")]')); 24 | --EXPECT-- 25 | Without parentheses 26 | array(1) { 27 | [0]=> 28 | array(3) { 29 | ["a"]=> 30 | string(4) "true" 31 | ["b"]=> 32 | string(5) "false" 33 | ["c"]=> 34 | string(5) "false" 35 | } 36 | } 37 | With parentheses 38 | bool(false) 39 | -------------------------------------------------------------------------------- /tests/expressions/003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter expression with double negation 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 0, 11 | ], 12 | [ 13 | "key" => 42, 14 | ], 15 | [ 16 | "key" => -1, 17 | ], 18 | [ 19 | "key" => 41, 20 | ], 21 | [ 22 | "key" => 43, 23 | ], 24 | [ 25 | "key" => 42.0001, 26 | ], 27 | [ 28 | "key" => 41.9999, 29 | ], 30 | [ 31 | "key" => 100, 32 | ], 33 | [ 34 | "key" => "43", 35 | ], 36 | [ 37 | "key" => "42", 38 | ], 39 | [ 40 | "key" => "41", 41 | ], 42 | [ 43 | "key" => "value", 44 | ], 45 | [ 46 | "some" => "value", 47 | ], 48 | ]; 49 | 50 | $jsonPath = new \JsonPath\JsonPath(); 51 | $result = $jsonPath->find($data, "$[?(!!(@.key==42))]"); 52 | 53 | var_dump($result); 54 | ?> 55 | --EXPECT-- 56 | array(1) { 57 | [0]=> 58 | array(1) { 59 | ["key"]=> 60 | int(42) 61 | } 62 | } -------------------------------------------------------------------------------- /tests/extension_info/001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test presence of extension section in phpinfo output 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 17 | --EXPECT-- 18 | jsonpath 19 | -------------------------------------------------------------------------------- /tests/extension_info/002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test presence of extension enabled info in phpinfo output 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | (.*)$/m', $info, $match); 14 | echo !empty($match) ? $match[0] : ''; 15 | 16 | ?> 17 | --EXPECTF-- 18 | jsonpath support => %s 19 | -------------------------------------------------------------------------------- /tests/extension_info/003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test presence of extension version info in phpinfo output 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | (.*)$/m', $info, $match); 14 | echo !empty($match) ? $match[0] : ''; 15 | 16 | ?> 17 | --EXPECTF-- 18 | jsonpath version => %s 19 | -------------------------------------------------------------------------------- /tests/isset/001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test isset as single operator in expression 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 10 | array( 11 | array( 12 | 'category' => 'reference', 13 | 'author' => 'Nigel Rees', 14 | 'title' => 'Sayings of the Century', 15 | 'price' => 8.9499999999999993, 16 | 'id' => 17 | array( 18 | 'isbn' => '684832674', 19 | ) 20 | ) 21 | ) 22 | ); 23 | 24 | $jsonPath = new \JsonPath\JsonPath(); 25 | 26 | print_r($jsonPath->find($obj, '$.book[?(@["id"]["isbn"])]')); 27 | 28 | ?> 29 | --EXPECT-- 30 | Array 31 | ( 32 | [0] => Array 33 | ( 34 | [category] => reference 35 | [author] => Nigel Rees 36 | [title] => Sayings of the Century 37 | [price] => 8.95 38 | [id] => Array 39 | ( 40 | [isbn] => 684832674 41 | ) 42 | 43 | ) 44 | 45 | ) -------------------------------------------------------------------------------- /tests/isset/002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test isset in conjunction with a second subexpression 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 10 | array( 11 | array( 12 | 'category' => 'fiction', 13 | 'author' => 'J. R. R. Tolkien', 14 | 'title' => 'The Lord of the Rings', 15 | 'price' => 22.99, 16 | 'id' => 17 | array( 18 | 'isbn' => '0-395-19395-8', 19 | ) 20 | ), 21 | array( 22 | 'category' => 'reference', 23 | 'author' => 'Nigel Rees', 24 | 'title' => 'Sayings of the Century', 25 | 'price' => 8.9499999999999993, 26 | 'id' => 27 | array( 28 | 'isbn' => '684832674', 29 | ) 30 | ) 31 | ) 32 | ); 33 | 34 | $jsonPath = new \JsonPath\JsonPath(); 35 | 36 | print_r($jsonPath->find($obj, '$.book[?(@["id"]["isbn"] && @.author == "Nigel Rees")]')); 37 | 38 | ?> 39 | --EXPECT-- 40 | Array 41 | ( 42 | [0] => Array 43 | ( 44 | [category] => reference 45 | [author] => Nigel Rees 46 | [title] => Sayings of the Century 47 | [price] => 8.95 48 | [id] => Array 49 | ( 50 | [isbn] => 684832674 51 | ) 52 | 53 | ) 54 | 55 | ) -------------------------------------------------------------------------------- /tests/isset/003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Ensure AST selector on right side of AND expression is not identified as ISSET 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 10 | array( 11 | array( 12 | 'category' => 'fiction', 13 | 'author' => 'J. R. R. Tolkien', 14 | 'title' => 'The Lord of the Rings', 15 | 'price' => 22.99, 16 | 'id' => 17 | array( 18 | 'isbn' => '0-395-19395-8', 19 | ) 20 | ), 21 | array( 22 | 'category' => 'reference', 23 | 'author' => 'Nigel Rees', 24 | 'title' => 'Sayings of the Century', 25 | 'price' => 8.9499999999999993, 26 | 'id' => 27 | array( 28 | 'isbn' => '684832674', 29 | ) 30 | ) 31 | ) 32 | ); 33 | 34 | $jsonPath = new \JsonPath\JsonPath(); 35 | 36 | print_r($jsonPath->find($obj, '$.book[?(@["id"]["isbn"] && "Nigel Rees" == @.author)]')); 37 | 38 | ?> 39 | --EXPECT-- 40 | Array 41 | ( 42 | [0] => Array 43 | ( 44 | [category] => reference 45 | [author] => Nigel Rees 46 | [title] => Sayings of the Century 47 | [price] => 8.95 48 | [id] => Array 49 | ( 50 | [isbn] => 684832674 51 | ) 52 | 53 | ) 54 | 55 | ) -------------------------------------------------------------------------------- /tests/issues/00143.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test binary operator with missing left-hand operand 3 | --DESCRIPTION-- 4 | https://github.com/supermetrics-public/pecl-jsonpath/issues/143 5 | --SKIPIF-- 6 | 7 | --FILE-- 8 | find([], '$.store.book[?(@.author == "Herman Melville" &&<@.t)tle == "Moby Dick" || @.or == "Evelyn Wa")]'); 12 | ?> 13 | --EXPECTF-- 14 | Fatal error: Uncaught JsonPath\JsonPathException: Expecting child node, filter, expression, or recursive node in %s 15 | Stack trace: 16 | %s 17 | %s 18 | %s -------------------------------------------------------------------------------- /tests/issues/00145.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test index filter query on input that contains a non-array element 3 | --DESCRIPTION-- 4 | https://github.com/supermetrics-public/pecl-jsonpath/issues/145 5 | --SKIPIF-- 6 | 7 | --FILE-- 8 | find(['test_string'], '$.*[61]'); 12 | ?> 13 | --EXPECT-- -------------------------------------------------------------------------------- /tests/issues/00146-1.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test union filter containing an array index and key with no separator 3 | --DESCRIPTION-- 4 | https://github.com/supermetrics-public/pecl-jsonpath/issues/146 5 | --SKIPIF-- 6 | 7 | --FILE-- 8 | [ 11 | 'val' => 1 12 | ] 13 | ]; 14 | 15 | $jsonPath = new \JsonPath\JsonPath(); 16 | print_r($jsonPath->find($obj, "$..['val'2]")); 17 | ?> 18 | --EXPECTF-- 19 | Fatal error: Uncaught JsonPath\JsonPathException: Expected comma `,` separator, got LEX_LITERAL_NUMERIC in union filter in %s 20 | Stack trace: 21 | %s 22 | %s 23 | %s -------------------------------------------------------------------------------- /tests/issues/00146-2.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test union filter containing an array index and key with comma separator 3 | --DESCRIPTION-- 4 | https://github.com/supermetrics-public/pecl-jsonpath/issues/146 5 | --SKIPIF-- 6 | 7 | --FILE-- 8 | [ 11 | 'val' => 1 12 | ] 13 | ]; 14 | 15 | $jsonPath = new \JsonPath\JsonPath(); 16 | print_r($jsonPath->find($obj, "$..['val',2]")); 17 | ?> 18 | --EXPECTF-- 19 | Fatal error: Uncaught JsonPath\JsonPathException: Expected string literal, got LEX_LITERAL_NUMERIC in key union filter in %s 20 | Stack trace: 21 | %s 22 | %s 23 | %s -------------------------------------------------------------------------------- /tests/issues/00156.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test empty filter operand with negation operator within expression 3 | --DESCRIPTION-- 4 | https://github.com/supermetrics-public/pecl-jsonpath/issues/156 5 | --SKIPIF-- 6 | 7 | --FILE-- 8 | find(["test" => [["id" => 1,"val" => 10,"val_str" => "table"]]], "$.test[?(![])]"); 12 | ?> 13 | --EXPECTF-- 14 | Fatal error: Uncaught JsonPath\JsonPathException: Filter must not be empty in %s 15 | Stack trace: 16 | %s 17 | %s 18 | %s -------------------------------------------------------------------------------- /tests/lex_errs/001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Ensure exception is thrown for missing closing bracket 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find([], "$.testl['test'"); 11 | --EXPECTF-- 12 | Fatal error: Uncaught JsonPath\JsonPathException: Missing filter end `]` in %s 13 | Stack trace: 14 | %s 15 | %s 16 | %s -------------------------------------------------------------------------------- /tests/lex_errs/002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Ensure exception is thrown for missing closing bracket 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find([], '$.testl["test"'); 11 | --EXPECTF-- 12 | Fatal error: Uncaught JsonPath\JsonPathException: Missing filter end `]` in %s 13 | Stack trace: 14 | %s 15 | %s 16 | %s -------------------------------------------------------------------------------- /tests/lex_errs/004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Ensure exception is thrown for missing double && 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find([], '$.book[?(@.id.isbn == "684832674" & @.author == "Herman Melville")]'); 11 | --EXPECTF-- 12 | Fatal error: Uncaught JsonPath\JsonPathException: AND operator must be double ampersand `&&` at position 35 in %s 13 | Stack trace: 14 | %s 15 | %s 16 | %s -------------------------------------------------------------------------------- /tests/lex_errs/005.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Ensure exception is thrown for missing double || 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find([], '$.book[?(@.id.isbn == "684832674" | @.author == "Herman Melville")]'); 11 | --EXPECTF-- 12 | Fatal error: Uncaught JsonPath\JsonPathException: OR operator must be double pipe `||` at position 35 in %s 13 | Stack trace: 14 | %s 15 | %s 16 | %s -------------------------------------------------------------------------------- /tests/parse_errs/001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Ensure exception is thrown for missing closing bracket 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find([], '$.book['); 11 | --EXPECTF-- 12 | Fatal error: Uncaught JsonPath\JsonPathException: Missing filter end `]` in %s 13 | Stack trace: 14 | %s 15 | %s 16 | %s -------------------------------------------------------------------------------- /tests/parse_errs/002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Ensure exception is thrown for missing closing bracket 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | find([], '$.store.book[?(@.author == "Evelyn Waugh"'); 11 | --EXPECTF-- 12 | Fatal error: Uncaught JsonPath\JsonPathException: Missing closing paren `)` in %s 13 | Stack trace: 14 | %s 15 | %s 16 | %s -------------------------------------------------------------------------------- /tests/references/001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test dot notation for a node that is a reference 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 42, 10 | ]; 11 | 12 | $another = [ 13 | "key" => 43, 14 | ]; 15 | 16 | $data["another"] =& $another; 17 | 18 | $jsonPath = new \JsonPath\JsonPath(); 19 | 20 | $result = $jsonPath->find($data, "$.another.key"); 21 | 22 | var_dump($result); 23 | ?> 24 | --EXPECT-- 25 | array(1) { 26 | [0]=> 27 | int(43) 28 | } -------------------------------------------------------------------------------- /tests/references/002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test bracket notation for a node that is a reference 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 42, 10 | ]; 11 | 12 | $another = [ 13 | "key" => 43, 14 | ]; 15 | 16 | $data["another"] =& $another; 17 | 18 | $jsonPath = new \JsonPath\JsonPath(); 19 | 20 | $result = $jsonPath->find($data, "$['another']['key']"); 21 | 22 | var_dump($result); 23 | ?> 24 | --EXPECT-- 25 | array(1) { 26 | [0]=> 27 | int(43) 28 | } -------------------------------------------------------------------------------- /tests/references/003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test array slice notation for a node that is a reference 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 42, 10 | ]; 11 | 12 | $another = [ 13 | 43, 14 | 44, 15 | 45, 16 | ]; 17 | 18 | $data["another"] =& $another; 19 | 20 | $jsonPath = new \JsonPath\JsonPath(); 21 | 22 | $result = $jsonPath->find($data, "$.another[1::]"); 23 | 24 | var_dump($result); 25 | ?> 26 | --EXPECT-- 27 | array(2) { 28 | [0]=> 29 | int(44) 30 | [1]=> 31 | int(45) 32 | } -------------------------------------------------------------------------------- /tests/references/004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test filter with a node that is a reference 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 42, 10 | ]; 11 | 12 | $another = [ 13 | [ 14 | "key" => 43, 15 | ], 16 | [ 17 | "key" => 53, 18 | ], 19 | ]; 20 | 21 | $data["another"] =& $another; 22 | 23 | $jsonPath = new \JsonPath\JsonPath(); 24 | 25 | $result = $jsonPath->find($data, "$.another[?(@.key <= 50)]"); 26 | 27 | var_dump($result); 28 | ?> 29 | --EXPECT-- 30 | array(1) { 31 | [0]=> 32 | array(1) { 33 | ["key"]=> 34 | int(43) 35 | } 36 | } -------------------------------------------------------------------------------- /tests/references/005.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test wildcard with a node that is a reference 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 42, 10 | ]; 11 | 12 | $another = [ 13 | "key" => 43, 14 | ]; 15 | 16 | $data["another"] =& $another; 17 | 18 | $jsonPath = new \JsonPath\JsonPath(); 19 | 20 | $result = $jsonPath->find($data, "$.another.*"); 21 | 22 | var_dump($result); 23 | ?> 24 | --EXPECT-- 25 | array(1) { 26 | [0]=> 27 | int(43) 28 | } -------------------------------------------------------------------------------- /tests/references/006.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test recursive descent with a node that is a reference 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 42, 10 | ]; 11 | 12 | $another = [ 13 | "key" => 43, 14 | ]; 15 | 16 | $data["another"] =& $another; 17 | 18 | $jsonPath = new \JsonPath\JsonPath(); 19 | 20 | $result = $jsonPath->find($data, "$..['key']"); 21 | 22 | var_dump($result); 23 | ?> 24 | --EXPECT-- 25 | array(2) { 26 | [0]=> 27 | int(42) 28 | [1]=> 29 | int(43) 30 | } -------------------------------------------------------------------------------- /tests/regex/001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test regex with a match 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | array( 12 | array ( 13 | 'id' => 1, 14 | 'val' => 10, 15 | 'val_str' => "PHP is the web scripting language of choice" 16 | ), 17 | ) 18 | ); 19 | 20 | var_dump($jsonPath->find($obj, '$.test[?(@.val_str =~ "/scripting/")]')); 21 | --EXPECT-- 22 | array(1) { 23 | [0]=> 24 | array(3) { 25 | ["id"]=> 26 | int(1) 27 | ["val"]=> 28 | int(10) 29 | ["val_str"]=> 30 | string(43) "PHP is the web scripting language of choice" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/regex/002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test regex without a match 3 | --SKIPIF-- 4 | 5 | --INI-- 6 | pcre.jit=0 7 | --FILE-- 8 | array( 14 | array ( 15 | 'id' => 1, 16 | 'val' => 10, 17 | 'val_str' => "PHP is the web scripting language of choice" 18 | ), 19 | ) 20 | ); 21 | 22 | var_dump($jsonPath->find($obj, '$.test[?(@.val_str =~ "/notfound/")]')); 23 | --EXPECT-- 24 | bool(false) 25 | -------------------------------------------------------------------------------- /tests/regex/003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test regex with broken regex pattern 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | [ 10 | [ 11 | 'id' => 1, 12 | 'val' => 10, 13 | 'val_str' => 'PHP is the web scripting language of choice', 14 | ], 15 | ], 16 | ]; 17 | 18 | $jsonPath = new \JsonPath\JsonPath(); 19 | $result = $jsonPath->find($data, '$.test[?(@.val_str =~ "/invalid([a-]+/")]'); 20 | 21 | var_dump($result); 22 | --EXPECTF-- 23 | Warning: JsonPath\JsonPath::find(): Compilation failed: missing closing parenthesis at offset 13 in %s 24 | 25 | Fatal error: Uncaught JsonPath\JsonPathException: Invalid regex pattern `/invalid([a-]+/` in %s 26 | Stack trace: 27 | %s 28 | %s 29 | %s 30 | -------------------------------------------------------------------------------- /tests/utils/sort_recursively.php: -------------------------------------------------------------------------------- 1 | gettype($b); 15 | } else { 16 | return $a <=> $b; 17 | } 18 | } 19 | 20 | /** 21 | * Sort an array by its values, recursively 22 | * @param array &$array 23 | */ 24 | function sortRecursively(array &$array): void 25 | { 26 | // Sequential array, re-index after sorting 27 | if (array_keys($array) === range(0, count($array) - 1)) { 28 | usort($array, 'byTypeAndValue'); 29 | } 30 | // Associative array, maintain keys 31 | else { 32 | uasort($array, 'byTypeAndValue'); 33 | } 34 | 35 | foreach ($array as &$value) { 36 | if (is_array($value)) { 37 | sortRecursively($value); 38 | } 39 | } 40 | } 41 | --------------------------------------------------------------------------------