diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 1846ecf..19319e9 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -12,11 +12,12 @@ jobs:
tests:
runs-on: ubuntu-latest
strategy:
+ fail-fast: false
matrix:
php-version:
- - "8.0"
- "8.1"
- "8.2"
+ - "8.3"
dependencies:
- lowest
- highest
@@ -32,6 +33,9 @@ jobs:
with:
php-version: ${{ matrix.php-version }}
+ - name: Install PHIVE
+ uses: szepeviktor/phive@v1
+
- name: Install lowest dependencies
if: ${{ matrix.dependencies == 'lowest' && matrix.platform-reqs == 'use-platform-reqs' }}
run: composer update --no-interaction --prefer-lowest
diff --git a/.gitignore b/.gitignore
index ae25df0..45ae9ab 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,9 @@
/build/
/vendor
/composer.lock
+/tools/
+/vendor-bin/**/vendor/
+/vendor-bin/**/composer.lock
/phpcs.xml
/phpunit.xml
/infection.json
diff --git a/.phive/phars.xml b/.phive/phars.xml
new file mode 100644
index 0000000..bda539d
--- /dev/null
+++ b/.phive/phars.xml
@@ -0,0 +1,4 @@
+
+
+
+
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f02592d..b8284e2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## [Unreleased]
+### Added
+- Added support for PHP 8.3.
+### Removed
+- Dropped support for PHP 8.0.
+
## [0.8.0] - 2023-06-17
### Removed
- Dropped support for PHP 7.
diff --git a/LICENSE b/LICENSE
index 5cd938c..b396c4a 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
MIT License
-Copyright (c) 2018-2021 Edward Surov
+Copyright (c) 2018-2024 Edward Surov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/composer.json b/composer.json
index 9187f7a..f1846a9 100644
--- a/composer.json
+++ b/composer.json
@@ -16,17 +16,16 @@
}
],
"require": {
- "php": "~8.0.0 || ~8.1.0 || ~8.2.0",
+ "php": "~8.1.0 || ~8.2.0 || ~8.3.0",
"ext-intl": "*",
"ext-json": "*",
- "remorhaz/php-unilex": "^0.5.2",
- "remorhaz/php-json-data": "^0.6",
- "nikic/php-parser": "^4.12"
+ "remorhaz/php-unilex": "^0.5.3",
+ "remorhaz/php-json-data": "^0.6.1",
+ "nikic/php-parser": "^4.12 || ^5"
},
"require-dev": {
- "infection/infection": "^0.26 || ^0.27",
- "phpunit/phpunit": "^9.6 || ^10",
- "squizlabs/php_codesniffer": "^3.7.2"
+ "bamarni/composer-bin-plugin": "^1.8",
+ "phpunit/phpunit": "^10.1 || ^11"
},
"autoload": {
"psr-4": {
@@ -42,13 +41,18 @@
}
},
"scripts": {
+ "post-update-cmd": ["@phive-install"],
+ "post-install-cmd": ["@phive-install"],
+ "phive-install": [
+ "`if [ -f tools/phive ]; then echo 'tools/'; fi`phive install --trust-gpg-keys C5095986493B4AA0"
+ ],
"build": [
"vendor/bin/unilex build-token-matcher --desc=\"JSONPath token matcher.\" spec/LexerSpec.php generated/TokenMatcher.php",
"vendor/bin/unilex build-lookup-table --type=LL_1 --symbol=Remorhaz\\\\JSON\\\\Path\\\\Parser\\\\SymbolType --token=Remorhaz\\\\JSON\\\\Path\\\\Parser\\\\TokenType --desc=\"JSONPath parser LL(1) lookup table.\" spec/GrammarSpec.php generated/LookupTable.php",
- "vendor/bin/phpcbf -p generated/; if [ $? -eq 1 ]; then exit 0; fi"
+ "vendor-bin/cs/vendor/bin/phpcbf -p generated/; if [ $? -eq 1 ]; then exit 0; fi"
],
"test-cs": [
- "vendor/bin/phpcs -sp"
+ "vendor-bin/cs/vendor/bin/phpcs -sp"
],
"test-unit": [
"vendor/bin/phpunit --coverage-xml=build/log/coverage-xml --coverage-clover=build/log/clover.xml --log-junit=build/log/junit.xml"
@@ -59,7 +63,7 @@
],
"infection": [
"mkdir -p build/log/infection",
- "vendor/bin/infection --threads=4 --coverage=build/log --no-progress --skip-initial-tests"
+ "tools/infection --threads=4 --coverage=build/log --no-progress --skip-initial-tests"
],
"test-infection": [
"@test-unit",
@@ -68,7 +72,14 @@
},
"config": {
"allow-plugins": {
- "infection/extension-installer": true
+ "bamarni/composer-bin-plugin": true
+ },
+ "sort-packages": true
+ },
+ "extra": {
+ "bamarni-bin": {
+ "bin-links": false,
+ "forward-command": true
}
}
}
diff --git a/docker-compose.yml b/docker-compose.yml
index 92abc6e..a3e8597 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -4,21 +4,21 @@ services:
php:
build:
context: .
- dockerfile: php-8.0.Dockerfile
+ dockerfile: php-8.1.Dockerfile
volumes:
- .:/app
working_dir: /app
- php8.1:
+ php8.2:
build:
context: .
- dockerfile: php-8.1.Dockerfile
+ dockerfile: php-8.2.Dockerfile
volumes:
- .:/app
working_dir: /app
- php8.2:
+ php8.3:
build:
context: .
- dockerfile: php-8.2.Dockerfile
+ dockerfile: php-8.3.Dockerfile
volumes:
- .:/app
working_dir: /app
diff --git a/generated/TokenMatcher.php b/generated/TokenMatcher.php
index 05ff001..ccfd7b8 100644
--- a/generated/TokenMatcher.php
+++ b/generated/TokenMatcher.php
@@ -2248,6 +2248,8 @@ private function isModeDefaultSymbol21(int $char): bool
0x0111DC == $char ||
0x011200 <= $char && $char <= 0x011211 ||
0x011213 <= $char && $char <= 0x01122B ||
+ 0x01123F == $char ||
+ 0x011240 == $char ||
0x011280 <= $char && $char <= 0x011286 ||
0x011288 == $char ||
0x01128A <= $char && $char <= 0x01128D ||
@@ -2316,12 +2318,16 @@ private function isModeDefaultSymbol21(int $char): bool
0x011D6A <= $char && $char <= 0x011D89 ||
0x011D98 == $char ||
0x011EE0 <= $char && $char <= 0x011EF2 ||
+ 0x011F02 == $char ||
+ 0x011F04 <= $char && $char <= 0x011F10 ||
+ 0x011F12 <= $char && $char <= 0x011F33 ||
0x011FB0 == $char ||
0x012000 <= $char && $char <= 0x012399 ||
0x012400 <= $char && $char <= 0x01246E ||
0x012480 <= $char && $char <= 0x012543 ||
0x012F90 <= $char && $char <= 0x012FF0 ||
- 0x013000 <= $char && $char <= 0x01342E ||
+ 0x013000 <= $char && $char <= 0x01342F ||
+ 0x013441 <= $char && $char <= 0x013446 ||
0x014400 <= $char && $char <= 0x014646 ||
0x016800 <= $char && $char <= 0x016A38 ||
0x016A40 <= $char && $char <= 0x016A5E ||
@@ -2346,7 +2352,9 @@ private function isModeDefaultSymbol21(int $char): bool
0x01AFFD == $char ||
0x01AFFE == $char ||
0x01B000 <= $char && $char <= 0x01B122 ||
+ 0x01B132 == $char ||
0x01B150 <= $char && $char <= 0x01B152 ||
+ 0x01B155 == $char ||
0x01B164 <= $char && $char <= 0x01B167 ||
0x01B170 <= $char && $char <= 0x01B2FB ||
0x01BC00 <= $char && $char <= 0x01BC6A ||
@@ -2386,11 +2394,14 @@ private function isModeDefaultSymbol21(int $char): bool
0x01D7AA <= $char && $char <= 0x01D7C2 ||
0x01D7C4 <= $char && $char <= 0x01D7CB ||
0x01DF00 <= $char && $char <= 0x01DF1E ||
+ 0x01DF25 <= $char && $char <= 0x01DF2A ||
+ 0x01E030 <= $char && $char <= 0x01E06D ||
0x01E100 <= $char && $char <= 0x01E12C ||
0x01E137 <= $char && $char <= 0x01E13D ||
0x01E14E == $char ||
0x01E290 <= $char && $char <= 0x01E2AD ||
0x01E2C0 <= $char && $char <= 0x01E2EB ||
+ 0x01E4D0 <= $char && $char <= 0x01E4EB ||
0x01E7E0 <= $char && $char <= 0x01E7E6 ||
0x01E7E8 <= $char && $char <= 0x01E7EB ||
0x01E7ED == $char ||
@@ -2436,12 +2447,14 @@ private function isModeDefaultSymbol21(int $char): bool
0x01EEA5 <= $char && $char <= 0x01EEA9 ||
0x01EEAB <= $char && $char <= 0x01EEBB ||
0x020000 <= $char && $char <= 0x02A6DF ||
- 0x02A700 <= $char && $char <= 0x02B738 ||
+ 0x02A700 <= $char && $char <= 0x02B739 ||
0x02B740 <= $char && $char <= 0x02B81D ||
0x02B820 <= $char && $char <= 0x02CEA1 ||
0x02CEB0 <= $char && $char <= 0x02EBE0 ||
+ 0x02EBF0 <= $char && $char <= 0x02EE5D ||
0x02F800 <= $char && $char <= 0x02FA1D ||
- 0x030000 <= $char && $char <= 0x03134A;
+ 0x030000 <= $char && $char <= 0x03134A ||
+ 0x031350 <= $char && $char <= 0x0323AF;
}
private function isModeDefaultSymbol22(int $char): bool
@@ -2552,6 +2565,7 @@ private function isModeDefaultSymbol22(int $char): bool
0x0CE2 == $char ||
0x0CE3 == $char ||
0x0CE6 <= $char && $char <= 0x0CEF ||
+ 0x0CF3 == $char ||
0x0D00 <= $char && $char <= 0x0D03 ||
0x0D3B == $char ||
0x0D3C == $char ||
@@ -2576,7 +2590,7 @@ private function isModeDefaultSymbol22(int $char): bool
0x0E50 <= $char && $char <= 0x0E59 ||
0x0EB1 == $char ||
0x0EB4 <= $char && $char <= 0x0EBC ||
- 0x0EC8 <= $char && $char <= 0x0ECD ||
+ 0x0EC8 <= $char && $char <= 0x0ECE ||
0x0ED0 <= $char && $char <= 0x0ED9 ||
0x0F18 == $char ||
0x0F19 == $char ||
@@ -2643,6 +2657,8 @@ private function isModeDefaultSymbol22(int $char): bool
0x1CF4 == $char ||
0x1CF7 <= $char && $char <= 0x1CF9 ||
0x1DC0 <= $char && $char <= 0x1DFF ||
+ 0x200C == $char ||
+ 0x200D == $char ||
0x203F == $char ||
0x2040 == $char ||
0x2054 == $char ||
@@ -2655,6 +2671,7 @@ private function isModeDefaultSymbol22(int $char): bool
0x302A <= $char && $char <= 0x302F ||
0x3099 == $char ||
0x309A == $char ||
+ 0x30FB == $char ||
0xA620 <= $char && $char <= 0xA629 ||
0xA66F == $char ||
0xA674 <= $char && $char <= 0xA67D ||
@@ -2708,6 +2725,7 @@ private function isModeDefaultSymbol22(int $char): bool
0xFE4D <= $char && $char <= 0xFE4F ||
0xFF10 <= $char && $char <= 0xFF19 ||
0xFF3F == $char ||
+ 0xFF65 == $char ||
0x0101FD == $char ||
0x0102E0 == $char ||
0x010376 <= $char && $char <= 0x01037A ||
@@ -2724,6 +2742,7 @@ private function isModeDefaultSymbol22(int $char): bool
0x010D30 <= $char && $char <= 0x010D39 ||
0x010EAB == $char ||
0x010EAC == $char ||
+ 0x010EFD <= $char && $char <= 0x010EFF ||
0x010F46 <= $char && $char <= 0x010F50 ||
0x010F82 <= $char && $char <= 0x010F85 ||
0x011000 <= $char && $char <= 0x011002 ||
@@ -2747,6 +2766,7 @@ private function isModeDefaultSymbol22(int $char): bool
0x0111CE <= $char && $char <= 0x0111D9 ||
0x01122C <= $char && $char <= 0x011237 ||
0x01123E == $char ||
+ 0x011241 == $char ||
0x0112DF <= $char && $char <= 0x0112EA ||
0x0112F0 <= $char && $char <= 0x0112F9 ||
0x011300 <= $char && $char <= 0x011303 ||
@@ -2813,6 +2833,14 @@ private function isModeDefaultSymbol22(int $char): bool
0x011D93 <= $char && $char <= 0x011D97 ||
0x011DA0 <= $char && $char <= 0x011DA9 ||
0x011EF3 <= $char && $char <= 0x011EF6 ||
+ 0x011F00 == $char ||
+ 0x011F01 == $char ||
+ 0x011F03 == $char ||
+ 0x011F34 <= $char && $char <= 0x011F3A ||
+ 0x011F3E <= $char && $char <= 0x011F42 ||
+ 0x011F50 <= $char && $char <= 0x011F59 ||
+ 0x013440 == $char ||
+ 0x013447 <= $char && $char <= 0x013455 ||
0x016A60 <= $char && $char <= 0x016A69 ||
0x016AC0 <= $char && $char <= 0x016AC9 ||
0x016AF0 <= $char && $char <= 0x016AF4 ||
@@ -2847,10 +2875,12 @@ private function isModeDefaultSymbol22(int $char): bool
0x01E023 == $char ||
0x01E024 == $char ||
0x01E026 <= $char && $char <= 0x01E02A ||
+ 0x01E08F == $char ||
0x01E130 <= $char && $char <= 0x01E136 ||
0x01E140 <= $char && $char <= 0x01E149 ||
0x01E2AE == $char ||
0x01E2EC <= $char && $char <= 0x01E2F9 ||
+ 0x01E4EC <= $char && $char <= 0x01E4F9 ||
0x01E8D0 <= $char && $char <= 0x01E8D6 ||
0x01E944 <= $char && $char <= 0x01E94A ||
0x01E950 <= $char && $char <= 0x01E959 ||
diff --git a/php-8.0.Dockerfile b/php-8.0.Dockerfile
deleted file mode 100644
index ed7e0f3..0000000
--- a/php-8.0.Dockerfile
+++ /dev/null
@@ -1,19 +0,0 @@
-FROM php:8.0-cli
-
-RUN apt-get update && apt-get install -y \
- zip \
- git \
- libicu-dev && \
- pecl install xdebug && \
- docker-php-ext-enable xdebug && \
- docker-php-ext-configure intl --enable-intl && \
- docker-php-ext-install intl pcntl && \
- echo "xdebug.mode = develop,coverage,debug" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" && \
- echo "xdebug.max_nesting_level = 1024" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini"
-
-
-ENV COMPOSER_ALLOW_SUPERUSER=1 \
- COMPOSER_PROCESS_TIMEOUT=1200
-
-RUN curl --silent --show-error https://getcomposer.org/installer | php -- \
- --install-dir=/usr/bin --filename=composer
diff --git a/php-8.1.Dockerfile b/php-8.1.Dockerfile
index 6faad4b..5df62cd 100644
--- a/php-8.1.Dockerfile
+++ b/php-8.1.Dockerfile
@@ -1,19 +1,27 @@
-FROM php:8.1-rc-cli
+FROM php:8.1-cli
RUN apt-get update && apt-get install -y \
- zip \
- git \
- libicu-dev && \
- pecl install -f -o xdebug && \
+ zip \
+ git \
+ wget \
+ gpg \
+ libicu-dev && \
+ pecl install xdebug && \
docker-php-ext-enable xdebug && \
docker-php-ext-configure intl --enable-intl && \
docker-php-ext-install intl pcntl && \
- echo "xdebug.mode = develop,coverage,debug" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" && \
- echo "xdebug.max_nesting_level = 1024" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini"
-
+ echo "xdebug.mode = develop,coverage,debug" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini"
ENV COMPOSER_ALLOW_SUPERUSER=1 \
COMPOSER_PROCESS_TIMEOUT=1200
RUN curl --silent --show-error https://getcomposer.org/installer | php -- \
- --install-dir=/usr/bin --filename=composer
+ --install-dir=/usr/bin --filename=composer && \
+ git config --global --add safe.directory "*"
+
+RUN wget -O phive.phar https://phar.io/releases/phive.phar && \
+ wget -O phive.phar.asc https://phar.io/releases/phive.phar.asc && \
+ gpg --keyserver hkps://keys.openpgp.org --recv-keys 0x9D8A98B29B2D5D79 && \
+ gpg --verify phive.phar.asc phive.phar && \
+ chmod +x phive.phar && \
+ mv phive.phar /usr/local/bin/phive \
diff --git a/php-8.2.Dockerfile b/php-8.2.Dockerfile
index 6faad4b..5794eeb 100644
--- a/php-8.2.Dockerfile
+++ b/php-8.2.Dockerfile
@@ -1,19 +1,27 @@
-FROM php:8.1-rc-cli
+FROM php:8.2-cli
RUN apt-get update && apt-get install -y \
- zip \
- git \
- libicu-dev && \
- pecl install -f -o xdebug && \
+ zip \
+ git \
+ wget \
+ gpg \
+ libicu-dev && \
+ pecl install xdebug && \
docker-php-ext-enable xdebug && \
docker-php-ext-configure intl --enable-intl && \
docker-php-ext-install intl pcntl && \
- echo "xdebug.mode = develop,coverage,debug" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" && \
- echo "xdebug.max_nesting_level = 1024" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini"
-
+ echo "xdebug.mode = develop,coverage,debug" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini"
ENV COMPOSER_ALLOW_SUPERUSER=1 \
COMPOSER_PROCESS_TIMEOUT=1200
RUN curl --silent --show-error https://getcomposer.org/installer | php -- \
- --install-dir=/usr/bin --filename=composer
+ --install-dir=/usr/bin --filename=composer && \
+ git config --global --add safe.directory "*"
+
+RUN wget -O phive.phar https://phar.io/releases/phive.phar && \
+ wget -O phive.phar.asc https://phar.io/releases/phive.phar.asc && \
+ gpg --keyserver hkps://keys.openpgp.org --recv-keys 0x9D8A98B29B2D5D79 && \
+ gpg --verify phive.phar.asc phive.phar && \
+ chmod +x phive.phar && \
+ mv phive.phar /usr/local/bin/phive \
diff --git a/php-8.3.Dockerfile b/php-8.3.Dockerfile
new file mode 100644
index 0000000..6a6bc0d
--- /dev/null
+++ b/php-8.3.Dockerfile
@@ -0,0 +1,27 @@
+FROM php:8.3-cli
+
+RUN apt-get update && apt-get install -y \
+ zip \
+ git \
+ wget \
+ gpg \
+ libicu-dev && \
+ pecl install xdebug && \
+ docker-php-ext-enable xdebug && \
+ docker-php-ext-configure intl --enable-intl && \
+ docker-php-ext-install intl pcntl && \
+ echo "xdebug.mode = develop,coverage,debug" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini"
+
+ENV COMPOSER_ALLOW_SUPERUSER=1 \
+ COMPOSER_PROCESS_TIMEOUT=1200
+
+RUN curl --silent --show-error https://getcomposer.org/installer | php -- \
+ --install-dir=/usr/bin --filename=composer && \
+ git config --global --add safe.directory "*"
+
+RUN wget -O phive.phar https://phar.io/releases/phive.phar && \
+ wget -O phive.phar.asc https://phar.io/releases/phive.phar.asc && \
+ gpg --keyserver hkps://keys.openpgp.org --recv-keys 0x9D8A98B29B2D5D79 && \
+ gpg --verify phive.phar.asc phive.phar && \
+ chmod +x phive.phar && \
+ mv phive.phar /usr/local/bin/phive \
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 6ca0ade..16f8906 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,21 +1,23 @@
-
+
-
-
- tests/
-
-
-
-
- src/
- generated/
-
-
- generated/LookupTable.php
-
-
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
+ defaultTestSuite="all"
+ cacheDirectory="build/.phpunit.cache"
+ requireCoverageMetadata="true">
+
+
+ tests/
+
+
+
diff --git a/src/Parser/Exception/ParserCreationFailedException.php b/src/Parser/Exception/ParserCreationFailedException.php
index 20f9ecf..850d956 100644
--- a/src/Parser/Exception/ParserCreationFailedException.php
+++ b/src/Parser/Exception/ParserCreationFailedException.php
@@ -11,6 +11,6 @@ final class ParserCreationFailedException extends LogicException implements Exce
{
public function __construct(?Throwable $previous = null)
{
- parent::__construct("Failed to create JSONPath parser", 0, $previous);
+ parent::__construct("Failed to create JSONPath parser", previous: $previous);
}
}
diff --git a/src/Parser/Exception/QueryAstNotBuiltException.php b/src/Parser/Exception/QueryAstNotBuiltException.php
index 64af814..0aa0f1d 100644
--- a/src/Parser/Exception/QueryAstNotBuiltException.php
+++ b/src/Parser/Exception/QueryAstNotBuiltException.php
@@ -13,7 +13,7 @@ public function __construct(
private string $source,
?Throwable $previous = null,
) {
- parent::__construct("Failed to build AST from JSONPath query: $this->source", 0, $previous);
+ parent::__construct("Failed to build AST from JSONPath query: $this->source", previous: $previous);
}
public function getSource(): string
diff --git a/src/Parser/Ll1ParserFactory.php b/src/Parser/Ll1ParserFactory.php
index 40bc437..875a64a 100644
--- a/src/Parser/Ll1ParserFactory.php
+++ b/src/Parser/Ll1ParserFactory.php
@@ -32,11 +32,11 @@ public function createParser(string $source, Tree $queryAst): Ll1Parser
new TranslationSchemeApplier($scheme),
);
$parser->loadLookupTable(__DIR__ . '/../../generated/LookupTable.php');
+
+ return $parser;
} catch (Throwable $e) {
throw new Exception\ParserCreationFailedException($e);
}
-
- return $parser;
}
/**
@@ -58,7 +58,7 @@ private function createSourceReader(string $source): TokenReaderInterface
return new TokenReader(
CharBufferFactory::createFromString($source),
new TokenMatcher(),
- new TokenFactory($this->getGrammar())
+ new TokenFactory($this->getGrammar()),
);
}
}
diff --git a/src/Parser/Ll1ParserFactoryInterface.php b/src/Parser/Ll1ParserFactoryInterface.php
index b119102..b333d0d 100644
--- a/src/Parser/Ll1ParserFactoryInterface.php
+++ b/src/Parser/Ll1ParserFactoryInterface.php
@@ -9,5 +9,5 @@
interface Ll1ParserFactoryInterface
{
- public function createParser(string $path, Tree $queryAst): Ll1Parser;
+ public function createParser(string $source, Tree $queryAst): Ll1Parser;
}
diff --git a/src/Parser/Parser.php b/src/Parser/Parser.php
index dc905a5..79d1c1b 100644
--- a/src/Parser/Parser.php
+++ b/src/Parser/Parser.php
@@ -10,7 +10,7 @@
final class Parser implements ParserInterface
{
public function __construct(
- private Ll1ParserFactoryInterface $ll1ParserFactory,
+ private readonly Ll1ParserFactoryInterface $ll1ParserFactory,
) {
}
diff --git a/src/Parser/TranslationScheme.php b/src/Parser/TranslationScheme.php
index f18cff9..1c5dd53 100644
--- a/src/Parser/TranslationScheme.php
+++ b/src/Parser/TranslationScheme.php
@@ -17,14 +17,10 @@
class TranslationScheme implements TranslationSchemeInterface
{
public function __construct(
- private AstBuilderInterface $queryAstBuilder,
+ private readonly AstBuilderInterface $queryAstBuilder,
) {
}
- /**
- * @param Symbol $symbol
- * @param Token $token
- */
public function applyTokenActions(Symbol $symbol, Token $token): void
{
$s = $symbol->getShortcut();
@@ -43,9 +39,6 @@ public function applyTokenActions(Symbol $symbol, Token $token): void
}
}
- /**
- * @param Production $production
- */
public function applyProductionActions(Production $production): void
{
$header = $production->getHeaderShortcut();
@@ -59,7 +52,7 @@ public function applyProductionActions(Production $production): void
->setOutput(
$symbols[0]['s.value_list_id'],
$symbols[0]['s.is_definite'],
- $symbols[0]['s.is_addressable']
+ $symbols[0]['s.is_addressable'],
);
break;
@@ -85,7 +78,7 @@ public function applyProductionActions(Production $production): void
->queryAstBuilder
->aggregate(
$header['i.filter_name'],
- $header['i.value_list_id']
+ $header['i.value_list_id'],
);
$header['s.is_definite'] = $header['i.is_definite'];
$header['s.is_addressable'] = false;
@@ -375,7 +368,7 @@ public function applyProductionActions(Production $production): void
->queryAstBuilder
->fetchChildren(
$header['i.value_list_id'],
- $this->queryAstBuilder->matchAnyChild()
+ $this->queryAstBuilder->matchAnyChild(),
);
$header['s.is_definite'] = false;
break;
@@ -387,7 +380,7 @@ public function applyProductionActions(Production $production): void
$header['i.value_list_id'],
$this
->queryAstBuilder
- ->matchPropertyStrictly(...$symbols[0]['s.text_list'])
+ ->matchPropertyStrictly(...$symbols[0]['s.text_list']),
);
$header['s.is_definite'] = $symbols[0]['s.is_definite'];
break;
@@ -429,7 +422,7 @@ public function applyProductionActions(Production $production): void
->queryAstBuilder
->evaluate($symbols[3]['i.value_list_id'], $symbols[3]['s.value_list_id']),
$symbols[3]['i.context_value_list_id'],
- )
+ ),
);
$header['s.is_definite'] = false;
break;
@@ -441,7 +434,7 @@ public function applyProductionActions(Production $production): void
->evaluateLogicalNot(
$this
->queryAstBuilder
- ->evaluate($header['i.value_list_id'], $symbols[1]['s.value_list_id'])
+ ->evaluate($header['i.value_list_id'], $symbols[1]['s.value_list_id']),
);
break;
@@ -726,14 +719,14 @@ public function applySymbolActions(Production $production, int $symbolIndex): vo
->queryAstBuilder
->evaluate(
$header['i.value_list_id'],
- $header['i.left_value_list_id']
+ $header['i.left_value_list_id'],
),
$this
->queryAstBuilder
->evaluate(
$header['i.value_list_id'],
- $symbols[2]['s.value_list_id']
- )
+ $symbols[2]['s.value_list_id'],
+ ),
);
break;
@@ -763,14 +756,14 @@ public function applySymbolActions(Production $production, int $symbolIndex): vo
->queryAstBuilder
->evaluate(
$header['i.value_list_id'],
- $header['i.left_value_list_id']
+ $header['i.left_value_list_id'],
),
$this
->queryAstBuilder
->evaluate(
$header['i.value_list_id'],
- $symbols[2]['s.value_list_id']
- )
+ $symbols[2]['s.value_list_id'],
+ ),
);
break;
@@ -826,7 +819,7 @@ public function applySymbolActions(Production $production, int $symbolIndex): vo
->queryAstBuilder
->calculateIsEqual(
$header['i.left_value_list_id'],
- $symbols[2]['s.value_list_id']
+ $symbols[2]['s.value_list_id'],
);
break;
@@ -840,8 +833,8 @@ public function applySymbolActions(Production $production, int $symbolIndex): vo
->queryAstBuilder
->calculateIsEqual(
$header['i.left_value_list_id'],
- $symbols[2]['s.value_list_id']
- )
+ $symbols[2]['s.value_list_id'],
+ ),
);
break;
@@ -852,7 +845,7 @@ public function applySymbolActions(Production $production, int $symbolIndex): vo
->queryAstBuilder
->calculateIsGreater(
$symbols[2]['s.value_list_id'],
- $header['i.left_value_list_id']
+ $header['i.left_value_list_id'],
);
break;
@@ -866,8 +859,8 @@ public function applySymbolActions(Production $production, int $symbolIndex): vo
->queryAstBuilder
->calculateIsGreater(
$header['i.left_value_list_id'],
- $symbols[2]['s.value_list_id']
- )
+ $symbols[2]['s.value_list_id'],
+ ),
);
break;
@@ -878,7 +871,7 @@ public function applySymbolActions(Production $production, int $symbolIndex): vo
->queryAstBuilder
->calculateIsGreater(
$header['i.left_value_list_id'],
- $symbols[2]['s.value_list_id']
+ $symbols[2]['s.value_list_id'],
);
break;
@@ -892,8 +885,8 @@ public function applySymbolActions(Production $production, int $symbolIndex): vo
->queryAstBuilder
->calculateIsGreater(
$symbols[2]['s.value_list_id'],
- $header['i.left_value_list_id']
- )
+ $header['i.left_value_list_id'],
+ ),
);
break;
@@ -992,7 +985,7 @@ public function applySymbolActions(Production $production, int $symbolIndex): vo
$header['i.value_list_id'],
$this
->queryAstBuilder
- ->matchPropertyStrictly($symbols[0]['s.text'])
+ ->matchPropertyStrictly($symbols[0]['s.text']),
);
$symbols[1]['i.is_definite'] = $header['i.is_definite'];
$symbols[1]['i.is_addressable'] = $header['i.is_addressable'];
@@ -1004,7 +997,7 @@ public function applySymbolActions(Production $production, int $symbolIndex): vo
->queryAstBuilder
->fetchChildren(
$header['i.value_list_id'],
- $this->queryAstBuilder->matchAnyChild()
+ $this->queryAstBuilder->matchAnyChild(),
);
$symbols[1]['i.is_definite'] = false;
$symbols[1]['i.is_addressable'] = $header['i.is_addressable'];
@@ -1032,7 +1025,7 @@ public function applySymbolActions(Production $production, int $symbolIndex): vo
$header['i.value_list_id'],
$this
->queryAstBuilder
- ->matchPropertyStrictly($header['i.filter_name'])
+ ->matchPropertyStrictly($header['i.filter_name']),
);
$symbols[0]['i.is_definite'] = $header['i.is_definite'];
$symbols[0]['i.is_addressable'] = $header['i.is_addressable'];
@@ -1048,7 +1041,7 @@ public function applySymbolActions(Production $production, int $symbolIndex): vo
$header['i.value_list_id'],
$this
->queryAstBuilder
- ->matchPropertyStrictly($symbols[0]['s.text'])
+ ->matchPropertyStrictly($symbols[0]['s.text']),
);
$symbols[1]['i.is_definite'] = false;
$symbols[1]['i.is_addressable'] = $header['i.is_addressable'];
@@ -1060,7 +1053,7 @@ public function applySymbolActions(Production $production, int $symbolIndex): vo
->queryAstBuilder
->fetchChildrenDeep(
$header['i.value_list_id'],
- $this->queryAstBuilder->matchAnyChild()
+ $this->queryAstBuilder->matchAnyChild(),
);
$symbols[1]['i.is_definite'] = false;
$symbols[1]['i.is_addressable'] = $header['i.is_addressable'];
@@ -1076,7 +1069,7 @@ public function applySymbolActions(Production $production, int $symbolIndex): vo
->queryAstBuilder
->fetchChildrenDeep(
$header['i.value_list_id'],
- $this->queryAstBuilder->matchAnyChild()
+ $this->queryAstBuilder->matchAnyChild(),
),
);
$symbols[0]['i.is_definite'] = false;
diff --git a/src/Processor/Exception/IndefiniteQueryException.php b/src/Processor/Exception/IndefiniteQueryException.php
index a4c0d59..3cfdb8a 100644
--- a/src/Processor/Exception/IndefiniteQueryException.php
+++ b/src/Processor/Exception/IndefiniteQueryException.php
@@ -11,10 +11,10 @@
final class IndefiniteQueryException extends RuntimeException implements ExceptionInterface
{
public function __construct(
- private QueryInterface $query,
+ private readonly QueryInterface $query,
?Throwable $previous = null,
) {
- parent::__construct("Query is indefinite", 0, $previous);
+ parent::__construct("Query is indefinite", previous: $previous);
}
public function getQuery(): QueryInterface
diff --git a/src/Processor/Exception/InvalidPathElementException.php b/src/Processor/Exception/InvalidPathElementException.php
index 1e3b6c7..2894682 100644
--- a/src/Processor/Exception/InvalidPathElementException.php
+++ b/src/Processor/Exception/InvalidPathElementException.php
@@ -12,10 +12,10 @@
final class InvalidPathElementException extends DomainException implements ExceptionInterface
{
public function __construct(
- private mixed $pathElement,
+ private readonly mixed $pathElement,
?Throwable $previous = null,
) {
- parent::__construct($this->buildMessage(), 0, $previous);
+ parent::__construct($this->buildMessage(), previous: $previous);
}
private function buildMessage(): string
diff --git a/src/Processor/Exception/QueryNotAddressableException.php b/src/Processor/Exception/QueryNotAddressableException.php
index e3c01bd..b7399b1 100644
--- a/src/Processor/Exception/QueryNotAddressableException.php
+++ b/src/Processor/Exception/QueryNotAddressableException.php
@@ -11,10 +11,10 @@
final class QueryNotAddressableException extends LogicException implements ExceptionInterface
{
public function __construct(
- private QueryInterface $query,
+ private readonly QueryInterface $query,
?Throwable $previous = null,
) {
- parent::__construct("Query is not addressable", 0, $previous);
+ parent::__construct("Query is not addressable", previous: $previous);
}
public function getQuery(): QueryInterface
diff --git a/src/Processor/Mutator/DeleteMutation.php b/src/Processor/Mutator/DeleteMutation.php
index 0232d0c..1a63a8b 100644
--- a/src/Processor/Mutator/DeleteMutation.php
+++ b/src/Processor/Mutator/DeleteMutation.php
@@ -4,7 +4,6 @@
namespace Remorhaz\JSON\Path\Processor\Mutator;
-use Generator;
use Iterator;
use Remorhaz\JSON\Data\Event\EventInterface;
use Remorhaz\JSON\Data\Path\PathInterface;
diff --git a/src/Processor/Mutator/Exception/ReplaceAtNestedPathsException.php b/src/Processor/Mutator/Exception/ReplaceAtNestedPathsException.php
index c18fefe..da66f87 100644
--- a/src/Processor/Mutator/Exception/ReplaceAtNestedPathsException.php
+++ b/src/Processor/Mutator/Exception/ReplaceAtNestedPathsException.php
@@ -11,11 +11,11 @@
final class ReplaceAtNestedPathsException extends LogicException implements ExceptionInterface
{
public function __construct(
- private PathInterface $parentPath,
- private PathInterface $nestedPath,
+ private readonly PathInterface $parentPath,
+ private readonly PathInterface $nestedPath,
?Throwable $previous = null,
) {
- parent::__construct("Attempt of replacing value at nested paths", 0, $previous);
+ parent::__construct("Attempt of replacing value at nested paths", previous: $previous);
}
public function getParentPath(): PathInterface
diff --git a/src/Processor/Mutator/Mutator.php b/src/Processor/Mutator/Mutator.php
index f385169..c15f28a 100644
--- a/src/Processor/Mutator/Mutator.php
+++ b/src/Processor/Mutator/Mutator.php
@@ -13,8 +13,8 @@
final class Mutator implements MutatorInterface
{
public function __construct(
- private ValueWalkerInterface $valueWalker,
- private EventDecoderInterface $eventDecoder,
+ private readonly ValueWalkerInterface $valueWalker,
+ private readonly EventDecoderInterface $eventDecoder,
) {
}
diff --git a/src/Processor/Mutator/ReplaceMutation.php b/src/Processor/Mutator/ReplaceMutation.php
index 7424eae..ed2a987 100644
--- a/src/Processor/Mutator/ReplaceMutation.php
+++ b/src/Processor/Mutator/ReplaceMutation.php
@@ -30,7 +30,7 @@ final class ReplaceMutation implements MutationInterface
private array $paths;
public function __construct(
- private NodeValueInterface $newNode,
+ private readonly NodeValueInterface $newNode,
PathInterface ...$paths,
) {
$this->paths = $this->getNonNestedPaths(...$paths);
diff --git a/src/Processor/PathEncoder.php b/src/Processor/PathEncoder.php
index b9ebfd5..378d793 100644
--- a/src/Processor/PathEncoder.php
+++ b/src/Processor/PathEncoder.php
@@ -16,7 +16,7 @@ final class PathEncoder implements PathEncoderInterface
{
public function encodePath(PathInterface $path): string
{
- return '$' . implode('', array_map([$this, 'encodePathElement'], $path->getElements()));
+ return '$' . implode('', array_map($this->encodePathElement(...), $path->getElements()));
}
private function encodePathElement($pathElement): string
@@ -28,7 +28,7 @@ private function encodePathElement($pathElement): string
if (is_string($pathElement)) {
$escapedElement = str_replace(['\\', '\''], ['\\\\', '\\\''], $pathElement);
- return "['{$escapedElement}']";
+ return "['$escapedElement']";
}
throw new Exception\InvalidPathElementException($pathElement);
diff --git a/src/Processor/Processor.php b/src/Processor/Processor.php
index b3f35dd..e459add 100644
--- a/src/Processor/Processor.php
+++ b/src/Processor/Processor.php
@@ -57,10 +57,10 @@ public static function create(): ProcessorInterface
}
public function __construct(
- private RuntimeInterface $runtime,
- private ResultFactoryInterface $resultFactory,
- private QueryValidatorInterface $queryValidator,
- private MutatorInterface $mutator,
+ private readonly RuntimeInterface $runtime,
+ private readonly ResultFactoryInterface $resultFactory,
+ private readonly QueryValidatorInterface $queryValidator,
+ private readonly MutatorInterface $mutator,
) {
}
diff --git a/src/Processor/Result/Exception/MoreThanOneValueInListException.php b/src/Processor/Result/Exception/MoreThanOneValueInListException.php
index 969a488..89d56e8 100644
--- a/src/Processor/Result/Exception/MoreThanOneValueInListException.php
+++ b/src/Processor/Result/Exception/MoreThanOneValueInListException.php
@@ -11,10 +11,10 @@
final class MoreThanOneValueInListException extends RuntimeException implements ExceptionInterface
{
public function __construct(
- private ValueListInterface $values,
+ private readonly ValueListInterface $values,
?Throwable $previous = null,
) {
- parent::__construct("More than 1 value in list", 0, $previous);
+ parent::__construct("More than 1 value in list", previous: $previous);
}
public function getValues(): ValueListInterface
diff --git a/src/Processor/Result/Exception/PathNotFoundInValueException.php b/src/Processor/Result/Exception/PathNotFoundInValueException.php
index ccde88e..ec941df 100644
--- a/src/Processor/Result/Exception/PathNotFoundInValueException.php
+++ b/src/Processor/Result/Exception/PathNotFoundInValueException.php
@@ -11,10 +11,10 @@
final class PathNotFoundInValueException extends LogicException implements ExceptionInterface
{
public function __construct(
- private ValueInterface $value,
+ private readonly ValueInterface $value,
?Throwable $previous = null,
) {
- parent::__construct("Path not found in value", 0, $previous);
+ parent::__construct("Path not found in value", previous: $previous);
}
public function getValue(): ValueInterface
diff --git a/src/Processor/Result/Exception/SelectedValueNotFoundException.php b/src/Processor/Result/Exception/SelectedValueNotFoundException.php
index 5f9eff5..ecd9b1f 100644
--- a/src/Processor/Result/Exception/SelectedValueNotFoundException.php
+++ b/src/Processor/Result/Exception/SelectedValueNotFoundException.php
@@ -11,6 +11,6 @@ final class SelectedValueNotFoundException extends LogicException implements Exc
{
public function __construct(?Throwable $previous = null)
{
- parent::__construct("Selected value not found", 0, $previous);
+ parent::__construct("Selected value not found", previous: $previous);
}
}
diff --git a/src/Processor/Result/ExistingSelectOnePathResult.php b/src/Processor/Result/ExistingSelectOnePathResult.php
index 3c8a0fc..8bc25da 100644
--- a/src/Processor/Result/ExistingSelectOnePathResult.php
+++ b/src/Processor/Result/ExistingSelectOnePathResult.php
@@ -15,8 +15,8 @@ public function exists(): bool
}
public function __construct(
- private PathEncoderInterface $encoder,
- private PathInterface $path,
+ private readonly PathEncoderInterface $encoder,
+ private readonly PathInterface $path,
) {
}
diff --git a/src/Processor/Result/ExistingValueResult.php b/src/Processor/Result/ExistingValueResult.php
index 64fc328..5c7cc4a 100644
--- a/src/Processor/Result/ExistingValueResult.php
+++ b/src/Processor/Result/ExistingValueResult.php
@@ -11,9 +11,9 @@
final class ExistingValueResult implements ValueResultInterface
{
public function __construct(
- private ValueEncoderInterface $jsonEncoder,
- private ValueDecoderInterface $jsonDecoder,
- private ValueInterface $value
+ private readonly ValueEncoderInterface $jsonEncoder,
+ private readonly ValueDecoderInterface $jsonDecoder,
+ private readonly ValueInterface $value,
) {
}
diff --git a/src/Processor/Result/ResultFactory.php b/src/Processor/Result/ResultFactory.php
index 68cfdcb..875aeed 100644
--- a/src/Processor/Result/ResultFactory.php
+++ b/src/Processor/Result/ResultFactory.php
@@ -18,9 +18,9 @@
final class ResultFactory implements ResultFactoryInterface
{
public function __construct(
- private ValueEncoderInterface $jsonEncoder,
- private ValueDecoderInterface $jsonDecoder,
- private PathEncoderInterface $pathsEncoder,
+ private readonly ValueEncoderInterface $jsonEncoder,
+ private readonly ValueDecoderInterface $jsonDecoder,
+ private readonly PathEncoderInterface $pathsEncoder,
) {
}
@@ -38,7 +38,7 @@ public function createSelectPathsResult(ValueListInterface $values): SelectPaths
{
return new SelectPathsResult(
$this->pathsEncoder,
- ...array_map([$this, 'getValuePath'], $values->getValues()),
+ ...array_map($this->getValuePath(...), $values->getValues()),
);
}
diff --git a/src/Processor/Result/SelectPathsResult.php b/src/Processor/Result/SelectPathsResult.php
index b429205..9a00352 100644
--- a/src/Processor/Result/SelectPathsResult.php
+++ b/src/Processor/Result/SelectPathsResult.php
@@ -15,10 +15,10 @@ final class SelectPathsResult implements SelectPathsResultInterface
/**
* @var list
*/
- private array $paths;
+ private readonly array $paths;
public function __construct(
- private PathEncoderInterface $encoder,
+ private readonly PathEncoderInterface $encoder,
PathInterface ...$paths,
) {
$this->paths = array_values($paths);
@@ -37,6 +37,6 @@ public function get(): array
*/
public function encode(): array
{
- return array_map([$this->encoder, 'encodePath'], $this->paths);
+ return array_map($this->encoder->encodePath(...), $this->paths);
}
}
diff --git a/src/Processor/Result/SelectResult.php b/src/Processor/Result/SelectResult.php
index fa359c1..374d1e1 100644
--- a/src/Processor/Result/SelectResult.php
+++ b/src/Processor/Result/SelectResult.php
@@ -19,8 +19,8 @@ final class SelectResult implements SelectResultInterface
private array $values;
public function __construct(
- private ValueEncoderInterface $encoder,
- private ValueDecoderInterface $decoder,
+ private readonly ValueEncoderInterface $encoder,
+ private readonly ValueDecoderInterface $decoder,
ValueInterface ...$values,
) {
$this->values = array_values($values);
@@ -33,7 +33,7 @@ public function __construct(
*/
public function decode(): array
{
- return array_map([$this->decoder, 'exportValue'], $this->values);
+ return array_map($this->decoder->exportValue(...), $this->values);
}
/**
@@ -43,7 +43,7 @@ public function decode(): array
*/
public function encode(): array
{
- return array_map([$this->encoder, 'exportValue'], $this->values);
+ return array_map($this->encoder->exportValue(...), $this->values);
}
/**
diff --git a/src/Query/AstBuilder.php b/src/Query/AstBuilder.php
index 4eb1ae7..dc64a58 100644
--- a/src/Query/AstBuilder.php
+++ b/src/Query/AstBuilder.php
@@ -12,7 +12,7 @@ final class AstBuilder implements AstBuilderInterface
private ?int $inputId = null;
public function __construct(
- private Tree $tree,
+ private readonly Tree $tree,
) {
}
diff --git a/src/Query/CallbackBuilder.php b/src/Query/CallbackBuilder.php
index 1878b4b..b6fbcac 100644
--- a/src/Query/CallbackBuilder.php
+++ b/src/Query/CallbackBuilder.php
@@ -125,7 +125,7 @@ public function onFinish(): void
function (PhpAstNode $stmt): PhpAstNode {
return $stmt instanceof Expr ? new Expression($stmt) : $stmt;
},
- $this->stmts
+ $this->stmts,
);
$this->callbackCode = (new Standard())->prettyPrint($stmts);
@@ -326,7 +326,7 @@ public function onFinishProduction(QueryAstNode $node): void
'matchPropertyStrictly',
...array_map(
[$this->php, 'val'],
- $node->getAttribute('names')
+ $node->getAttribute('names'),
),
);
break;
@@ -339,7 +339,7 @@ public function onFinishProduction(QueryAstNode $node): void
'matchElementStrictly',
...array_map(
[$this->php, 'val'],
- $node->getAttribute('indexes')
+ $node->getAttribute('indexes'),
),
);
break;
@@ -450,8 +450,8 @@ private function hasReference(QueryAstNode $node): bool
private function getReference(QueryAstNode $node): Expr
{
- return $this->references[$node->getId()]
- ?? throw new Exception\ReferenceNotFoundException($node->getId());
+ return $this->references[$node->getId()] ??
+ throw new Exception\ReferenceNotFoundException($node->getId());
}
/**
@@ -460,7 +460,7 @@ private function getReference(QueryAstNode $node): Expr
*/
private function getReferences(QueryAstNode ...$nodes): array
{
- return array_map([$this, 'getReference'], array_values($nodes));
+ return array_map($this->getReference(...), array_values($nodes));
}
private function addMethodCall(QueryAstNode $node, Expr $object, string $method, PhpAstNode ...$args): void
diff --git a/src/Query/Capabilities.php b/src/Query/Capabilities.php
index 9a082fe..70d4555 100644
--- a/src/Query/Capabilities.php
+++ b/src/Query/Capabilities.php
@@ -7,8 +7,8 @@
final class Capabilities implements CapabilitiesInterface
{
public function __construct(
- private bool $isDefinite,
- private bool $isAddressable,
+ private readonly bool $isDefinite,
+ private readonly bool $isAddressable,
) {
}
diff --git a/src/Query/Exception/CapabilitiesNotFoundException.php b/src/Query/Exception/CapabilitiesNotFoundException.php
index 0dda4a2..5fd6079 100644
--- a/src/Query/Exception/CapabilitiesNotFoundException.php
+++ b/src/Query/Exception/CapabilitiesNotFoundException.php
@@ -11,6 +11,6 @@ final class CapabilitiesNotFoundException extends LogicException implements Exce
{
public function __construct(?Throwable $previous = null)
{
- parent::__construct("Properties are accessed before being set", 0, $previous);
+ parent::__construct("Properties are accessed before being set", previous: $previous);
}
}
diff --git a/src/Query/Exception/QueryAstNotTranslatedException.php b/src/Query/Exception/QueryAstNotTranslatedException.php
index 1f281ae..3d76c96 100644
--- a/src/Query/Exception/QueryAstNotTranslatedException.php
+++ b/src/Query/Exception/QueryAstNotTranslatedException.php
@@ -11,10 +11,10 @@
final class QueryAstNotTranslatedException extends LogicException implements ExceptionInterface
{
public function __construct(
- private Tree $queryAst,
+ private readonly Tree $queryAst,
?Throwable $previous = null,
) {
- parent::__construct("Query AST was not translated to callback function", 0, $previous);
+ parent::__construct("Query AST was not translated to callback function", previous: $previous);
}
public function getQueryAst(): Tree
diff --git a/src/Query/Exception/QueryCallbackCodeNotFoundException.php b/src/Query/Exception/QueryCallbackCodeNotFoundException.php
index 54ca15b..74cc9db 100644
--- a/src/Query/Exception/QueryCallbackCodeNotFoundException.php
+++ b/src/Query/Exception/QueryCallbackCodeNotFoundException.php
@@ -11,6 +11,6 @@ final class QueryCallbackCodeNotFoundException extends LogicException implements
{
public function __construct(?Throwable $previous = null)
{
- parent::__construct("Query callback code is accessed before being generated", 0, $previous);
+ parent::__construct("Query callback code is accessed before being generated", previous: $previous);
}
}
diff --git a/src/Query/Exception/QueryExecutionFailedException.php b/src/Query/Exception/QueryExecutionFailedException.php
index 9dc53c0..45e8f5d 100644
--- a/src/Query/Exception/QueryExecutionFailedException.php
+++ b/src/Query/Exception/QueryExecutionFailedException.php
@@ -11,11 +11,11 @@
final class QueryExecutionFailedException extends LogicException implements ExceptionInterface
{
public function __construct(
- private string $source,
- private string $callbackCode,
+ private readonly string $source,
+ private readonly string $callbackCode,
?Throwable $previous = null,
) {
- parent::__construct($this->buildMessage(), 0, $previous);
+ parent::__construct($this->buildMessage(), previous: $previous);
}
private function buildMessage(): string
diff --git a/src/Query/Exception/ReferenceAlreadyExistsException.php b/src/Query/Exception/ReferenceAlreadyExistsException.php
index 7fb8495..1873e16 100644
--- a/src/Query/Exception/ReferenceAlreadyExistsException.php
+++ b/src/Query/Exception/ReferenceAlreadyExistsException.php
@@ -10,10 +10,10 @@
final class ReferenceAlreadyExistsException extends LogicException implements ExceptionInterface
{
public function __construct(
- private int $referenceId,
+ private readonly int $referenceId,
?Throwable $previous = null,
) {
- parent::__construct("Reference #$this->referenceId already exists", 0, $previous);
+ parent::__construct("Reference #$this->referenceId already exists", previous: $previous);
}
public function getReferenceId(): int
diff --git a/src/Query/Exception/ReferenceNotFoundException.php b/src/Query/Exception/ReferenceNotFoundException.php
index e8630f5..8227da5 100644
--- a/src/Query/Exception/ReferenceNotFoundException.php
+++ b/src/Query/Exception/ReferenceNotFoundException.php
@@ -10,10 +10,10 @@
final class ReferenceNotFoundException extends OutOfRangeException implements ExceptionInterface
{
public function __construct(
- private int $referenceId,
+ private readonly int $referenceId,
?Throwable $previous = null,
) {
- parent::__construct("Reference #$this->referenceId not found", 0, $previous);
+ parent::__construct("Reference #$this->referenceId not found", previous: $previous);
}
public function getReferenceId(): int
diff --git a/src/Query/LazyQuery.php b/src/Query/LazyQuery.php
index 0e5a998..a0099ea 100644
--- a/src/Query/LazyQuery.php
+++ b/src/Query/LazyQuery.php
@@ -14,10 +14,10 @@ final class LazyQuery implements QueryInterface
private ?QueryInterface $loadedQuery = null;
public function __construct(
- private string $source,
- private ParserInterface $parser,
- private AstTranslatorInterface $astTranslator,
- private CallbackBuilderInterface $callbackBuilder,
+ private readonly string $source,
+ private readonly ParserInterface $parser,
+ private readonly AstTranslatorInterface $astTranslator,
+ private readonly CallbackBuilderInterface $callbackBuilder,
) {
}
diff --git a/src/Query/Query.php b/src/Query/Query.php
index 056c934..3d3a645 100644
--- a/src/Query/Query.php
+++ b/src/Query/Query.php
@@ -15,8 +15,8 @@
final class Query implements QueryInterface
{
public function __construct(
- private string $source,
- private CallbackBuilderInterface $callbackBuilder,
+ private readonly string $source,
+ private readonly CallbackBuilderInterface $callbackBuilder,
) {
}
diff --git a/src/Query/QueryFactory.php b/src/Query/QueryFactory.php
index 7f50058..6ea8ec6 100644
--- a/src/Query/QueryFactory.php
+++ b/src/Query/QueryFactory.php
@@ -19,8 +19,8 @@ public static function create(): QueryFactoryInterface
}
public function __construct(
- private ParserInterface $parser,
- private AstTranslatorInterface $astTranslator,
+ private readonly ParserInterface $parser,
+ private readonly AstTranslatorInterface $astTranslator,
) {
}
diff --git a/src/Runtime/Aggregator/Exception/AggregateFunctionNotFoundException.php b/src/Runtime/Aggregator/Exception/AggregateFunctionNotFoundException.php
index 5309f41..7227c04 100644
--- a/src/Runtime/Aggregator/Exception/AggregateFunctionNotFoundException.php
+++ b/src/Runtime/Aggregator/Exception/AggregateFunctionNotFoundException.php
@@ -10,10 +10,10 @@
final class AggregateFunctionNotFoundException extends DomainException implements ExceptionInterface
{
public function __construct(
- private string $name,
+ private readonly string $name,
?Throwable $previous = null,
) {
- parent::__construct("Aggregate function not found: $this->name", 0, $previous);
+ parent::__construct("Aggregate function not found: $this->name", previous: $previous);
}
public function getName(): string
diff --git a/src/Runtime/Aggregator/Exception/MaxElementNotFoundException.php b/src/Runtime/Aggregator/Exception/MaxElementNotFoundException.php
index 173fb85..76d6705 100644
--- a/src/Runtime/Aggregator/Exception/MaxElementNotFoundException.php
+++ b/src/Runtime/Aggregator/Exception/MaxElementNotFoundException.php
@@ -16,12 +16,12 @@ final class MaxElementNotFoundException extends LogicException implements Except
* @param Throwable|null $previous
*/
public function __construct(
- private array $dataList,
- private array $elements,
+ private readonly array $dataList,
+ private readonly array $elements,
?Throwable $previous = null,
) {
- parent::__construct("Max element not found", 0, $previous);
+ parent::__construct("Max element not found", previous: $previous);
}
public function getDataList(): array
diff --git a/src/Runtime/Aggregator/Exception/MinElementNotFoundException.php b/src/Runtime/Aggregator/Exception/MinElementNotFoundException.php
index b1447fd..276c6a0 100644
--- a/src/Runtime/Aggregator/Exception/MinElementNotFoundException.php
+++ b/src/Runtime/Aggregator/Exception/MinElementNotFoundException.php
@@ -16,11 +16,11 @@ final class MinElementNotFoundException extends LogicException implements Except
* @param Throwable|null $previous
*/
public function __construct(
- private array $dataList,
- private array $elements,
+ private readonly array $dataList,
+ private readonly array $elements,
?Throwable $previous = null,
) {
- parent::__construct("Min element not found", 0, $previous);
+ parent::__construct("Min element not found", previous: $previous);
}
public function getDataList(): array
diff --git a/src/Runtime/Aggregator/NumericAggregator.php b/src/Runtime/Aggregator/NumericAggregator.php
index 9e2599c..1b13887 100644
--- a/src/Runtime/Aggregator/NumericAggregator.php
+++ b/src/Runtime/Aggregator/NumericAggregator.php
@@ -79,7 +79,7 @@ protected function getElementDataList(ScalarValueInterface ...$elements): array
{
return array_values(
array_filter(
- array_map([$this, 'findElementData'], $elements),
+ array_map($this->findElementData(...), $elements),
),
);
}
diff --git a/src/Runtime/Aggregator/StdDevAggregator.php b/src/Runtime/Aggregator/StdDevAggregator.php
index 60c142c..63d4eb6 100644
--- a/src/Runtime/Aggregator/StdDevAggregator.php
+++ b/src/Runtime/Aggregator/StdDevAggregator.php
@@ -28,9 +28,7 @@ protected function aggregateNumericData(array $dataList, ScalarValueInterface ..
}
$meanValue = array_sum($dataList) / $count;
- $calculateSquaredDifferenceFromMean = function ($value) use ($meanValue): float {
- return ($value - $meanValue) ** 2;
- };
+ $calculateSquaredDifferenceFromMean = static fn ($value): float => ($value - $meanValue) ** 2;
$squaredDifferencesSum = array_sum(array_map($calculateSquaredDifferenceFromMean, $dataList));
$variance = $squaredDifferencesSum / ($count - 1);
diff --git a/src/Runtime/ComparatorCollection.php b/src/Runtime/ComparatorCollection.php
index 4f2103a..707f8df 100644
--- a/src/Runtime/ComparatorCollection.php
+++ b/src/Runtime/ComparatorCollection.php
@@ -12,7 +12,7 @@
final class ComparatorCollection implements ComparatorCollectionInterface
{
public function __construct(
- private Collator $collator,
+ private readonly Collator $collator,
) {
}
diff --git a/src/Runtime/Evaluator.php b/src/Runtime/Evaluator.php
index 54a2714..4bffc79 100644
--- a/src/Runtime/Evaluator.php
+++ b/src/Runtime/Evaluator.php
@@ -22,8 +22,8 @@
final class Evaluator implements EvaluatorInterface
{
public function __construct(
- private ComparatorCollectionInterface $comparators,
- private Aggregator\AggregatorCollectionInterface $aggregators,
+ private readonly ComparatorCollectionInterface $comparators,
+ private readonly Aggregator\AggregatorCollectionInterface $aggregators,
) {
}
diff --git a/src/Runtime/Exception/IndexMapMatchFailedException.php b/src/Runtime/Exception/IndexMapMatchFailedException.php
index 9565c44..a5cc2ba 100644
--- a/src/Runtime/Exception/IndexMapMatchFailedException.php
+++ b/src/Runtime/Exception/IndexMapMatchFailedException.php
@@ -11,11 +11,11 @@
final class IndexMapMatchFailedException extends LogicException implements ExceptionInterface
{
public function __construct(
- private ValueListInterface $leftValues,
- private ValueListInterface $rightValues,
+ private readonly ValueListInterface $leftValues,
+ private readonly ValueListInterface $rightValues,
?Throwable $previous = null,
) {
- parent::__construct("Index map match failed", 0, $previous);
+ parent::__construct("Index map match failed", previous: $previous);
}
public function getLeftValues(): ValueListInterface
diff --git a/src/Runtime/Exception/InvalidContextValueException.php b/src/Runtime/Exception/InvalidContextValueException.php
index 0fc07b0..c208973 100644
--- a/src/Runtime/Exception/InvalidContextValueException.php
+++ b/src/Runtime/Exception/InvalidContextValueException.php
@@ -11,10 +11,10 @@
final class InvalidContextValueException extends LogicException implements ExceptionInterface
{
public function __construct(
- private ValueInterface $value,
+ private readonly ValueInterface $value,
?Throwable $previous = null,
) {
- parent::__construct("Invalid context value", 0, $previous);
+ parent::__construct("Invalid context value", previous: $previous);
}
public function getValue(): ValueInterface
diff --git a/src/Runtime/Exception/InvalidFilterValueException.php b/src/Runtime/Exception/InvalidFilterValueException.php
index 33df694..a35d2f4 100644
--- a/src/Runtime/Exception/InvalidFilterValueException.php
+++ b/src/Runtime/Exception/InvalidFilterValueException.php
@@ -11,10 +11,10 @@
final class InvalidFilterValueException extends LogicException implements ExceptionInterface
{
public function __construct(
- private ValueInterface $value,
+ private readonly ValueInterface $value,
?Throwable $previous = null,
) {
- parent::__construct("Invalid filter value", 0, $previous);
+ parent::__construct("Invalid filter value", previous: $previous);
}
public function getValue(): ValueInterface
diff --git a/src/Runtime/Exception/InvalidRegExpException.php b/src/Runtime/Exception/InvalidRegExpException.php
index d7ed0e5..b9ec3f5 100644
--- a/src/Runtime/Exception/InvalidRegExpException.php
+++ b/src/Runtime/Exception/InvalidRegExpException.php
@@ -10,10 +10,10 @@
final class InvalidRegExpException extends RuntimeException implements ExceptionInterface
{
public function __construct(
- private string $pattern,
+ private readonly string $pattern,
?Throwable $previous = null,
) {
- parent::__construct("Error processing regular expression: $this->pattern", 0, $previous);
+ parent::__construct("Error processing regular expression: $this->pattern", previous: $previous);
}
public function getPattern(): string
diff --git a/src/Runtime/Exception/LiteralEvaluationFailedException.php b/src/Runtime/Exception/LiteralEvaluationFailedException.php
index ae08ddc..3dde4a1 100644
--- a/src/Runtime/Exception/LiteralEvaluationFailedException.php
+++ b/src/Runtime/Exception/LiteralEvaluationFailedException.php
@@ -11,10 +11,10 @@
final class LiteralEvaluationFailedException extends LogicException implements ExceptionInterface
{
public function __construct(
- private LiteralValueInterface $literal,
+ private readonly LiteralValueInterface $literal,
?Throwable $previous = null,
) {
- parent::__construct("Failed to evaluate literal value", 0, $previous);
+ parent::__construct("Failed to evaluate literal value", previous: $previous);
}
public function getLiteral(): LiteralValueInterface
diff --git a/src/Runtime/Exception/UnexpectedNodeValueFetchedException.php b/src/Runtime/Exception/UnexpectedNodeValueFetchedException.php
index 1cb8456..b267c5e 100644
--- a/src/Runtime/Exception/UnexpectedNodeValueFetchedException.php
+++ b/src/Runtime/Exception/UnexpectedNodeValueFetchedException.php
@@ -11,10 +11,10 @@
final class UnexpectedNodeValueFetchedException extends LogicException implements ExceptionInterface
{
public function __construct(
- private NodeValueInterface $value,
+ private readonly NodeValueInterface $value,
?Throwable $previous = null,
) {
- parent::__construct("Unexpected node value fetched", 0, $previous);
+ parent::__construct("Unexpected node value fetched", previous: $previous);
}
public function getValue(): NodeValueInterface
diff --git a/src/Runtime/Matcher/Exception/AddressNotSortableException.php b/src/Runtime/Matcher/Exception/AddressNotSortableException.php
index a4b21ed..b4ee223 100644
--- a/src/Runtime/Matcher/Exception/AddressNotSortableException.php
+++ b/src/Runtime/Matcher/Exception/AddressNotSortableException.php
@@ -10,10 +10,10 @@
final class AddressNotSortableException extends DomainException implements ExceptionInterface
{
public function __construct(
- private int|string $address,
+ private readonly int|string $address,
?Throwable $previous = null,
) {
- parent::__construct("Index/property is not sortable: {$this->address}", 0, $previous);
+ parent::__construct("Index/property is not sortable: $this->address", previous: $previous);
}
public function getAddress(): int|string
diff --git a/src/Runtime/Matcher/SliceElementMatcher.php b/src/Runtime/Matcher/SliceElementMatcher.php
index 8afb2dd..e34f430 100644
--- a/src/Runtime/Matcher/SliceElementMatcher.php
+++ b/src/Runtime/Matcher/SliceElementMatcher.php
@@ -18,8 +18,8 @@ final class SliceElementMatcher implements SortedChildMatcherInterface
private bool $isReverse;
public function __construct(
- private ?int $start,
- private ?int $end,
+ private readonly ?int $start,
+ private readonly ?int $end,
?int $step,
) {
$this->step = $step ?? 1;
@@ -94,8 +94,8 @@ private function getIndex(int $address, int $start): int
public function getSortIndex(int|string $address, NodeValueInterface $value, NodeValueInterface $container): int
{
- $count = $this->findArrayLength($container)
- ?? throw new Exception\AddressNotSortableException($address);
+ $count = $this->findArrayLength($container) ??
+ throw new Exception\AddressNotSortableException($address);
return $this->getIndex($address, $this->detectStart($count));
}
diff --git a/src/Runtime/Matcher/StrictElementMatcher.php b/src/Runtime/Matcher/StrictElementMatcher.php
index 17621c0..1cbd366 100644
--- a/src/Runtime/Matcher/StrictElementMatcher.php
+++ b/src/Runtime/Matcher/StrictElementMatcher.php
@@ -12,7 +12,7 @@
final class StrictElementMatcher implements SortedChildMatcherInterface
{
- private $indexes;
+ private array $indexes;
public function __construct(int ...$indexes)
{
diff --git a/src/Runtime/Matcher/StrictPropertyMatcher.php b/src/Runtime/Matcher/StrictPropertyMatcher.php
index 0abe68d..91830e1 100644
--- a/src/Runtime/Matcher/StrictPropertyMatcher.php
+++ b/src/Runtime/Matcher/StrictPropertyMatcher.php
@@ -10,7 +10,7 @@
final class StrictPropertyMatcher implements SortedChildMatcherInterface
{
- private $properties;
+ private array $properties;
public function __construct(string ...$properties)
{
diff --git a/src/Runtime/Runtime.php b/src/Runtime/Runtime.php
index 4b7b92e..7c1dde1 100644
--- a/src/Runtime/Runtime.php
+++ b/src/Runtime/Runtime.php
@@ -7,10 +7,10 @@
final class Runtime implements RuntimeInterface
{
public function __construct(
- private ValueListFetcherInterface $valueListFetcher,
- private EvaluatorInterface $evaluator,
- private LiteralFactoryInterface $literalFactory,
- private Matcher\MatcherFactoryInterface $matcherFactory,
+ private readonly ValueListFetcherInterface $valueListFetcher,
+ private readonly EvaluatorInterface $evaluator,
+ private readonly LiteralFactoryInterface $literalFactory,
+ private readonly Matcher\MatcherFactoryInterface $matcherFactory,
) {
}
diff --git a/src/Runtime/ValueFetcher.php b/src/Runtime/ValueFetcher.php
index 864247c..eb129ba 100644
--- a/src/Runtime/ValueFetcher.php
+++ b/src/Runtime/ValueFetcher.php
@@ -44,7 +44,7 @@ public function createChildrenIterator(
private function createUnsortedChildStructIterator(
Matcher\ChildMatcherInterface $matcher,
- NodeValueInterface $value
+ NodeValueInterface $value,
): Iterator {
if (!$value instanceof StructValueInterface) {
return;
diff --git a/src/Runtime/ValueListFetcher.php b/src/Runtime/ValueListFetcher.php
index 4aafea9..8736f89 100644
--- a/src/Runtime/ValueListFetcher.php
+++ b/src/Runtime/ValueListFetcher.php
@@ -16,7 +16,7 @@
final class ValueListFetcher implements ValueListFetcherInterface
{
public function __construct(
- private ValueFetcherInterface $valueFetcher,
+ private readonly ValueFetcherInterface $valueFetcher,
) {
}
diff --git a/src/Value/EvaluatedValue.php b/src/Value/EvaluatedValue.php
index 9971839..a26f3d1 100644
--- a/src/Value/EvaluatedValue.php
+++ b/src/Value/EvaluatedValue.php
@@ -7,7 +7,7 @@
final class EvaluatedValue implements EvaluatedValueInterface
{
public function __construct(
- private bool $value,
+ private readonly bool $value,
) {
}
diff --git a/src/Value/EvaluatedValueList.php b/src/Value/EvaluatedValueList.php
index 3f7fe0d..e12d170 100644
--- a/src/Value/EvaluatedValueList.php
+++ b/src/Value/EvaluatedValueList.php
@@ -19,7 +19,7 @@ final class EvaluatedValueList implements EvaluatedValueListInterface
private array $values;
public function __construct(
- private IndexMapInterface $indexMap,
+ private readonly IndexMapInterface $indexMap,
bool ...$results,
) {
$this->results = array_values($results);
@@ -45,8 +45,8 @@ public function getResults(): array
public function getResult(int $index): bool
{
- return $this->results[$index]
- ?? throw new Exception\ResultNotFoundException($index, $this);
+ return $this->results[$index] ??
+ throw new Exception\ResultNotFoundException($index, $this);
}
/**
@@ -54,7 +54,7 @@ public function getResult(int $index): bool
*/
public function getValues(): array
{
- return $this->values ??= array_map([$this, 'createResultValue'], $this->results);
+ return $this->values ??= array_map($this->createResultValue(...), $this->results);
}
private function createResultValue(bool $result): EvaluatedValueInterface
diff --git a/src/Value/Exception/InvalidScalarDataException.php b/src/Value/Exception/InvalidScalarDataException.php
index c0d0ac5..8d487a8 100644
--- a/src/Value/Exception/InvalidScalarDataException.php
+++ b/src/Value/Exception/InvalidScalarDataException.php
@@ -13,10 +13,10 @@ final class InvalidScalarDataException extends DomainException implements
DataAwareInterface
{
public function __construct(
- private mixed $data,
+ private readonly mixed $data,
?Throwable $previous = null,
) {
- parent::__construct($this->buildMessage(), 0, $previous);
+ parent::__construct($this->buildMessage(), previous: $previous);
}
private function buildMessage(): string
diff --git a/src/Value/Exception/OuterIndexNotFoundException.php b/src/Value/Exception/OuterIndexNotFoundException.php
index 75d299c..ccbb2fb 100644
--- a/src/Value/Exception/OuterIndexNotFoundException.php
+++ b/src/Value/Exception/OuterIndexNotFoundException.php
@@ -11,11 +11,11 @@
final class OuterIndexNotFoundException extends OutOfRangeException implements ExceptionInterface
{
public function __construct(
- private int $innerIndex,
- private IndexMapInterface $indexMap,
+ private readonly int $innerIndex,
+ private readonly IndexMapInterface $indexMap,
?Throwable $previous = null,
) {
- parent::__construct($this->buildMessage(), 0, $previous);
+ parent::__construct($this->buildMessage(), previous: $previous);
}
private function buildMessage(): string
diff --git a/src/Value/Exception/ResultNotFoundException.php b/src/Value/Exception/ResultNotFoundException.php
index 4ee0e30..08c168b 100644
--- a/src/Value/Exception/ResultNotFoundException.php
+++ b/src/Value/Exception/ResultNotFoundException.php
@@ -11,11 +11,11 @@
final class ResultNotFoundException extends OutOfRangeException implements ExceptionInterface
{
public function __construct(
- private int $index,
- private ValueListInterface $values,
+ private readonly int $index,
+ private readonly ValueListInterface $values,
?Throwable $previous = null,
) {
- parent::__construct($this->buildMessage(), 0, $previous);
+ parent::__construct($this->buildMessage(), previous: $previous);
}
private function buildMessage(): string
diff --git a/src/Value/Exception/ValueInListWithAnotherOuterIndexException.php b/src/Value/Exception/ValueInListWithAnotherOuterIndexException.php
index 62cbe69..80e7923 100644
--- a/src/Value/Exception/ValueInListWithAnotherOuterIndexException.php
+++ b/src/Value/Exception/ValueInListWithAnotherOuterIndexException.php
@@ -11,12 +11,12 @@
final class ValueInListWithAnotherOuterIndexException extends LogicException implements ExceptionInterface
{
public function __construct(
- private NodeValueInterface $value,
- private int $expectedIndex,
- private int $actualIndex,
+ private readonly NodeValueInterface $value,
+ private readonly int $expectedIndex,
+ private readonly int $actualIndex,
?Throwable $previous = null,
) {
- parent::__construct($this->buildMessage(), 0, $previous);
+ parent::__construct($this->buildMessage(), previous: $previous);
}
private function buildMessage(): string
diff --git a/src/Value/Exception/ValueNotFoundException.php b/src/Value/Exception/ValueNotFoundException.php
index b30134c..b1956eb 100644
--- a/src/Value/Exception/ValueNotFoundException.php
+++ b/src/Value/Exception/ValueNotFoundException.php
@@ -11,11 +11,11 @@
final class ValueNotFoundException extends OutOfRangeException implements ExceptionInterface
{
public function __construct(
- private int $index,
- private ValueListInterface $values,
+ private readonly int $index,
+ private readonly ValueListInterface $values,
?Throwable $previous = null,
) {
- parent::__construct($this->buildMessage(), 0, $previous);
+ parent::__construct($this->buildMessage(), previous: $previous);
}
private function buildMessage(): string
diff --git a/src/Value/IndexMap.php b/src/Value/IndexMap.php
index f05ec13..e1b107c 100644
--- a/src/Value/IndexMap.php
+++ b/src/Value/IndexMap.php
@@ -45,8 +45,8 @@ public function getOuterIndexes(): array
public function getOuterIndex(int $innerIndex): int
{
- return $this->outerIndexes[$innerIndex]
- ?? throw new Exception\OuterIndexNotFoundException($innerIndex, $this);
+ return $this->outerIndexes[$innerIndex] ??
+ throw new Exception\OuterIndexNotFoundException($innerIndex, $this);
}
public function outerIndexExists(int $outerIndex): bool
diff --git a/src/Value/LiteralArrayValue.php b/src/Value/LiteralArrayValue.php
index 5abd3b2..d2101cb 100644
--- a/src/Value/LiteralArrayValue.php
+++ b/src/Value/LiteralArrayValue.php
@@ -7,7 +7,6 @@
use ArrayIterator;
use Iterator;
use Remorhaz\JSON\Data\Value\ArrayValueInterface;
-use Remorhaz\JSON\Data\Value\NodeValueInterface;
use Remorhaz\JSON\Data\Value\ValueInterface;
use function array_values;
diff --git a/src/Value/LiteralValueList.php b/src/Value/LiteralValueList.php
index 0a32c2f..6ac3236 100644
--- a/src/Value/LiteralValueList.php
+++ b/src/Value/LiteralValueList.php
@@ -11,8 +11,8 @@
final class LiteralValueList implements LiteralValueListInterface
{
public function __construct(
- private IndexMapInterface $indexMap,
- private LiteralValueInterface $value,
+ private readonly IndexMapInterface $indexMap,
+ private readonly LiteralValueInterface $value,
) {
}
diff --git a/src/Value/NodeValueList.php b/src/Value/NodeValueList.php
index 08fc28c..31b83cf 100644
--- a/src/Value/NodeValueList.php
+++ b/src/Value/NodeValueList.php
@@ -17,7 +17,7 @@ final class NodeValueList implements NodeValueListInterface
private array $values;
public function __construct(
- private IndexMapInterface $indexMap,
+ private readonly IndexMapInterface $indexMap,
NodeValueInterface ...$values,
) {
$this->values = array_values($values);
diff --git a/src/Value/ValueList.php b/src/Value/ValueList.php
index 15b37f0..d3f93e8 100644
--- a/src/Value/ValueList.php
+++ b/src/Value/ValueList.php
@@ -16,7 +16,7 @@ final class ValueList implements ValueListInterface
private array $values;
public function __construct(
- private IndexMapInterface $indexMap,
+ private readonly IndexMapInterface $indexMap,
ValueInterface ...$values,
) {
$this->values = array_values($values);
diff --git a/tests/JsonPathTest.php b/tests/JsonPathTest.php
index c6addb7..7bfefe2 100644
--- a/tests/JsonPathTest.php
+++ b/tests/JsonPathTest.php
@@ -4,6 +4,8 @@
namespace Remorhaz\JSON\Path\Test;
+use PHPUnit\Framework\Attributes\CoversNothing;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Processor\Processor;
use Remorhaz\JSON\Path\Query\QueryFactory;
@@ -11,12 +13,10 @@
use function file_get_contents;
-/**
- * @coversNothing
- */
+#[CoversNothing]
class JsonPathTest extends TestCase
{
- private $example;
+ private ?string $example;
public function setUp(): void
{
@@ -51,21 +51,24 @@ public function testSelect_FirstQueryAgainAfterSecond_ReturnsCorrectResult(): vo
}
/**
- * @param string $path
- * @param array $expectedValue
- * @dataProvider providerGoessnerExamples
+ * @param string $path
+ * @param list $expectedValue
*/
+ #[DataProvider('providerGoessnerExamples')]
public function testSelect_GoessnerExamples_WorkAsExpected(string $path, array $expectedValue): void
{
$result = Processor::create()->select(
QueryFactory::create()->createQuery($path),
- NodeValueFactory::create()->createValue($this->example)
+ NodeValueFactory::create()->createValue($this->example),
);
self::assertEquals($expectedValue, $result->encode());
}
- public function providerGoessnerExamples(): array
+ /**
+ * @return iterable}>
+ */
+ public static function providerGoessnerExamples(): iterable
{
return [
'the authors of all books in the store' => [
diff --git a/tests/MemoryLeakTest.php b/tests/MemoryLeakTest.php
index 817ec08..b8a5c55 100644
--- a/tests/MemoryLeakTest.php
+++ b/tests/MemoryLeakTest.php
@@ -4,6 +4,7 @@
namespace Remorhaz\JSON\Path\Test;
+use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Query\QueryFactory;
@@ -11,9 +12,7 @@
use function array_unique;
use function memory_get_usage;
-/**
- * @coversNothing
- */
+#[CoversNothing]
class MemoryLeakTest extends TestCase
{
public function testQueryCompilation(): void
diff --git a/tests/Parser/Exception/ParserCreationFailedExceptionTest.php b/tests/Parser/Exception/ParserCreationFailedExceptionTest.php
index 21b8f13..8ab5686 100644
--- a/tests/Parser/Exception/ParserCreationFailedExceptionTest.php
+++ b/tests/Parser/Exception/ParserCreationFailedExceptionTest.php
@@ -5,12 +5,11 @@
namespace Remorhaz\JSON\Path\Test\Parser\Exception;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Parser\Exception\ParserCreationFailedException;
-/**
- * @covers \Remorhaz\JSON\Path\Parser\Exception\ParserCreationFailedException
- */
+#[CoversClass(ParserCreationFailedException::class)]
class ParserCreationFailedExceptionTest extends TestCase
{
public function testGetMessage_Constructed_ReturnsMatchingValue(): void
@@ -19,12 +18,6 @@ public function testGetMessage_Constructed_ReturnsMatchingValue(): void
self::assertSame('Failed to create JSONPath parser', $exception->getMessage());
}
- public function testGetCode_Always_ReturnsZero(): void
- {
- $exception = new ParserCreationFailedException();
- self::assertSame(0, $exception->getCode());
- }
-
public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void
{
$exception = new ParserCreationFailedException();
diff --git a/tests/Parser/Exception/QueryAstNotBuiltExceptionTest.php b/tests/Parser/Exception/QueryAstNotBuiltExceptionTest.php
index cd93c1e..526eca1 100644
--- a/tests/Parser/Exception/QueryAstNotBuiltExceptionTest.php
+++ b/tests/Parser/Exception/QueryAstNotBuiltExceptionTest.php
@@ -5,12 +5,11 @@
namespace Remorhaz\JSON\Path\Test\Parser\Exception;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Parser\Exception\QueryAstNotBuiltException;
-/**
- * @covers \Remorhaz\JSON\Path\Parser\Exception\QueryAstNotBuiltException
- */
+#[CoversClass(QueryAstNotBuiltException::class)]
class QueryAstNotBuiltExceptionTest extends TestCase
{
public function testGetMessage_Constructed_ReturnsMatchingValue(): void
diff --git a/tests/Parser/Ll1ParserFactoryTest.php b/tests/Parser/Ll1ParserFactoryTest.php
index 307c820..1a23da6 100644
--- a/tests/Parser/Ll1ParserFactoryTest.php
+++ b/tests/Parser/Ll1ParserFactoryTest.php
@@ -4,27 +4,25 @@
namespace Remorhaz\JSON\Path\Test\Parser;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Parser\Ll1ParserFactory;
use Remorhaz\UniLex\AST\Tree;
use Remorhaz\UniLex\Exception as UniLexException;
use Remorhaz\UniLex\Parser\LL1\UnexpectedTokenException;
-/**
- * @covers \Remorhaz\JSON\Path\Parser\Ll1ParserFactory
- */
+#[CoversClass(Ll1ParserFactory::class)]
class Ll1ParserFactoryTest extends TestCase
{
/**
- * @param string $source
- * @param bool $isDefinite
* @throws UnexpectedTokenException
* @throws UniLexException
- * @dataProvider providerCreateParserIsDefinite
*/
+ #[DataProvider('providerCreateParserIsDefinite')]
public function testCreateParser_Constructed_ResultBuildsAstWithMatchingIsDefiniteFlagOnRun(
string $source,
- bool $isDefinite
+ bool $isDefinite,
): void {
$queryAst = new Tree();
$ll1Parser = (new Ll1ParserFactory())->createParser($source, $queryAst);
@@ -34,7 +32,10 @@ public function testCreateParser_Constructed_ResultBuildsAstWithMatchingIsDefini
self::assertSame($isDefinite, $astRootNode->getAttribute('is_definite'));
}
- public function providerCreateParserIsDefinite(): array
+ /**
+ * @return iterable
+ */
+ public static function providerCreateParserIsDefinite(): iterable
{
return [
'Definite path' => ['$', true],
@@ -43,15 +44,13 @@ public function providerCreateParserIsDefinite(): array
}
/**
- * @param string $source
- * @param bool $isAddressable
* @throws UnexpectedTokenException
* @throws UniLexException
- * @dataProvider providerCreateParserIsAddressable
*/
+ #[DataProvider('providerCreateParserIsAddressable')]
public function testCreateParser_Constructed_ResultBuildsAstWithMatchingIsAddressableFlagOnRun(
string $source,
- bool $isAddressable
+ bool $isAddressable,
): void {
$queryAst = new Tree();
$ll1Parser = (new Ll1ParserFactory())->createParser($source, $queryAst);
@@ -61,7 +60,10 @@ public function testCreateParser_Constructed_ResultBuildsAstWithMatchingIsAddres
self::assertSame($isAddressable, $astRootNode->getAttribute('is_addressable'));
}
- public function providerCreateParserIsAddressable(): array
+ /**
+ * @return iterable
+ */
+ public static function providerCreateParserIsAddressable(): iterable
{
return [
'Addressable path' => ['$', true],
diff --git a/tests/Parser/ParserTest.php b/tests/Parser/ParserTest.php
index 445f4ff..3145071 100644
--- a/tests/Parser/ParserTest.php
+++ b/tests/Parser/ParserTest.php
@@ -5,6 +5,7 @@
namespace Remorhaz\JSON\Path\Test\Parser;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Parser\Exception\QueryAstNotBuiltException;
use Remorhaz\JSON\Path\Parser\Ll1ParserFactoryInterface;
@@ -12,9 +13,7 @@
use Remorhaz\UniLex\AST\Tree;
use Remorhaz\UniLex\Parser\LL1\Parser as Ll1Parser;
-/**
- * @covers \Remorhaz\JSON\Path\Parser\Parser
- */
+#[CoversClass(Parser::class)]
class ParserTest extends TestCase
{
public function testBuildQueryAst_Constructed_ReturnsTreeInstancePassedToLl1ParserFactory(): void
diff --git a/tests/Parser/TranslationSchemeTest.php b/tests/Parser/TranslationSchemeTest.php
index 594239f..81084a6 100644
--- a/tests/Parser/TranslationSchemeTest.php
+++ b/tests/Parser/TranslationSchemeTest.php
@@ -2,32 +2,34 @@
namespace Remorhaz\JSON\Path\Test\Parser;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Value\DecodedJson\NodeValueFactory;
+use Remorhaz\JSON\Path\Parser\TranslationScheme;
use Remorhaz\JSON\Path\Processor\Processor;
use Remorhaz\JSON\Path\Query\QueryFactory;
/**
- * @covers \Remorhaz\JSON\Path\Parser\TranslationScheme
- * @todo Maybe it's better to test in isolation, checking the resulting AST.
+ * @todo Maybe it's better to test in isolation, checking the resulting AST.
*/
+#[CoversClass(TranslationScheme::class)]
class TranslationSchemeTest extends TestCase
{
- /**
- * @param string $path
- * @param bool $expectedValue
- * @dataProvider providerIsAddressableCapability
- */
+ #[DataProvider('providerIsAddressableCapability')]
public function testIsAddressableCapability_GivenQueryParsed_ContainsMatchingValue(
string $path,
- bool $expectedValue
+ bool $expectedValue,
): void {
$query = QueryFactory::create()->createQuery($path);
self::assertSame($expectedValue, $query->getCapabilities()->isAddressable());
}
- public function providerIsAddressableCapability(): array
+ /**
+ * @return iterable
+ */
+ public static function providerIsAddressableCapability(): iterable
{
return [
'Dot-notation star' => ['$.*', true],
@@ -44,17 +46,17 @@ public function providerIsAddressableCapability(): array
/**
* Because of the scheme complexity it's more convenient to test it in full integration.
*
- * @param $json
- * @param string $path
- * @param array $expectedValue
- * @param bool $isDefinite
- * @dataProvider providerParser
+ * @param mixed $json
+ * @param string $path
+ * @param list $expectedValue
+ * @param bool $isDefinite
*/
+ #[DataProvider('providerParser')]
public function testTranslationListenerMethods_AssembledWithParser_QueryWorksAsExpected(
- $json,
+ mixed $json,
string $path,
array $expectedValue,
- bool $isDefinite
+ bool $isDefinite,
): void {
$query = QueryFactory::create()->createQuery($path);
// TODO: extract isDefinite test
@@ -62,13 +64,16 @@ public function testTranslationListenerMethods_AssembledWithParser_QueryWorksAsE
$result = Processor::create()->select(
$query,
- NodeValueFactory::create()->createValue($json)
+ NodeValueFactory::create()->createValue($json),
);
self::assertEquals($expectedValue, $result->encode());
}
- public function providerParser(): array
+ /**
+ * @return iterable, bool>
+ */
+ public static function providerParser(): iterable
{
return [
'Dot-notation alpha property' => [
diff --git a/tests/Processor/Exception/IndefiniteQueryExceptionTest.php b/tests/Processor/Exception/IndefiniteQueryExceptionTest.php
index b102943..84d7286 100644
--- a/tests/Processor/Exception/IndefiniteQueryExceptionTest.php
+++ b/tests/Processor/Exception/IndefiniteQueryExceptionTest.php
@@ -5,19 +5,18 @@
namespace Remorhaz\JSON\Path\Test\Processor\Exception;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Processor\Exception\IndefiniteQueryException;
use Remorhaz\JSON\Path\Query\QueryInterface;
-/**
- * @covers \Remorhaz\JSON\Path\Processor\Exception\IndefiniteQueryException
- */
+#[CoversClass(IndefiniteQueryException::class)]
class IndefiniteQueryExceptionTest extends TestCase
{
public function testGetMessage_Constructed_ReturnsMatchingValue(): void
{
$exception = new IndefiniteQueryException(
- $this->createMock(QueryInterface::class)
+ $this->createMock(QueryInterface::class),
);
self::assertSame('Query is indefinite', $exception->getMessage());
}
@@ -29,18 +28,10 @@ public function testGetQuery_ConstructedWithQuery_ReturnsSameInstance(): void
self::assertSame($query, $exception->getQuery());
}
- public function testGetCode_Always_ReturnsZero(): void
- {
- $exception = new IndefiniteQueryException(
- $this->createMock(QueryInterface::class)
- );
- self::assertSame(0, $exception->getCode());
- }
-
public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void
{
$exception = new IndefiniteQueryException(
- $this->createMock(QueryInterface::class)
+ $this->createMock(QueryInterface::class),
);
self::assertNull($exception->getPrevious());
}
@@ -50,7 +41,7 @@ public function testGetPrevious_ConstructedWithPrevious_ReturnsSameInstance(): v
$previous = new Exception();
$exception = new IndefiniteQueryException(
$this->createMock(QueryInterface::class),
- $previous
+ $previous,
);
self::assertSame($previous, $exception->getPrevious());
}
diff --git a/tests/Processor/Exception/InvalidPathElementExceptionTest.php b/tests/Processor/Exception/InvalidPathElementExceptionTest.php
index 8e3466a..7f04d4b 100644
--- a/tests/Processor/Exception/InvalidPathElementExceptionTest.php
+++ b/tests/Processor/Exception/InvalidPathElementExceptionTest.php
@@ -5,12 +5,11 @@
namespace Remorhaz\JSON\Path\Test\Processor\Exception;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Processor\Exception\InvalidPathElementException;
-/**
- * @covers \Remorhaz\JSON\Path\Processor\Exception\InvalidPathElementException
- */
+#[CoversClass(InvalidPathElementException::class)]
class InvalidPathElementExceptionTest extends TestCase
{
public function testGetMessage_Constructed_ReturnsMatchingValue(): void
@@ -25,12 +24,6 @@ public function testGetPathElement_ConstructedWithPathElement_ReturnsSameValue()
self::assertSame('a', $exception->getPathElement());
}
- public function testGetCode_Always_ReturnsZero(): void
- {
- $exception = new InvalidPathElementException(1);
- self::assertSame(0, $exception->getCode());
- }
-
public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void
{
$exception = new InvalidPathElementException(1);
diff --git a/tests/Processor/Exception/QueryNotAddressableExceptionTest.php b/tests/Processor/Exception/QueryNotAddressableExceptionTest.php
index 24b6363..87548e1 100644
--- a/tests/Processor/Exception/QueryNotAddressableExceptionTest.php
+++ b/tests/Processor/Exception/QueryNotAddressableExceptionTest.php
@@ -5,19 +5,18 @@
namespace Remorhaz\JSON\Path\Test\Processor\Exception;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Processor\Exception\QueryNotAddressableException;
use Remorhaz\JSON\Path\Query\QueryInterface;
-/**
- * @covers \Remorhaz\JSON\Path\Processor\Exception\QueryNotAddressableException
- */
+#[CoversClass(QueryNotAddressableException::class)]
class QueryNotAddressableExceptionTest extends TestCase
{
public function testGetMessage_Constructed_ReturnsMatchingValue(): void
{
$exception = new QueryNotAddressableException(
- $this->createMock(QueryInterface::class)
+ $this->createMock(QueryInterface::class),
);
self::assertSame('Query is not addressable', $exception->getMessage());
}
@@ -29,18 +28,10 @@ public function testGetQuery_ConstructedWithQuery_ReturnsSameInstance(): void
self::assertSame($query, $exception->getQuery());
}
- public function testGetCode_Always_ReturnsZero(): void
- {
- $exception = new QueryNotAddressableException(
- $this->createMock(QueryInterface::class)
- );
- self::assertSame(0, $exception->getCode());
- }
-
public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void
{
$exception = new QueryNotAddressableException(
- $this->createMock(QueryInterface::class)
+ $this->createMock(QueryInterface::class),
);
self::assertNull($exception->getPrevious());
}
@@ -50,7 +41,7 @@ public function testGetPrevious_ConstructedWithPrevious_ReturnsSameInstance(): v
$previous = new Exception();
$exception = new QueryNotAddressableException(
$this->createMock(QueryInterface::class),
- $previous
+ $previous,
);
self::assertSame($previous, $exception->getPrevious());
}
diff --git a/tests/Processor/Mutator/Exception/ReplaceAtNestedPathsExceptionTest.php b/tests/Processor/Mutator/Exception/ReplaceAtNestedPathsExceptionTest.php
index ff24754..d269cfc 100644
--- a/tests/Processor/Mutator/Exception/ReplaceAtNestedPathsExceptionTest.php
+++ b/tests/Processor/Mutator/Exception/ReplaceAtNestedPathsExceptionTest.php
@@ -5,20 +5,19 @@
namespace Remorhaz\JSON\Path\Test\Processor\Mutator\Exception;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Path\PathInterface;
use Remorhaz\JSON\Path\Processor\Mutator\Exception\ReplaceAtNestedPathsException;
-/**
- * @covers \Remorhaz\JSON\Path\Processor\Mutator\Exception\ReplaceAtNestedPathsException
- */
+#[CoversClass(ReplaceAtNestedPathsException::class)]
class ReplaceAtNestedPathsExceptionTest extends TestCase
{
public function testGetMessage_Constructed_ReturnsMatchingValue(): void
{
$exception = new ReplaceAtNestedPathsException(
$this->createMock(PathInterface::class),
- $this->createMock(PathInterface::class)
+ $this->createMock(PathInterface::class),
);
self::assertSame('Attempt of replacing value at nested paths', $exception->getMessage());
}
@@ -28,7 +27,7 @@ public function testGetParentPath_ConstructedWithParentPath_ReturnsSameInstance(
$parentPath = $this->createMock(PathInterface::class);
$exception = new ReplaceAtNestedPathsException(
$parentPath,
- $this->createMock(PathInterface::class)
+ $this->createMock(PathInterface::class),
);
self::assertSame($parentPath, $exception->getParentPath());
}
@@ -38,25 +37,16 @@ public function testGetNestedPath_ConstructedWithNestedPath_ReturnsSameInstance(
$nestedPath = $this->createMock(PathInterface::class);
$exception = new ReplaceAtNestedPathsException(
$this->createMock(PathInterface::class),
- $nestedPath
+ $nestedPath,
);
self::assertSame($nestedPath, $exception->getNestedPath());
}
- public function testGetCode_Always_ReturnsZero(): void
- {
- $exception = new ReplaceAtNestedPathsException(
- $this->createMock(PathInterface::class),
- $this->createMock(PathInterface::class)
- );
- self::assertSame(0, $exception->getCode());
- }
-
public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void
{
$exception = new ReplaceAtNestedPathsException(
$this->createMock(PathInterface::class),
- $this->createMock(PathInterface::class)
+ $this->createMock(PathInterface::class),
);
self::assertNull($exception->getPrevious());
}
@@ -67,7 +57,7 @@ public function testGetPrevious_ConstructedWithPrevious_ReturnsSameInstance(): v
$exception = new ReplaceAtNestedPathsException(
$this->createMock(PathInterface::class),
$this->createMock(PathInterface::class),
- $previous
+ $previous,
);
self::assertSame($previous, $exception->getPrevious());
}
diff --git a/tests/Processor/PathEncoderTest.php b/tests/Processor/PathEncoderTest.php
index 953b129..69c391a 100644
--- a/tests/Processor/PathEncoderTest.php
+++ b/tests/Processor/PathEncoderTest.php
@@ -4,32 +4,35 @@
namespace Remorhaz\JSON\Path\Test\Processor;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Path\Path;
use Remorhaz\JSON\Data\Path\PathInterface;
use Remorhaz\JSON\Path\Processor\Exception\InvalidPathElementException;
use Remorhaz\JSON\Path\Processor\PathEncoder;
-/**
- * @covers \Remorhaz\JSON\Path\Processor\PathEncoder
- */
+#[CoversClass(PathEncoder::class)]
class PathEncoderTest extends TestCase
{
/**
- * @param array $pathElements
- * @param string $expectedValue
- * @dataProvider providerEncodePath
+ * @param list $pathElements
+ * @param string $expectedValue
*/
+ #[DataProvider('providerEncodePath')]
public function testEncodePath_ConstructedWithGivenElements_ReturnsMatchingValue(
array $pathElements,
- string $expectedValue
+ string $expectedValue,
): void {
$path = new Path(...$pathElements);
$actualValue = (new PathEncoder())->encodePath($path);
self::assertSame($expectedValue, $actualValue);
}
- public function providerEncodePath(): array
+ /**
+ * @return iterable, string}>
+ */
+ public static function providerEncodePath(): iterable
{
return [
'Empty path' => [[], '$'],
diff --git a/tests/Processor/ProcessorTest.php b/tests/Processor/ProcessorTest.php
index d4858f7..06b8f86 100644
--- a/tests/Processor/ProcessorTest.php
+++ b/tests/Processor/ProcessorTest.php
@@ -4,6 +4,8 @@
namespace Remorhaz\JSON\Path\Test\Processor;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Value\EncodedJson\NodeValueFactory;
use Remorhaz\JSON\Path\Processor\Exception\IndefiniteQueryException;
@@ -12,21 +14,17 @@
use Remorhaz\JSON\Path\Processor\Processor;
use Remorhaz\JSON\Path\Query\QueryFactory;
-/**
- * @covers \Remorhaz\JSON\Path\Processor\Processor
- */
+#[CoversClass(Processor::class)]
class ProcessorTest extends TestCase
{
/**
- * @param string $json
- * @param string $path
- * @param array $expectedValue
* @dataProvider providerSelect
*/
+ #[DataProvider('providerSelect')]
public function testSelect_GivenQueryAndData_ReturnsMatchingData(
string $json,
string $path,
- array $expectedValue
+ array $expectedValue,
): void {
$actualValue = Processor::create()->select(
QueryFactory::create()->createQuery($path),
@@ -35,7 +33,10 @@ public function testSelect_GivenQueryAndData_ReturnsMatchingData(
self::assertSame($expectedValue, $actualValue->encode());
}
- public function providerSelect(): array
+ /**
+ * @return iterable}>
+ */
+ public static function providerSelect(): iterable
{
return [
'Query matches nothing' => ['{}', '$.a', []],
@@ -48,16 +49,11 @@ public function providerSelect(): array
];
}
- /**
- * @param string $json
- * @param string $path
- * @param array $expectedValue
- * @dataProvider providerSelectPaths
- */
+ #[DataProvider('providerSelectPaths')]
public function testSelectPaths_GivenQueryAndData_ResultContainsMatchingPaths(
string $json,
string $path,
- array $expectedValue
+ array $expectedValue,
): void {
$actualValue = Processor::create()->selectPaths(
QueryFactory::create()->createQuery($path),
@@ -66,7 +62,10 @@ public function testSelectPaths_GivenQueryAndData_ResultContainsMatchingPaths(
self::assertSame($expectedValue, $actualValue->encode());
}
- public function providerSelectPaths(): array
+ /**
+ * @return iterable}>
+ */
+ public static function providerSelectPaths(): iterable
{
return [
'Query matches nothing' => ['{}', '$.a', []],
@@ -77,7 +76,7 @@ public function providerSelectPaths(): array
[
"\$['a']",
"\$['a']['a']",
- ]
+ ],
],
];
}
@@ -86,7 +85,7 @@ public function testSelectOne_DefiniteQueryMatchesData_ResultContainsMatchingDat
{
$actualData = Processor::create()->selectOne(
QueryFactory::create()->createQuery('$.a'),
- NodeValueFactory::create()->createValue('{"a":1}')
+ NodeValueFactory::create()->createValue('{"a":1}'),
);
self::assertSame('1', $actualData->encode());
}
@@ -95,7 +94,7 @@ public function testSelectOne_DefiniteQueryMatchesNothing_ResultNotExists(): voi
{
$actualData = Processor::create()->selectOne(
QueryFactory::create()->createQuery('$.a'),
- NodeValueFactory::create()->createValue('{}')
+ NodeValueFactory::create()->createValue('{}'),
);
self::assertFalse($actualData->exists());
}
@@ -114,7 +113,7 @@ public function testSelectOnePath_DefinitePathQueryMatchesData_ResultContainsMat
{
$actualData = Processor::create()->selectOnePath(
QueryFactory::create()->createQuery('$.a'),
- NodeValueFactory::create()->createValue('{"a":1}')
+ NodeValueFactory::create()->createValue('{"a":1}'),
);
self::assertSame("\$['a']", $actualData->encode());
}
@@ -123,7 +122,7 @@ public function testSelectOnePath_DefinitePathQueryMatchesNothing_ResultNotExist
{
$actualData = Processor::create()->selectOnePath(
QueryFactory::create()->createQuery('$.a'),
- NodeValueFactory::create()->createValue('{}')
+ NodeValueFactory::create()->createValue('{}'),
);
self::assertFalse($actualData->exists());
}
diff --git a/tests/Processor/Result/Exception/MoreThanOneValueInListExceptionTest.php b/tests/Processor/Result/Exception/MoreThanOneValueInListExceptionTest.php
index 010f71f..e8a2514 100644
--- a/tests/Processor/Result/Exception/MoreThanOneValueInListExceptionTest.php
+++ b/tests/Processor/Result/Exception/MoreThanOneValueInListExceptionTest.php
@@ -5,19 +5,18 @@
namespace Remorhaz\JSON\Path\Test\Processor\Result\Exception;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Processor\Result\Exception\MoreThanOneValueInListException;
use Remorhaz\JSON\Path\Value\ValueListInterface;
-/**
- * @covers \Remorhaz\JSON\Path\Processor\Result\Exception\MoreThanOneValueInListException
- */
+#[CoversClass(MoreThanOneValueInListException::class)]
class MoreThanOneValueInListExceptionTest extends TestCase
{
public function testGetMessage_Constructed_ReturnsMatchingValue(): void
{
$exception = new MoreThanOneValueInListException(
- $this->createMock(ValueListInterface::class)
+ $this->createMock(ValueListInterface::class),
);
self::assertSame('More than 1 value in list', $exception->getMessage());
@@ -30,18 +29,10 @@ public function testGetValues_ConstructedWithValues_ReturnsSameInstance(): void
self::assertSame($values, $exception->getValues());
}
- public function testGetCode_Always_ReturnsZero(): void
- {
- $exception = new MoreThanOneValueInListException(
- $this->createMock(ValueListInterface::class)
- );
- self::assertSame(0, $exception->getCode());
- }
-
public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void
{
$exception = new MoreThanOneValueInListException(
- $this->createMock(ValueListInterface::class)
+ $this->createMock(ValueListInterface::class),
);
self::assertNull($exception->getPrevious());
}
@@ -51,7 +42,7 @@ public function testGetPrevious_ConstructedWithPrevious_ReturnsSameInstance(): v
$previous = new Exception();
$exception = new MoreThanOneValueInListException(
$this->createMock(ValueListInterface::class),
- $previous
+ $previous,
);
self::assertSame($previous, $exception->getPrevious());
}
diff --git a/tests/Processor/Result/Exception/PathNotFoundInValueExceptionTest.php b/tests/Processor/Result/Exception/PathNotFoundInValueExceptionTest.php
index a09a24f..eb4600d 100644
--- a/tests/Processor/Result/Exception/PathNotFoundInValueExceptionTest.php
+++ b/tests/Processor/Result/Exception/PathNotFoundInValueExceptionTest.php
@@ -5,19 +5,18 @@
namespace Remorhaz\JSON\Path\Test\Processor\Result\Exception;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Value\ValueInterface;
use Remorhaz\JSON\Path\Processor\Result\Exception\PathNotFoundInValueException;
-/**
- * @covers \Remorhaz\JSON\Path\Processor\Result\Exception\PathNotFoundInValueException
- */
+#[CoversClass(PathNotFoundInValueException::class)]
class PathNotFoundInValueExceptionTest extends TestCase
{
public function testGetMessage_Constructed_ReturnsMatchingValue(): void
{
$exception = new PathNotFoundInValueException(
- $this->createMock(ValueInterface::class)
+ $this->createMock(ValueInterface::class),
);
self::assertSame('Path not found in value', $exception->getMessage());
}
@@ -29,18 +28,10 @@ public function testGetValue_ConstructedWithValue_ReturnsSameInstance(): void
self::assertSame($value, $exception->getValue());
}
- public function testGetCode_Always_ReturnsZero(): void
- {
- $exception = new PathNotFoundInValueException(
- $this->createMock(ValueInterface::class)
- );
- self::assertSame(0, $exception->getCode());
- }
-
public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void
{
$exception = new PathNotFoundInValueException(
- $this->createMock(ValueInterface::class)
+ $this->createMock(ValueInterface::class),
);
self::assertNull($exception->getPrevious());
}
@@ -50,7 +41,7 @@ public function testGetPrevious_ConstructedWithPrevious_ReturnsSameInstance(): v
$previous = new Exception();
$exception = new PathNotFoundInValueException(
$this->createMock(ValueInterface::class),
- $previous
+ $previous,
);
self::assertSame($previous, $exception->getPrevious());
}
diff --git a/tests/Processor/Result/Exception/SelectedValueNotFoundExceptionTest.php b/tests/Processor/Result/Exception/SelectedValueNotFoundExceptionTest.php
index 157a111..94f02d6 100644
--- a/tests/Processor/Result/Exception/SelectedValueNotFoundExceptionTest.php
+++ b/tests/Processor/Result/Exception/SelectedValueNotFoundExceptionTest.php
@@ -5,12 +5,11 @@
namespace Remorhaz\JSON\Path\Test\Processor\Result\Exception;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Processor\Result\Exception\SelectedValueNotFoundException;
-/**
- * @covers \Remorhaz\JSON\Path\Processor\Result\Exception\SelectedValueNotFoundException
- */
+#[CoversClass(SelectedValueNotFoundException::class)]
class SelectedValueNotFoundExceptionTest extends TestCase
{
public function testGetMessage_Constructed_ReturnsMatchingValue(): void
@@ -19,12 +18,6 @@ public function testGetMessage_Constructed_ReturnsMatchingValue(): void
self::assertSame('Selected value not found', $exception->getMessage());
}
- public function testGetCode_Always_ReturnsZero(): void
- {
- $exception = new SelectedValueNotFoundException();
- self::assertSame(0, $exception->getCode());
- }
-
public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void
{
$exception = new SelectedValueNotFoundException();
diff --git a/tests/Processor/Result/ExistingSelectOnePathResultTest.php b/tests/Processor/Result/ExistingSelectOnePathResultTest.php
index 5c30888..dda0290 100644
--- a/tests/Processor/Result/ExistingSelectOnePathResultTest.php
+++ b/tests/Processor/Result/ExistingSelectOnePathResultTest.php
@@ -4,21 +4,20 @@
namespace Remorhaz\JSON\Path\Test\Processor\Result;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Path\PathInterface;
use Remorhaz\JSON\Path\Processor\PathEncoderInterface;
use Remorhaz\JSON\Path\Processor\Result\ExistingSelectOnePathResult;
-/**
- * @covers \Remorhaz\JSON\Path\Processor\Result\ExistingSelectOnePathResult
- */
+#[CoversClass(ExistingSelectOnePathResult::class)]
class ExistingSelectOnePathResultTest extends TestCase
{
public function testExists_Always_ReturnsTrue(): void
{
$result = new ExistingSelectOnePathResult(
$this->createMock(PathEncoderInterface::class),
- $this->createMock(PathInterface::class)
+ $this->createMock(PathInterface::class),
);
self::assertTrue($result->exists());
}
@@ -28,7 +27,7 @@ public function testGet_ConstructedWithPath_ReturnsSameInstance(): void
$path = $this->createMock(PathInterface::class);
$result = new ExistingSelectOnePathResult(
$this->createMock(PathEncoderInterface::class),
- $path
+ $path,
);
self::assertSame($path, $result->get());
}
@@ -51,7 +50,7 @@ public function testEncode_EncoderResultsValue_ReturnsSameValue(): void
$encoder = $this->createMock(PathEncoderInterface::class);
$result = new ExistingSelectOnePathResult(
$encoder,
- $this->createMock(PathInterface::class)
+ $this->createMock(PathInterface::class),
);
$encoder
diff --git a/tests/Processor/Result/ExistingValueResultTest.php b/tests/Processor/Result/ExistingValueResultTest.php
index 175de8f..c94e46a 100644
--- a/tests/Processor/Result/ExistingValueResultTest.php
+++ b/tests/Processor/Result/ExistingValueResultTest.php
@@ -4,15 +4,14 @@
namespace Remorhaz\JSON\Path\Test\Processor\Result;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Export\ValueDecoderInterface;
use Remorhaz\JSON\Data\Export\ValueEncoderInterface;
use Remorhaz\JSON\Data\Value\ValueInterface;
use Remorhaz\JSON\Path\Processor\Result\ExistingValueResult;
-/**
- * @covers \Remorhaz\JSON\Path\Processor\Result\ExistingValueResult
- */
+#[CoversClass(ExistingValueResult::class)]
class ExistingValueResultTest extends TestCase
{
public function testExists_Always_ReturnsTrue(): void
@@ -20,7 +19,7 @@ public function testExists_Always_ReturnsTrue(): void
$result = new ExistingValueResult(
$this->createMock(ValueEncoderInterface::class),
$this->createMock(ValueDecoderInterface::class),
- $this->createMock(ValueInterface::class)
+ $this->createMock(ValueInterface::class),
);
self::assertTrue($result->exists());
}
@@ -31,7 +30,7 @@ public function testGet_ConstructedWithValue_ReturnsSameInstance(): void
$result = new ExistingValueResult(
$this->createMock(ValueEncoderInterface::class),
$this->createMock(ValueDecoderInterface::class),
- $value
+ $value,
);
self::assertSame($value, $result->get());
}
@@ -43,7 +42,7 @@ public function testEncode_Constructed_PassesValueToEncoder(): void
$result = new ExistingValueResult(
$encoder,
$this->createMock(ValueDecoderInterface::class),
- $value
+ $value,
);
$encoder
->expects(self::once())
@@ -59,7 +58,7 @@ public function testEncode_EncoderReturnsValue_ReturnsSameValue(): void
$result = new ExistingValueResult(
$encoder,
$this->createMock(ValueDecoderInterface::class),
- $value
+ $value,
);
$encoder
->method('exportValue')
@@ -74,7 +73,7 @@ public function testDecode_Constructed_PassesValueToDecoder(): void
$result = new ExistingValueResult(
$this->createMock(ValueEncoderInterface::class),
$decoder,
- $value
+ $value,
);
$decoder
->expects(self::once())
@@ -90,7 +89,7 @@ public function testDecode_DecoderReturnsValue_ReturnsSameValue(): void
$result = new ExistingValueResult(
$this->createMock(ValueEncoderInterface::class),
$decoder,
- $value
+ $value,
);
$decoder
->method('exportValue')
diff --git a/tests/Processor/Result/NonExistingSelectOnePathResultTest.php b/tests/Processor/Result/NonExistingSelectOnePathResultTest.php
index f329ef5..b4fbb43 100644
--- a/tests/Processor/Result/NonExistingSelectOnePathResultTest.php
+++ b/tests/Processor/Result/NonExistingSelectOnePathResultTest.php
@@ -4,13 +4,12 @@
namespace Remorhaz\JSON\Path\Test\Processor\Result;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Processor\Result\Exception\SelectedValueNotFoundException;
use Remorhaz\JSON\Path\Processor\Result\NonExistingSelectOnePathResult;
-/**
- * @covers \Remorhaz\JSON\Path\Processor\Result\NonExistingSelectOnePathResult
- */
+#[CoversClass(NonExistingSelectOnePathResult::class)]
class NonExistingSelectOnePathResultTest extends TestCase
{
public function testExists_Always_ReturnsFalse(): void
diff --git a/tests/Processor/Result/NonExistingValueResultTest.php b/tests/Processor/Result/NonExistingValueResultTest.php
index 07dffb9..13f1d1d 100644
--- a/tests/Processor/Result/NonExistingValueResultTest.php
+++ b/tests/Processor/Result/NonExistingValueResultTest.php
@@ -4,13 +4,12 @@
namespace Remorhaz\JSON\Path\Test\Processor\Result;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Processor\Result\Exception\SelectedValueNotFoundException;
use Remorhaz\JSON\Path\Processor\Result\NonExistingValueResult;
-/**
- * @covers \Remorhaz\JSON\Path\Processor\Result\NonExistingValueResult
- */
+#[CoversClass(NonExistingValueResult::class)]
class NonExistingValueResultTest extends TestCase
{
public function testExists_Always_ReturnsFalse(): void
diff --git a/tests/Processor/Result/ResultFactoryTest.php b/tests/Processor/Result/ResultFactoryTest.php
index 23bd0cf..1ef6277 100644
--- a/tests/Processor/Result/ResultFactoryTest.php
+++ b/tests/Processor/Result/ResultFactoryTest.php
@@ -4,6 +4,7 @@
namespace Remorhaz\JSON\Path\Test\Processor\Result;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Export\ValueDecoderInterface;
use Remorhaz\JSON\Data\Export\ValueEncoderInterface;
@@ -16,9 +17,7 @@
use Remorhaz\JSON\Path\Processor\Result\ResultFactory;
use Remorhaz\JSON\Path\Value\ValueListInterface;
-/**
- * @covers \Remorhaz\JSON\Path\Processor\Result\ResultFactory
- */
+#[CoversClass(ResultFactory::class)]
class ResultFactoryTest extends TestCase
{
public function testCreateSelectResult_NoValuesInList_ResultEncodesToEmptyArray(): void
@@ -26,10 +25,10 @@ public function testCreateSelectResult_NoValuesInList_ResultEncodesToEmptyArray(
$factory = new ResultFactory(
$this->createMock(ValueEncoderInterface::class),
$this->createMock(ValueDecoderInterface::class),
- $this->createMock(PathEncoderInterface::class)
+ $this->createMock(PathEncoderInterface::class),
);
$result = $factory->createSelectResult(
- $this->createMock(ValueListInterface::class)
+ $this->createMock(ValueListInterface::class),
);
self::assertSame([], $result->encode());
}
@@ -40,7 +39,7 @@ public function testCreateSelectResult_GivenValueInList_ResultPassesSameValueToE
$factory = new ResultFactory(
$encoder,
$this->createMock(ValueDecoderInterface::class),
- $this->createMock(PathEncoderInterface::class)
+ $this->createMock(PathEncoderInterface::class),
);
$values = $this->createMock(ValueListInterface::class);
$value = $this->createMock(ValueInterface::class);
@@ -62,7 +61,7 @@ public function testCreateSelectResult_GivenValue_ResultPassesSameValueToDecoder
$factory = new ResultFactory(
$this->createMock(ValueEncoderInterface::class),
$decoder,
- $this->createMock(PathEncoderInterface::class)
+ $this->createMock(PathEncoderInterface::class),
);
$values = $this->createMock(ValueListInterface::class);
$value = $this->createMock(ValueInterface::class);
@@ -83,7 +82,7 @@ public function testCreateSelectOneResult_NoValuesInList_ResultNotExists(): void
$factory = new ResultFactory(
$this->createMock(ValueEncoderInterface::class),
$this->createMock(ValueDecoderInterface::class),
- $this->createMock(PathEncoderInterface::class)
+ $this->createMock(PathEncoderInterface::class),
);
$values = $this->createMock(ValueListInterface::class);
$values
@@ -98,7 +97,7 @@ public function testCreateSelectOneResult_MoreThanOneValueInList_ThrowsException
$factory = new ResultFactory(
$this->createMock(ValueEncoderInterface::class),
$this->createMock(ValueDecoderInterface::class),
- $this->createMock(PathEncoderInterface::class)
+ $this->createMock(PathEncoderInterface::class),
);
$values = $this->createMock(ValueListInterface::class);
$value = $this->createMock(ValueInterface::class);
@@ -115,7 +114,7 @@ public function testCreateSelectOneResult_ExactlyOneValueInList_ResultExists():
$factory = new ResultFactory(
$encoder,
$this->createMock(ValueDecoderInterface::class),
- $this->createMock(PathEncoderInterface::class)
+ $this->createMock(PathEncoderInterface::class),
);
$values = $this->createMock(ValueListInterface::class);
$value = $this->createMock(ValueInterface::class);
@@ -136,7 +135,7 @@ public function testCreateSelectOneResult_ExactlyOneValueInList_ResultPassesSame
$factory = new ResultFactory(
$encoder,
$this->createMock(ValueDecoderInterface::class),
- $this->createMock(PathEncoderInterface::class)
+ $this->createMock(PathEncoderInterface::class),
);
$values = $this->createMock(ValueListInterface::class);
$value = $this->createMock(ValueInterface::class);
@@ -161,7 +160,7 @@ public function testCreateSelectOneResult_ExactlyOneValueInList_ResultPassesSame
$factory = new ResultFactory(
$this->createMock(ValueEncoderInterface::class),
$decoder,
- $this->createMock(PathEncoderInterface::class)
+ $this->createMock(PathEncoderInterface::class),
);
$values = $this->createMock(ValueListInterface::class);
$value = $this->createMock(ValueInterface::class);
@@ -185,7 +184,7 @@ public function testCreateSelectPathResult_ValueWithoutPathInList_ThrowsExceptio
$factory = new ResultFactory(
$this->createMock(ValueEncoderInterface::class),
$this->createMock(ValueDecoderInterface::class),
- $this->createMock(PathEncoderInterface::class)
+ $this->createMock(PathEncoderInterface::class),
);
$values = $this->createMock(ValueListInterface::class);
$values
@@ -201,7 +200,7 @@ public function testCreateSelectPathResult_ValueWithPathInList_ResultPassesSameI
$factory = new ResultFactory(
$this->createMock(ValueEncoderInterface::class),
$this->createMock(ValueDecoderInterface::class),
- $pathEncoder
+ $pathEncoder,
);
$values = $this->createMock(ValueListInterface::class);
$value = $this->createMock(NodeValueInterface::class);
@@ -225,7 +224,7 @@ public function testCreateSelectOnePathResult_NoValuesInList_ResultNotExists():
$factory = new ResultFactory(
$this->createMock(ValueEncoderInterface::class),
$this->createMock(ValueDecoderInterface::class),
- $this->createMock(PathEncoderInterface::class)
+ $this->createMock(PathEncoderInterface::class),
);
$values = $this->createMock(ValueListInterface::class);
$values
@@ -240,7 +239,7 @@ public function testCreateSelectOnePathResult_MoreThanOneValueInListThrowsExcept
$factory = new ResultFactory(
$this->createMock(ValueEncoderInterface::class),
$this->createMock(ValueDecoderInterface::class),
- $this->createMock(PathEncoderInterface::class)
+ $this->createMock(PathEncoderInterface::class),
);
$values = $this->createMock(ValueListInterface::class);
$value = $this->createMock(NodeValueInterface::class);
@@ -256,7 +255,7 @@ public function testCreateSelectOnePathResult_ValueWithoutPathInListThrowsExcept
$factory = new ResultFactory(
$this->createMock(ValueEncoderInterface::class),
$this->createMock(ValueDecoderInterface::class),
- $this->createMock(PathEncoderInterface::class)
+ $this->createMock(PathEncoderInterface::class),
);
$values = $this->createMock(ValueListInterface::class);
$value = $this->createMock(ValueInterface::class);
@@ -272,7 +271,7 @@ public function testCreateSelectOnePathResult_ExactlyOneValueWithPathInList_Resu
$factory = new ResultFactory(
$this->createMock(ValueEncoderInterface::class),
$this->createMock(ValueDecoderInterface::class),
- $this->createMock(PathEncoderInterface::class)
+ $this->createMock(PathEncoderInterface::class),
);
$values = $this->createMock(ValueListInterface::class);
$value = $this->createMock(NodeValueInterface::class);
@@ -297,7 +296,7 @@ public function testCreateSelectOnePathResult_ExactlyOneValueWithPathInList_Resu
$factory = new ResultFactory(
$this->createMock(ValueEncoderInterface::class),
$this->createMock(ValueDecoderInterface::class),
- $pathEncoder
+ $pathEncoder,
);
$values = $this->createMock(ValueListInterface::class);
$value = $this->createMock(NodeValueInterface::class);
@@ -326,7 +325,7 @@ public function testCreateValueResult_NoValue_ResultNotExists(): void
$factory = new ResultFactory(
$this->createMock(ValueEncoderInterface::class),
$this->createMock(ValueDecoderInterface::class),
- $this->createMock(PathEncoderInterface::class)
+ $this->createMock(PathEncoderInterface::class),
);
$result = $factory->createValueResult(null);
self::assertFalse($result->exists());
@@ -337,10 +336,10 @@ public function testCreateValueResult_GivenValue_ResultExists(): void
$factory = new ResultFactory(
$this->createMock(ValueEncoderInterface::class),
$this->createMock(ValueDecoderInterface::class),
- $this->createMock(PathEncoderInterface::class)
+ $this->createMock(PathEncoderInterface::class),
);
$result = $factory->createValueResult(
- $this->createMock(ValueInterface::class)
+ $this->createMock(ValueInterface::class),
);
self::assertTrue($result->exists());
}
@@ -351,7 +350,7 @@ public function testCreateValueResult_GivenValue_ResultPassesSameInstanceToEncod
$factory = new ResultFactory(
$encoder,
$this->createMock(ValueDecoderInterface::class),
- $this->createMock(PathEncoderInterface::class)
+ $this->createMock(PathEncoderInterface::class),
);
$value = $this->createMock(ValueInterface::class);
$result = $factory->createValueResult($value);
@@ -368,7 +367,7 @@ public function testCreateValueResult_GivenValue_ResultPassesSameInstanceToDecod
$factory = new ResultFactory(
$this->createMock(ValueEncoderInterface::class),
$decoder,
- $this->createMock(PathEncoderInterface::class)
+ $this->createMock(PathEncoderInterface::class),
);
$value = $this->createMock(ValueInterface::class);
$result = $factory->createValueResult($value);
diff --git a/tests/Processor/Result/SelectPathsResultTest.php b/tests/Processor/Result/SelectPathsResultTest.php
index 13fd127..d15c88a 100644
--- a/tests/Processor/Result/SelectPathsResultTest.php
+++ b/tests/Processor/Result/SelectPathsResultTest.php
@@ -4,20 +4,19 @@
namespace Remorhaz\JSON\Path\Test\Processor\Result;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Path\PathInterface;
use Remorhaz\JSON\Path\Processor\PathEncoderInterface;
use Remorhaz\JSON\Path\Processor\Result\SelectPathsResult;
-/**
- * @covers \Remorhaz\JSON\Path\Processor\Result\SelectPathsResult
- */
+#[CoversClass(SelectPathsResult::class)]
class SelectPathsResultTest extends TestCase
{
public function testGet_ConstructedWithoutPaths_ReturnsEmptyArray(): void
{
$result = new SelectPathsResult(
- $this->createMock(PathEncoderInterface::class)
+ $this->createMock(PathEncoderInterface::class),
);
self::assertSame([], $result->get());
}
@@ -27,7 +26,7 @@ public function testGet_ConstructedWithPath_ReturnsSameInstanceInArray(): void
$path = $this->createMock(PathInterface::class);
$result = new SelectPathsResult(
$this->createMock(PathEncoderInterface::class),
- $path
+ $path,
);
self::assertSame([$path], $result->get());
}
@@ -35,7 +34,7 @@ public function testGet_ConstructedWithPath_ReturnsSameInstanceInArray(): void
public function testEncode_ConstructedWithoutPath_ReturnsEmptyArray(): void
{
$result = new SelectPathsResult(
- $this->createMock(PathEncoderInterface::class)
+ $this->createMock(PathEncoderInterface::class),
);
self::assertSame([], $result->encode());
}
diff --git a/tests/Processor/Result/SelectResultTest.php b/tests/Processor/Result/SelectResultTest.php
index 85a9925..78ece52 100644
--- a/tests/Processor/Result/SelectResultTest.php
+++ b/tests/Processor/Result/SelectResultTest.php
@@ -4,22 +4,21 @@
namespace Remorhaz\JSON\Path\Test\Processor\Result;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Export\ValueDecoderInterface;
use Remorhaz\JSON\Data\Export\ValueEncoderInterface;
use Remorhaz\JSON\Data\Value\ValueInterface;
use Remorhaz\JSON\Path\Processor\Result\SelectResult;
-/**
- * @covers \Remorhaz\JSON\Path\Processor\Result\SelectResult
- */
+#[CoversClass(SelectResult::class)]
class SelectResultTest extends TestCase
{
public function testGet_ConstructedWithoutValues_ReturnsEmptyArray(): void
{
$result = new SelectResult(
$this->createMock(ValueEncoderInterface::class),
- $this->createMock(ValueDecoderInterface::class)
+ $this->createMock(ValueDecoderInterface::class),
);
self::assertSame([], $result->get());
}
@@ -30,7 +29,7 @@ public function testGet_ConstructedWithValue_ReturnsSameInstanceInArray(): void
$result = new SelectResult(
$this->createMock(ValueEncoderInterface::class),
$this->createMock(ValueDecoderInterface::class),
- $value
+ $value,
);
self::assertSame([$value], $result->get());
}
@@ -39,7 +38,7 @@ public function testEncode_ConstructedWithoutValues_ReturnsEmptyArray(): void
{
$result = new SelectResult(
$this->createMock(ValueEncoderInterface::class),
- $this->createMock(ValueDecoderInterface::class)
+ $this->createMock(ValueDecoderInterface::class),
);
self::assertSame([], $result->encode());
}
@@ -51,7 +50,7 @@ public function testEncode_ConstructedWithValue_PassesSameInstanceToEncoder(): v
$result = new SelectResult(
$encoder,
$this->createMock(ValueDecoderInterface::class),
- $value
+ $value,
);
$encoder
@@ -68,7 +67,7 @@ public function testDecode_ConstructedWithValue_PassesSameInstanceToDecoder(): v
$result = new SelectResult(
$this->createMock(ValueEncoderInterface::class),
$decoder,
- $value
+ $value,
);
$decoder
@@ -84,7 +83,7 @@ public function testEncode_EncoderReturnsValue_ReturnsSameValueInArray(): void
$result = new SelectResult(
$encoder,
$this->createMock(ValueDecoderInterface::class),
- $this->createMock(ValueInterface::class)
+ $this->createMock(ValueInterface::class),
);
$encoder
@@ -99,7 +98,7 @@ public function testDecode_DecoderReturnsValue_ReturnsSameValueInArray(): void
$result = new SelectResult(
$this->createMock(ValueEncoderInterface::class),
$decoder,
- $this->createMock(ValueInterface::class)
+ $this->createMock(ValueInterface::class),
);
$decoder
diff --git a/tests/Query/AstTranslatorTest.php b/tests/Query/AstTranslatorTest.php
index 3567c08..58f68a8 100644
--- a/tests/Query/AstTranslatorTest.php
+++ b/tests/Query/AstTranslatorTest.php
@@ -5,6 +5,7 @@
namespace Remorhaz\JSON\Path\Test\Query;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Value\NodeValueInterface;
use Remorhaz\JSON\Path\Query\Exception\ExceptionInterface;
@@ -23,9 +24,7 @@
use Remorhaz\UniLex\AST\Tree;
use Remorhaz\UniLex\Exception as UniLexException;
-/**
- * @covers \Remorhaz\JSON\Path\Query\AstTranslator
- */
+#[CoversClass(AstTranslator::class)]
class AstTranslatorTest extends TestCase
{
/**
@@ -131,7 +130,7 @@ public function testBuildQuery_CallbackBuilderProvidesCallback_OnInvocationResul
$evaluator,
$literalFactory,
$matcherFactory,
- &$isCallbackCalledWithMatchingArgs
+ &$isCallbackCalledWithMatchingArgs,
): ValueListInterface {
$args = func_get_args();
/** @var NodeValueListInterface $input */
diff --git a/tests/Query/CallbackBuilderTest.php b/tests/Query/CallbackBuilderTest.php
index 9e6f61e..c6faea1 100644
--- a/tests/Query/CallbackBuilderTest.php
+++ b/tests/Query/CallbackBuilderTest.php
@@ -4,6 +4,8 @@
namespace Remorhaz\JSON\Path\Test\Query;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Query\Exception\CapabilitiesNotFoundException;
use Remorhaz\JSON\Path\Query\Exception\QueryCallbackCodeNotFoundException;
@@ -13,9 +15,7 @@
use Remorhaz\UniLex\Exception as UniLexException;
use Remorhaz\UniLex\Stack\PushInterface;
-/**
- * @covers \Remorhaz\JSON\Path\Query\CallbackBuilder
- */
+#[CoversClass(CallbackBuilder::class)]
class CallbackBuilderTest extends TestCase
{
public function testGetCallbackCode_CallbackIsNotSet_ThrowsException(): void
@@ -35,14 +35,12 @@ public function testGetCapabilities_QueryCapabilitiesNotSet_ThrowsException(): v
}
/**
- * @param bool $isDefinite
- * @param bool $expectedValue
* @throws UniLexException
- * @dataProvider providerIsDefinite
*/
+ #[DataProvider('providerIsDefinite')]
public function testGetCapabilities_SetOutputProductionFinishedWithGivenCapabilities_ReturnsMatchingCapabilities(
bool $isDefinite,
- bool $expectedValue
+ bool $expectedValue,
): void {
$callbackBuilder = new CallbackBuilder();
$callbackBuilder->onStart($this->createMock(Node::class));
@@ -61,7 +59,10 @@ public function testGetCapabilities_SetOutputProductionFinishedWithGivenCapabili
self::assertSame($expectedValue, $callbackBuilder->getCapabilities()->isDefinite());
}
- public function providerIsDefinite(): array
+ /**
+ * @return iterable
+ */
+ public static function providerIsDefinite(): iterable
{
return [
'TRUE' => [true, true],
diff --git a/tests/Query/CapabilitiesTest.php b/tests/Query/CapabilitiesTest.php
index 97b9419..346704f 100644
--- a/tests/Query/CapabilitiesTest.php
+++ b/tests/Query/CapabilitiesTest.php
@@ -4,28 +4,27 @@
namespace Remorhaz\JSON\Path\Test\Query;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Query\Capabilities;
-/**
- * @covers \Remorhaz\JSON\Path\Query\Capabilities
- */
+#[CoversClass(Capabilities::class)]
class CapabilitiesTest extends TestCase
{
- /**
- * @param bool $isDefinite
- * @param bool $expectedValue
- * @dataProvider providerIsDefinite
- */
+ #[DataProvider('providerIsDefinite')]
public function testIsDefinite_ConstructedWithIsDefiniteFlag_ReturnsSameValue(
bool $isDefinite,
- bool $expectedValue
+ bool $expectedValue,
): void {
$properties = new Capabilities($isDefinite, false);
self::assertSame($expectedValue, $properties->isDefinite());
}
- public function providerIsDefinite(): array
+ /**
+ * @return iterable
+ */
+ public static function providerIsDefinite(): iterable
{
return [
'TRUE' => [true, true],
@@ -33,20 +32,19 @@ public function providerIsDefinite(): array
];
}
- /**
- * @param bool $isPath
- * @param bool $expectedValue
- * @dataProvider providerIsAddressable
- */
+ #[DataProvider('providerIsAddressable')]
public function testIsAddressable_ConstructedWithIsPathFlag_ReturnsSameValue(
bool $isPath,
- bool $expectedValue
+ bool $expectedValue,
): void {
$properties = new Capabilities(false, $isPath);
self::assertSame($expectedValue, $properties->isAddressable());
}
- public function providerIsAddressable(): array
+ /**
+ * @return iterable
+ */
+ public static function providerIsAddressable(): iterable
{
return [
'TRUE' => [true, true],
diff --git a/tests/Query/Exception/PropertiesNotFoundExceptionTest.php b/tests/Query/Exception/PropertiesNotFoundExceptionTest.php
index 19606ce..94eff2f 100644
--- a/tests/Query/Exception/PropertiesNotFoundExceptionTest.php
+++ b/tests/Query/Exception/PropertiesNotFoundExceptionTest.php
@@ -5,12 +5,11 @@
namespace Remorhaz\JSON\Path\Test\Query\Exception;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Query\Exception\CapabilitiesNotFoundException;
-/**
- * @covers \Remorhaz\JSON\Path\Query\Exception\CapabilitiesNotFoundException
- */
+#[CoversClass(CapabilitiesNotFoundException::class)]
class PropertiesNotFoundExceptionTest extends TestCase
{
public function testGetMessage_Constructed_ReturnsMatchingValue(): void
@@ -19,12 +18,6 @@ public function testGetMessage_Constructed_ReturnsMatchingValue(): void
self::assertSame('Properties are accessed before being set', $exception->getMessage());
}
- public function testGetCode_Always_ReturnsZero(): void
- {
- $exception = new CapabilitiesNotFoundException();
- self::assertSame(0, $exception->getCode());
- }
-
public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void
{
$exception = new CapabilitiesNotFoundException();
diff --git a/tests/Query/Exception/QueryAstNotTranslatedExceptionTest.php b/tests/Query/Exception/QueryAstNotTranslatedExceptionTest.php
index 35209e3..cda3cbb 100644
--- a/tests/Query/Exception/QueryAstNotTranslatedExceptionTest.php
+++ b/tests/Query/Exception/QueryAstNotTranslatedExceptionTest.php
@@ -5,13 +5,12 @@
namespace Remorhaz\JSON\Path\Test\Query\Exception;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Query\Exception\QueryAstNotTranslatedException;
use Remorhaz\UniLex\AST\Tree;
-/**
- * @covers \Remorhaz\JSON\Path\Query\Exception\QueryAstNotTranslatedException
- */
+#[CoversClass(QueryAstNotTranslatedException::class)]
class QueryAstNotTranslatedExceptionTest extends TestCase
{
public function testGetMessage_Constructed_ReturnsMatchingValue(): void
@@ -27,12 +26,6 @@ public function testGetQueryAst_ConstructedWithGivenQueryAst_ReturnsSameInstance
self::assertSame($tree, $exception->getQueryAst());
}
- public function testGetCode_Always_ReturnsZero(): void
- {
- $exception = new QueryAstNotTranslatedException(new Tree());
- self::assertSame(0, $exception->getCode());
- }
-
public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void
{
$exception = new QueryAstNotTranslatedException(new Tree());
diff --git a/tests/Query/Exception/QueryCallbackCodeNotFoundExceptionTest.php b/tests/Query/Exception/QueryCallbackCodeNotFoundExceptionTest.php
index af06606..84adab5 100644
--- a/tests/Query/Exception/QueryCallbackCodeNotFoundExceptionTest.php
+++ b/tests/Query/Exception/QueryCallbackCodeNotFoundExceptionTest.php
@@ -5,12 +5,11 @@
namespace Remorhaz\JSON\Path\Test\Query\Exception;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Query\Exception\QueryCallbackCodeNotFoundException;
-/**
- * @covers \Remorhaz\JSON\Path\Query\Exception\QueryCallbackCodeNotFoundException
- */
+#[CoversClass(QueryCallbackCodeNotFoundException::class)]
class QueryCallbackCodeNotFoundExceptionTest extends TestCase
{
public function testGetMessage_Constructed_ReturnsMatchingValue(): void
@@ -19,12 +18,6 @@ public function testGetMessage_Constructed_ReturnsMatchingValue(): void
self::assertSame('Query callback code is accessed before being generated', $exception->getMessage());
}
- public function testGetCode_Always_ReturnsZero(): void
- {
- $exception = new QueryCallbackCodeNotFoundException();
- self::assertSame(0, $exception->getCode());
- }
-
public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void
{
$exception = new QueryCallbackCodeNotFoundException();
diff --git a/tests/Query/Exception/QueryExecutionFailedExceptionTest.php b/tests/Query/Exception/QueryExecutionFailedExceptionTest.php
index 95df2a7..aab84c2 100644
--- a/tests/Query/Exception/QueryExecutionFailedExceptionTest.php
+++ b/tests/Query/Exception/QueryExecutionFailedExceptionTest.php
@@ -5,12 +5,11 @@
namespace Remorhaz\JSON\Path\Test\Query\Exception;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Query\Exception\QueryExecutionFailedException;
-/**
- * @covers \Remorhaz\JSON\Path\Query\Exception\QueryExecutionFailedException
- */
+#[CoversClass(QueryExecutionFailedException::class)]
class QueryExecutionFailedExceptionTest extends TestCase
{
public function testGetSource_ConstructedWithGivenSource_ReturnsSameValue(): void
@@ -31,12 +30,6 @@ public function testGetMessage_Constructed_ReturnsMatchingValue(): void
self::assertSame("Failed to execute JSONPath query: a\n\nb", $exception->getMessage());
}
- public function testGetCode_Always_ReturnsZero(): void
- {
- $exception = new QueryExecutionFailedException('a', 'b');
- self::assertSame(0, $exception->getCode());
- }
-
public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void
{
$exception = new QueryExecutionFailedException('a', 'b');
diff --git a/tests/Query/Exception/ReferenceAlreadyExistsExceptionTest.php b/tests/Query/Exception/ReferenceAlreadyExistsExceptionTest.php
index b6099d0..59670bd 100644
--- a/tests/Query/Exception/ReferenceAlreadyExistsExceptionTest.php
+++ b/tests/Query/Exception/ReferenceAlreadyExistsExceptionTest.php
@@ -5,12 +5,11 @@
namespace Remorhaz\JSON\Path\Test\Query\Exception;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Query\Exception\ReferenceAlreadyExistsException;
-/**
- * @covers \Remorhaz\JSON\Path\Query\Exception\ReferenceAlreadyExistsException
- */
+#[CoversClass(ReferenceAlreadyExistsException::class)]
class ReferenceAlreadyExistsExceptionTest extends TestCase
{
public function testGetMessage_Constructed_ReturnsMatchingValue(): void
diff --git a/tests/Query/Exception/ReferenceNotFoundExceptionTest.php b/tests/Query/Exception/ReferenceNotFoundExceptionTest.php
index 492a18c..7a4327f 100644
--- a/tests/Query/Exception/ReferenceNotFoundExceptionTest.php
+++ b/tests/Query/Exception/ReferenceNotFoundExceptionTest.php
@@ -5,12 +5,11 @@
namespace Remorhaz\JSON\Path\Test\Query\Exception;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Query\Exception\ReferenceNotFoundException;
-/**
- * @covers \Remorhaz\JSON\Path\Query\Exception\ReferenceNotFoundException
- */
+#[CoversClass(ReferenceNotFoundException::class)]
class ReferenceNotFoundExceptionTest extends TestCase
{
public function testGetMessage_Constructed_ReturnsMatchingValue(): void
diff --git a/tests/Query/LazyQueryTest.php b/tests/Query/LazyQueryTest.php
index c372edb..d444506 100644
--- a/tests/Query/LazyQueryTest.php
+++ b/tests/Query/LazyQueryTest.php
@@ -4,6 +4,7 @@
namespace Remorhaz\JSON\Path\Test\Query;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Value\NodeValueInterface;
use Remorhaz\JSON\Path\Parser\ParserInterface;
@@ -16,9 +17,7 @@
use Remorhaz\JSON\Path\Runtime\RuntimeInterface;
use Remorhaz\UniLex\AST\Tree;
-/**
- * @covers \Remorhaz\JSON\Path\Query\LazyQuery
- */
+#[CoversClass(LazyQuery::class)]
class LazyQueryTest extends TestCase
{
/**
@@ -160,7 +159,7 @@ public function testGetCapabilities_AstTranslatorReturnsQueryWithGivenProperties
'a',
$this->createStub(ParserInterface::class),
$astTranslator,
- $this->createStub(CallbackBuilderInterface::class)
+ $this->createStub(CallbackBuilderInterface::class),
);
self::assertSame($properties, $lazyQuery->getCapabilities());
diff --git a/tests/Query/QueryFactoryTest.php b/tests/Query/QueryFactoryTest.php
index bb5d911..f8d9c08 100644
--- a/tests/Query/QueryFactoryTest.php
+++ b/tests/Query/QueryFactoryTest.php
@@ -4,6 +4,7 @@
namespace Remorhaz\JSON\Path\Test\Query;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Value\NodeValueInterface;
use Remorhaz\JSON\Path\Parser\ParserInterface;
@@ -14,9 +15,7 @@
use Remorhaz\JSON\Path\Runtime\RuntimeInterface;
use Remorhaz\UniLex\AST\Tree;
-/**
- * @covers \Remorhaz\JSON\Path\Query\QueryFactory
- */
+#[CoversClass(QueryFactory::class)]
class QueryFactoryTest extends TestCase
{
public function testCreate_Always_ReturnsQueryFactoryInstance(): void
@@ -28,7 +27,7 @@ public function testCreateQuery_Constructed_ReturnsLazyQueryInstance(): void
{
$factory = new QueryFactory(
$this->createMock(ParserInterface::class),
- $this->createMock(AstTranslatorInterface::class)
+ $this->createMock(AstTranslatorInterface::class),
);
$actualValue = $factory->createQuery('a');
@@ -44,7 +43,7 @@ public function testCreateQuery_AstTranslatorReturnsQuery_ResultInvocationInvoke
->willReturn($query);
$factory = new QueryFactory(
$this->createMock(ParserInterface::class),
- $astTranslator
+ $astTranslator,
);
$lazyQuery = $factory->createQuery('a');
@@ -63,7 +62,7 @@ public function testCreateQuery_ConstructedWithPath_OnResultInvocationParserAcce
$factory = new QueryFactory(
$parser,
- $this->createMock(AstTranslatorInterface::class)
+ $this->createMock(AstTranslatorInterface::class),
);
$lazyQuery = $factory->createQuery('a');
diff --git a/tests/Query/QueryTest.php b/tests/Query/QueryTest.php
index 652787c..740b641 100644
--- a/tests/Query/QueryTest.php
+++ b/tests/Query/QueryTest.php
@@ -5,6 +5,7 @@
namespace Remorhaz\JSON\Path\Test\Query;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Value\NodeValueInterface;
use Remorhaz\JSON\Path\Query\CallbackBuilderInterface;
@@ -21,9 +22,7 @@
use function array_shift;
-/**
- * @covers \Remorhaz\JSON\Path\Query\Query
- */
+#[CoversClass(Query::class)]
class QueryTest extends TestCase
{
public function testInvoke_ConstructedWithCallback_CallsSameCallback(): void
@@ -54,7 +53,7 @@ public function testInvoke_ConstructedWithCallback_CallsSameCallback(): void
$evaluator,
$literalFactory,
$matcherFactory,
- &$isCallbackCalledWithMatchingArgs
+ &$isCallbackCalledWithMatchingArgs,
): ValueListInterface {
$args = func_get_args();
/** @var NodeValueListInterface $input */
@@ -125,7 +124,10 @@ public function testGetCapabilities_CallbackBuilderProvedesGivenCapabilities_Ret
self::assertSame($capabilities, $query->getCapabilities());
}
- public function providerIsDefinite(): array
+ /**
+ * @return iterable
+ */
+ public static function providerIsDefinite(): iterable
{
return [
'TRUE' => [true, true],
diff --git a/tests/Query/QueryValidatorTest.php b/tests/Query/QueryValidatorTest.php
index 923414f..1884abe 100644
--- a/tests/Query/QueryValidatorTest.php
+++ b/tests/Query/QueryValidatorTest.php
@@ -4,6 +4,7 @@
namespace Remorhaz\JSON\Path\Test\Query;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Processor\Exception\IndefiniteQueryException;
use Remorhaz\JSON\Path\Processor\Exception\QueryNotAddressableException;
@@ -11,9 +12,7 @@
use Remorhaz\JSON\Path\Query\QueryInterface;
use Remorhaz\JSON\Path\Query\QueryValidator;
-/**
- * @covers \Remorhaz\JSON\Path\Query\QueryValidator
- */
+#[CoversClass(QueryValidator::class)]
class QueryValidatorTest extends TestCase
{
public function testGetDefiniteQuery_GivenDefiniteQuery_ReturnsSameInstance(): void
diff --git a/tests/Runtime/Aggregator/AggregatorCollectionTest.php b/tests/Runtime/Aggregator/AggregatorCollectionTest.php
index 1f3fb05..665efa2 100644
--- a/tests/Runtime/Aggregator/AggregatorCollectionTest.php
+++ b/tests/Runtime/Aggregator/AggregatorCollectionTest.php
@@ -4,6 +4,8 @@
namespace Remorhaz\JSON\Path\Test\Runtime\Aggregator;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Runtime\Aggregator\AggregatorCollection;
use Remorhaz\JSON\Path\Runtime\Aggregator\AvgAggregator;
@@ -13,23 +15,24 @@
use Remorhaz\JSON\Path\Runtime\Aggregator\MinAggregator;
use Remorhaz\JSON\Path\Runtime\Aggregator\StdDevAggregator;
-/**
- * @covers \Remorhaz\JSON\Path\Runtime\Aggregator\AggregatorCollection
- */
+#[CoversClass(AggregatorCollection::class)]
class AggregatorCollectionTest extends TestCase
{
/**
* @param string $name
- * @param string $expectedClass
- * @dataProvider providerByName
+ * @param class-string $expectedClass
*/
+ #[DataProvider('providerByName')]
public function testByName_KnownName_ReturnsMatchingInstance(string $name, string $expectedClass): void
{
$aggregators = new AggregatorCollection();
self::assertInstanceOf($expectedClass, $aggregators->byName($name));
}
- public function providerByName(): array
+ /**
+ * @return iterable
+ */
+ public static function providerByName(): iterable
{
return [
'min' => ['min', MinAggregator::class],
diff --git a/tests/Runtime/Aggregator/AvgAggregatorTest.php b/tests/Runtime/Aggregator/AvgAggregatorTest.php
index 2a467a0..31b4070 100644
--- a/tests/Runtime/Aggregator/AvgAggregatorTest.php
+++ b/tests/Runtime/Aggregator/AvgAggregatorTest.php
@@ -5,15 +5,14 @@
namespace Remorhaz\JSON\Path\Test\Runtime\Aggregator;
use ArrayIterator;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Value\ArrayValueInterface;
use Remorhaz\JSON\Data\Value\ScalarValueInterface;
use Remorhaz\JSON\Data\Value\ValueInterface;
use Remorhaz\JSON\Path\Runtime\Aggregator\AvgAggregator;
-/**
- * @covers \Remorhaz\JSON\Path\Runtime\Aggregator\AvgAggregator
- */
+#[CoversClass(AvgAggregator::class)]
class AvgAggregatorTest extends TestCase
{
public function testTryAggregate_EmptyArray_ReturnsNull(): void
@@ -58,7 +57,7 @@ public function testTryAggregate_ArrayWithTwoElements_ReturnsMatchingValue(): vo
self::assertSame(1.5, $this->exportValueData($aggregator->tryAggregate($value)));
}
- private function exportValueData(?ValueInterface $value)
+ private function exportValueData(?ValueInterface $value): int|float|string|bool|null
{
if (!isset($value)) {
return null;
diff --git a/tests/Runtime/Aggregator/Exception/AggregateFunctionNotFoundExceptionTest.php b/tests/Runtime/Aggregator/Exception/AggregateFunctionNotFoundExceptionTest.php
index 11b0a5b..eeabb16 100644
--- a/tests/Runtime/Aggregator/Exception/AggregateFunctionNotFoundExceptionTest.php
+++ b/tests/Runtime/Aggregator/Exception/AggregateFunctionNotFoundExceptionTest.php
@@ -5,12 +5,11 @@
namespace Remorhaz\JSON\Path\Test\Runtime\Aggregator\Exception;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Runtime\Aggregator\Exception\AggregateFunctionNotFoundException;
-/**
- * @covers \Remorhaz\JSON\Path\Runtime\Aggregator\Exception\AggregateFunctionNotFoundException
- */
+#[CoversClass(AggregateFunctionNotFoundException::class)]
class AggregateFunctionNotFoundExceptionTest extends TestCase
{
public function testGetMessage_Constructed_ReturnsMatchingValue(): void
@@ -25,12 +24,6 @@ public function testGetName_ConstructedWithName_ReturnsSameValue(): void
self::assertSame('a', $exception->getName());
}
- public function testGetCode_Always_ReturnsZero(): void
- {
- $exception = new AggregateFunctionNotFoundException('a');
- self::assertSame(0, $exception->getCode());
- }
-
public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void
{
$exception = new AggregateFunctionNotFoundException('a');
diff --git a/tests/Runtime/Aggregator/Exception/MaxElementNotFoundExceptionTest.php b/tests/Runtime/Aggregator/Exception/MaxElementNotFoundExceptionTest.php
index 76804a2..548ed0e 100644
--- a/tests/Runtime/Aggregator/Exception/MaxElementNotFoundExceptionTest.php
+++ b/tests/Runtime/Aggregator/Exception/MaxElementNotFoundExceptionTest.php
@@ -5,13 +5,12 @@
namespace Remorhaz\JSON\Path\Test\Runtime\Aggregator\Exception;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Value\ScalarValueInterface;
use Remorhaz\JSON\Path\Runtime\Aggregator\Exception\MaxElementNotFoundException;
-/**
- * @covers \Remorhaz\JSON\Path\Runtime\Aggregator\Exception\MaxElementNotFoundException
- */
+#[CoversClass(MaxElementNotFoundException::class)]
class MaxElementNotFoundExceptionTest extends TestCase
{
public function testGetMessage_Constructed_ReturnsMatchingValue(): void
@@ -20,7 +19,7 @@ public function testGetMessage_Constructed_ReturnsMatchingValue(): void
self::assertSame('Max element not found', $exception->getMessage());
}
- public function testGetDataLiist_ConstructedWithDataList_ReturnsSameValue(): void
+ public function testGetDataList_ConstructedWithDataList_ReturnsSameValue(): void
{
$exception = new MaxElementNotFoundException(['a'], []);
self::assertSame(['a'], $exception->getDataList());
@@ -33,12 +32,6 @@ public function testGetElements_ConstructedWithElements_ReturnsSameInstances():
self::assertSame([$element], $exception->getElements());
}
- public function testGetCode_Always_ReturnsZero(): void
- {
- $exception = new MaxElementNotFoundException([], []);
- self::assertSame(0, $exception->getCode());
- }
-
public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void
{
$exception = new MaxElementNotFoundException([], []);
diff --git a/tests/Runtime/Aggregator/Exception/MinElementNotFoundExceptionTest.php b/tests/Runtime/Aggregator/Exception/MinElementNotFoundExceptionTest.php
index f7ca6ba..4ccf939 100644
--- a/tests/Runtime/Aggregator/Exception/MinElementNotFoundExceptionTest.php
+++ b/tests/Runtime/Aggregator/Exception/MinElementNotFoundExceptionTest.php
@@ -5,13 +5,12 @@
namespace Remorhaz\JSON\Path\Test\Runtime\Aggregator\Exception;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Value\ScalarValueInterface;
use Remorhaz\JSON\Path\Runtime\Aggregator\Exception\MinElementNotFoundException;
-/**
- * @covers \Remorhaz\JSON\Path\Runtime\Aggregator\Exception\MinElementNotFoundException
- */
+#[CoversClass(MinElementNotFoundException::class)]
class MinElementNotFoundExceptionTest extends TestCase
{
public function testGetMessage_Constructed_ReturnsMatchingValue(): void
@@ -20,7 +19,7 @@ public function testGetMessage_Constructed_ReturnsMatchingValue(): void
self::assertSame('Min element not found', $exception->getMessage());
}
- public function testGetDataLiist_ConstructedWithDataList_ReturnsSameValue(): void
+ public function testGetDataList_ConstructedWithDataList_ReturnsSameValue(): void
{
$exception = new MinElementNotFoundException(['a'], []);
self::assertSame(['a'], $exception->getDataList());
@@ -33,12 +32,6 @@ public function testGetElements_ConstructedWithElements_ReturnsSameInstances():
self::assertSame([$element], $exception->getElements());
}
- public function testGetCode_Always_ReturnsZero(): void
- {
- $exception = new MinElementNotFoundException([], []);
- self::assertSame(0, $exception->getCode());
- }
-
public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void
{
$exception = new MinElementNotFoundException([], []);
diff --git a/tests/Runtime/Aggregator/LengthAggregatorTest.php b/tests/Runtime/Aggregator/LengthAggregatorTest.php
index 7b0aa64..d08dfd4 100644
--- a/tests/Runtime/Aggregator/LengthAggregatorTest.php
+++ b/tests/Runtime/Aggregator/LengthAggregatorTest.php
@@ -5,6 +5,8 @@
namespace Remorhaz\JSON\Path\Test\Runtime\Aggregator;
use ArrayIterator;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Value\ArrayValueInterface;
use Remorhaz\JSON\Data\Value\ScalarValueInterface;
@@ -13,9 +15,7 @@
use function array_fill;
-/**
- * @covers \Remorhaz\JSON\Path\Runtime\Aggregator\LengthAggregator
- */
+#[CoversClass(LengthAggregator::class)]
class LengthAggregatorTest extends TestCase
{
public function testTryAggregate_NonArrayValue_ReturnsNull(): void
@@ -25,11 +25,7 @@ public function testTryAggregate_NonArrayValue_ReturnsNull(): void
self::assertNull($aggregator->tryAggregate($value));
}
- /**
- * @param int $count
- * @param array $expectedValue
- * @dataProvider providerArrayCount
- */
+ #[DataProvider('providerArrayCount')]
public function testTryAggregate_ArrayValue_ReturnsValueWithArrayLength(int $count, array $expectedValue): void
{
$aggregator = new LengthAggregator();
@@ -41,7 +37,10 @@ public function testTryAggregate_ArrayValue_ReturnsValueWithArrayLength(int $cou
self::assertSame($expectedValue, $this->exportValueData($aggregator->tryAggregate($value)));
}
- public function providerArrayCount(): array
+ /**
+ * @return iterable
+ */
+ public static function providerArrayCount(): iterable
{
return [
'Empty array' => [0, ['data' => 0]],
@@ -50,7 +49,7 @@ public function providerArrayCount(): array
];
}
- private function exportValueData(?ValueInterface $value)
+ private function exportValueData(?ValueInterface $value): ?array
{
if (!isset($value)) {
return null;
diff --git a/tests/Runtime/Aggregator/MaxAggregatorTest.php b/tests/Runtime/Aggregator/MaxAggregatorTest.php
index d25a92a..0516793 100644
--- a/tests/Runtime/Aggregator/MaxAggregatorTest.php
+++ b/tests/Runtime/Aggregator/MaxAggregatorTest.php
@@ -5,14 +5,13 @@
namespace Remorhaz\JSON\Path\Test\Runtime\Aggregator;
use ArrayIterator;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Value\ArrayValueInterface;
use Remorhaz\JSON\Data\Value\ScalarValueInterface;
use Remorhaz\JSON\Path\Runtime\Aggregator\MaxAggregator;
-/**
- * @covers \Remorhaz\JSON\Path\Runtime\Aggregator\MaxAggregator
- */
+#[CoversClass(MaxAggregator::class)]
class MaxAggregatorTest extends TestCase
{
public function testTryAggregate_ArrayWithZeroElement_ReturnsNull(): void
diff --git a/tests/Runtime/Aggregator/MinAggregatorTest.php b/tests/Runtime/Aggregator/MinAggregatorTest.php
index 7022e99..f8eb0a7 100644
--- a/tests/Runtime/Aggregator/MinAggregatorTest.php
+++ b/tests/Runtime/Aggregator/MinAggregatorTest.php
@@ -5,14 +5,13 @@
namespace Remorhaz\JSON\Path\Test\Runtime\Aggregator;
use ArrayIterator;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Value\ArrayValueInterface;
use Remorhaz\JSON\Data\Value\ScalarValueInterface;
use Remorhaz\JSON\Path\Runtime\Aggregator\MinAggregator;
-/**
- * @covers \Remorhaz\JSON\Path\Runtime\Aggregator\MinAggregator
- */
+#[CoversClass(MinAggregator::class)]
class MinAggregatorTest extends TestCase
{
public function testTryAggregate_ArrayWithZeroElement_ReturnsNull(): void
diff --git a/tests/Runtime/Aggregator/NumericAggregatorTest.php b/tests/Runtime/Aggregator/NumericAggregatorTest.php
index 8ef39b4..16f26cd 100644
--- a/tests/Runtime/Aggregator/NumericAggregatorTest.php
+++ b/tests/Runtime/Aggregator/NumericAggregatorTest.php
@@ -5,27 +5,33 @@
namespace Remorhaz\JSON\Path\Test\Runtime\Aggregator;
use ArrayIterator;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Value\ArrayValueInterface;
use Remorhaz\JSON\Data\Value\ScalarValueInterface;
use Remorhaz\JSON\Data\Value\ValueInterface;
use Remorhaz\JSON\Path\Runtime\Aggregator\NumericAggregator;
-/**
- * @covers \Remorhaz\JSON\Path\Runtime\Aggregator\NumericAggregator
- */
+#[CoversClass(NumericAggregator::class)]
class NumericAggregatorTest extends TestCase
{
public function testTryAggregate_NonArrayValue_ReturnsNull(): void
{
- $aggregator = $this->getMockForAbstractClass(NumericAggregator::class);
+ $aggregator = $this
+ ->getMockBuilder(NumericAggregator::class)
+ ->onlyMethods(['aggregateNumericData'])
+ ->getMock();
$value = $this->createMock(ValueInterface::class);
self::assertNull($aggregator->tryAggregate($value));
}
public function testTryAggregate_ArrayWithNonScalarElement_ReturnsNull(): void
{
- $aggregator = $this->getMockForAbstractClass(NumericAggregator::class);
+ $aggregator = $this
+ ->getMockBuilder(NumericAggregator::class)
+ ->onlyMethods(['aggregateNumericData'])
+ ->getMock();
$value = $this->createMock(ArrayValueInterface::class);
$element = $this->createMock(ValueInterface::class);
$value
@@ -36,7 +42,10 @@ public function testTryAggregate_ArrayWithNonScalarElement_ReturnsNull(): void
public function testTryAggregate_ArrayWithNonNumericScalarElement_ReturnsNull(): void
{
- $aggregator = $this->getMockForAbstractClass(NumericAggregator::class);
+ $aggregator = $this
+ ->getMockBuilder(NumericAggregator::class)
+ ->onlyMethods(['aggregateNumericData'])
+ ->getMock();
$value = $this->createMock(ArrayValueInterface::class);
$element = $this->createMock(ScalarValueInterface::class);
$value
@@ -48,13 +57,13 @@ public function testTryAggregate_ArrayWithNonNumericScalarElement_ReturnsNull():
self::assertNull($aggregator->tryAggregate($value));
}
- /**
- * @param int|float $data
- * @dataProvider providerNumericData
- */
- public function testTryAggregate_ArrayWithNumericScalarElement_AggregatesElement($data): void
+ #[DataProvider('providerNumericData')]
+ public function testTryAggregate_ArrayWithNumericScalarElement_AggregatesElement(int|float $data): void
{
- $aggregator = $this->getMockForAbstractClass(NumericAggregator::class);
+ $aggregator = $this
+ ->getMockBuilder(NumericAggregator::class)
+ ->onlyMethods(['aggregateNumericData'])
+ ->getMock();
$value = $this->createMock(ArrayValueInterface::class);
$element = $this->createMock(ScalarValueInterface::class);
$value
@@ -73,7 +82,10 @@ public function testTryAggregate_ArrayWithNumericScalarElement_AggregatesElement
$aggregator->tryAggregate($value);
}
- public function providerNumericData(): array
+ /**
+ * @return iterable
+ */
+ public static function providerNumericData(): iterable
{
return [
'Integer data' => [1],
@@ -83,7 +95,10 @@ public function providerNumericData(): array
public function testTryAggregate_ArrayWithNumericAndNonNumericElements_AggregatesOnlyNumericElements(): void
{
- $aggregator = $this->getMockForAbstractClass(NumericAggregator::class);
+ $aggregator = $this
+ ->getMockBuilder(NumericAggregator::class)
+ ->onlyMethods(['aggregateNumericData'])
+ ->getMock();
$value = $this->createMock(ArrayValueInterface::class);
$numericElement = $this->createMock(ScalarValueInterface::class);
$numericElement
@@ -108,7 +123,10 @@ public function testTryAggregate_ArrayWithNumericAndNonNumericElements_Aggregate
public function testTryAggregate_AggregationReturnsValue_ReturnsSameInstance(): void
{
- $aggregator = $this->getMockForAbstractClass(NumericAggregator::class);
+ $aggregator = $this
+ ->getMockBuilder(NumericAggregator::class)
+ ->onlyMethods(['aggregateNumericData'])
+ ->getMock();
$value = $this->createMock(ArrayValueInterface::class);
$element = $this->createMock(ScalarValueInterface::class);
$value
@@ -126,7 +144,10 @@ public function testTryAggregate_AggregationReturnsValue_ReturnsSameInstance():
public function testTryAggregate_AggregationReturnsNull_ReturnsNull(): void
{
- $aggregator = $this->getMockForAbstractClass(NumericAggregator::class);
+ $aggregator = $this
+ ->getMockBuilder(NumericAggregator::class)
+ ->onlyMethods(['aggregateNumericData'])
+ ->getMock();
$value = $this->createMock(ArrayValueInterface::class);
$element = $this->createMock(ScalarValueInterface::class);
$value
diff --git a/tests/Runtime/Aggregator/StdDevAggregatorTest.php b/tests/Runtime/Aggregator/StdDevAggregatorTest.php
index 19ab230..dbad8d9 100644
--- a/tests/Runtime/Aggregator/StdDevAggregatorTest.php
+++ b/tests/Runtime/Aggregator/StdDevAggregatorTest.php
@@ -5,15 +5,14 @@
namespace Remorhaz\JSON\Path\Test\Runtime\Aggregator;
use ArrayIterator;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Value\ArrayValueInterface;
use Remorhaz\JSON\Data\Value\ScalarValueInterface;
use Remorhaz\JSON\Data\Value\ValueInterface;
use Remorhaz\JSON\Path\Runtime\Aggregator\StdDevAggregator;
-/**
- * @covers \Remorhaz\JSON\Path\Runtime\Aggregator\StdDevAggregator
- */
+#[CoversClass(StdDevAggregator::class)]
class StdDevAggregatorTest extends TestCase
{
public function testTryAggregate_EmptyArray_ReturnsNull(): void
@@ -65,7 +64,7 @@ public function testTryAggregate_ArrayWithThreeElements_ReturnsMatchingValue():
);
}
- private function exportValueData(?ValueInterface $value)
+ private function exportValueData(?ValueInterface $value): string|int|float|bool|null
{
if (!isset($value)) {
return null;
diff --git a/tests/Runtime/Aggregator/UniqueNumericAggregatorTest.php b/tests/Runtime/Aggregator/UniqueNumericAggregatorTest.php
index 561a43c..f153390 100644
--- a/tests/Runtime/Aggregator/UniqueNumericAggregatorTest.php
+++ b/tests/Runtime/Aggregator/UniqueNumericAggregatorTest.php
@@ -5,19 +5,21 @@
namespace Remorhaz\JSON\Path\Test\Runtime\Aggregator;
use ArrayIterator;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Value\ArrayValueInterface;
use Remorhaz\JSON\Data\Value\ScalarValueInterface;
use Remorhaz\JSON\Path\Runtime\Aggregator\UniqueNumericAggregator;
-/**
- * @covers \Remorhaz\JSON\Path\Runtime\Aggregator\UniqueNumericAggregator
- */
+#[CoversClass(UniqueNumericAggregator::class)]
class UniqueNumericAggregatorTest extends TestCase
{
public function testTryAggregate_ArrayWithDifferentValues_AggregatesBothValues(): void
{
- $aggregator = $this->getMockForAbstractClass(UniqueNumericAggregator::class);
+ $aggregator = $this
+ ->getMockBuilder(UniqueNumericAggregator::class)
+ ->onlyMethods(['aggregateNumericData'])
+ ->getMock();
$value = $this->createMock(ArrayValueInterface::class);
$firstElement = $this->createMock(ScalarValueInterface::class);
$firstElement
@@ -36,14 +38,17 @@ public function testTryAggregate_ArrayWithDifferentValues_AggregatesBothValues()
->with(
self::identicalTo([1, 1.2]),
self::identicalTo($firstElement),
- self::identicalTo($secondElement)
+ self::identicalTo($secondElement),
);
$aggregator->tryAggregate($value);
}
public function testTryAggregate_ArrayWithEqualValues_AggregatesOnlyFirstValue(): void
{
- $aggregator = $this->getMockForAbstractClass(UniqueNumericAggregator::class);
+ $aggregator = $this
+ ->getMockBuilder(UniqueNumericAggregator::class)
+ ->onlyMethods(['aggregateNumericData'])
+ ->getMock();
$value = $this->createMock(ArrayValueInterface::class);
$firstElement = $this->createMock(ScalarValueInterface::class);
$firstElement
@@ -61,7 +66,7 @@ public function testTryAggregate_ArrayWithEqualValues_AggregatesOnlyFirstValue()
->method('aggregateNumericData')
->with(
self::identicalTo([1]),
- self::identicalTo($firstElement)
+ self::identicalTo($firstElement),
);
$aggregator->tryAggregate($value);
}
diff --git a/tests/Runtime/ComparatorCollectionTest.php b/tests/Runtime/ComparatorCollectionTest.php
index a8c3811..2b78eb3 100644
--- a/tests/Runtime/ComparatorCollectionTest.php
+++ b/tests/Runtime/ComparatorCollectionTest.php
@@ -5,21 +5,20 @@
namespace Remorhaz\JSON\Path\Test\Runtime;
use Collator;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Comparator\EqualValueComparator;
use Remorhaz\JSON\Data\Comparator\GreaterValueComparator;
use Remorhaz\JSON\Data\Value\ScalarValueInterface;
use Remorhaz\JSON\Path\Runtime\ComparatorCollection;
-/**
- * @covers \Remorhaz\JSON\Path\Runtime\ComparatorCollection
- */
+#[CoversClass(ComparatorCollection::class)]
class ComparatorCollectionTest extends TestCase
{
public function testEqual_Constructed_ReturnsEqualComparatorInstance(): void
{
$comparators = new ComparatorCollection(
- $this->createMock(Collator::class)
+ $this->createMock(Collator::class),
);
self::assertInstanceOf(EqualValueComparator::class, $comparators->equal());
}
@@ -43,7 +42,7 @@ public function testEqual_ConstructedWithCollator_ResultUsesSameInstanceOnCompar
public function testGreater_Constructed_ReturnsGreaterComparatorInstance(): void
{
$comparators = new ComparatorCollection(
- $this->createMock(Collator::class)
+ $this->createMock(Collator::class),
);
self::assertInstanceOf(GreaterValueComparator::class, $comparators->greater());
}
diff --git a/tests/Runtime/EvaluatorTest.php b/tests/Runtime/EvaluatorTest.php
index 93ee910..86e5006 100644
--- a/tests/Runtime/EvaluatorTest.php
+++ b/tests/Runtime/EvaluatorTest.php
@@ -4,6 +4,8 @@
namespace Remorhaz\JSON\Path\Test\Runtime;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Comparator\ComparatorInterface;
use Remorhaz\JSON\Data\Value\ScalarValueInterface;
@@ -24,47 +26,48 @@
use Remorhaz\JSON\Path\Value\ValueList;
use Remorhaz\JSON\Path\Value\ValueListInterface;
-/**
- * @covers \Remorhaz\JSON\Path\Runtime\Evaluator
- */
+#[CoversClass(Evaluator::class)]
class EvaluatorTest extends TestCase
{
public function testLogicalOr_EmptyLists_ReturnsEmptyList(): void
{
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$result = $evaluator->logicalOr(
new EvaluatedValueList(new IndexMap()),
- new EvaluatedValueList(new IndexMap())
+ new EvaluatedValueList(new IndexMap()),
);
self::assertSame([], $result->getResults());
}
/**
- * @param bool $leftResult
- * @param bool $rightResult
- * @param array $expectedValues
- * @dataProvider providerLogicalOr
+ * @param bool $leftResult
+ * @param bool $rightResult
+ * @param list $expectedValues
*/
+ #[DataProvider('providerLogicalOr')]
public function testLogicalOr_CompatibleLists_ReturnsMatching(
bool $leftResult,
bool $rightResult,
- array $expectedValues
+ array $expectedValues,
): void {
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$result = $evaluator->logicalOr(
new EvaluatedValueList(new IndexMap(), $leftResult),
- new EvaluatedValueList(new IndexMap(), $rightResult)
+ new EvaluatedValueList(new IndexMap(), $rightResult),
);
self::assertSame($expectedValues, $result->getResults());
}
- public function providerLogicalOr(): array
+ /**
+ * @return iterable}>
+ */
+ public static function providerLogicalOr(): iterable
{
return [
'Both false' => [false, false, [false]],
@@ -78,7 +81,7 @@ public function testLogicalOr_IncompatibleIndexMaps_ThrowsException(): void
{
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$leftValues = new EvaluatedValueList(new IndexMap(1));
$rightValues = new EvaluatedValueList(new IndexMap(2, 3));
@@ -90,38 +93,41 @@ public function testLogicalAnd_EmptyLists_ReturnsEmptyList(): void
{
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$result = $evaluator->logicalAnd(
new EvaluatedValueList(new IndexMap()),
- new EvaluatedValueList(new IndexMap())
+ new EvaluatedValueList(new IndexMap()),
);
self::assertSame([], $result->getResults());
}
/**
- * @param bool $leftResult
- * @param bool $rightResult
- * @param array $expectedValues
- * @dataProvider providerLogicalAnd
+ * @param bool $leftResult
+ * @param bool $rightResult
+ * @param list $expectedValues
*/
+ #[DataProvider('providerLogicalAnd')]
public function testLogicalAnd_CompatibleLists_ReturnsMatching(
bool $leftResult,
bool $rightResult,
- array $expectedValues
+ array $expectedValues,
): void {
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$result = $evaluator->logicalAnd(
new EvaluatedValueList(new IndexMap(), $leftResult),
- new EvaluatedValueList(new IndexMap(), $rightResult)
+ new EvaluatedValueList(new IndexMap(), $rightResult),
);
self::assertSame($expectedValues, $result->getResults());
}
- public function providerLogicalAnd(): array
+ /**
+ * @return iterable}>
+ */
+ public static function providerLogicalAnd(): iterable
{
return [
'Both false' => [false, false, [false]],
@@ -135,7 +141,7 @@ public function testLogicalAnd_IncompatibleIndexMaps_ThrowsException(): void
{
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$leftValues = new EvaluatedValueList(new IndexMap(1));
$rightValues = new EvaluatedValueList(new IndexMap(2, 3));
@@ -147,7 +153,7 @@ public function testLogicalNot_NoValueInList_ReturnsEmptyList(): void
{
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$values = new EvaluatedValueList(new IndexMap());
$result = $evaluator->logicalNot($values);
@@ -158,7 +164,7 @@ public function testLogicalNot_ListWithIndexMap_ReturnsListWithSameMapInstance()
{
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$indexMap = new IndexMap();
$values = new EvaluatedValueList($indexMap);
@@ -167,22 +173,25 @@ public function testLogicalNot_ListWithIndexMap_ReturnsListWithSameMapInstance()
}
/**
- * @param bool $value
- * @param array $expectedValues
- * @dataProvider providerLogicalNot
+ * @param bool $value
+ * @param list $expectedValues
*/
+ #[DataProvider('providerLogicalNot')]
public function testLogicalNot_ValueInList_ReturnsMatchingList(bool $value, array $expectedValues): void
{
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$values = new EvaluatedValueList(new IndexMap(), $value);
$result = $evaluator->logicalNot($values);
self::assertSame($expectedValues, $result->getResults());
}
- public function providerLogicalNot(): array
+ /**
+ * @return iterable}>
+ */
+ public static function providerLogicalNot(): iterable
{
return [
'True becomes false' => [true, [false]],
@@ -194,27 +203,23 @@ public function testIsEqual_EmptyIndexMapsInLists_ReturnsEmptyList(): void
{
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$result = $evaluator->isEqual(
new ValueList(new IndexMap()),
- new ValueList(new IndexMap())
+ new ValueList(new IndexMap()),
);
self::assertSame([], $result->getResults());
}
- /**
- * @param int|null $leftOuterIndex
- * @param int|null $rightOuterIndex
- * @dataProvider providerNullOuterIndex
- */
+ #[DataProvider('providerNullOuterIndex')]
public function testIsEqual_NullIndexMapsInLists_ReturnsEmptyList(
?int $leftOuterIndex,
- ?int $rightOuterIndex
+ ?int $rightOuterIndex,
): void {
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$result = $evaluator->isEqual(
new ValueList(new IndexMap($leftOuterIndex)),
@@ -223,7 +228,10 @@ public function testIsEqual_NullIndexMapsInLists_ReturnsEmptyList(
self::assertSame([], $result->getResults());
}
- public function providerNullOuterIndex(): array
+ /**
+ * @return iterable
+ */
+ public static function providerNullOuterIndex(): iterable
{
return [
'Both indexes are null' => [null, null],
@@ -236,11 +244,11 @@ public function testIsEqual_IndexMapsWithDifferentOuterIndexesInLists_ReturnsEmp
{
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$result = $evaluator->isEqual(
new ValueList(new IndexMap(1)),
- new ValueList(new IndexMap(2))
+ new ValueList(new IndexMap(2)),
);
self::assertSame([], $result->getResults());
}
@@ -250,7 +258,7 @@ public function testIsEqual_IndexMapsWithSameOuterIndexesInLists_PassesValuesToC
$comparators = $this->createMock(ComparatorCollectionInterface::class);
$evaluator = new Evaluator(
$comparators,
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$leftValue = $this->createMock(ValueInterface::class);
$rightValue = $this->createMock(ValueInterface::class);
@@ -265,23 +273,23 @@ public function testIsEqual_IndexMapsWithSameOuterIndexesInLists_PassesValuesToC
->with(self::identicalTo($leftValue), self::identicalTo($rightValue));
$evaluator->isEqual(
new ValueList(new IndexMap(1), $leftValue),
- new ValueList(new IndexMap(1), $rightValue)
+ new ValueList(new IndexMap(1), $rightValue),
);
}
/**
- * @param bool $comparison
- * @param array $expectedValues
- * @dataProvider providerIsEqual
+ * @param bool $comparison
+ * @param list $expectedValues
*/
+ #[DataProvider('providerIsEqual')]
public function testIsEqual_ComparatorReturnsResult_ReturnsListWithSameResult(
bool $comparison,
- array $expectedValues
+ array $expectedValues,
): void {
$comparators = $this->createMock(ComparatorCollectionInterface::class);
$evaluator = new Evaluator(
$comparators,
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$leftValue = $this->createMock(ValueInterface::class);
$rightValue = $this->createMock(ValueInterface::class);
@@ -295,12 +303,15 @@ public function testIsEqual_ComparatorReturnsResult_ReturnsListWithSameResult(
->willReturn($comparison);
$result = $evaluator->isEqual(
new ValueList(new IndexMap(1), $leftValue),
- new ValueList(new IndexMap(1), $rightValue)
+ new ValueList(new IndexMap(1), $rightValue),
);
self::assertSame($expectedValues, $result->getResults());
}
- public function providerIsEqual(): array
+ /**
+ * @return iterable}>
+ */
+ public static function providerIsEqual(): iterable
{
return [
'True' => [true, [true]],
@@ -312,11 +323,11 @@ public function testIsEqual_IndexMapsWithSameOuterIndexesInLists_ReturnsListWith
{
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$result = $evaluator->isEqual(
new ValueList(new IndexMap(1), $this->createMock(ValueInterface::class)),
- new ValueList(new IndexMap(1), $this->createMock(ValueInterface::class))
+ new ValueList(new IndexMap(1), $this->createMock(ValueInterface::class)),
);
self::assertSame([1], $result->getIndexMap()->getOuterIndexes());
}
@@ -325,11 +336,11 @@ public function testIsGreater_IndexMapsWithDifferentOuterIndexesInLists_ReturnsE
{
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$result = $evaluator->isGreater(
new ValueList(new IndexMap(1)),
- new ValueList(new IndexMap(2))
+ new ValueList(new IndexMap(2)),
);
self::assertSame([], $result->getResults());
}
@@ -339,7 +350,7 @@ public function testIsGreater_IndexMapsWithSameOuterIndexesInLists_PassesValuesT
$comparators = $this->createMock(ComparatorCollectionInterface::class);
$evaluator = new Evaluator(
$comparators,
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$leftValue = $this->createMock(ValueInterface::class);
$rightValue = $this->createMock(ValueInterface::class);
@@ -354,18 +365,18 @@ public function testIsGreater_IndexMapsWithSameOuterIndexesInLists_PassesValuesT
->with(self::identicalTo($leftValue), self::identicalTo($rightValue));
$evaluator->isGreater(
new ValueList(new IndexMap(1), $leftValue),
- new ValueList(new IndexMap(1), $rightValue)
+ new ValueList(new IndexMap(1), $rightValue),
);
}
/**
- * @param bool $comparison
- * @param array $expectedValues
- * @dataProvider providerIsGreater
+ * @param bool $comparison
+ * @param list $expectedValues
*/
+ #[DataProvider('providerIsGreater')]
public function testIsGreater_ComparatorReturnsResult_ReturnsListWithSameResult(
bool $comparison,
- array $expectedValues
+ array $expectedValues,
): void {
$comparators = $this->createMock(ComparatorCollectionInterface::class);
$evaluator = new Evaluator(
@@ -389,7 +400,10 @@ public function testIsGreater_ComparatorReturnsResult_ReturnsListWithSameResult(
self::assertSame($expectedValues, $result->getResults());
}
- public function providerIsGreater(): array
+ /**
+ * @return iterable}>
+ */
+ public static function providerIsGreater(): iterable
{
return [
'True' => [true, [true]],
@@ -401,11 +415,11 @@ public function testIsGreater_IndexMapsWithSameOuterIndexesInLists_ReturnsListWi
{
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$result = $evaluator->isGreater(
new ValueList(new IndexMap(1), $this->createMock(ValueInterface::class)),
- new ValueList(new IndexMap(1), $this->createMock(ValueInterface::class))
+ new ValueList(new IndexMap(1), $this->createMock(ValueInterface::class)),
);
self::assertSame([1], $result->getIndexMap()->getOuterIndexes());
}
@@ -414,7 +428,7 @@ public function testIsRegExp_EmptyList_ReturnsEmptyList(): void
{
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$values = new ValueList(new IndexMap());
$result = $evaluator->isRegExp('//', $values);
@@ -425,7 +439,7 @@ public function testIsRegExp_NonScalarValueInList_ReturnsFalseResultInList(): vo
{
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$values = new ValueList(new IndexMap(1), $this->createMock(ValueInterface::class));
$result = $evaluator->isRegExp('//', $values);
@@ -436,7 +450,7 @@ public function testIsRegExp_NonStringScalarValueInList_ReturnsFalseResultInList
{
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$value = $this->createMock(ScalarValueInterface::class);
$value
@@ -451,7 +465,7 @@ public function testIsRegExp_InvalidRegExp_ThrowsException(): void
{
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$value = $this->createMock(ScalarValueInterface::class);
$value
@@ -466,7 +480,7 @@ public function testIsRegExp_NonMatchingStringScalarValueInList_ReturnsFalseResu
{
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$value = $this->createMock(ScalarValueInterface::class);
$value
@@ -481,7 +495,7 @@ public function testIsRegExp_MatchingStringScalarValueInList_ReturnsTrueResultIn
{
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$value = $this->createMock(ScalarValueInterface::class);
$value
@@ -496,7 +510,7 @@ public function testIsRegExp_IndexMapInList_ReturnsListWithSameIndexMapInstance(
{
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$indexMap = new IndexMap();
$values = new ValueList($indexMap);
@@ -508,12 +522,12 @@ public function testEvaluate_EvaluatedResults_ReturnsSameInstance(): void
{
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$values = $this->createMock(EvaluatedValueListInterface::class);
$result = $evaluator->evaluate(
$this->createMock(ValueListInterface::class),
- $values
+ $values,
);
self::assertSame($values, $result);
}
@@ -522,12 +536,12 @@ public function testEvaluate_EmptyIndexMapInSource_ReturnsEmptyResult(): void
{
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$source = new ValueList(new IndexMap());
$result = $evaluator->evaluate(
$source,
- $this->createMock(ValueListInterface::class)
+ $this->createMock(ValueListInterface::class),
);
self::assertSame([], $result->getResults());
}
@@ -536,12 +550,12 @@ public function testEvaluate_NullOuterIndexInSource_ReturnsFalseResultInList():
{
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$source = new ValueList(new IndexMap(null));
$result = $evaluator->evaluate(
$source,
- $this->createMock(ValueListInterface::class)
+ $this->createMock(ValueListInterface::class),
);
self::assertSame([false], $result->getResults());
}
@@ -550,12 +564,12 @@ public function testEvaluate_OuterIndexInSourceNotExistsInValues_ReturnsFalseRes
{
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$source = new ValueList(new IndexMap(1));
$result = $evaluator->evaluate(
$source,
- new ValueList(new IndexMap(2))
+ new ValueList(new IndexMap(2)),
);
self::assertSame([false], $result->getResults());
}
@@ -564,12 +578,12 @@ public function testEvaluate_OuterIndexInSourceExistsInValues_ReturnsTrueResultI
{
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$source = new ValueList(new IndexMap(1));
$result = $evaluator->evaluate(
$source,
- new ValueList(new IndexMap(1))
+ new ValueList(new IndexMap(1)),
);
self::assertSame([true], $result->getResults());
}
@@ -578,7 +592,7 @@ public function testEvaluate_NonScalarLiteralInList_ThrowsException(): void
{
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$values = $this->createMock(LiteralValueListInterface::class);
$values
@@ -596,7 +610,7 @@ public function testEvaluate_NonBooleanScalarLiteralInList_ThrowsException(): vo
{
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$values = $this->createMock(LiteralValueListInterface::class);
$values
@@ -621,7 +635,7 @@ public function testEvaluate_BooleanScalarLiteralInList_ReturnsMatchingResultInL
): void {
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$values = $this->createMock(LiteralValueListInterface::class);
$values
@@ -635,7 +649,10 @@ public function testEvaluate_BooleanScalarLiteralInList_ReturnsMatchingResultInL
self::assertSame($expectedValues, $result->getResults());
}
- public function providerEvaluateLiteral(): array
+ /**
+ * @return iterable>
+ */
+ public static function providerEvaluateLiteral(): iterable
{
return [
'True' => [true, [true]],
@@ -648,7 +665,7 @@ public function testAggregate_NoValueInList_NeverCallsAggregator(): void
$aggregators = $this->createMock(AggregatorCollectionInterface::class);
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $aggregators
+ $aggregators,
);
$aggregator = $this->createMock(ValueAggregatorInterface::class);
$aggregators
@@ -670,7 +687,7 @@ public function testAggregate_NoValueInList_ReturnsEmptyList(): void
{
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $this->createMock(AggregatorCollectionInterface::class)
+ $this->createMock(AggregatorCollectionInterface::class),
);
$values = $this->createMock(ValueListInterface::class);
$values
@@ -686,7 +703,7 @@ public function testAggregate_ValueInList_PassesSameInstanceToAggregator(): void
$aggregators = $this->createMock(AggregatorCollectionInterface::class);
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $aggregators
+ $aggregators,
);
$aggregator = $this->createMock(ValueAggregatorInterface::class);
$aggregators
@@ -711,7 +728,7 @@ public function testAggregate_AggregatorReturnsNull_ReturnsEmptyList(): void
$aggregators = $this->createMock(AggregatorCollectionInterface::class);
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $aggregators
+ $aggregators,
);
$aggregator = $this->createMock(ValueAggregatorInterface::class);
$aggregators
@@ -737,7 +754,7 @@ public function testAggregate_AggregatorReturnsValue_ReturnsListWithSameInstance
$aggregators = $this->createMock(AggregatorCollectionInterface::class);
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $aggregators
+ $aggregators,
);
$aggregator = $this->createMock(ValueAggregatorInterface::class);
$aggregators
@@ -764,7 +781,7 @@ public function testAggregate_AggregatorReturnsValue_ReturnsListWithMatchingInde
$aggregators = $this->createMock(AggregatorCollectionInterface::class);
$evaluator = new Evaluator(
$this->createMock(ComparatorCollectionInterface::class),
- $aggregators
+ $aggregators,
);
$aggregator = $this->createMock(ValueAggregatorInterface::class);
$aggregators
diff --git a/tests/Runtime/Exception/IndexMapMatchFailedExceptionTest.php b/tests/Runtime/Exception/IndexMapMatchFailedExceptionTest.php
index c273c2d..5fec643 100644
--- a/tests/Runtime/Exception/IndexMapMatchFailedExceptionTest.php
+++ b/tests/Runtime/Exception/IndexMapMatchFailedExceptionTest.php
@@ -5,13 +5,12 @@
namespace Remorhaz\JSON\Path\Test\Runtime\Exception;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Runtime\Exception\IndexMapMatchFailedException;
use Remorhaz\JSON\Path\Value\ValueListInterface;
-/**
- * @covers \Remorhaz\JSON\Path\Runtime\Exception\IndexMapMatchFailedException
- */
+#[CoversClass(IndexMapMatchFailedException::class)]
class IndexMapMatchFailedExceptionTest extends TestCase
{
public function testGetLeftValues_ConstructedWithGivenLeftValues_ReturnsSameInstance(): void
@@ -19,7 +18,7 @@ public function testGetLeftValues_ConstructedWithGivenLeftValues_ReturnsSameInst
$leftValues = $this->createMock(ValueListInterface::class);
$exception = new IndexMapMatchFailedException(
$leftValues,
- $this->createMock(ValueListInterface::class)
+ $this->createMock(ValueListInterface::class),
);
self::assertSame($leftValues, $exception->getLeftValues());
}
@@ -29,7 +28,7 @@ public function testGetRightValues_ConstructedWithGivenRightValues_ReturnsSameIn
$rightValues = $this->createMock(ValueListInterface::class);
$exception = new IndexMapMatchFailedException(
$this->createMock(ValueListInterface::class),
- $rightValues
+ $rightValues,
);
self::assertSame($rightValues, $exception->getRightValues());
}
@@ -38,25 +37,16 @@ public function testGetMessage_Constructed_ReturnsMatchingValue(): void
{
$exception = new IndexMapMatchFailedException(
$this->createMock(ValueListInterface::class),
- $this->createMock(ValueListInterface::class)
- );
- self::assertSame('Index map match failed', $exception->getMessage());
- }
-
- public function testGetCode_Always_ReturnsZero(): void
- {
- $exception = new IndexMapMatchFailedException(
$this->createMock(ValueListInterface::class),
- $this->createMock(ValueListInterface::class)
);
- self::assertSame(0, $exception->getCode());
+ self::assertSame('Index map match failed', $exception->getMessage());
}
public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void
{
$exception = new IndexMapMatchFailedException(
$this->createMock(ValueListInterface::class),
- $this->createMock(ValueListInterface::class)
+ $this->createMock(ValueListInterface::class),
);
self::assertNull($exception->getPrevious());
}
@@ -67,7 +57,7 @@ public function testGetPrevious_ConstructedWithGivenPrevious_ReturnsSameInstance
$exception = new IndexMapMatchFailedException(
$this->createMock(ValueListInterface::class),
$this->createMock(ValueListInterface::class),
- $previous
+ $previous,
);
self::assertSame($previous, $exception->getPrevious());
}
diff --git a/tests/Runtime/Exception/InvalidContextValueExceptionTest.php b/tests/Runtime/Exception/InvalidContextValueExceptionTest.php
index c02b543..5a58103 100644
--- a/tests/Runtime/Exception/InvalidContextValueExceptionTest.php
+++ b/tests/Runtime/Exception/InvalidContextValueExceptionTest.php
@@ -5,19 +5,18 @@
namespace Remorhaz\JSON\Path\Test\Runtime\Exception;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Value\ValueInterface;
use Remorhaz\JSON\Path\Runtime\Exception\InvalidContextValueException;
-/**
- * @covers \Remorhaz\JSON\Path\Runtime\Exception\InvalidContextValueException
- */
+#[CoversClass(InvalidContextValueException::class)]
class InvalidContextValueExceptionTest extends TestCase
{
public function testGetMessage_Constructed_ReturnsMatchingValue(): void
{
$exception = new InvalidContextValueException(
- $this->createMock(ValueInterface::class)
+ $this->createMock(ValueInterface::class),
);
self::assertSame('Invalid context value', $exception->getMessage());
}
@@ -29,18 +28,10 @@ public function testGetValue_ConstructedWithValue_ReturnsSameValue(): void
self::assertSame($value, $exception->getValue());
}
- public function testGetCode_Always_ReturnsZero(): void
- {
- $exception = new InvalidContextValueException(
- $this->createMock(ValueInterface::class)
- );
- self::assertSame(0, $exception->getCode());
- }
-
public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void
{
$exception = new InvalidContextValueException(
- $this->createMock(ValueInterface::class)
+ $this->createMock(ValueInterface::class),
);
self::assertNull($exception->getPrevious());
}
@@ -50,7 +41,7 @@ public function testGetPrevious_ConstructedWithPrevious_ReturnsSameInstance(): v
$previous = new Exception();
$exception = new InvalidContextValueException(
$this->createMock(ValueInterface::class),
- $previous
+ $previous,
);
self::assertSame($previous, $exception->getPrevious());
}
diff --git a/tests/Runtime/Exception/InvalidFilterValueExceptionTest.php b/tests/Runtime/Exception/InvalidFilterValueExceptionTest.php
index 3b29002..c809897 100644
--- a/tests/Runtime/Exception/InvalidFilterValueExceptionTest.php
+++ b/tests/Runtime/Exception/InvalidFilterValueExceptionTest.php
@@ -5,19 +5,18 @@
namespace Remorhaz\JSON\Path\Test\Runtime\Exception;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Value\ValueInterface;
use Remorhaz\JSON\Path\Runtime\Exception\InvalidFilterValueException;
-/**
- * @covers \Remorhaz\JSON\Path\Runtime\Exception\InvalidFilterValueException
- */
+#[CoversClass(InvalidFilterValueException::class)]
class InvalidFilterValueExceptionTest extends TestCase
{
public function testGetMessage_Constructed_ReturnsMatchingValue(): void
{
$exception = new InvalidFilterValueException(
- $this->createMock(ValueInterface::class)
+ $this->createMock(ValueInterface::class),
);
self::assertSame('Invalid filter value', $exception->getMessage());
}
@@ -29,18 +28,10 @@ public function testGetValue_ConstructedWithValue_ReturnsSameInstance(): void
self::assertSame($value, $exception->getValue());
}
- public function testGetCode_Always_ReturnZero(): void
- {
- $exception = new InvalidFilterValueException(
- $this->createMock(ValueInterface::class)
- );
- self::assertSame(0, $exception->getCode());
- }
-
public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void
{
$exception = new InvalidFilterValueException(
- $this->createMock(ValueInterface::class)
+ $this->createMock(ValueInterface::class),
);
self::assertNull($exception->getPrevious());
}
@@ -50,7 +41,7 @@ public function testGetPrevious_ConstructedWithPrevious_ReturnsSameInstance(): v
$previous = new Exception();
$exception = new InvalidFilterValueException(
$this->createMock(ValueInterface::class),
- $previous
+ $previous,
);
self::assertSame($previous, $exception->getPrevious());
}
diff --git a/tests/Runtime/Exception/InvalidRegExpExceptionTest.php b/tests/Runtime/Exception/InvalidRegExpExceptionTest.php
index e020c12..2f9ddfd 100644
--- a/tests/Runtime/Exception/InvalidRegExpExceptionTest.php
+++ b/tests/Runtime/Exception/InvalidRegExpExceptionTest.php
@@ -5,12 +5,11 @@
namespace Remorhaz\JSON\Path\Test\Runtime\Exception;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Runtime\Exception\InvalidRegExpException;
-/**
- * @covers \Remorhaz\JSON\Path\Runtime\Exception\InvalidRegExpException
- */
+#[CoversClass(InvalidRegExpException::class)]
class InvalidRegExpExceptionTest extends TestCase
{
public function testGetMessage_Constructed_ReturnsMatchingValue(): void
diff --git a/tests/Runtime/Exception/LiteralEvaluationFailedExceptionTest.php b/tests/Runtime/Exception/LiteralEvaluationFailedExceptionTest.php
index b9fb5a9..3dc780b 100644
--- a/tests/Runtime/Exception/LiteralEvaluationFailedExceptionTest.php
+++ b/tests/Runtime/Exception/LiteralEvaluationFailedExceptionTest.php
@@ -5,19 +5,18 @@
namespace Remorhaz\JSON\Path\Test\Runtime\Exception;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Runtime\Exception\LiteralEvaluationFailedException;
use Remorhaz\JSON\Path\Value\LiteralValueInterface;
-/**
- * @covers \Remorhaz\JSON\Path\Runtime\Exception\LiteralEvaluationFailedException
- */
+#[CoversClass(LiteralEvaluationFailedException::class)]
class LiteralEvaluationFailedExceptionTest extends TestCase
{
public function testGetMessage_Constructed_ReturnsMatchingValue(): void
{
$exception = new LiteralEvaluationFailedException(
- $this->createMock(LiteralValueInterface::class)
+ $this->createMock(LiteralValueInterface::class),
);
self::assertSame('Failed to evaluate literal value', $exception->getMessage());
}
@@ -29,18 +28,10 @@ public function testGetLiteral_ConstructedWithLiteral_ReturnsSameInstance(): voi
self::assertSame($value, $exception->getLiteral());
}
- public function testGetCode_Always_ReturnZero(): void
- {
- $exception = new LiteralEvaluationFailedException(
- $this->createMock(LiteralValueInterface::class)
- );
- self::assertSame(0, $exception->getCode());
- }
-
public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void
{
$exception = new LiteralEvaluationFailedException(
- $this->createMock(LiteralValueInterface::class)
+ $this->createMock(LiteralValueInterface::class),
);
self::assertNull($exception->getPrevious());
}
@@ -50,7 +41,7 @@ public function testGetPrevious_ConstructedWithPrevious_ReturnsSameInstance(): v
$previous = new Exception();
$exception = new LiteralEvaluationFailedException(
$this->createMock(LiteralValueInterface::class),
- $previous
+ $previous,
);
self::assertSame($previous, $exception->getPrevious());
}
diff --git a/tests/Runtime/Exception/UnexpectedNodeValueFetchedExceptionTest.php b/tests/Runtime/Exception/UnexpectedNodeValueFetchedExceptionTest.php
index 5962203..7120f74 100644
--- a/tests/Runtime/Exception/UnexpectedNodeValueFetchedExceptionTest.php
+++ b/tests/Runtime/Exception/UnexpectedNodeValueFetchedExceptionTest.php
@@ -5,19 +5,18 @@
namespace Remorhaz\JSON\Path\Test\Runtime\Exception;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Value\NodeValueInterface;
use Remorhaz\JSON\Path\Runtime\Exception\UnexpectedNodeValueFetchedException;
-/**
- * @covers \Remorhaz\JSON\Path\Runtime\Exception\UnexpectedNodeValueFetchedException
- */
+#[CoversClass(UnexpectedNodeValueFetchedException::class)]
class UnexpectedNodeValueFetchedExceptionTest extends TestCase
{
public function testGetMessage_Constructed_ReturnsMatchingValue(): void
{
$exception = new UnexpectedNodeValueFetchedException(
- $this->createMock(NodeValueInterface::class)
+ $this->createMock(NodeValueInterface::class),
);
self::assertSame('Unexpected node value fetched', $exception->getMessage());
}
@@ -29,18 +28,10 @@ public function testGetValue_ConstructedWithValue_ReturnsSameInstance(): void
self::assertSame($value, $exception->getValue());
}
- public function testGetCode_Always_ReturnZero(): void
- {
- $exception = new UnexpectedNodeValueFetchedException(
- $this->createMock(NodeValueInterface::class)
- );
- self::assertSame(0, $exception->getCode());
- }
-
public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void
{
$exception = new UnexpectedNodeValueFetchedException(
- $this->createMock(NodeValueInterface::class)
+ $this->createMock(NodeValueInterface::class),
);
self::assertNull($exception->getPrevious());
}
@@ -50,7 +41,7 @@ public function testGetPrevious_ConstructedWithPrevious_ReturnsSameInstance(): v
$previous = new Exception();
$exception = new UnexpectedNodeValueFetchedException(
$this->createMock(NodeValueInterface::class),
- $previous
+ $previous,
);
self::assertSame($previous, $exception->getPrevious());
}
diff --git a/tests/Runtime/Matcher/AnyChildMatcherTest.php b/tests/Runtime/Matcher/AnyChildMatcherTest.php
index b208d86..ea86f6a 100644
--- a/tests/Runtime/Matcher/AnyChildMatcherTest.php
+++ b/tests/Runtime/Matcher/AnyChildMatcherTest.php
@@ -4,13 +4,12 @@
namespace Remorhaz\JSON\Path\Test\Runtime\Matcher;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Value\NodeValueInterface;
use Remorhaz\JSON\Path\Runtime\Matcher\AnyChildMatcher;
-/**
- * @covers \Remorhaz\JSON\Path\Runtime\Matcher\AnyChildMatcher
- */
+#[CoversClass(AnyChildMatcher::class)]
class AnyChildMatcherTest extends TestCase
{
public function testMatch_Always_ReturnsTrue(): void
@@ -19,7 +18,7 @@ public function testMatch_Always_ReturnsTrue(): void
$actualValue = $matcher->match(
'',
$this->createMock(NodeValueInterface::class),
- $this->createMock(NodeValueInterface::class)
+ $this->createMock(NodeValueInterface::class),
);
self::assertTrue($actualValue);
}
diff --git a/tests/Runtime/Matcher/Exception/AddressNotSortableExceptionTest.php b/tests/Runtime/Matcher/Exception/AddressNotSortableExceptionTest.php
index f649fdf..3cf8157 100644
--- a/tests/Runtime/Matcher/Exception/AddressNotSortableExceptionTest.php
+++ b/tests/Runtime/Matcher/Exception/AddressNotSortableExceptionTest.php
@@ -5,12 +5,12 @@
namespace Remorhaz\JSON\Path\Test\Runtime\Matcher\Exception;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Runtime\Matcher\Exception\AddressNotSortableException;
-/**
- * @covers \Remorhaz\JSON\Path\Runtime\Matcher\Exception\AddressNotSortableException
- */
+#[CoversClass(AddressNotSortableException::class)]
class AddressNotSortableExceptionTest extends TestCase
{
public function testGetMessage_ConstructedWithAddress_ReturnsMatchingValue(): void
@@ -19,18 +19,19 @@ public function testGetMessage_ConstructedWithAddress_ReturnsMatchingValue(): vo
self::assertSame('Index/property is not sortable: 1', $exception->getMessage());
}
- /**
- * @param $address
- * @param $expectedValue
- * @dataProvider providerGetAddress
- */
- public function testGetAddress_ConstructedWithAddress_ReturnsSameValue($address, $expectedValue): void
- {
+ #[DataProvider('providerGetAddress')]
+ public function testGetAddress_ConstructedWithAddress_ReturnsSameValue(
+ int|string $address,
+ int|string $expectedValue,
+ ): void {
$exception = new AddressNotSortableException($address);
self::assertSame($expectedValue, $exception->getAddress());
}
- public function providerGetAddress(): array
+ /**
+ * @return iterable
+ */
+ public static function providerGetAddress(): iterable
{
return [
'String value' => ['a', 'a'],
diff --git a/tests/Runtime/Matcher/MatcherFactoryTest.php b/tests/Runtime/Matcher/MatcherFactoryTest.php
index d907f48..fbdc17f 100644
--- a/tests/Runtime/Matcher/MatcherFactoryTest.php
+++ b/tests/Runtime/Matcher/MatcherFactoryTest.php
@@ -4,6 +4,7 @@
namespace Remorhaz\JSON\Path\Test\Runtime\Matcher;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Path\PathInterface;
use Remorhaz\JSON\Data\Value\DecodedJson\NodeArrayValue;
@@ -12,9 +13,7 @@
use Remorhaz\JSON\Path\Runtime\Matcher\AnyChildMatcher;
use Remorhaz\JSON\Path\Runtime\Matcher\MatcherFactory;
-/**
- * @covers \Remorhaz\JSON\Path\Runtime\Matcher\MatcherFactory
- */
+#[CoversClass(MatcherFactory::class)]
class MatcherFactoryTest extends TestCase
{
public function testMatchAnyChild_Constructed_ReturnsAnyChildMatcherInstance(): void
@@ -31,7 +30,7 @@ public function testMatchPropertyStrictly_PropertyList_NonExistingPropertyNotMat
->match(
'b',
$this->createMock(NodeValueInterface::class),
- $this->createMock(NodeValueInterface::class)
+ $this->createMock(NodeValueInterface::class),
);
self::assertFalse($actualValue);
}
@@ -44,7 +43,7 @@ public function testMatchPropertyStrictly_PropertyList_ExistingPropertyMatches()
->match(
'a',
$this->createMock(NodeValueInterface::class),
- $this->createMock(NodeValueInterface::class)
+ $this->createMock(NodeValueInterface::class),
);
self::assertTrue($actualValue);
}
@@ -57,7 +56,7 @@ public function testMatchElementStrictly_IndexList_NonExistingIndexNotMatches():
->match(
2,
$this->createMock(NodeValueInterface::class),
- $this->createMock(NodeValueInterface::class)
+ $this->createMock(NodeValueInterface::class),
);
self::assertFalse($actualValue);
}
@@ -70,7 +69,7 @@ public function testMatchElementStrictly_IndexList_ExistingIndexMatches(): void
->match(
1,
$this->createMock(NodeValueInterface::class),
- $this->createMock(NodeValueInterface::class)
+ $this->createMock(NodeValueInterface::class),
);
self::assertTrue($actualValue);
}
@@ -86,8 +85,8 @@ public function testMatchElementSlice_Slice_NonMatchingIndexNotMatches(): void
new NodeArrayValue(
['a', 'b'],
$this->createMock(PathInterface::class),
- $this->createMock(NodeValueFactoryInterface::class)
- )
+ $this->createMock(NodeValueFactoryInterface::class),
+ ),
);
self::assertFalse($actualValue);
}
@@ -103,8 +102,8 @@ public function testMatchElementSlice_Slice_MatchingIndexMatches(): void
new NodeArrayValue(
['a', 'b'],
$this->createMock(PathInterface::class),
- $this->createMock(NodeValueFactoryInterface::class)
- )
+ $this->createMock(NodeValueFactoryInterface::class),
+ ),
);
self::assertTrue($actualValue);
}
diff --git a/tests/Runtime/Matcher/SliceElementMatcherTest.php b/tests/Runtime/Matcher/SliceElementMatcherTest.php
index cf7f91b..d6c3ba3 100644
--- a/tests/Runtime/Matcher/SliceElementMatcherTest.php
+++ b/tests/Runtime/Matcher/SliceElementMatcherTest.php
@@ -4,6 +4,8 @@
namespace Remorhaz\JSON\Path\Test\Runtime\Matcher;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Path\PathInterface;
use Remorhaz\JSON\Data\Value\DecodedJson\NodeArrayValue;
@@ -13,9 +15,7 @@
use function array_fill;
-/**
- * @covers \Remorhaz\JSON\Path\Runtime\Matcher\SliceElementMatcher
- */
+#[CoversClass(SliceElementMatcher::class)]
class SliceElementMatcherTest extends TestCase
{
public function testMatch_MatchingIndexNonArrayContainer_ReturnsFalse(): void
@@ -24,36 +24,32 @@ public function testMatch_MatchingIndexNonArrayContainer_ReturnsFalse(): void
$actualValue = $matcher->match(
0,
$this->createMock(NodeValueInterface::class),
- $this->createMock(NodeValueInterface::class)
+ $this->createMock(NodeValueInterface::class),
);
self::assertFalse($actualValue);
}
- /**
- * @param int|null $start
- * @param int|null $end
- * @param int|null $step
- * @param $address
- * @param $elementCount
- * @dataProvider providerNonMatchingIndex
- */
+ #[DataProvider('providerNonMatchingIndex')]
public function testMatch_NonMatchingIndexArrayContainer_ReturnsFalse(
?int $start,
?int $end,
?int $step,
- $address,
- $elementCount
+ int|string $address,
+ int $elementCount,
): void {
$matcher = new SliceElementMatcher($start, $end, $step);
$actualValue = $matcher->match(
$address,
$this->createMock(NodeValueInterface::class),
- $this->createArrayValueOfLength($elementCount)
+ $this->createArrayValueOfLength($elementCount),
);
self::assertFalse($actualValue);
}
- public function providerNonMatchingIndex(): array
+ /**
+ * @return iterable
+ */
+ public static function providerNonMatchingIndex(): iterable
{
return [
'Zero step, int address, non-empty container' => [null, null, 0, 1, 2],
@@ -85,31 +81,27 @@ private function createArrayValueOfLength(int $length): NodeValueInterface
);
}
- /**
- * @param int|null $start
- * @param int|null $end
- * @param int|null $step
- * @param $address
- * @param $elementCount
- * @dataProvider providerMatchingIndex
- */
+ #[DataProvider('providerMatchingIndex')]
public function testMatch_MatchingIndex_ReturnsTrue(
?int $start,
?int $end,
?int $step,
- $address,
- $elementCount
+ int|string $address,
+ int $elementCount,
): void {
$matcher = new SliceElementMatcher($start, $end, $step);
$actualValue = $matcher->match(
$address,
$this->createMock(NodeValueInterface::class),
- $this->createArrayValueOfLength($elementCount)
+ $this->createArrayValueOfLength($elementCount),
);
self::assertTrue($actualValue);
}
- public function providerMatchingIndex(): array
+ /**
+ * @return iterable
+ */
+ public static function providerMatchingIndex(): iterable
{
return [
'At container start (straight range)' => [null, null, 1, 0, 2],
diff --git a/tests/Runtime/Matcher/StrictElementMatcherTest.php b/tests/Runtime/Matcher/StrictElementMatcherTest.php
index 2c130df..d59c6ff 100644
--- a/tests/Runtime/Matcher/StrictElementMatcherTest.php
+++ b/tests/Runtime/Matcher/StrictElementMatcherTest.php
@@ -4,13 +4,13 @@
namespace Remorhaz\JSON\Path\Test\Runtime\Matcher;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Value\NodeValueInterface;
use Remorhaz\JSON\Path\Runtime\Matcher\StrictElementMatcher;
-/**
- * @covers \Remorhaz\JSON\Path\Runtime\Matcher\StrictElementMatcher
- */
+#[CoversClass(StrictElementMatcher::class)]
class StrictElementMatcherTest extends TestCase
{
public function testMatch_ConstructedWithGivenAddressInIndexes_ReturnsTrue(): void
@@ -19,28 +19,33 @@ public function testMatch_ConstructedWithGivenAddressInIndexes_ReturnsTrue(): vo
$actualValue = $matcher->match(
1,
$this->createMock(NodeValueInterface::class),
- $this->createMock(NodeValueInterface::class)
+ $this->createMock(NodeValueInterface::class),
);
self::assertTrue($actualValue);
}
/**
- * @param array $indexes
- * @param $address
- * @dataProvider providerNoAddressAmongIndexes
+ * @param list $indexes
+ * @param int|string $address
*/
- public function testMatch_ConstructedWithoutGivenAddressInIndexes_ReturnsFalse(array $indexes, $address): void
- {
+ #[DataProvider('providerNoAddressAmongIndexes')]
+ public function testMatch_ConstructedWithoutGivenAddressInIndexes_ReturnsFalse(
+ array $indexes,
+ int|string $address,
+ ): void {
$matcher = new StrictElementMatcher(...$indexes);
$actualValue = $matcher->match(
$address,
$this->createMock(NodeValueInterface::class),
- $this->createMock(NodeValueInterface::class)
+ $this->createMock(NodeValueInterface::class),
);
self::assertFalse($actualValue);
}
- public function providerNoAddressAmongIndexes(): array
+ /**
+ * @return iterable, int|string}>
+ */
+ public static function providerNoAddressAmongIndexes(): iterable
{
return [
'Index not listed' => [[], 1],
diff --git a/tests/Runtime/Matcher/StrictPropertyMatcherTest.php b/tests/Runtime/Matcher/StrictPropertyMatcherTest.php
index 7296197..a962d0d 100644
--- a/tests/Runtime/Matcher/StrictPropertyMatcherTest.php
+++ b/tests/Runtime/Matcher/StrictPropertyMatcherTest.php
@@ -4,13 +4,13 @@
namespace Remorhaz\JSON\Path\Test\Runtime\Matcher;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Value\NodeValueInterface;
use Remorhaz\JSON\Path\Runtime\Matcher\StrictPropertyMatcher;
-/**
- * @covers \Remorhaz\JSON\Path\Runtime\Matcher\StrictPropertyMatcher
- */
+#[CoversClass(StrictPropertyMatcher::class)]
class StrictPropertyMatcherTest extends TestCase
{
public function testMatch_ConstructedWithGivenAddressInProperties_ReturnsTrue(): void
@@ -19,28 +19,31 @@ public function testMatch_ConstructedWithGivenAddressInProperties_ReturnsTrue():
$actualValue = $matcher->match(
'a',
$this->createMock(NodeValueInterface::class),
- $this->createMock(NodeValueInterface::class)
+ $this->createMock(NodeValueInterface::class),
);
self::assertTrue($actualValue);
}
/**
- * @param array $properties
- * @param $address
- * @dataProvider providerNoAddressAmongProperties
+ * @param list $properties
+ * @param int|string $address
*/
+ #[DataProvider('providerNoAddressAmongProperties')]
public function testMatch_ConstructedWithoutGivenAddressInProperties_ReturnsFalse(array $properties, $address): void
{
$matcher = new StrictPropertyMatcher(...$properties);
$actualValue = $matcher->match(
$address,
$this->createMock(NodeValueInterface::class),
- $this->createMock(NodeValueInterface::class)
+ $this->createMock(NodeValueInterface::class),
);
self::assertFalse($actualValue);
}
- public function providerNoAddressAmongProperties(): array
+ /**
+ * @return iterable, int|string}>
+ */
+ public static function providerNoAddressAmongProperties(): iterable
{
return [
'Property not listed' => [[], 'a'],
diff --git a/tests/Runtime/RuntimeTest.php b/tests/Runtime/RuntimeTest.php
index ead0d9c..dd447ae 100644
--- a/tests/Runtime/RuntimeTest.php
+++ b/tests/Runtime/RuntimeTest.php
@@ -4,6 +4,7 @@
namespace Remorhaz\JSON\Path\Test\Runtime;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Runtime\EvaluatorInterface;
use Remorhaz\JSON\Path\Runtime\LiteralFactoryInterface;
@@ -11,9 +12,7 @@
use Remorhaz\JSON\Path\Runtime\Runtime;
use Remorhaz\JSON\Path\Runtime\ValueListFetcherInterface;
-/**
- * @covers \Remorhaz\JSON\Path\Runtime\Runtime
- */
+#[CoversClass(Runtime::class)]
class RuntimeTest extends TestCase
{
public function testGetEvaluator_ConstructedWithGivenEvaluator_ReturnsSameInstance(): void
diff --git a/tests/TokenMatcherTest.php b/tests/TokenMatcherTest.php
index c025750..a042dbc 100644
--- a/tests/TokenMatcherTest.php
+++ b/tests/TokenMatcherTest.php
@@ -2,6 +2,8 @@
namespace Remorhaz\JSON\Path\Test;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\TokenMatcher;
use Remorhaz\JSON\Path\Parser\TokenType;
@@ -10,20 +12,18 @@
use Remorhaz\UniLex\Lexer\TokenReader;
use Remorhaz\UniLex\Unicode\CharBufferFactory;
-/**
- * @covers \Remorhaz\JSON\Path\TokenMatcher
- */
+#[CoversClass(TokenMatcher::class)]
class TokenMatcherTest extends TestCase
{
/**
- * @param string $input
- * @param array $expectedValue
+ * @param string $input
+ * @param list $expectedValue
* @throws UniLexException
- * @dataProvider providerValidInputTokenTypeList
*/
+ #[DataProvider('providerValidInputTokenTypeList')]
public function testMatch_TokenReaderUsedToMatchAllTokensFromValidInput_ProducesMatchingTokenTypeList(
string $input,
- array $expectedValue
+ array $expectedValue,
): void {
$matcher = new TokenMatcher();
$buffer = CharBufferFactory::createFromString($input);
@@ -37,7 +37,10 @@ public function testMatch_TokenReaderUsedToMatchAllTokensFromValidInput_Produces
self::assertSame($expectedValue, $actualValue);
}
- public function providerValidInputTokenTypeList(): array
+ /**
+ * @return iterable}>
+ */
+ public static function providerValidInputTokenTypeList(): iterable
{
return [
"One-symbol name (root)" => ['$', [TokenType::ROOT_ABSOLUTE, TokenType::EOI]],
@@ -248,10 +251,7 @@ public function providerValidInputTokenTypeList(): array
];
}
- /**
- * @param string $input
- * @dataProvider providerInvalidInputTokenTypeList
- */
+ #[DataProvider('providerInvalidInputTokenTypeList')]
public function testMatch_TokenReaderUsedToMatchAllTokensFromInvalidInput_ReturnsFalse(string $input): void
{
$matcher = new TokenMatcher();
@@ -261,7 +261,10 @@ public function testMatch_TokenReaderUsedToMatchAllTokensFromInvalidInput_Return
self::assertFalse($actualValue);
}
- public function providerInvalidInputTokenTypeList(): array
+ /**
+ * @return iterable
+ */
+ public static function providerInvalidInputTokenTypeList(): iterable
{
return [
"Empty input" => [''],
diff --git a/tests/Value/EvaluatedValueListBuilderTest.php b/tests/Value/EvaluatedValueListBuilderTest.php
index 09bca26..a1171e9 100644
--- a/tests/Value/EvaluatedValueListBuilderTest.php
+++ b/tests/Value/EvaluatedValueListBuilderTest.php
@@ -4,12 +4,12 @@
namespace Remorhaz\JSON\Path\Test\Value;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Value\EvaluatedValueListBuilder;
-/**
- * @covers \Remorhaz\JSON\Path\Value\EvaluatedValueListBuilder
- */
+#[CoversClass(EvaluatedValueListBuilder::class)]
class EvaluatedValueListBuilderTest extends TestCase
{
public function testBuild_NoResultsAdded_ReturnsListWithEmptyIndexMap(): void
@@ -27,10 +27,10 @@ public function testBuild_NoResultsAdded_ReturnsEmptyList(): void
}
/**
- * @param bool $result
- * @param bool[] $expectedValues
- * @dataProvider providerResultAdded
+ * @param bool $result
+ * @param list $expectedValues
*/
+ #[DataProvider('providerResultAdded')]
public function testBuild_ResultAdded_ReturnsListWithSameResult(bool $result, array $expectedValues): void
{
$builder = new EvaluatedValueListBuilder();
@@ -39,7 +39,10 @@ public function testBuild_ResultAdded_ReturnsListWithSameResult(bool $result, ar
self::assertSame($expectedValues, $values->getResults());
}
- public function providerResultAdded(): array
+ /**
+ * @return iterable}>
+ */
+ public static function providerResultAdded(): iterable
{
return [
'False' => [false, [false]],
diff --git a/tests/Value/EvaluatedValueListTest.php b/tests/Value/EvaluatedValueListTest.php
index 455b213..c2b43c8 100644
--- a/tests/Value/EvaluatedValueListTest.php
+++ b/tests/Value/EvaluatedValueListTest.php
@@ -4,6 +4,8 @@
namespace Remorhaz\JSON\Path\Test\Value;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Value\ScalarValueInterface;
use Remorhaz\JSON\Data\Value\ValueInterface;
@@ -16,9 +18,7 @@
use function array_map;
use function get_class;
-/**
- * @covers \Remorhaz\JSON\Path\Value\EvaluatedValueList
- */
+#[CoversClass(EvaluatedValueList::class)]
class EvaluatedValueListTest extends TestCase
{
public function testGetIndexMap_ConstructedWithIndexMap_ReturnsSameInstance(): void
@@ -35,19 +35,22 @@ public function testGetResults_ConstructedWithoutResults_ReturnsEmptyArray(): vo
}
/**
- * @param bool[] $results
- * @param bool[] $expectedValues
- * @dataProvider providerResults
+ * @param list $results
+ * @param list $expectedValues
*/
+ #[DataProvider('providerResults')]
public function testGetResults_ConstructedWithResults_ReturnsSameResults(
array $results,
- array $expectedValues
+ array $expectedValues,
): void {
$values = new EvaluatedValueList(new IndexMap(), ...$results);
self::assertSame($expectedValues, $values->getResults());
}
- public function providerResults(): array
+ /**
+ * @return iterable}>
+ */
+ public static function providerResults(): iterable
{
return [
'Single TRUE' => [[true], [true]],
@@ -64,21 +67,24 @@ public function testGetResult_NonExistingIndex_ThrowsException(): void
}
/**
- * @param bool[] $results
- * @param int $index
- * @param bool $expectedValue
- * @dataProvider providerResult
+ * @param list $results
+ * @param int $index
+ * @param bool $expectedValue
*/
+ #[DataProvider('providerResult')]
public function testGetResult_ExistingIndex_ReturnsMatchingResult(
array $results,
int $index,
- bool $expectedValue
+ bool $expectedValue,
): void {
$values = new EvaluatedValueList(new IndexMap(), ...$results);
self::assertSame($expectedValue, $values->getResult($index));
}
- public function providerResult(): array
+ /**
+ * @return iterable, int, bool}>
+ */
+ public static function providerResult(): iterable
{
return [
'First FALSE' => [[false, true], 0, false],
@@ -94,21 +100,24 @@ public function testGetValue_NonExistingIndex_ThrowsException(): void
}
/**
- * @param bool[] $results
- * @param int $index
- * @param array $expectedValue
- * @dataProvider providerValue
+ * @param list $results
+ * @param int $index
+ * @param array $expectedValue
*/
+ #[DataProvider('providerValue')]
public function testGetValue_ExistingIndex_ReturnsMatchingValue(
array $results,
int $index,
- array $expectedValue
+ array $expectedValue,
): void {
$values = new EvaluatedValueList(new IndexMap(), ...$results);
self::assertSame($expectedValue, $this->exportValue($values->getValue($index)));
}
- public function providerValue(): array
+ /**
+ * @return iterable, int, array}>
+ */
+ public static function providerValue(): iterable
{
return [
'First FALSE' => [
@@ -144,19 +153,22 @@ public function testGetValues_ConstructedWithoutResults_ReturnsEmptyArray(): voi
}
/**
- * @param array $results
- * @param array $expectedValues
- * @dataProvider providerGetValues
+ * @param list $results
+ * @param array $expectedValues
*/
+ #[DataProvider('providerGetValues')]
public function testGetValues_ConstructedWithResults_ReturnsMatchingValues(
array $results,
- array $expectedValues
+ array $expectedValues,
): void {
$values = new EvaluatedValueList(new IndexMap(), ...$results);
self::assertSame($expectedValues, $this->exportValues(...$values->getValues()));
}
- public function providerGetValues(): array
+ /**
+ * @return iterable, array}>
+ */
+ public static function providerGetValues(): iterable
{
return [
'Two different results' => [
@@ -192,6 +204,6 @@ private function exportValue(ValueInterface $value): array
private function exportValues(ValueInterface ...$values): array
{
- return array_map([$this, 'exportValue'], $values);
+ return array_map($this->exportValue(...), $values);
}
}
diff --git a/tests/Value/EvaluatedValueTest.php b/tests/Value/EvaluatedValueTest.php
index 2c7a6a8..e27fcec 100644
--- a/tests/Value/EvaluatedValueTest.php
+++ b/tests/Value/EvaluatedValueTest.php
@@ -4,26 +4,25 @@
namespace Remorhaz\JSON\Path\Test\Value;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Value\EvaluatedValue;
-/**
- * @covers \Remorhaz\JSON\Path\Value\EvaluatedValue
- */
+#[CoversClass(EvaluatedValue::class)]
class EvaluatedValueTest extends TestCase
{
- /**
- * @param bool $value
- * @param bool $expectedValue
- * @dataProvider providerGetData
- */
+ #[DataProvider('providerGetData')]
public function testGetData_ConstructedWithGivenValue_ReturnsSameValue(bool $value, bool $expectedValue): void
{
$value = new EvaluatedValue($value);
self::assertSame($expectedValue, $value->getData());
}
- public function providerGetData(): array
+ /**
+ * @return iterable
+ */
+ public static function providerGetData(): iterable
{
return [
'TRUE' => [true, true],
diff --git a/tests/Value/Exception/InvalidScalarDataExceptionTest.php b/tests/Value/Exception/InvalidScalarDataExceptionTest.php
index dab2177..10819c2 100644
--- a/tests/Value/Exception/InvalidScalarDataExceptionTest.php
+++ b/tests/Value/Exception/InvalidScalarDataExceptionTest.php
@@ -5,12 +5,11 @@
namespace Remorhaz\JSON\Path\Test\Value\Exception;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Value\Exception\InvalidScalarDataException;
-/**
- * @covers \Remorhaz\JSON\Path\Value\Exception\InvalidScalarDataException
- */
+#[CoversClass(InvalidScalarDataException::class)]
class InvalidScalarDataExceptionTest extends TestCase
{
public function testGetMessage_Constructed_ReturnsMatchingValue(): void
@@ -25,12 +24,6 @@ public function testGetData_ConstructedWithGivenData_ReturnsSameValue(): void
self::assertSame([1, 2], $exception->getData());
}
- public function testGetCode_Always_ReturnsZero(): void
- {
- $exception = new InvalidScalarDataException(null);
- self::assertSame(0, $exception->getCode());
- }
-
public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void
{
$exception = new InvalidScalarDataException(null);
diff --git a/tests/Value/Exception/OuterIndexNotFoundExceptionTest.php b/tests/Value/Exception/OuterIndexNotFoundExceptionTest.php
index a11753f..850fbfb 100644
--- a/tests/Value/Exception/OuterIndexNotFoundExceptionTest.php
+++ b/tests/Value/Exception/OuterIndexNotFoundExceptionTest.php
@@ -5,20 +5,19 @@
namespace Remorhaz\JSON\Path\Test\Value\Exception;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Value\Exception\OuterIndexNotFoundException;
use Remorhaz\JSON\Path\Value\IndexMapInterface;
-/**
- * @covers \Remorhaz\JSON\Path\Value\Exception\OuterIndexNotFoundException
- */
+#[CoversClass(OuterIndexNotFoundException::class)]
class OuterIndexNotFoundExceptionTest extends TestCase
{
public function testGetMessage_Constructed_ReturnsMatchingValue(): void
{
$exception = new OuterIndexNotFoundException(
1,
- $this->createMock(IndexMapInterface::class)
+ $this->createMock(IndexMapInterface::class),
);
self::assertSame('Outer index not found in index map for inner index 1', $exception->getMessage());
}
@@ -27,7 +26,7 @@ public function testGetInnerIndex_ConstructedWithGivenInnerIndex_ReturnsSameValu
{
$exception = new OuterIndexNotFoundException(
1,
- $this->createMock(IndexMapInterface::class)
+ $this->createMock(IndexMapInterface::class),
);
self::assertSame(1, $exception->getInnerIndex());
}
@@ -39,20 +38,11 @@ public function testGetIndexMap_ConstructedWithGivenIndexMap_ReturnsSameInstance
self::assertSame($indexMap, $exception->getIndexMap());
}
- public function testGetCode_Always_ReturnsZero(): void
- {
- $exception = new OuterIndexNotFoundException(
- 1,
- $this->createMock(IndexMapInterface::class)
- );
- self::assertSame(0, $exception->getCode());
- }
-
public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void
{
$exception = new OuterIndexNotFoundException(
1,
- $this->createMock(IndexMapInterface::class)
+ $this->createMock(IndexMapInterface::class),
);
self::assertNull($exception->getPrevious());
}
@@ -63,7 +53,7 @@ public function testGetPrevious_ConstructedWithGivenPrevious_ReturnsSameInstance
$exception = new OuterIndexNotFoundException(
1,
$this->createMock(IndexMapInterface::class),
- $previous
+ $previous,
);
self::assertSame($previous, $exception->getPrevious());
}
diff --git a/tests/Value/Exception/ResultNotFoundExceptionTest.php b/tests/Value/Exception/ResultNotFoundExceptionTest.php
index f57ea32..e3b67c5 100644
--- a/tests/Value/Exception/ResultNotFoundExceptionTest.php
+++ b/tests/Value/Exception/ResultNotFoundExceptionTest.php
@@ -5,20 +5,19 @@
namespace Remorhaz\JSON\Path\Test\Value\Exception;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Value\Exception\ResultNotFoundException;
use Remorhaz\JSON\Path\Value\ValueListInterface;
-/**
- * @covers \Remorhaz\JSON\Path\Value\Exception\ResultNotFoundException
- */
+#[CoversClass(ResultNotFoundException::class)]
class ResultNotFoundExceptionTest extends TestCase
{
public function testGetMessage_Constructed_ReturnsMatchingValue(): void
{
$exception = new ResultNotFoundException(
1,
- $this->createMock(ValueListInterface::class)
+ $this->createMock(ValueListInterface::class),
);
self::assertSame('Result not found in list at position 1', $exception->getMessage());
}
@@ -27,7 +26,7 @@ public function testGetIndex_ConstructedWithGivenIndex_ReturnsSameValue(): void
{
$exception = new ResultNotFoundException(
1,
- $this->createMock(ValueListInterface::class)
+ $this->createMock(ValueListInterface::class),
);
self::assertSame(1, $exception->getIndex());
}
@@ -39,20 +38,11 @@ public function testGetValues_ConstructedWithGivenValues_ReturnsSameInstance():
self::assertSame($values, $exception->getValues());
}
- public function testGetCode_Always_ReturnsZero(): void
+ public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void
{
$exception = new ResultNotFoundException(
1,
- $this->createMock(ValueListInterface::class)
- );
- self::assertSame(0, $exception->getCode());
- }
-
- public function testGetPrevious_ConstructedWithouitPrevious_ReturnsNull(): void
- {
- $exception = new ResultNotFoundException(
- 1,
- $this->createMock(ValueListInterface::class)
+ $this->createMock(ValueListInterface::class),
);
self::assertNull($exception->getPrevious());
}
@@ -63,7 +53,7 @@ public function testGetPrevious_ConstructedWithGivenPrevious_ReturnsSameInstance
$exception = new ResultNotFoundException(
1,
$this->createMock(ValueListInterface::class),
- $previous
+ $previous,
);
self::assertSame($previous, $exception->getPrevious());
}
diff --git a/tests/Value/Exception/ValueInListWithAnotherOuterIndexExceptionTest.php b/tests/Value/Exception/ValueInListWithAnotherOuterIndexExceptionTest.php
index 1e52ac7..79a7730 100644
--- a/tests/Value/Exception/ValueInListWithAnotherOuterIndexExceptionTest.php
+++ b/tests/Value/Exception/ValueInListWithAnotherOuterIndexExceptionTest.php
@@ -5,13 +5,12 @@
namespace Remorhaz\JSON\Path\Test\Value\Exception;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Value\NodeValueInterface;
use Remorhaz\JSON\Path\Value\Exception\ValueInListWithAnotherOuterIndexException;
-/**
- * @covers \Remorhaz\JSON\Path\Value\Exception\ValueInListWithAnotherOuterIndexException
- */
+#[CoversClass(ValueInListWithAnotherOuterIndexException::class)]
class ValueInListWithAnotherOuterIndexExceptionTest extends TestCase
{
public function testGetMessage_ConstructedWithIndexes_ReturnsMatchingValue(): void
@@ -42,13 +41,6 @@ public function testGetActualIndex_ConstructedWithActualIndex_ReturnsSameValue()
self::assertSame(2, $exception->getActualIndex());
}
- public function testGetCode_Always_ReturnsZero(): void
- {
- $value = $this->createMock(NodeValueInterface::class);
- $exception = new ValueInListWithAnotherOuterIndexException($value, 1, 2);
- self::assertSame(0, $exception->getCode());
- }
-
public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void
{
$value = $this->createMock(NodeValueInterface::class);
diff --git a/tests/Value/Exception/ValueNotFoundExceptionTest.php b/tests/Value/Exception/ValueNotFoundExceptionTest.php
index 26f15a9..16ec9dc 100644
--- a/tests/Value/Exception/ValueNotFoundExceptionTest.php
+++ b/tests/Value/Exception/ValueNotFoundExceptionTest.php
@@ -5,20 +5,19 @@
namespace Remorhaz\JSON\Path\Test\Value\Exception;
use Exception;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Value\Exception\ValueNotFoundException;
use Remorhaz\JSON\Path\Value\ValueListInterface;
-/**
- * @covers \Remorhaz\JSON\Path\Value\Exception\ValueNotFoundException
- */
+#[CoversClass(ValueNotFoundException::class)]
class ValueNotFoundExceptionTest extends TestCase
{
public function testGetMessage_Constructed_ReturnsMatchingValue(): void
{
$exception = new ValueNotFoundException(
1,
- $this->createMock(ValueListInterface::class)
+ $this->createMock(ValueListInterface::class),
);
self::assertSame('Value not found in list at position 1', $exception->getMessage());
}
@@ -27,7 +26,7 @@ public function testGetIndex_ConstructedWithGivenIndex_ReturnsSameValue(): void
{
$exception = new ValueNotFoundException(
1,
- $this->createMock(ValueListInterface::class)
+ $this->createMock(ValueListInterface::class),
);
self::assertSame(1, $exception->getIndex());
}
@@ -39,20 +38,11 @@ public function testGetValues_ConstructedWithGivenValues_ReturnsSameInstance():
self::assertSame($values, $exception->getValues());
}
- public function testGetCode_Always_ReturnsZero(): void
+ public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void
{
$exception = new ValueNotFoundException(
1,
- $this->createMock(ValueListInterface::class)
- );
- self::assertSame(0, $exception->getCode());
- }
-
- public function testGetPrevious_ConstructedWithouitPrevious_ReturnsNull(): void
- {
- $exception = new ValueNotFoundException(
- 1,
- $this->createMock(ValueListInterface::class)
+ $this->createMock(ValueListInterface::class),
);
self::assertNull($exception->getPrevious());
}
@@ -63,7 +53,7 @@ public function testGetPrevious_ConstructedWithGivenPrevious_ReturnsSameInstance
$exception = new ValueNotFoundException(
1,
$this->createMock(ValueListInterface::class),
- $previous
+ $previous,
);
self::assertSame($previous, $exception->getPrevious());
}
diff --git a/tests/Value/IndexMapTest.php b/tests/Value/IndexMapTest.php
index df522f1..95fda8d 100644
--- a/tests/Value/IndexMapTest.php
+++ b/tests/Value/IndexMapTest.php
@@ -4,29 +4,32 @@
namespace Remorhaz\JSON\Path\Test\Value;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Value\Exception\OuterIndexNotFoundException;
use Remorhaz\JSON\Path\Value\IndexMap;
-/**
- * @covers \Remorhaz\JSON\Path\Value\IndexMap
- */
+#[CoversClass(IndexMap::class)]
class IndexMapTest extends TestCase
{
/**
- * @param array $outerIndexes
- * @param array $expectedValue
- * @dataProvider providerGetOuterIndexes
+ * @param list $outerIndexes
+ * @param list $expectedValue
*/
+ #[DataProvider('providerGetOuterIndexes')]
public function testGetOuterIndexes_ConstructedWithOuterIndexes_ReturnsSameValuesInArray(
array $outerIndexes,
- array $expectedValue
+ array $expectedValue,
): void {
$map = new IndexMap(...$outerIndexes);
self::assertSame($expectedValue, $map->getOuterIndexes());
}
- public function providerGetOuterIndexes(): array
+ /**
+ * @return iterable
+ */
+ public static function providerGetOuterIndexes(): iterable
{
return [
'Empty map' => [[], []],
@@ -37,19 +40,22 @@ public function providerGetOuterIndexes(): array
}
/**
- * @param array $outerIndexes
- * @param int $expectedValue
- * @dataProvider providerCount
+ * @param list $outerIndexes
+ * @param int $expectedValue
*/
+ #[DataProvider('providerCount')]
public function testCount_ConstructedWithOuterIndexes_ReturnsMatchingValue(
array $outerIndexes,
- int $expectedValue
+ int $expectedValue,
): void {
$map = new IndexMap(...$outerIndexes);
self::assertCount($expectedValue, $map);
}
- public function providerCount(): array
+ /**
+ * @return iterable, int}>
+ */
+ public static function providerCount(): iterable
{
return [
'Empty map' => [[], 0],
@@ -60,19 +66,22 @@ public function providerCount(): array
}
/**
- * @param array $outerIndexes
- * @param array $expectedValue
- * @dataProvider providerGetInnerIndexes
+ * @param list $outerIndexes
+ * @param list $expectedValue
*/
+ #[DataProvider('providerGetInnerIndexes')]
public function testGetInnerIndexes_ConstructedWithOuterIndexes_ReturnsMatchingArray(
array $outerIndexes,
- array $expectedValue
+ array $expectedValue,
): void {
$map = new IndexMap(...$outerIndexes);
self::assertSame($expectedValue, $map->getInnerIndexes());
}
- public function providerGetInnerIndexes(): array
+ /**
+ * @return iterable, list}>
+ */
+ public static function providerGetInnerIndexes(): iterable
{
return [
'Empty map' => [[], []],
@@ -115,19 +124,22 @@ public function testOuterIndexExists_OuterIndexNotExists_ReturnsTrue(): void
}
/**
- * @param int[] $outerIndexes
- * @param int[] $expectedValue
- * @dataProvider providerSplit
+ * @param list $outerIndexes
+ * @param list $expectedValue
*/
+ #[DataProvider('providerSplit')]
public function testSplit_ConstructedWithOuterIndexes_ReturnsMatchingMap(
array $outerIndexes,
- array $expectedValue
+ array $expectedValue,
): void {
$map = new IndexMap(...$outerIndexes);
self::assertSame($expectedValue, $map->split()->getOuterIndexes());
}
- public function providerSplit(): array
+ /**
+ * @return iterable, list}>
+ */
+ public static function providerSplit(): iterable
{
return [
'Empty map' => [[], []],
@@ -138,15 +150,15 @@ public function providerSplit(): array
}
/**
- * @param array $mapOuterIndexes
- * @param array $argOuterIndexes
- * @param array $expectedValue
- * @dataProvider providerJoin
+ * @param list $mapOuterIndexes
+ * @param list $argOuterIndexes
+ * @param list $expectedValue
*/
+ #[DataProvider('providerJoin')]
public function testJoin_GivenAnotherMap_ReturnsMatchingMap(
array $mapOuterIndexes,
array $argOuterIndexes,
- array $expectedValue
+ array $expectedValue,
): void {
$map = new IndexMap(...$mapOuterIndexes);
$actualValue = $map
@@ -155,7 +167,10 @@ public function testJoin_GivenAnotherMap_ReturnsMatchingMap(
self::assertSame($expectedValue, $actualValue);
}
- public function providerJoin(): array
+ /**
+ * @return iterable, list, list}>
+ */
+ public static function providerJoin(): iterable
{
return [
'Both maps are empty' => [[], [], []],
@@ -166,20 +181,23 @@ public function providerJoin(): array
}
/**
- * @param array $mapOuterIndexes
- * @param array $argOuterIndexes
- * @dataProvider providerEqualMaps
+ * @param list $mapOuterIndexes
+ * @param list $argOuterIndexes
*/
+ #[DataProvider('providerEqualMaps')]
public function testEquals_EqualMaps_ReturnsTrue(
array $mapOuterIndexes,
- array $argOuterIndexes
+ array $argOuterIndexes,
): void {
$map = new IndexMap(...$mapOuterIndexes);
$actualValue = $map->equals(new IndexMap(...$argOuterIndexes));
self::assertTrue($actualValue);
}
- public function providerEqualMaps(): array
+ /**
+ * @return iterable, list}>
+ */
+ public static function providerEqualMaps(): iterable
{
return [
'Empty maps' => [[], []],
@@ -195,20 +213,23 @@ public function testEquals_NotEqualMaps_ReturnsFalse(): void
}
/**
- * @param array $firstOuterIndexes
- * @param array $secondOuterIndexes
- * @dataProvider providerIncompatibleMaps
+ * @param list $firstOuterIndexes
+ * @param list $secondOuterIndexes
*/
+ #[DataProvider('providerIncompatibleMaps')]
public function testIsCompatible_IncompatibleMaps_ReturnsFalse(
array $firstOuterIndexes,
- array $secondOuterIndexes
+ array $secondOuterIndexes,
): void {
$firstMap = new IndexMap(...$firstOuterIndexes);
$secondMap = new IndexMap(...$secondOuterIndexes);
self::assertFalse($firstMap->isCompatible($secondMap));
}
- public function providerIncompatibleMaps(): array
+ /**
+ * @return iterable, list}>
+ */
+ public static function providerIncompatibleMaps(): iterable
{
return [
'Different map sizes' => [[1], [1, 2]],
@@ -217,20 +238,23 @@ public function providerIncompatibleMaps(): array
}
/**
- * @param array $firstOuterIndexes
- * @param array $secondOuterIndexes
- * @dataProvider providerCompatibleMaps
+ * @param list $firstOuterIndexes
+ * @param list $secondOuterIndexes
*/
+ #[DataProvider('providerCompatibleMaps')]
public function testIsCompatible_CompatibleMaps_ReturnsTrue(
array $firstOuterIndexes,
- array $secondOuterIndexes
+ array $secondOuterIndexes,
): void {
$firstMap = new IndexMap(...$firstOuterIndexes);
$secondMap = new IndexMap(...$secondOuterIndexes);
self::assertTrue($firstMap->isCompatible($secondMap));
}
- public function providerCompatibleMaps(): array
+ /**
+ * @return iterable, list}>
+ */
+ public static function providerCompatibleMaps(): iterable
{
return [
'Empty maps' => [[], []],
diff --git a/tests/Value/LiteralArrayValueListExceptionTest.php b/tests/Value/LiteralArrayValueListExceptionTest.php
index 47121b8..819eaa1 100644
--- a/tests/Value/LiteralArrayValueListExceptionTest.php
+++ b/tests/Value/LiteralArrayValueListExceptionTest.php
@@ -4,15 +4,14 @@
namespace Remorhaz\JSON\Path\Test\Value;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Value\ArrayValueInterface;
use Remorhaz\JSON\Path\Value\Exception\ValueNotFoundException;
use Remorhaz\JSON\Path\Value\IndexMapInterface;
use Remorhaz\JSON\Path\Value\ValueList;
-/**
- * @covers \Remorhaz\JSON\Path\Value\ValueList
- */
+#[CoversClass(ValueList::class)]
class LiteralArrayValueListExceptionTest extends TestCase
{
public function testGetIndexMap_ConstructedWithGivenIndexMap_ReturnsSameInstance(): void
diff --git a/tests/Value/LiteralArrayValueTest.php b/tests/Value/LiteralArrayValueTest.php
index b8c07bc..e9811db 100644
--- a/tests/Value/LiteralArrayValueTest.php
+++ b/tests/Value/LiteralArrayValueTest.php
@@ -4,15 +4,14 @@
namespace Remorhaz\JSON\Path\Test\Value;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Value\ValueInterface;
use Remorhaz\JSON\Path\Value\LiteralArrayValue;
use function iterator_to_array;
-/**
- * @covers \Remorhaz\JSON\Path\Value\LiteralArrayValue
- */
+#[CoversClass(LiteralArrayValue::class)]
class LiteralArrayValueTest extends TestCase
{
public function testCreateChildIterator_ConstructedWithoutValues_ReturnsEmptyIterator(): void
diff --git a/tests/Value/LiteralScalarValueTest.php b/tests/Value/LiteralScalarValueTest.php
index a73f336..66fc3ee 100644
--- a/tests/Value/LiteralScalarValueTest.php
+++ b/tests/Value/LiteralScalarValueTest.php
@@ -4,13 +4,13 @@
namespace Remorhaz\JSON\Path\Test\Value;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Value\Exception\InvalidScalarDataException;
use Remorhaz\JSON\Path\Value\LiteralScalarValue;
-/**
- * @covers \Remorhaz\JSON\Path\Value\LiteralScalarValue
- */
+#[CoversClass(LiteralScalarValue::class)]
class LiteralScalarValueTest extends TestCase
{
public function testConstruct_InvalidValue_ThrowsException(): void
@@ -19,18 +19,17 @@ public function testConstruct_InvalidValue_ThrowsException(): void
new LiteralScalarValue([]);
}
- /**
- * @param mixed $value
- * @param mixed $expectedValue
- * @dataProvider providerGetData
- */
- public function testGetData_ConstructedWithGivenValue_ReturnsSameValue($value, $expectedValue): void
+ #[DataProvider('providerGetData')]
+ public function testGetData_ConstructedWithGivenValue_ReturnsSameValue(mixed $value, mixed $expectedValue): void
{
$value = new LiteralScalarValue($value);
self::assertSame($expectedValue, $value->getData());
}
- public function providerGetData(): array
+ /**
+ * @return iterable
+ */
+ public static function providerGetData(): iterable
{
return [
'TRUE' => [true, true],
diff --git a/tests/Value/LiteralValueListTest.php b/tests/Value/LiteralValueListTest.php
index a1091ff..ed56c4b 100644
--- a/tests/Value/LiteralValueListTest.php
+++ b/tests/Value/LiteralValueListTest.php
@@ -4,6 +4,7 @@
namespace Remorhaz\JSON\Path\Test\Value;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Path\Value\Exception\ValueNotFoundException;
use Remorhaz\JSON\Path\Value\IndexMap;
@@ -11,9 +12,7 @@
use Remorhaz\JSON\Path\Value\LiteralValueInterface;
use Remorhaz\JSON\Path\Value\LiteralValueList;
-/**
- * @covers \Remorhaz\JSON\Path\Value\LiteralValueList
- */
+#[CoversClass(LiteralValueList::class)]
class LiteralValueListTest extends TestCase
{
public function testGetIndexMap_ConstructedWithGivenIndexMap_ReturnsSameInstance(): void
@@ -21,7 +20,7 @@ public function testGetIndexMap_ConstructedWithGivenIndexMap_ReturnsSameInstance
$indexMap = $this->createMock(IndexMapInterface::class);
$valueList = new LiteralValueList(
$indexMap,
- $this->createMock(LiteralValueInterface::class)
+ $this->createMock(LiteralValueInterface::class),
);
self::assertSame($indexMap, $valueList->getIndexMap());
}
@@ -31,7 +30,7 @@ public function testGetLiteral_ConstructedWithGivenLiteral_ReturnsSameInstance()
$value = $this->createMock(LiteralValueInterface::class);
$valueList = new LiteralValueList(
$this->createMock(IndexMapInterface::class),
- $value
+ $value,
);
self::assertSame($value, $valueList->getLiteral());
}
diff --git a/tests/Value/NodeValueListBuilderTest.php b/tests/Value/NodeValueListBuilderTest.php
index 7cb475d..49131f3 100644
--- a/tests/Value/NodeValueListBuilderTest.php
+++ b/tests/Value/NodeValueListBuilderTest.php
@@ -4,15 +4,14 @@
namespace Remorhaz\JSON\Path\Test\Value;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Path\PathInterface;
use Remorhaz\JSON\Data\Value\NodeValueInterface;
use Remorhaz\JSON\Path\Value\Exception\ValueInListWithAnotherOuterIndexException;
use Remorhaz\JSON\Path\Value\NodeValueListBuilder;
-/**
- * @covers \Remorhaz\JSON\Path\Value\NodeValueListBuilder
- */
+#[CoversClass(NodeValueListBuilder::class)]
class NodeValueListBuilderTest extends TestCase
{
public function testBuild_NoValuesAdded_ReturnsListWithEmptyIndexMap(): void
diff --git a/tests/Value/NodeValueListTest.php b/tests/Value/NodeValueListTest.php
index efbc091..03cba8c 100644
--- a/tests/Value/NodeValueListTest.php
+++ b/tests/Value/NodeValueListTest.php
@@ -4,15 +4,14 @@
namespace Remorhaz\JSON\Path\Test\Value;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Value\NodeValueInterface;
use Remorhaz\JSON\Path\Value\Exception\ValueNotFoundException;
use Remorhaz\JSON\Path\Value\IndexMapInterface;
use Remorhaz\JSON\Path\Value\NodeValueList;
-/**
- * @covers \Remorhaz\JSON\Path\Value\NodeValueList
- */
+#[CoversClass(NodeValueList::class)]
class NodeValueListTest extends TestCase
{
public function testGetIndexMap_ConstructedWithGivenIndexMapInstance_ReturnsSameInstance(): void
@@ -35,7 +34,7 @@ public function testGetValues_ConstructedWithTwoValues_ReturnsSameInstances(): v
$valueList = new NodeValueList(
$this->createMock(IndexMapInterface::class),
$firstValue,
- $secondValue
+ $secondValue,
);
self::assertSame([$firstValue, $secondValue], $valueList->getValues());
}
@@ -45,7 +44,7 @@ public function testGeValue_ValueExistsAtGivenIndex_ReturnsMatchingInstance(): v
$value = $this->createMock(NodeValueInterface::class);
$valueList = new NodeValueList(
$this->createMock(IndexMapInterface::class),
- $value
+ $value,
);
self::assertSame($value, $valueList->getValue(0));
}
diff --git a/tests/Value/ValueListBuilderTest.php b/tests/Value/ValueListBuilderTest.php
index c214fe5..d0f1ed2 100644
--- a/tests/Value/ValueListBuilderTest.php
+++ b/tests/Value/ValueListBuilderTest.php
@@ -4,13 +4,12 @@
namespace Remorhaz\JSON\Path\Test\Value;
+use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Remorhaz\JSON\Data\Value\ValueInterface;
use Remorhaz\JSON\Path\Value\ValueListBuilder;
-/**
- * @covers \Remorhaz\JSON\Path\Value\ValueListBuilder
- */
+#[CoversClass(ValueListBuilder::class)]
class ValueListBuilderTest extends TestCase
{
public function testBuild_NoValuesAdded_ReturnsListWithEmptyIndexMap(): void
diff --git a/vendor-bin/cs/composer.json b/vendor-bin/cs/composer.json
new file mode 100644
index 0000000..05a4dfe
--- /dev/null
+++ b/vendor-bin/cs/composer.json
@@ -0,0 +1,5 @@
+{
+ "require-dev": {
+ "squizlabs/php_codesniffer": "^3.8.1"
+ }
+}