diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fd03c2d..e20a23a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,9 +12,9 @@ jobs: fail-fast: false matrix: php-version: - - "8.0" - "8.1" - "8.2" + - "8.3" os: - ubuntu-latest - macOS-latest @@ -36,6 +36,9 @@ jobs: coverage: xdebug ini-values: error_reporting=E_ALL + - name: Install PHIVE + uses: szepeviktor/phive@v1 + - name: Install dependencies run: composer update --prefer-dist diff --git a/.gitignore b/.gitignore index c97a28e..805aaba 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ /build/ /vendor/ /composer.lock +/tools/ +/vendor-bin/**/vendor/ +/vendor-bin/**/composer.lock .phpunit.result.cache 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 b71054c..8fa9053 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] +### Removed +- Dropped PHP 8.0 support. +### Added +- Added PHP 8.3 support. + ## [0.7.0] - 2023-09-19 ### Removed - Dropped PHP 7 support. diff --git a/composer.json b/composer.json index 2d44d0a..dd02179 100644 --- a/composer.json +++ b/composer.json @@ -17,14 +17,13 @@ } ], "require": { - "php": "~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0", - "remorhaz/php-json-data": "^0.6", - "remorhaz/php-unilex": "^0.5.2" + "php": "~8.1.0 || ~8.2.0 || ~8.3.0", + "remorhaz/php-json-data": "^0.7", + "remorhaz/php-unilex": "^0.5.3" }, "require-dev": { - "phpunit/phpunit": "^9.6.13 || ^10", - "infection/infection": "^0.26.19 || ^0.27.2", - "squizlabs/php_codesniffer": "^3.7.2" + "bamarni/composer-bin-plugin": "^1.8", + "phpunit/phpunit": "^10.1 || ^11" }, "autoload": { "psr-4": { @@ -43,13 +42,18 @@ "remorhaz/php-json-patch": "Uses JSON Pointers to implement the declarative way of altering JSON data (RFC-6902)" }, "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=\"JSON Pointer token matcher.\" spec/LexerSpec.php generated/TokenMatcher.php", "vendor/bin/unilex build-lookup-table --type=LL_1 --symbol=Remorhaz\\\\JSON\\\\Pointer\\\\Parser\\\\SymbolType --token=Remorhaz\\\\JSON\\\\Pointer\\\\Parser\\\\TokenType --desc=\"JSON Pointer 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-clover=build/logs/clover.xml --coverage-xml=build/logs/coverage-xml --log-junit=build/logs/junit.xml" @@ -61,12 +65,19 @@ "infection": [ "@test-unit", "mkdir -p ./build/logs", - "vendor/bin/infection --coverage=build/logs --threads=4 --no-progress --skip-initial-tests" + "tools/infection --coverage=build/logs --threads=4 --no-progress --skip-initial-tests" ] }, "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 4bb810f..a3e8597 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,14 +4,21 @@ services: php: build: context: . - dockerfile: php-8.0.Dockerfile + dockerfile: php-8.1.Dockerfile volumes: - .:/app working_dir: /app - php8.0: + php8.2: build: context: . - dockerfile: php-8.0.Dockerfile + dockerfile: php-8.2.Dockerfile + volumes: + - .:/app + working_dir: /app + php8.3: + build: + context: . + dockerfile: php-8.3.Dockerfile volumes: - .:/app working_dir: /app diff --git a/php-8.0.Dockerfile b/php-8.0.Dockerfile deleted file mode 100644 index 9b2d835..0000000 --- a/php-8.0.Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -FROM php:8.0-cli - -RUN apt-get update && apt-get install -y \ - zip \ - git \ - libicu-dev && \ - pecl install -o -f 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 '*' diff --git a/php-8.1.Dockerfile b/php-8.1.Dockerfile new file mode 100644 index 0000000..5df62cd --- /dev/null +++ b/php-8.1.Dockerfile @@ -0,0 +1,27 @@ +FROM php:8.1-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/php-8.2.Dockerfile b/php-8.2.Dockerfile new file mode 100644 index 0000000..5794eeb --- /dev/null +++ b/php-8.2.Dockerfile @@ -0,0 +1,27 @@ +FROM php:8.2-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/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 5268f66..8c4d4da 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,22 +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" + colors="true" + cacheDirectory="build/.phpunit.cache" + requireCoverageMetadata="true"> + + + tests/ + + + + + src/ + generated/ + + + generated/LookupTable.php + + diff --git a/src/Locator/Exception/LocatorAlreadyBuiltException.php b/src/Locator/Exception/LocatorAlreadyBuiltException.php index 8cb3396..e612ace 100644 --- a/src/Locator/Exception/LocatorAlreadyBuiltException.php +++ b/src/Locator/Exception/LocatorAlreadyBuiltException.php @@ -11,6 +11,6 @@ final class LocatorAlreadyBuiltException extends LogicException implements Excep { public function __construct(?Throwable $previous = null) { - parent::__construct("Locator is already built", 0, $previous); + parent::__construct("Locator is already built", previous: $previous); } } diff --git a/src/Locator/IndexReference.php b/src/Locator/IndexReference.php index bb86f6d..250270f 100644 --- a/src/Locator/IndexReference.php +++ b/src/Locator/IndexReference.php @@ -7,7 +7,7 @@ final class IndexReference implements IndexReferenceInterface { public function __construct( - private int $elementIndex, + private readonly int $elementIndex, ) { } diff --git a/src/Locator/ListedReference.php b/src/Locator/ListedReference.php index 2cc3a42..e0a3a96 100644 --- a/src/Locator/ListedReference.php +++ b/src/Locator/ListedReference.php @@ -7,8 +7,8 @@ final class ListedReference implements ListedReferenceInterface { public function __construct( - private ReferenceInterface $reference, - private bool $isLast, + private readonly ReferenceInterface $reference, + private readonly bool $isLast, ) { } diff --git a/src/Locator/Locator.php b/src/Locator/Locator.php index bc089a8..9945d42 100644 --- a/src/Locator/Locator.php +++ b/src/Locator/Locator.php @@ -12,15 +12,23 @@ final class Locator implements LocatorInterface /** * @var list */ - private array $listedReferences; + private readonly array $listedReferences; public function __construct(ReferenceInterface ...$references) + { + $this->listedReferences = $this->buildListedReferences(...$references); + } + + + private function buildListedReferences(ReferenceInterface ...$references): array { $listSize = count($references); - $this->listedReferences = []; + $listedReferences = []; foreach (array_values($references) as $index => $reference) { - $this->listedReferences[] = new ListedReference($reference, $index + 1 == $listSize); + $listedReferences[] = new ListedReference($reference, $index + 1 == $listSize); } + + return $listedReferences; } /** diff --git a/src/Locator/LocatorBuilder.php b/src/Locator/LocatorBuilder.php index f1d93c1..de3bcbc 100644 --- a/src/Locator/LocatorBuilder.php +++ b/src/Locator/LocatorBuilder.php @@ -23,7 +23,7 @@ public static function create(): LocatorBuilderInterface } public function __construct( - private ReferenceFactoryInterface $referenceFactory, + private readonly ReferenceFactoryInterface $referenceFactory, ) { } diff --git a/src/Locator/PropertyReference.php b/src/Locator/PropertyReference.php index 12d2a37..a63b2ed 100644 --- a/src/Locator/PropertyReference.php +++ b/src/Locator/PropertyReference.php @@ -7,7 +7,7 @@ final class PropertyReference implements ReferenceInterface { public function __construct( - private string $propertyName, + private readonly string $propertyName, ) { } diff --git a/src/Parser/Exception/LL1ParserNotCreatedException.php b/src/Parser/Exception/LL1ParserNotCreatedException.php index 9f713d8..73584e4 100644 --- a/src/Parser/Exception/LL1ParserNotCreatedException.php +++ b/src/Parser/Exception/LL1ParserNotCreatedException.php @@ -11,6 +11,6 @@ final class LL1ParserNotCreatedException extends LogicException implements Excep { public function __construct(?Throwable $previous = null) { - parent::__construct("Failed to create LL(1) parser", 0, $previous); + parent::__construct("Failed to create LL(1) parser", previous: $previous); } } diff --git a/src/Parser/Parser.php b/src/Parser/Parser.php index 1ba1d22..75028d8 100644 --- a/src/Parser/Parser.php +++ b/src/Parser/Parser.php @@ -21,8 +21,8 @@ public static function create(): ParserInterface } public function __construct( - private Ll1ParserFactoryInterface $ll1ParserFactory, - private ReferenceFactoryInterface $referenceFactory, + private readonly Ll1ParserFactoryInterface $ll1ParserFactory, + private readonly ReferenceFactoryInterface $referenceFactory, ) { } diff --git a/src/Parser/TranslationScheme.php b/src/Parser/TranslationScheme.php index 127c6f9..f654865 100644 --- a/src/Parser/TranslationScheme.php +++ b/src/Parser/TranslationScheme.php @@ -13,7 +13,7 @@ final class TranslationScheme implements TranslationSchemeInterface { public function __construct( - private LocatorBuilderInterface $locatorBuilder, + private readonly LocatorBuilderInterface $locatorBuilder, ) { } diff --git a/src/Processor/Mutator/AppendElementMutation.php b/src/Processor/Mutator/AppendElementMutation.php index 5260a52..44e8e1f 100644 --- a/src/Processor/Mutator/AppendElementMutation.php +++ b/src/Processor/Mutator/AppendElementMutation.php @@ -19,9 +19,9 @@ final class AppendElementMutation implements MutationInterface private int $elementCounter = 0; public function __construct( - private NodeValueInterface $value, - private PathInterface $path, - private ?int $elementIndex = null, + private readonly NodeValueInterface $value, + private readonly PathInterface $path, + private readonly ?int $elementIndex = null, ) { } diff --git a/src/Processor/Mutator/AppendPropertyMutation.php b/src/Processor/Mutator/AppendPropertyMutation.php index cbc57de..3414a9d 100644 --- a/src/Processor/Mutator/AppendPropertyMutation.php +++ b/src/Processor/Mutator/AppendPropertyMutation.php @@ -17,9 +17,9 @@ final class AppendPropertyMutation implements MutationInterface { public function __construct( - private NodeValueInterface $value, - private PathInterface $path, - private string $propertyName, + private readonly NodeValueInterface $value, + private readonly PathInterface $path, + private readonly string $propertyName, ) { } diff --git a/src/Processor/Mutator/DeleteElementMutation.php b/src/Processor/Mutator/DeleteElementMutation.php index 4257ff5..34e2e1c 100644 --- a/src/Processor/Mutator/DeleteElementMutation.php +++ b/src/Processor/Mutator/DeleteElementMutation.php @@ -25,8 +25,8 @@ final class DeleteElementMutation implements MutationInterface private EventDecoder $eventDecoder; public function __construct( - private PathInterface $arrayPath, - private PathInterface $elementPath, + private readonly PathInterface $arrayPath, + private readonly PathInterface $elementPath, ) { $this->eventDecoder = new EventDecoder(); } @@ -85,8 +85,6 @@ public function __invoke(EventInterface $event, ValueWalkerInterface $valueWalke ->copyWithElement($this->elementCounter) ); } - - return; } public function reset(): void diff --git a/src/Processor/Mutator/DeletePropertyMutation.php b/src/Processor/Mutator/DeletePropertyMutation.php index 4d67b48..943a735 100644 --- a/src/Processor/Mutator/DeletePropertyMutation.php +++ b/src/Processor/Mutator/DeletePropertyMutation.php @@ -13,7 +13,7 @@ final class DeletePropertyMutation implements MutationInterface { public function __construct( - private PathInterface $path, + private readonly PathInterface $path, ) { } diff --git a/src/Processor/Mutator/InsertElementMutation.php b/src/Processor/Mutator/InsertElementMutation.php index 7457552..61ef9f8 100644 --- a/src/Processor/Mutator/InsertElementMutation.php +++ b/src/Processor/Mutator/InsertElementMutation.php @@ -24,9 +24,9 @@ final class InsertElementMutation implements MutationInterface private EventDecoder $eventDecoder; public function __construct( - private NodeValueInterface $value, - private PathInterface $path, - private int $elementIndex, + private readonly NodeValueInterface $value, + private readonly PathInterface $path, + private readonly int $elementIndex, ) { $this->eventDecoder = new EventDecoder(); } diff --git a/src/Processor/Mutator/Mutator.php b/src/Processor/Mutator/Mutator.php index 754d275..7b8c262 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 a472206..ec0ed45 100644 --- a/src/Processor/Mutator/ReplaceMutation.php +++ b/src/Processor/Mutator/ReplaceMutation.php @@ -21,8 +21,8 @@ final class ReplaceMutation implements MutationInterface { public function __construct( - private NodeValueInterface $newNode, - private PathInterface $path, + private readonly NodeValueInterface $newNode, + private readonly PathInterface $path, ) { } diff --git a/src/Processor/Processor.php b/src/Processor/Processor.php index 4542685..8c01ad8 100644 --- a/src/Processor/Processor.php +++ b/src/Processor/Processor.php @@ -48,9 +48,9 @@ public static function create(): ProcessorInterface } public function __construct( - private ValueEncoderInterface $encoder, - private ValueDecoderInterface $decoder, - private MutatorInterface $mutator, + private readonly ValueEncoderInterface $encoder, + private readonly ValueDecoderInterface $decoder, + private readonly MutatorInterface $mutator, ) { } diff --git a/src/Processor/Result/Exception/ResultNotFoundException.php b/src/Processor/Result/Exception/ResultNotFoundException.php index 1e55b38..f6d55ce 100644 --- a/src/Processor/Result/Exception/ResultNotFoundException.php +++ b/src/Processor/Result/Exception/ResultNotFoundException.php @@ -10,10 +10,10 @@ final class ResultNotFoundException extends LogicException implements ExceptionInterface { public function __construct( - private string $source, + private readonly string $source, ?Throwable $previous = null, ) { - parent::__construct("Result not found for query '$this->source'", 0, $previous); + parent::__construct("Result not found for query '$this->source'", previous: $previous); } public function getSource(): string diff --git a/src/Processor/Result/ExistingResult.php b/src/Processor/Result/ExistingResult.php index 14d8119..bcf338c 100644 --- a/src/Processor/Result/ExistingResult.php +++ b/src/Processor/Result/ExistingResult.php @@ -11,9 +11,9 @@ final class ExistingResult implements ResultInterface { public function __construct( - private ValueEncoderInterface $encoder, - private ValueDecoderInterface $decoder, - private NodeValueInterface $nodeValue, + private readonly ValueEncoderInterface $encoder, + private readonly ValueDecoderInterface $decoder, + private readonly NodeValueInterface $nodeValue, ) { } diff --git a/src/Processor/Result/NonExistingResult.php b/src/Processor/Result/NonExistingResult.php index da3af3e..28af74a 100644 --- a/src/Processor/Result/NonExistingResult.php +++ b/src/Processor/Result/NonExistingResult.php @@ -9,7 +9,7 @@ final class NonExistingResult implements ResultInterface { public function __construct( - private string $source, + private readonly string $source, ) { } diff --git a/src/Query/Exception/LastReferenceNotFoundException.php b/src/Query/Exception/LastReferenceNotFoundException.php index b798482..7da64ac 100644 --- a/src/Query/Exception/LastReferenceNotFoundException.php +++ b/src/Query/Exception/LastReferenceNotFoundException.php @@ -10,10 +10,10 @@ final class LastReferenceNotFoundException extends LogicException implements ExceptionInterface { public function __construct( - private string $source, + private readonly string $source, ?Throwable $previous = null, ) { - parent::__construct("Query '$this->source' selected no last reference", 0, $previous); + parent::__construct("Query '$this->source' selected no last reference", previous: $previous); } public function getSource(): string diff --git a/src/Query/Exception/ParentNotFoundException.php b/src/Query/Exception/ParentNotFoundException.php index 6f7c4f2..b3e2046 100644 --- a/src/Query/Exception/ParentNotFoundException.php +++ b/src/Query/Exception/ParentNotFoundException.php @@ -10,10 +10,10 @@ final class ParentNotFoundException extends LogicException implements ExceptionInterface { public function __construct( - private string $source, + private readonly string $source, ?Throwable $previous = null, ) { - parent::__construct("Query '{$this->source}' selected no parent node", 0, $previous); + parent::__construct("Query '$this->source' selected no parent node", previous: $previous); } public function getSource(): string diff --git a/src/Query/Exception/SelectionNotFoundException.php b/src/Query/Exception/SelectionNotFoundException.php index bc0a2fa..94050bb 100644 --- a/src/Query/Exception/SelectionNotFoundException.php +++ b/src/Query/Exception/SelectionNotFoundException.php @@ -10,10 +10,10 @@ final class SelectionNotFoundException extends LogicException implements ExceptionInterface { public function __construct( - private string $source, + private readonly string $source, ?Throwable $previous = null, ) { - parent::__construct("Query '$this->source' produced no selection", 0, $previous); + parent::__construct("Query '$this->source' produced no selection", previous: $previous); } public function getSource(): string diff --git a/src/Query/LazyQuery.php b/src/Query/LazyQuery.php index bd77b85..2baed8d 100644 --- a/src/Query/LazyQuery.php +++ b/src/Query/LazyQuery.php @@ -12,8 +12,8 @@ final class LazyQuery implements QueryInterface private ?QueryInterface $loadedQuery = null; public function __construct( - private string $source, - private ?ParserInterface $parser, + private readonly string $source, + private readonly ?ParserInterface $parser, ) { } diff --git a/src/Query/Query.php b/src/Query/Query.php index eb2c4b2..4f6c2df 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 LocatorInterface $locator, + private readonly string $source, + private readonly LocatorInterface $locator, ) { } diff --git a/src/Query/QueryFactory.php b/src/Query/QueryFactory.php index 44d5df5..43108f3 100644 --- a/src/Query/QueryFactory.php +++ b/src/Query/QueryFactory.php @@ -15,7 +15,7 @@ public static function create(): QueryFactoryInterface } public function __construct( - private ParserInterface $parser, + private readonly ParserInterface $parser, ) { } diff --git a/src/Query/QueryResult.php b/src/Query/QueryResult.php index 6567b53..d55304e 100644 --- a/src/Query/QueryResult.php +++ b/src/Query/QueryResult.php @@ -10,10 +10,10 @@ final class QueryResult implements QueryResultInterface { public function __construct( - private string $source, - private ?NodeValueInterface $selection = null, - private ?NodeValueInterface $parent = null, - private ?ReferenceInterface $lastReference = null, + private readonly string $source, + private readonly ?NodeValueInterface $selection = null, + private readonly ?NodeValueInterface $parent = null, + private readonly ?ReferenceInterface $lastReference = null, ) { } diff --git a/tests/AcceptanceTest.php b/tests/AcceptanceTest.php index 8e4e2b5..5293663 100644 --- a/tests/AcceptanceTest.php +++ b/tests/AcceptanceTest.php @@ -4,6 +4,8 @@ namespace Remorhaz\JSON\Pointer\Test; +use PHPUnit\Framework\Attributes\CoversNothing; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Remorhaz\JSON\Data\Value\EncodedJson\NodeValueFactory; use Remorhaz\JSON\Pointer\Processor\Processor; @@ -13,13 +15,11 @@ * Examples from RFC-6901 * * @see https://tools.ietf.org/html/rfc6901 - * @coversNothing */ +#[CoversNothing] class AcceptanceTest extends TestCase { - /** - * @dataProvider providerSelect - */ + #[DataProvider('providerSelect')] public function testSelect(string $document, string $pointer, string $expectedValue): void { $rootNode = NodeValueFactory::create()->createValue($document); @@ -53,9 +53,7 @@ public static function providerSelect(): iterable ]; } - /** - * @dataProvider providerDelete - */ + #[DataProvider('providerDelete')] public function testDelete(string $document, string $pointer, string $expectedValue): void { $rootNode = NodeValueFactory::create()->createValue($document); @@ -85,9 +83,7 @@ public static function providerDelete(): iterable ]; } - /** - * @dataProvider providerAdd - */ + #[DataProvider('providerAdd')] public function testAdd(string $document, string $pointer, string $value, string $expectedValue): void { $rootNode = NodeValueFactory::create()->createValue($document); diff --git a/tests/Locator/Exception/LocatorAlreadyBuiltExceptionTest.php b/tests/Locator/Exception/LocatorAlreadyBuiltExceptionTest.php index c32c5d7..d4b046a 100644 --- a/tests/Locator/Exception/LocatorAlreadyBuiltExceptionTest.php +++ b/tests/Locator/Exception/LocatorAlreadyBuiltExceptionTest.php @@ -5,12 +5,11 @@ namespace Remorhaz\JSON\Pointer\Test\Locator\Exception; use Exception; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Remorhaz\JSON\Pointer\Locator\Exception\LocatorAlreadyBuiltException; -/** - * @covers \Remorhaz\JSON\Pointer\Locator\Exception\LocatorAlreadyBuiltException - */ +#[CoversClass(LocatorAlreadyBuiltException::class)] class LocatorAlreadyBuiltExceptionTest extends TestCase { public function testGetMessage_Constructed_ReturnsMatchingValue(): void @@ -19,12 +18,6 @@ public function testGetMessage_Constructed_ReturnsMatchingValue(): void self::assertSame('Locator is already built', $exception->getMessage()); } - public function testGetCode_Always_ReturnsZero(): void - { - $exception = new LocatorAlreadyBuiltException(); - self::assertSame(0, $exception->getCode()); - } - public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void { $exception = new LocatorAlreadyBuiltException(); diff --git a/tests/Locator/IndexReferenceTest.php b/tests/Locator/IndexReferenceTest.php index eab254f..9863e37 100644 --- a/tests/Locator/IndexReferenceTest.php +++ b/tests/Locator/IndexReferenceTest.php @@ -4,12 +4,11 @@ namespace Remorhaz\JSON\Pointer\Test\Locator; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Remorhaz\JSON\Pointer\Locator\IndexReference; -/** - * @covers \Remorhaz\JSON\Pointer\Locator\IndexReference - */ +#[CoversClass(IndexReference::class)] class IndexReferenceTest extends TestCase { public function testGetElementIndex_ConstructedWithElementIndex_ReturnsSameValue(): void diff --git a/tests/Locator/ListedReferenceTest.php b/tests/Locator/ListedReferenceTest.php index a91e472..ffe0c56 100644 --- a/tests/Locator/ListedReferenceTest.php +++ b/tests/Locator/ListedReferenceTest.php @@ -4,29 +4,27 @@ namespace Remorhaz\JSON\Pointer\Test\Locator; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Remorhaz\JSON\Pointer\Locator\ListedReference; use Remorhaz\JSON\Pointer\Locator\ReferenceInterface; -/** - * @covers \Remorhaz\JSON\Pointer\Locator\ListedReference - */ +#[CoversClass(ListedReference::class)] class ListedReferenceTest extends TestCase { public function testGetReference_ConstructedWithReference_ReturnsSameInstance(): void { - $reference = $this->createMock(ReferenceInterface::class); + $reference = self::createStub(ReferenceInterface::class); $listedReference = new ListedReference($reference, false); self::assertSame($reference, $listedReference->getReference()); } - /** - * @dataProvider providerIsLast - */ + #[DataProvider('providerIsLast')] public function testIsLast_ConstructedWithValue_ReturnsSameValue(bool $isValue, bool $expectedValue): void { $listedReference = new ListedReference( - $this->createMock(ReferenceInterface::class), + self::createStub(ReferenceInterface::class), $isValue ); self::assertSame($expectedValue, $listedReference->isLast()); diff --git a/tests/Locator/LocatorBuilderTest.php b/tests/Locator/LocatorBuilderTest.php index a99d5bb..c56a56a 100644 --- a/tests/Locator/LocatorBuilderTest.php +++ b/tests/Locator/LocatorBuilderTest.php @@ -4,6 +4,8 @@ namespace Remorhaz\JSON\Pointer\Test\Locator; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Remorhaz\JSON\Pointer\Locator\ListedReferenceInterface; use Remorhaz\JSON\Pointer\Locator\ReferenceFactory; @@ -14,9 +16,7 @@ use function array_map; -/** - * @covers \Remorhaz\JSON\Pointer\Locator\LocatorBuilder - */ +#[CoversClass(LocatorBuilder::class)] class LocatorBuilderTest extends TestCase { public function testCreate_Always_ReturnsLocatorBuilderInstance(): void @@ -26,21 +26,21 @@ public function testCreate_Always_ReturnsLocatorBuilderInstance(): void public function testGetLocator_ReferencesNotAdded_ReturnsEmptyLocator(): void { - $builder = new LocatorBuilder($this->createMock(ReferenceFactoryInterface::class)); + $builder = new LocatorBuilder(self::createStub(ReferenceFactoryInterface::class)); $locator = $builder->getLocator(); self::assertCount(0, $locator->references()); } public function testGetLocator_CalledTwice_ReturnsSameInstance(): void { - $builder = new LocatorBuilder($this->createMock(ReferenceFactoryInterface::class)); + $builder = new LocatorBuilder(self::createStub(ReferenceFactoryInterface::class)); $locator = $builder->getLocator(); self::assertSame($locator, $builder->getLocator()); } public function testAddReference_GetLocatorCalled_ThrowsException(): void { - $builder = new LocatorBuilder($this->createMock(ReferenceFactoryInterface::class)); + $builder = new LocatorBuilder(self::createStub(ReferenceFactoryInterface::class)); $builder->getLocator(); $this->expectException(LocatorAlreadyBuiltException::class); $builder->addReference('a'); @@ -48,7 +48,7 @@ public function testAddReference_GetLocatorCalled_ThrowsException(): void public function testAddReference_ExportCalled_ThrowsException(): void { - $builder = new LocatorBuilder($this->createMock(ReferenceFactoryInterface::class)); + $builder = new LocatorBuilder(self::createStub(ReferenceFactoryInterface::class)); $builder->export(); $this->expectException(LocatorAlreadyBuiltException::class); $builder->addReference('a'); @@ -68,11 +68,11 @@ public function testAddReference_ConstructedWithReferenceFactory_PassesTextToSam public function testAddReference_ConstructedWithReferenceFactory_ResultIsAddedToLocator(): void { - $referenceFactory = $this->createMock(ReferenceFactoryInterface::class); + $referenceFactory = self::createStub(ReferenceFactoryInterface::class); $builder = new LocatorBuilder($referenceFactory); - $firstReference = $this->createMock(ReferenceInterface::class); - $secondReference = $this->createMock(ReferenceInterface::class); + $firstReference = self::createStub(ReferenceInterface::class); + $secondReference = self::createStub(ReferenceInterface::class); $referenceFactory ->method('createReference') ->willReturnOnConsecutiveCalls($firstReference, $secondReference); @@ -83,24 +83,20 @@ public function testAddReference_ConstructedWithReferenceFactory_ResultIsAddedTo ->getLocator() ->references(); $actualValue = array_map( - function (ListedReferenceInterface $listedReference): ReferenceInterface { - return $listedReference->getReference(); - }, - $listedReferences + fn (ListedReferenceInterface $listedReference): ReferenceInterface => $listedReference->getReference(), + $listedReferences, ); self::assertSame([$firstReference, $secondReference], $actualValue); } public function testExport_NoReferencesAdded_ReturnsEmptyPointer(): void { - $referenceFactory = $this->createMock(ReferenceFactoryInterface::class); + $referenceFactory = self::createStub(ReferenceFactoryInterface::class); $builder = new LocatorBuilder($referenceFactory); self::assertSame('', $builder->export()); } - /** - * @dataProvider providerExportSingleReference - */ + #[DataProvider('providerExportSingleReference')] public function testExport_SingleReferenceAdded_ReturnsMatchingPointer(string $text, string $expectedValue): void { $builder = new LocatorBuilder(new ReferenceFactory()); diff --git a/tests/Locator/LocatorTest.php b/tests/Locator/LocatorTest.php index 45f1940..e2110fb 100644 --- a/tests/Locator/LocatorTest.php +++ b/tests/Locator/LocatorTest.php @@ -4,6 +4,8 @@ namespace Remorhaz\JSON\Pointer\Test\Locator; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Remorhaz\JSON\Pointer\Locator\ListedReferenceInterface; use Remorhaz\JSON\Pointer\Locator\Locator; @@ -12,9 +14,7 @@ use function array_fill; use function array_map; -/** - * @covers \Remorhaz\JSON\Pointer\Locator\Locator - */ +#[CoversClass(Locator::class)] class LocatorTest extends TestCase { public function testReferences_ConstructedWithoutReferences_ReturnsEmptyList(): void @@ -25,13 +25,11 @@ public function testReferences_ConstructedWithoutReferences_ReturnsEmptyList(): public function testReferences_ConstructedWithSingleReference_ResultListsSameReferenceInstance(): void { - $reference = $this->createMock(ReferenceInterface::class); + $reference = self::createStub(ReferenceInterface::class); $locator = new Locator($reference); $references = array_map( - function (ListedReferenceInterface $listedReference): ReferenceInterface { - return $listedReference->getReference(); - }, - $locator->references() + fn (ListedReferenceInterface $listedReference): ReferenceInterface => $listedReference->getReference(), + $locator->references(), ); self::assertSame([$reference], $references); } @@ -39,8 +37,8 @@ function (ListedReferenceInterface $listedReference): ReferenceInterface { /** * @param int $referenceCount * @param list $expectedValue - * @dataProvider providerIsLast */ + #[DataProvider('providerIsLast')] public function testReferences_Constructed_ResultListsMatchingIsLastState( int $referenceCount, array $expectedValue, @@ -48,14 +46,12 @@ public function testReferences_Constructed_ResultListsMatchingIsLastState( $references = array_fill( 0, $referenceCount, - $this->createMock(ReferenceInterface::class) + self::createStub(ReferenceInterface::class), ); $locator = new Locator(...$references); $isLastStates = array_map( - function (ListedReferenceInterface $listedReference): bool { - return $listedReference->isLast(); - }, - $locator->references() + fn (ListedReferenceInterface $listedReference): bool => $listedReference->isLast(), + $locator->references(), ); self::assertSame($expectedValue, $isLastStates); } diff --git a/tests/Locator/NextIndexReferenceTest.php b/tests/Locator/NextIndexReferenceTest.php index a1568b7..9fd529e 100644 --- a/tests/Locator/NextIndexReferenceTest.php +++ b/tests/Locator/NextIndexReferenceTest.php @@ -4,12 +4,11 @@ namespace Remorhaz\JSON\Pointer\Test\Locator; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Remorhaz\JSON\Pointer\Locator\NextIndexReference; -/** - * @covers \Remorhaz\JSON\Pointer\Locator\NextIndexReference - */ +#[CoversClass(NextIndexReference::class)] class NextIndexReferenceTest extends TestCase { public function testGetPropertyName_Always_ReturnsHyphen(): void diff --git a/tests/Locator/PropertyReferenceTest.php b/tests/Locator/PropertyReferenceTest.php index 4aa5af0..d85104a 100644 --- a/tests/Locator/PropertyReferenceTest.php +++ b/tests/Locator/PropertyReferenceTest.php @@ -4,12 +4,11 @@ namespace Remorhaz\JSON\Pointer\Test\Locator; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Remorhaz\JSON\Pointer\Locator\PropertyReference; -/** - * @covers \Remorhaz\JSON\Pointer\Locator\PropertyReference - */ +#[CoversClass(PropertyReference::class)] class PropertyReferenceTest extends TestCase { public function testGetPropertyName_ConstructedWithPropertyName_ReturnsSameValue(): void diff --git a/tests/Locator/ReferenceFactoryTest.php b/tests/Locator/ReferenceFactoryTest.php index abcc561..4ad7b3d 100644 --- a/tests/Locator/ReferenceFactoryTest.php +++ b/tests/Locator/ReferenceFactoryTest.php @@ -4,6 +4,8 @@ namespace Remorhaz\JSON\Pointer\Test\Locator; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Remorhaz\JSON\Pointer\Locator\IndexReference; use Remorhaz\JSON\Pointer\Locator\IndexReferenceInterface; @@ -12,18 +14,14 @@ use Remorhaz\JSON\Pointer\Locator\ReferenceFactory; use Remorhaz\JSON\Pointer\Locator\ReferenceInterface; -use function get_class; - -/** - * @covers \Remorhaz\JSON\Pointer\Locator\ReferenceFactory - */ +#[CoversClass(ReferenceFactory::class)] class ReferenceFactoryTest extends TestCase { /** * @param string $text * @param array{class:class-string, propertyName:string, elementIndex?:int} $expectedValue - * @dataProvider providerCreateReference */ + #[DataProvider('providerCreateReference')] public function testCreateReference_GivenText_ReturnsMatchingReference(string $text, array $expectedValue): void { $factory = new ReferenceFactory(); diff --git a/tests/Parser/Exception/LL1ParserNotCreatedExceptionTest.php b/tests/Parser/Exception/LL1ParserNotCreatedExceptionTest.php index af27b04..e914b0d 100644 --- a/tests/Parser/Exception/LL1ParserNotCreatedExceptionTest.php +++ b/tests/Parser/Exception/LL1ParserNotCreatedExceptionTest.php @@ -5,12 +5,11 @@ namespace Remorhaz\JSON\Pointer\Test\Parser\Exception; use Exception; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Remorhaz\JSON\Pointer\Parser\Exception\LL1ParserNotCreatedException; -/** - * @covers \Remorhaz\JSON\Pointer\Parser\Exception\LL1ParserNotCreatedException - */ +#[CoversClass(LL1ParserNotCreatedException::class)] class LL1ParserNotCreatedExceptionTest extends TestCase { public function testGetMessage_Constructed_ReturnsMatchingValue(): void @@ -19,12 +18,6 @@ public function testGetMessage_Constructed_ReturnsMatchingValue(): void self::assertSame('Failed to create LL(1) parser', $exception->getMessage()); } - public function testGetCode_Always_ReturnsZero(): void - { - $exception = new LL1ParserNotCreatedException(); - self::assertSame(0, $exception->getCode()); - } - public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void { $exception = new LL1ParserNotCreatedException(); diff --git a/tests/Parser/ParserTest.php b/tests/Parser/ParserTest.php index e273806..887450d 100644 --- a/tests/Parser/ParserTest.php +++ b/tests/Parser/ParserTest.php @@ -4,6 +4,7 @@ namespace Remorhaz\JSON\Pointer\Test\Parser; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Remorhaz\JSON\Pointer\Locator\ReferenceFactoryInterface; use Remorhaz\JSON\Pointer\Locator\ReferenceInterface; @@ -13,9 +14,7 @@ use Remorhaz\UniLex\Exception as UniLexException; use Remorhaz\UniLex\Parser\LL1\Parser as LL1Parser; -/** - * @covers \Remorhaz\JSON\Pointer\Parser\Parser - */ +#[CoversClass(Parser::class)] class ParserTest extends TestCase { public function testCreate_Always_CreatesParserInstance(): void @@ -31,7 +30,7 @@ public function testBuildLocator_ConstructedWithLL1ParserFactory_PassesPointerTo $ll1ParserFactory = $this->createMock(Ll1ParserFactoryInterface::class); $parser = new Parser( $ll1ParserFactory, - $this->createMock(ReferenceFactoryInterface::class) + self::createStub(ReferenceFactoryInterface::class), ); $ll1ParserFactory @@ -46,10 +45,10 @@ public function testBuildLocator_ConstructedWithLL1ParserFactory_PassesPointerTo */ public function testBuildLocator_ConstructedWithLL1ParserFactory_RunsCreatedParserInstance(): void { - $ll1ParserFactory = $this->createMock(Ll1ParserFactoryInterface::class); + $ll1ParserFactory = self::createStub(Ll1ParserFactoryInterface::class); $parser = new Parser( $ll1ParserFactory, - $this->createMock(ReferenceFactoryInterface::class) + self::createStub(ReferenceFactoryInterface::class), ); $ll1Parser = $this->createMock(LL1Parser::class); @@ -92,7 +91,7 @@ public function testBuildLocator_ReferenceFactoryReturnsValue_ResultHasSameValue { $referenceFactory = $this->createMock(ReferenceFactoryInterface::class); $parser = new Parser(new Ll1ParserFactory(), $referenceFactory); - $reference = $this->createMock(ReferenceInterface::class); + $reference = self::createStub(ReferenceInterface::class); $referenceFactory ->method('createReference') ->willReturn($reference); diff --git a/tests/Parser/TranslationSchemeTest.php b/tests/Parser/TranslationSchemeTest.php index fdf19b5..dd799ca 100644 --- a/tests/Parser/TranslationSchemeTest.php +++ b/tests/Parser/TranslationSchemeTest.php @@ -4,6 +4,8 @@ namespace Remorhaz\JSON\Pointer\Test\Parser; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Remorhaz\JSON\Pointer\Locator\LocatorBuilderInterface; use Remorhaz\JSON\Pointer\Parser\TranslationScheme; @@ -18,19 +20,15 @@ use Remorhaz\UniLex\Parser\LL1\UnexpectedTokenException; use Remorhaz\UniLex\Unicode\CharBufferFactory; -use function count; - -/** - * @covers \Remorhaz\JSON\Pointer\Parser\TranslationScheme - */ +#[CoversClass(TranslationScheme::class)] class TranslationSchemeTest extends TestCase { /** * @param string $source * @param list $expectedValues * @throws UniLexException - * @dataProvider providerValidBuffer */ + #[DataProvider('providerValidBuffer')] public function testTranslation_ValidBuffer_BuildsMatchingLocator(string $source, array $expectedValues): void { $locatorBuilder = $this->createMock(LocatorBuilderInterface::class); @@ -62,12 +60,12 @@ private function createParser(TranslationSchemeInterface $scheme, string $source $reader = new TokenReader( CharBufferFactory::createFromString($source), new TokenMatcher(), - new TokenFactory($grammar) + new TokenFactory($grammar), ); $parser = new Ll1Parser( $grammar, $reader, - new TranslationSchemeApplier($scheme) + new TranslationSchemeApplier($scheme), ); $parser->loadLookupTable(__DIR__ . '/../../generated/LookupTable.php'); @@ -100,11 +98,11 @@ public static function providerValidBuffer(): iterable /** * @param string $source * @throws UniLexException - * @dataProvider providerInvalidBuffer */ + #[DataProvider('providerInvalidBuffer')] public function testTranslation_InvalidBuffer_ThrowsException(string $source): void { - $locatorBuilder = $this->createMock(LocatorBuilderInterface::class); + $locatorBuilder = self::createStub(LocatorBuilderInterface::class); $scheme = new TranslationScheme($locatorBuilder); $parser = $this->createParser($scheme, $source); $this->expectException(UnexpectedTokenException::class); diff --git a/tests/Processor/AcceptanceTest.php b/tests/Processor/AcceptanceTest.php index 67142f0..5338893 100644 --- a/tests/Processor/AcceptanceTest.php +++ b/tests/Processor/AcceptanceTest.php @@ -1,21 +1,19 @@ createQuery($text); $document = NodeValueFactory::create()->createValue($data); @@ -44,10 +42,8 @@ public static function providerSelectExistingData(): iterable ]; } - /** - * @dataProvider providerSelectNonExistingData - */ - public function testSelect_NonExistingData_ResultNotExists(string $text, string $data) + #[DataProvider('providerSelectNonExistingData')] + public function testSelect_NonExistingData_ResultNotExists(string $text, string $data): void { $query = QueryFactory::create()->createQuery($text); $document = NodeValueFactory::create()->createValue($data); @@ -79,11 +75,13 @@ public static function providerSelectNonExistingData(): iterable ]; } - /** - * @dataProvider providerAddableQuery - */ - public function testAdd_AddableQuery_DataAdded(string $data, string $query, string $value, string $expectedData) - { + #[DataProvider('providerAddableQuery')] + public function testAdd_AddableQuery_DataAdded( + string $data, + string $query, + string $value, + string $expectedData, + ): void { $query = QueryFactory::create()->createQuery($query); $nodeValueFactory = NodeValueFactory::create(); $document = $nodeValueFactory->createValue($data); @@ -110,10 +108,8 @@ public static function providerAddableQuery(): iterable ]; } - /** - * @dataProvider providerAddNonExistingSelection - */ - public function testAdd_NonAddableQuery_ResultNotExists(string $data, string $text, string $value) + #[DataProvider('providerAddNonExistingSelection')] + public function testAdd_NonAddableQuery_ResultNotExists(string $data, string $text, string $value): void { $query = QueryFactory::create()->createQuery($text); $nodeValueFactory = NodeValueFactory::create(); @@ -139,10 +135,8 @@ public static function providerAddNonExistingSelection(): iterable ]; } - /** - * @dataProvider providerRemoveExistingData - */ - public function testRemove_ExistingData_Removed(string $text, string $data, string $expectedData) + #[DataProvider('providerRemoveExistingData')] + public function testRemove_ExistingData_Removed(string $text, string $data, string $expectedData): void { $query = QueryFactory::create()->createQuery($text); $document = NodeValueFactory::create()->createValue($data); @@ -190,10 +184,8 @@ public static function providerRemoveExistingData(): iterable ]; } - /** - * @dataProvider providerRemoveNonExistingData - */ - public function testRemove_NonExistingData_ResultNotExists(string $text, string $data) + #[DataProvider('providerRemoveNonExistingData')] + public function testRemove_NonExistingData_ResultNotExists(string $text, string $data): void { $query = QueryFactory::create()->createQuery($text); $document = NodeValueFactory::create()->createValue($data); @@ -217,15 +209,13 @@ public static function providerRemoveNonExistingData(): iterable ]; } - /** - * @dataProvider providerReplaceValueExists - */ + #[DataProvider('providerReplaceValueExists')] public function testReplace_ValueExists_DataReplaced( string $data, string $text, string $value, string $expectedData, - ) { + ): void { $query = QueryFactory::create()->createQuery($text); $nodeValueFactory = NodeValueFactory::create(); $document = $nodeValueFactory->createValue($data); @@ -249,14 +239,12 @@ public static function providerReplaceValueExists(): iterable ]; } - /** - * @dataProvider providerReplaceValueNotExists - */ + #[DataProvider('providerReplaceValueNotExists')] public function testReplace_ValueNotExists_ResultNotExists( string $data, string $text, string $value, - ) { + ): void { $query = QueryFactory::create()->createQuery($text); $nodeValueFactory = NodeValueFactory::create(); $document = $nodeValueFactory->createValue($data); diff --git a/tests/Processor/Mutator/MutatorTest.php b/tests/Processor/Mutator/MutatorTest.php index 3d77995..0c9ed67 100644 --- a/tests/Processor/Mutator/MutatorTest.php +++ b/tests/Processor/Mutator/MutatorTest.php @@ -5,6 +5,7 @@ namespace Remorhaz\JSON\Pointer\Test\Processor\Mutator; use Iterator; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Remorhaz\JSON\Data\Export\EventDecoderInterface; use Remorhaz\JSON\Data\Path\PathInterface; @@ -13,18 +14,16 @@ use Remorhaz\JSON\Data\Walker\ValueWalkerInterface; use Remorhaz\JSON\Pointer\Processor\Mutator\Mutator; -/** - * @covers \Remorhaz\JSON\Pointer\Processor\Mutator\Mutator - */ +#[CoversClass(Mutator::class)] class MutatorTest extends TestCase { public function testMutate_Constructed_DecoderExportsEventsFromWalker(): void { - $valueWalker = $this->createMock(ValueWalkerInterface::class); + $valueWalker = self::createStub(ValueWalkerInterface::class); $eventDecoder = $this->createMock(EventDecoderInterface::class); $mutator = new Mutator($valueWalker, $eventDecoder); - $events = $this->createMock(Iterator::class); + $events = self::createStub(Iterator::class); $valueWalker ->method('createMutableEventIterator') ->willReturn($events); @@ -33,44 +32,44 @@ public function testMutate_Constructed_DecoderExportsEventsFromWalker(): void ->method('exportEvents') ->with($events); $mutator->mutate( - $this->createMock(NodeValueInterface::class), - $this->createMock(MutationInterface::class) + self::createStub(NodeValueInterface::class), + self::createStub(MutationInterface::class), ); } public function testMutate_DecoderReturnsNull_ReturnsNull(): void { - $eventDecoder = $this->createMock(EventDecoderInterface::class); + $eventDecoder = self::createStub(EventDecoderInterface::class); $mutator = new Mutator( - $this->createMock(ValueWalkerInterface::class), - $eventDecoder + self::createStub(ValueWalkerInterface::class), + $eventDecoder, ); $eventDecoder ->method('exportEvents') ->willReturn(null); $actualValue = $mutator->mutate( - $this->createMock(NodeValueInterface::class), - $this->createMock(MutationInterface::class) + self::createStub(NodeValueInterface::class), + self::createStub(MutationInterface::class), ); self::assertNull($actualValue); } public function testMutate_DecoderReturnsValue_ReturnsSameInstance(): void { - $eventDecoder = $this->createMock(EventDecoderInterface::class); + $eventDecoder = self::createStub(EventDecoderInterface::class); $mutator = new Mutator( - $this->createMock(ValueWalkerInterface::class), - $eventDecoder + self::createStub(ValueWalkerInterface::class), + $eventDecoder, ); - $value = $this->createMock(NodeValueInterface::class); + $value = self::createStub(NodeValueInterface::class); $eventDecoder ->method('exportEvents') ->willReturn($value); $actualValue = $mutator->mutate( - $this->createMock(NodeValueInterface::class), - $this->createMock(MutationInterface::class) + self::createStub(NodeValueInterface::class), + self::createStub(MutationInterface::class), ); self::assertSame($value, $actualValue); } @@ -80,10 +79,10 @@ public function testMutate_GivenRootNodeAndMutation_SameInstancesPassedToValueWa $valueWalker = $this->createMock(ValueWalkerInterface::class); $mutator = new Mutator( $valueWalker, - $this->createMock(EventDecoderInterface::class) + self::createStub(EventDecoderInterface::class), ); - $rootValue = $this->createMock(NodeValueInterface::class); - $mutation = $this->createMock(MutationInterface::class); + $rootValue = self::createStub(NodeValueInterface::class); + $mutation = self::createStub(MutationInterface::class); $valueWalker ->expects(self::once()) @@ -91,7 +90,7 @@ public function testMutate_GivenRootNodeAndMutation_SameInstancesPassedToValueWa ->with( self::identicalTo($rootValue), self::anything(), - self::identicalTo($mutation) + self::identicalTo($mutation), ); $mutator->mutate($rootValue, $mutation); } @@ -101,7 +100,7 @@ public function testMutate_ConstructedWithValueWalker_EmptyPathPassedToSameInsta $valueWalker = $this->createMock(ValueWalkerInterface::class); $mutator = new Mutator( $valueWalker, - $this->createMock(EventDecoderInterface::class) + self::createStub(EventDecoderInterface::class), ); $valueWalker @@ -109,16 +108,12 @@ public function testMutate_ConstructedWithValueWalker_EmptyPathPassedToSameInsta ->method('createMutableEventIterator') ->with( self::anything(), - self::callback( - function (PathInterface $path): bool { - return empty($path->getElements()); - } - ), - self::anything() + self::callback(fn (PathInterface $path): bool => empty($path->getElements())), + self::anything(), ); $mutator->mutate( - $this->createMock(NodeValueInterface::class), - $this->createMock(MutationInterface::class) + self::createStub(NodeValueInterface::class), + self::createStub(MutationInterface::class), ); } } diff --git a/tests/Processor/ProcessorTest.php b/tests/Processor/ProcessorTest.php index 3c391bc..224ba14 100644 --- a/tests/Processor/ProcessorTest.php +++ b/tests/Processor/ProcessorTest.php @@ -4,6 +4,8 @@ namespace Remorhaz\JSON\Pointer\Test\Processor; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Remorhaz\JSON\Data\Export\ValueDecoderInterface; use Remorhaz\JSON\Data\Export\ValueEncoderInterface; @@ -27,9 +29,7 @@ use Remorhaz\JSON\Pointer\Query\QueryResult; use Remorhaz\JSON\Pointer\Query\QueryResultInterface; -/** - * @covers \Remorhaz\JSON\Pointer\Processor\Processor - */ +#[CoversClass(Processor::class)] class ProcessorTest extends TestCase { public function testCreate_Always_ReturnsProcessorInstance(): void @@ -41,7 +41,7 @@ public function testSelect_GivenQuery_ExecutesSameInstance(): void { $processor = Processor::create(); $query = $this->createMock(QueryInterface::class); - $rootNode = $this->createMock(NodeValueInterface::class); + $rootNode = self::createStub(NodeValueInterface::class); $query ->expects(self::once()) @@ -53,9 +53,9 @@ public function testSelect_GivenQuery_ExecutesSameInstance(): void public function testSelect_QueryResultHasNoSelection_ResultNotExists(): void { $processor = Processor::create(); - $query = $this->createMock(QueryInterface::class); + $query = self::createStub(QueryInterface::class); - $queryResult = $this->createMock(QueryResultInterface::class); + $queryResult = self::createStub(QueryResultInterface::class); $queryResult ->method('hasSelection') ->willReturn(false); @@ -65,7 +65,7 @@ public function testSelect_QueryResultHasNoSelection_ResultNotExists(): void $result = $processor->select( $query, - $this->createMock(NodeValueInterface::class) + self::createStub(NodeValueInterface::class), ); self::assertFalse($result->exists()); } @@ -73,9 +73,9 @@ public function testSelect_QueryResultHasNoSelection_ResultNotExists(): void public function testSelect_QueryResultHasSelection_ResultExists(): void { $processor = Processor::create(); - $query = $this->createMock(QueryInterface::class); + $query = self::createStub(QueryInterface::class); - $queryResult = $this->createMock(QueryResultInterface::class); + $queryResult = self::createStub(QueryResultInterface::class); $queryResult ->method('hasSelection') ->willReturn(true); @@ -85,7 +85,7 @@ public function testSelect_QueryResultHasSelection_ResultExists(): void $result = $processor->select( $query, - $this->createMock(NodeValueInterface::class) + self::createStub(NodeValueInterface::class), ); self::assertTrue($result->exists()); } @@ -95,16 +95,16 @@ public function testSelect_QueryResultHasSelection_SelectionPassedToEncoderOnEnc $encoder = $this->createMock(ValueEncoderInterface::class); $processor = new Processor( $encoder, - $this->createMock(ValueDecoderInterface::class), - $this->createMock(MutatorInterface::class) + self::createStub(ValueDecoderInterface::class), + self::createStub(MutatorInterface::class) ); - $query = $this->createMock(QueryInterface::class); + $query = self::createStub(QueryInterface::class); - $queryResult = $this->createMock(QueryResultInterface::class); + $queryResult = self::createStub(QueryResultInterface::class); $queryResult ->method('hasSelection') ->willReturn(true); - $selection = $this->createMock(NodeValueInterface::class); + $selection = self::createStub(NodeValueInterface::class); $queryResult ->method('getSelection') ->willReturn($selection); @@ -114,7 +114,7 @@ public function testSelect_QueryResultHasSelection_SelectionPassedToEncoderOnEnc $result = $processor->select( $query, - $this->createMock(NodeValueInterface::class) + self::createStub(NodeValueInterface::class), ); $encoder @@ -128,17 +128,17 @@ public function testSelect_QueryResultHasSelection_SelectionPassedToDecoderOnDec { $decoder = $this->createMock(ValueDecoderInterface::class); $processor = new Processor( - $this->createMock(ValueEncoderInterface::class), + self::createStub(ValueEncoderInterface::class), $decoder, - $this->createMock(MutatorInterface::class) + self::createStub(MutatorInterface::class), ); - $query = $this->createMock(QueryInterface::class); + $query = self::createStub(QueryInterface::class); - $queryResult = $this->createMock(QueryResultInterface::class); + $queryResult = self::createStub(QueryResultInterface::class); $queryResult ->method('hasSelection') ->willReturn(true); - $selection = $this->createMock(NodeValueInterface::class); + $selection = self::createStub(NodeValueInterface::class); $queryResult ->method('getSelection') ->willReturn($selection); @@ -148,7 +148,7 @@ public function testSelect_QueryResultHasSelection_SelectionPassedToDecoderOnDec $result = $processor->select( $query, - $this->createMock(NodeValueInterface::class) + $this->createMock(NodeValueInterface::class), ); $decoder @@ -162,7 +162,7 @@ public function testDelete_GivenQuery_ExecutesSameInstance(): void { $processor = Processor::create(); $query = $this->createMock(QueryInterface::class); - $rootNode = $this->createMock(NodeValueInterface::class); + $rootNode = self::createStub(NodeValueInterface::class); $query ->expects(self::once()) @@ -174,12 +174,12 @@ public function testDelete_GivenQuery_ExecutesSameInstance(): void public function testDelete_QueryResultHasNoSelectionButHasParent_ResultNotExists(): void { $processor = Processor::create(); - $query = $this->createMock(QueryInterface::class); + $query = self::createStub(QueryInterface::class); $queryResult = new QueryResult( '', null, - $this->createMock(NodeValueInterface::class) + self::createStub(NodeValueInterface::class) ); $query ->method('__invoke') @@ -187,24 +187,23 @@ public function testDelete_QueryResultHasNoSelectionButHasParent_ResultNotExists $result = $processor->delete( $query, - $this->createMock(NodeValueInterface::class) + self::createStub(NodeValueInterface::class) ); self::assertFalse($result->exists()); } public function testDelete_QueryResultHasSelectionButNoParent_ResultNotExists(): void { - $mutator = $this->createMock(MutatorInterface::class); $processor = new Processor( - $this->createMock(ValueEncoderInterface::class), - $this->createMock(ValueDecoderInterface::class), - $mutator, + self::createStub(ValueEncoderInterface::class), + self::createStub(ValueDecoderInterface::class), + self::createStub(MutatorInterface::class), ); - $query = $this->createMock(QueryInterface::class); + $query = self::createStub(QueryInterface::class); $queryResult = new QueryResult( '', - $this->createMock(NodeValueInterface::class) + self::createStub(NodeValueInterface::class), ); $query ->method('__invoke') @@ -212,25 +211,25 @@ public function testDelete_QueryResultHasSelectionButNoParent_ResultNotExists(): $result = $processor->delete( $query, - $this->createMock(NodeValueInterface::class) + self::createStub(NodeValueInterface::class), ); self::assertFalse($result->exists()); } public function testDelete_ParentIsNotStruct_ResultNotExists(): void { - $mutator = $this->createMock(MutatorInterface::class); + $mutator = self::createStub(MutatorInterface::class); $processor = new Processor( - $this->createMock(ValueEncoderInterface::class), - $this->createMock(ValueDecoderInterface::class), + self::createStub(ValueEncoderInterface::class), + self::createStub(ValueDecoderInterface::class), $mutator, ); - $query = $this->createMock(QueryInterface::class); + $query = self::createStub(QueryInterface::class); $queryResult = new QueryResult( '', - $this->createMock(NodeValueInterface::class), - $this->createMock(NodeValueInterface::class) + self::createStub(NodeValueInterface::class), + self::createStub(NodeValueInterface::class), ); $query ->method('__invoke') @@ -241,28 +240,28 @@ public function testDelete_ParentIsNotStruct_ResultNotExists(): void ->willReturn($this->createMock(NodeValueInterface::class)); $result = $processor->delete( $query, - $this->createMock(NodeValueInterface::class) + self::createStub(NodeValueInterface::class), ); self::assertFalse($result->exists()); } public function testDelete_MutatorReturnsNull_ResultNotExists(): void { - $mutator = $this->createMock(MutatorInterface::class); + $mutator = self::createStub(MutatorInterface::class); $processor = new Processor( - $this->createMock(ValueEncoderInterface::class), - $this->createMock(ValueDecoderInterface::class), + self::createStub(ValueEncoderInterface::class), + self::createStub(ValueDecoderInterface::class), $mutator, ); - $query = $this->createMock(QueryInterface::class); + $query = self::createStub(QueryInterface::class); $queryResult = new QueryResult( '', - $this->createMock(NodeValueInterface::class), + self::createStub(NodeValueInterface::class), new NodeArrayValue( [], - $this->createMock(PathInterface::class), - $this->createMock(NodeValueFactoryInterface::class) + self::createStub(PathInterface::class), + self::createStub(NodeValueFactoryInterface::class), ) ); $query @@ -274,25 +273,25 @@ public function testDelete_MutatorReturnsNull_ResultNotExists(): void ->willReturn(null); $result = $processor->delete( $query, - $this->createMock(NodeValueInterface::class) + self::createStub(NodeValueInterface::class), ); self::assertFalse($result->exists()); } public function testDelete_NonStructParent_ResultNotExists(): void { - $mutator = $this->createMock(MutatorInterface::class); + $mutator = self::createStub(MutatorInterface::class); $processor = new Processor( - $this->createMock(ValueEncoderInterface::class), - $this->createMock(ValueDecoderInterface::class), + self::createStub(ValueEncoderInterface::class), + self::createStub(ValueDecoderInterface::class), $mutator, ); - $query = $this->createMock(QueryInterface::class); + $query = self::createStub(QueryInterface::class); $queryResult = new QueryResult( '', - $this->createMock(NodeValueInterface::class), - $this->createMock(NodeValueInterface::class) + self::createStub(NodeValueInterface::class), + self::createStub(NodeValueInterface::class), ); $query ->method('__invoke') @@ -300,31 +299,31 @@ public function testDelete_NonStructParent_ResultNotExists(): void $mutator ->method('mutate') - ->willReturn($this->createMock(NodeValueInterface::class)); + ->willReturn(self::createStub(NodeValueInterface::class)); $result = $processor->delete( $query, - $this->createMock(NodeValueInterface::class) + self::createStub(NodeValueInterface::class), ); self::assertFalse($result->exists()); } public function testDelete_ParentIsArray_ResultExists(): void { - $mutator = $this->createMock(MutatorInterface::class); + $mutator = self::createStub(MutatorInterface::class); $processor = new Processor( - $this->createMock(ValueEncoderInterface::class), - $this->createMock(ValueDecoderInterface::class), + self::createStub(ValueEncoderInterface::class), + self::createStub(ValueDecoderInterface::class), $mutator, ); - $query = $this->createMock(QueryInterface::class); + $query = self::createStub(QueryInterface::class); $queryResult = new QueryResult( '', - $this->createMock(NodeValueInterface::class), + self::createStub(NodeValueInterface::class), new NodeArrayValue( [], - $this->createMock(PathInterface::class), - $this->createMock(NodeValueFactoryInterface::class) + self::createStub(PathInterface::class), + self::createStub(NodeValueFactoryInterface::class), ) ); $query @@ -332,31 +331,31 @@ public function testDelete_ParentIsArray_ResultExists(): void ->willReturn($queryResult); $mutator ->method('mutate') - ->willReturn($this->createMock(NodeValueInterface::class)); + ->willReturn(self::createStub(NodeValueInterface::class)); $result = $processor->delete( $query, - $this->createMock(NodeValueInterface::class) + self::createStub(NodeValueInterface::class), ); self::assertTrue($result->exists()); } public function testDelete_ParentIsObject_ResultExists(): void { - $mutator = $this->createMock(MutatorInterface::class); + $mutator = self::createStub(MutatorInterface::class); $processor = new Processor( - $this->createMock(ValueEncoderInterface::class), - $this->createMock(ValueDecoderInterface::class), + self::createStub(ValueEncoderInterface::class), + self::createStub(ValueDecoderInterface::class), $mutator, ); - $query = $this->createMock(QueryInterface::class); + $query = self::createStub(QueryInterface::class); $queryResult = new QueryResult( '', - $this->createMock(NodeValueInterface::class), + self::createStub(NodeValueInterface::class), new NodeObjectValue( (object) [], - $this->createMock(PathInterface::class), - $this->createMock(NodeValueFactoryInterface::class) + self::createStub(PathInterface::class), + self::createStub(NodeValueFactoryInterface::class), ) ); $query @@ -365,10 +364,10 @@ public function testDelete_ParentIsObject_ResultExists(): void $mutator ->method('mutate') - ->willReturn($this->createMock(NodeValueInterface::class)); + ->willReturn(self::createStub(NodeValueInterface::class)); $result = $processor->delete( $query, - $this->createMock(NodeValueInterface::class) + self::createStub(NodeValueInterface::class), ); self::assertTrue($result->exists()); } @@ -377,26 +376,26 @@ public function testDelete_ParentIsArray_DeleteElementMutationPassedToMutator(): { $mutator = $this->createMock(MutatorInterface::class); $processor = new Processor( - $this->createMock(ValueEncoderInterface::class), - $this->createMock(ValueDecoderInterface::class), + self::createStub(ValueEncoderInterface::class), + self::createStub(ValueDecoderInterface::class), $mutator, ); - $query = $this->createMock(QueryInterface::class); + $query = self::createStub(QueryInterface::class); $queryResult = new QueryResult( '', - $this->createMock(NodeValueInterface::class), + self::createStub(NodeValueInterface::class), new NodeArrayValue( [], - $this->createMock(PathInterface::class), - $this->createMock(NodeValueFactoryInterface::class) + self::createStub(PathInterface::class), + self::createStub(NodeValueFactoryInterface::class), ) ); $query ->method('__invoke') ->willReturn($queryResult); - $rootNode = $this->createMock(NodeValueInterface::class); + $rootNode = self::createStub(NodeValueInterface::class); $mutator ->expects(self::once()) ->method('mutate') @@ -411,32 +410,32 @@ public function testDelete_ParentIsObject_DeletePropertyMutationPassedToMutator( { $mutator = $this->createMock(MutatorInterface::class); $processor = new Processor( - $this->createMock(ValueEncoderInterface::class), - $this->createMock(ValueDecoderInterface::class), + self::createStub(ValueEncoderInterface::class), + self::createStub(ValueDecoderInterface::class), $mutator, ); - $query = $this->createMock(QueryInterface::class); + $query = self::createStub(QueryInterface::class); $queryResult = new QueryResult( '', - $this->createMock(NodeValueInterface::class), + self::createStub(NodeValueInterface::class), new NodeObjectValue( (object) [], - $this->createMock(PathInterface::class), - $this->createMock(NodeValueFactoryInterface::class) + self::createStub(PathInterface::class), + self::createStub(NodeValueFactoryInterface::class), ) ); $query ->method('__invoke') ->willReturn($queryResult); - $rootNode = $this->createMock(NodeValueInterface::class); + $rootNode = self::createStub(NodeValueInterface::class); $mutator ->expects(self::once()) ->method('mutate') ->with( self::identicalTo($rootNode), - self::isInstanceOf(DeletePropertyMutation::class) + self::isInstanceOf(DeletePropertyMutation::class), ); $processor->delete($query, $rootNode); } @@ -444,33 +443,33 @@ public function testDelete_ParentIsObject_DeletePropertyMutationPassedToMutator( public function testDelete_MutatorReturnsValue_SameInstancePassedToEncoderOnEncode(): void { $encoder = $this->createMock(ValueEncoderInterface::class); - $mutator = $this->createMock(MutatorInterface::class); + $mutator = self::createStub(MutatorInterface::class); $processor = new Processor( $encoder, - $this->createMock(ValueDecoderInterface::class), + self::createStub(ValueDecoderInterface::class), $mutator, ); - $query = $this->createMock(QueryInterface::class); + $query = self::createStub(QueryInterface::class); $queryResult = new QueryResult( '', - $this->createMock(NodeValueInterface::class), + self::createStub(NodeValueInterface::class), new NodeArrayValue( [], - $this->createMock(PathInterface::class), - $this->createMock(NodeValueFactoryInterface::class) + self::createStub(PathInterface::class), + self::createStub(NodeValueFactoryInterface::class), ) ); $query ->method('__invoke') ->willReturn($queryResult); - $mutatedNode = $this->createMock(NodeValueInterface::class); + $mutatedNode = self::createStub(NodeValueInterface::class); $mutator ->method('mutate') ->willReturn($mutatedNode); $result = $processor->delete( $query, - $this->createMock(NodeValueInterface::class) + self::createStub(NodeValueInterface::class), ); $encoder ->expects(self::once()) @@ -483,7 +482,7 @@ public function testReplace_GivenQuery_ExecutesSameInstance(): void { $processor = Processor::create(); $query = $this->createMock(QueryInterface::class); - $rootNode = $this->createMock(NodeValueInterface::class); + $rootNode = self::createStub(NodeValueInterface::class); $query ->expects(self::once()) @@ -492,16 +491,16 @@ public function testReplace_GivenQuery_ExecutesSameInstance(): void $processor->replace( $query, $rootNode, - $this->createMock(NodeValueInterface::class) + self::createStub(NodeValueInterface::class), ); } public function testReplace_QueryResultHasNoSelection_ResultNotExists(): void { $processor = Processor::create(); - $query = $this->createMock(QueryInterface::class); + $query = self::createStub(QueryInterface::class); - $queryResult = $this->createMock(QueryResultInterface::class); + $queryResult = self::createStub(QueryResultInterface::class); $queryResult ->method('hasSelection') ->willReturn(false); @@ -511,23 +510,23 @@ public function testReplace_QueryResultHasNoSelection_ResultNotExists(): void $result = $processor->replace( $query, - $this->createMock(NodeValueInterface::class), - $this->createMock(NodeValueInterface::class) + self::createStub(NodeValueInterface::class), + self::createStub(NodeValueInterface::class), ); self::assertFalse($result->exists()); } public function testReplace_QueryResultHasSelectionButMutatorReturnsNull_ResultNotExists(): void { - $mutator = $this->createMock(MutatorInterface::class); + $mutator = self::createStub(MutatorInterface::class); $processor = new Processor( - $this->createMock(ValueEncoderInterface::class), - $this->createMock(ValueDecoderInterface::class), + self::createStub(ValueEncoderInterface::class), + self::createStub(ValueDecoderInterface::class), $mutator, ); - $query = $this->createMock(QueryInterface::class); + $query = self::createStub(QueryInterface::class); - $queryResult = $this->createMock(QueryResultInterface::class); + $queryResult = self::createStub(QueryResultInterface::class); $queryResult ->method('hasSelection') ->willReturn(true); @@ -540,23 +539,23 @@ public function testReplace_QueryResultHasSelectionButMutatorReturnsNull_ResultN ->willReturn(null); $result = $processor->replace( $query, - $this->createMock(NodeValueInterface::class), - $this->createMock(NodeValueInterface::class) + self::createStub(NodeValueInterface::class), + self::createStub(NodeValueInterface::class), ); self::assertFalse($result->exists()); } public function testReplace_MutatorReturnsValue_ResultExists(): void { - $mutator = $this->createMock(MutatorInterface::class); + $mutator = self::createStub(MutatorInterface::class); $processor = new Processor( - $this->createMock(ValueEncoderInterface::class), - $this->createMock(ValueDecoderInterface::class), + self::createStub(ValueEncoderInterface::class), + self::createStub(ValueDecoderInterface::class), $mutator, ); - $query = $this->createMock(QueryInterface::class); + $query = self::createStub(QueryInterface::class); - $queryResult = $this->createMock(QueryResultInterface::class); + $queryResult = self::createStub(QueryResultInterface::class); $queryResult ->method('hasSelection') ->willReturn(true); @@ -566,11 +565,11 @@ public function testReplace_MutatorReturnsValue_ResultExists(): void $mutator ->method('mutate') - ->willReturn($this->createMock(NodeValueInterface::class)); + ->willReturn(self::createStub(NodeValueInterface::class)); $result = $processor->replace( $query, - $this->createMock(NodeValueInterface::class), - $this->createMock(NodeValueInterface::class) + self::createStub(NodeValueInterface::class), + self::createStub(NodeValueInterface::class), ); self::assertTrue($result->exists()); } @@ -579,13 +578,13 @@ public function testReplace_QueryResultHasSelection_ReplaceMutationPassedToMutat { $mutator = $this->createMock(MutatorInterface::class); $processor = new Processor( - $this->createMock(ValueEncoderInterface::class), - $this->createMock(ValueDecoderInterface::class), + self::createStub(ValueEncoderInterface::class), + self::createStub(ValueDecoderInterface::class), $mutator, ); - $query = $this->createMock(QueryInterface::class); + $query = self::createStub(QueryInterface::class); - $queryResult = $this->createMock(QueryResultInterface::class); + $queryResult = self::createStub(QueryResultInterface::class); $queryResult ->method('hasSelection') ->willReturn(true); @@ -593,47 +592,47 @@ public function testReplace_QueryResultHasSelection_ReplaceMutationPassedToMutat ->method('__invoke') ->willReturn($queryResult); - $rootNode = $this->createMock(NodeValueInterface::class); + $rootNode = self::createStub(NodeValueInterface::class); $mutator ->expects(self::once()) ->method('mutate') ->with( self::identicalTo($rootNode), - self::isInstanceOf(ReplaceMutation::class) + self::isInstanceOf(ReplaceMutation::class), ); $processor->replace( $query, $rootNode, - $this->createMock(NodeValueInterface::class) + self::createStub(NodeValueInterface::class), ); } public function testReplace_MutatorReturnsValue_SameInstancePassedToEncoderOnEncode(): void { $encoder = $this->createMock(ValueEncoderInterface::class); - $mutator = $this->createMock(MutatorInterface::class); + $mutator = self::createStub(MutatorInterface::class); $processor = new Processor( $encoder, - $this->createMock(ValueDecoderInterface::class), + self::createStub(ValueDecoderInterface::class), $mutator, ); - $query = $this->createMock(QueryInterface::class); + $query = self::createStub(QueryInterface::class); - $queryResult = $this->createMock(QueryResultInterface::class); + $queryResult = self::createStub(QueryResultInterface::class); $queryResult ->method('hasSelection') ->willReturn(true); $query ->method('__invoke') ->willReturn($queryResult); - $mutatedNode = $this->createMock(NodeValueInterface::class); + $mutatedNode = self::createStub(NodeValueInterface::class); $mutator ->method('mutate') ->willReturn($mutatedNode); $result = $processor->replace( $query, - $this->createMock(NodeValueInterface::class), - $this->createMock(NodeValueInterface::class) + self::createStub(NodeValueInterface::class), + self::createStub(NodeValueInterface::class), ); $encoder ->expects(self::once()) @@ -646,7 +645,7 @@ public function testAdd_GivenQuery_ExecutesSameInstance(): void { $processor = Processor::create(); $query = $this->createMock(QueryInterface::class); - $rootNode = $this->createMock(NodeValueInterface::class); + $rootNode = self::createStub(NodeValueInterface::class); $query ->expects(self::once()) @@ -655,21 +654,19 @@ public function testAdd_GivenQuery_ExecutesSameInstance(): void $processor->add( $query, $rootNode, - $this->createMock(NodeValueInterface::class) + self::createStub(NodeValueInterface::class), ); } - /** - * @dataProvider providerHasParentOrLastReference - */ + #[DataProvider('providerHasParentOrLastReference')] public function testAdd_QueryResultHasNoParentOrLastReference_ResultNotExists( bool $hasParent, bool $hasLastReference, ): void { $processor = Processor::create(); - $query = $this->createMock(QueryInterface::class); + $query = self::createStub(QueryInterface::class); - $queryResult = $this->createMock(QueryResultInterface::class); + $queryResult = self::createStub(QueryResultInterface::class); $queryResult ->method('hasParent') ->willReturn($hasParent); @@ -682,8 +679,8 @@ public function testAdd_QueryResultHasNoParentOrLastReference_ResultNotExists( $result = $processor->replace( $query, - $this->createMock(NodeValueInterface::class), - $this->createMock(NodeValueInterface::class) + self::createStub(NodeValueInterface::class), + self::createStub(NodeValueInterface::class), ); self::assertFalse($result->exists()); } @@ -703,12 +700,12 @@ public static function providerHasParentOrLastReference(): iterable public function testAdd_QueryResultHasNonStructParent_ResultNotExists(): void { $processor = Processor::create(); - $query = $this->createMock(QueryInterface::class); + $query = self::createStub(QueryInterface::class); $queryResult = new QueryResult( '', null, - $this->createMock(NodeValueInterface::class), - $this->createMock(ReferenceInterface::class) + self::createStub(NodeValueInterface::class), + self::createStub(ReferenceInterface::class), ); $query ->method('__invoke') @@ -716,32 +713,32 @@ public function testAdd_QueryResultHasNonStructParent_ResultNotExists(): void $result = $processor->add( $query, - $this->createMock(NodeValueInterface::class), - $this->createMock(NodeValueInterface::class) + self::createStub(NodeValueInterface::class), + self::createStub(NodeValueInterface::class), ); self::assertFalse($result->exists()); } /** * @param class-string $lastReferenceClass - * @dataProvider providerAddSelectableNonInsertable */ + #[DataProvider('providerAddSelectableNonInsertable')] public function testAdd_QueryResultHasArrayParentHasSelectionHasNotIndexLastReference_ResultNotExists( string $lastReferenceClass, ): void { $processor = Processor::create(); - $query = $this->createMock(QueryInterface::class); + $query = self::createStub(QueryInterface::class); $parent = new NodeArrayValue( [], - $this->createMock(PathInterface::class), - $this->createMock(NodeValueFactoryInterface::class), + self::createStub(PathInterface::class), + self::createStub(NodeValueFactoryInterface::class), ); /** @var ReferenceInterface $reference */ - $reference = $this->createMock($lastReferenceClass); + $reference = self::createStub($lastReferenceClass); $queryResult = new QueryResult( '', - $this->createMock(NodeValueInterface::class), + self::createStub(NodeValueInterface::class), $parent, $reference, ); @@ -751,8 +748,8 @@ public function testAdd_QueryResultHasArrayParentHasSelectionHasNotIndexLastRefe $result = $processor->add( $query, - $this->createMock(NodeValueInterface::class), - $this->createMock(NodeValueInterface::class), + self::createStub(NodeValueInterface::class), + self::createStub(NodeValueInterface::class), ); self::assertFalse($result->exists()); } @@ -771,18 +768,18 @@ public static function providerAddSelectableNonInsertable(): iterable public function testAdd_QueryResultHasArrayParentHasNoSelectionHasPropertyLastReference_ResultNotExists(): void { $processor = Processor::create(); - $query = $this->createMock(QueryInterface::class); + $query = self::createStub(QueryInterface::class); $parent = new NodeArrayValue( [], - $this->createMock(PathInterface::class), - $this->createMock(NodeValueFactoryInterface::class), + self::createStub(PathInterface::class), + self::createStub(NodeValueFactoryInterface::class), ); $queryResult = new QueryResult( '', null, $parent, - $this->createMock(ReferenceInterface::class), + self::createStub(ReferenceInterface::class), ); $query ->method('__invoke') @@ -790,45 +787,45 @@ public function testAdd_QueryResultHasArrayParentHasNoSelectionHasPropertyLastRe $result = $processor->add( $query, - $this->createMock(NodeValueInterface::class), - $this->createMock(NodeValueInterface::class), + self::createStub(NodeValueInterface::class), + self::createStub(NodeValueInterface::class), ); self::assertFalse($result->exists()); } /** * @param string $lastReferenceClass - * @dataProvider providerArrayParentIndexProperty */ + #[DataProvider('providerArrayParentIndexProperty')] public function testAdd_QueryResultHasArrayParentHasNoSelectionHasIndexProperty_ResultExists( - string $lastReferenceClass + string $lastReferenceClass, ): void { - $mutator = $this->createMock(MutatorInterface::class); + $mutator = self::createStub(MutatorInterface::class); $processor = new Processor( - $this->createMock(ValueEncoderInterface::class), - $this->createMock(ValueDecoderInterface::class), + self::createStub(ValueEncoderInterface::class), + self::createStub(ValueDecoderInterface::class), $mutator, ); - $query = $this->createMock(QueryInterface::class); + $query = self::createStub(QueryInterface::class); $parent = new NodeArrayValue( [], - $this->createMock(PathInterface::class), - $this->createMock(NodeValueFactoryInterface::class), + self::createStub(PathInterface::class), + self::createStub(NodeValueFactoryInterface::class), ); /** @var ReferenceInterface $reference */ - $reference = $this->createMock($lastReferenceClass); + $reference = self::createStub($lastReferenceClass); $queryResult = new QueryResult('', null, $parent, $reference); $query ->method('__invoke') ->willReturn($queryResult); $mutator ->method('mutate') - ->willReturn($this->createMock(NodeValueInterface::class)); + ->willReturn(self::createStub(NodeValueInterface::class)); $result = $processor->add( $query, - $this->createMock(NodeValueInterface::class), - $this->createMock(NodeValueInterface::class), + self::createStub(NodeValueInterface::class), + self::createStub(NodeValueInterface::class), ); self::assertTrue($result->exists()); } @@ -846,31 +843,31 @@ public static function providerArrayParentIndexProperty(): iterable /** * @param string $lastReferenceClass - * @dataProvider providerArrayParentIndexProperty */ + #[DataProvider('providerArrayParentIndexProperty')] public function testAdd_QueryResultHasArrayParentHasNoSelectionHasIndexProperty_PassesAppendElementMutation( - string $lastReferenceClass + string $lastReferenceClass, ): void { $mutator = $this->createMock(MutatorInterface::class); $processor = new Processor( - $this->createMock(ValueEncoderInterface::class), - $this->createMock(ValueDecoderInterface::class), - $mutator + self::createStub(ValueEncoderInterface::class), + self::createStub(ValueDecoderInterface::class), + $mutator, ); - $query = $this->createMock(QueryInterface::class); + $query = self::createStub(QueryInterface::class); $parent = new NodeArrayValue( [], - $this->createMock(PathInterface::class), - $this->createMock(NodeValueFactoryInterface::class) + self::createStub(PathInterface::class), + self::createStub(NodeValueFactoryInterface::class), ); /** @var ReferenceInterface $reference */ - $reference = $this->createMock($lastReferenceClass); + $reference = self::createStub($lastReferenceClass); $queryResult = new QueryResult('', null, $parent, $reference); $query ->method('__invoke') ->willReturn($queryResult); - $rootNode = $this->createMock(NodeValueInterface::class); + $rootNode = self::createStub(NodeValueInterface::class); $mutator ->expects(self::once()) ->method('mutate') @@ -878,41 +875,41 @@ public function testAdd_QueryResultHasArrayParentHasNoSelectionHasIndexProperty_ $processor->add( $query, $rootNode, - $this->createMock(NodeValueInterface::class) + self::createStub(NodeValueInterface::class), ); } public function testAdd_QueryResultHasArrayParentHasSelectionHasIndexProperty_ResultExists(): void { - $mutator = $this->createMock(MutatorInterface::class); + $mutator = self::createStub(MutatorInterface::class); $processor = new Processor( - $this->createMock(ValueEncoderInterface::class), - $this->createMock(ValueDecoderInterface::class), - $mutator + self::createStub(ValueEncoderInterface::class), + self::createStub(ValueDecoderInterface::class), + $mutator, ); - $query = $this->createMock(QueryInterface::class); + $query = self::createStub(QueryInterface::class); $parent = new NodeArrayValue( [], - $this->createMock(PathInterface::class), - $this->createMock(NodeValueFactoryInterface::class) + self::createStub(PathInterface::class), + self::createStub(NodeValueFactoryInterface::class), ); $queryResult = new QueryResult( '', - $this->createMock(NodeValueInterface::class), + self::createStub(NodeValueInterface::class), $parent, - $this->createMock(IndexReferenceInterface::class) + self::createStub(IndexReferenceInterface::class), ); $query ->method('__invoke') ->willReturn($queryResult); $mutator ->method('mutate') - ->willReturn($this->createMock(NodeValueInterface::class)); + ->willReturn(self::createStub(NodeValueInterface::class)); $result = $processor->add( $query, - $this->createMock(NodeValueInterface::class), - $this->createMock(NodeValueInterface::class) + self::createStub(NodeValueInterface::class), + self::createStub(NodeValueInterface::class), ); self::assertTrue($result->exists()); } @@ -921,27 +918,27 @@ public function testAdd_QueryResultHasArrayParentHasSelectionHasIndexProperty_Pa { $mutator = $this->createMock(MutatorInterface::class); $processor = new Processor( - $this->createMock(ValueEncoderInterface::class), - $this->createMock(ValueDecoderInterface::class), - $mutator + self::createStub(ValueEncoderInterface::class), + self::createStub(ValueDecoderInterface::class), + $mutator, ); - $query = $this->createMock(QueryInterface::class); + $query = self::createStub(QueryInterface::class); $parent = new NodeArrayValue( [], - $this->createMock(PathInterface::class), - $this->createMock(NodeValueFactoryInterface::class) + self::createStub(PathInterface::class), + self::createStub(NodeValueFactoryInterface::class), ); $queryResult = new QueryResult( '', - $this->createMock(NodeValueInterface::class), + self::createStub(NodeValueInterface::class), $parent, - $this->createMock(IndexReferenceInterface::class) + self::createStub(IndexReferenceInterface::class), ); $query ->method('__invoke') ->willReturn($queryResult); - $rootNode = $this->createMock(NodeValueInterface::class); + $rootNode = self::createStub(NodeValueInterface::class); $mutator ->expects(self::once()) ->method('mutate') @@ -949,7 +946,7 @@ public function testAdd_QueryResultHasArrayParentHasSelectionHasIndexProperty_Pa $processor->add( $query, $rootNode, - $this->createMock(NodeValueInterface::class) + self::createStub(NodeValueInterface::class), ); } @@ -957,28 +954,28 @@ public function testAdd_QueryResultHasObjectParentHasSelection_PassesReplaceMuta { $mutator = $this->createMock(MutatorInterface::class); $processor = new Processor( - $this->createMock(ValueEncoderInterface::class), - $this->createMock(ValueDecoderInterface::class), - $mutator + self::createStub(ValueEncoderInterface::class), + self::createStub(ValueDecoderInterface::class), + $mutator, ); $parent = new NodeObjectValue( (object) [], - $this->createMock(PathInterface::class), - $this->createMock(NodeValueFactoryInterface::class) + self::createStub(PathInterface::class), + self::createStub(NodeValueFactoryInterface::class), ); $queryResult = new QueryResult( '', - $this->createMock(NodeValueInterface::class), + self::createStub(NodeValueInterface::class), $parent, - $this->createMock(ReferenceInterface::class) + self::createStub(ReferenceInterface::class), ); - $query = $this->createMock(QueryInterface::class); + $query = self::createStub(QueryInterface::class); $query ->method('__invoke') ->willReturn($queryResult); - $rootNode = $this->createMock(NodeValueInterface::class); + $rootNode = self::createStub(NodeValueInterface::class); $mutator ->expects(self::once()) ->method('mutate') @@ -986,42 +983,42 @@ public function testAdd_QueryResultHasObjectParentHasSelection_PassesReplaceMuta $processor->add( $query, $rootNode, - $this->createMock(NodeValueInterface::class) + self::createStub(NodeValueInterface::class), ); } public function testAdd_QueryResultHasObjectParentHasSelection_ResultExists(): void { - $mutator = $this->createMock(MutatorInterface::class); + $mutator = self::createStub(MutatorInterface::class); $processor = new Processor( - $this->createMock(ValueEncoderInterface::class), - $this->createMock(ValueDecoderInterface::class), - $mutator + self::createStub(ValueEncoderInterface::class), + self::createStub(ValueDecoderInterface::class), + $mutator, ); $parent = new NodeObjectValue( (object) [], - $this->createMock(PathInterface::class), - $this->createMock(NodeValueFactoryInterface::class) + self::createStub(PathInterface::class), + self::createStub(NodeValueFactoryInterface::class), ); $queryResult = new QueryResult( '', - $this->createMock(NodeValueInterface::class), + self::createStub(NodeValueInterface::class), $parent, - $this->createMock(ReferenceInterface::class) + self::createStub(ReferenceInterface::class), ); - $query = $this->createMock(QueryInterface::class); + $query = self::createStub(QueryInterface::class); $query ->method('__invoke') ->willReturn($queryResult); $mutator ->method('mutate') - ->willReturn($this->createMock(NodeValueInterface::class)); + ->willReturn(self::createStub(NodeValueInterface::class)); $result = $processor->add( $query, - $this->createMock(NodeValueInterface::class), - $this->createMock(NodeValueInterface::class) + self::createStub(NodeValueInterface::class), + self::createStub(NodeValueInterface::class), ); self::assertTrue($result->exists()); } @@ -1030,28 +1027,28 @@ public function testAdd_QueryResultHasObjectParentHasNoSelection_PassesAppendPro { $mutator = $this->createMock(MutatorInterface::class); $processor = new Processor( - $this->createMock(ValueEncoderInterface::class), - $this->createMock(ValueDecoderInterface::class), - $mutator + self::createStub(ValueEncoderInterface::class), + self::createStub(ValueDecoderInterface::class), + $mutator, ); $parent = new NodeObjectValue( (object) [], - $this->createMock(PathInterface::class), - $this->createMock(NodeValueFactoryInterface::class) + self::createStub(PathInterface::class), + self::createStub(NodeValueFactoryInterface::class), ); $queryResult = new QueryResult( '', null, $parent, - $this->createMock(ReferenceInterface::class) + self::createStub(ReferenceInterface::class), ); - $query = $this->createMock(QueryInterface::class); + $query = self::createStub(QueryInterface::class); $query ->method('__invoke') ->willReturn($queryResult); - $rootNode = $this->createMock(NodeValueInterface::class); + $rootNode = self::createStub(NodeValueInterface::class); $mutator ->expects(self::once()) ->method('mutate') @@ -1059,42 +1056,42 @@ public function testAdd_QueryResultHasObjectParentHasNoSelection_PassesAppendPro $processor->add( $query, $rootNode, - $this->createMock(NodeValueInterface::class) + self::createStub(NodeValueInterface::class), ); } public function testAdd_QueryResultHasObjectParentHasNoSelection_ResultExists(): void { - $mutator = $this->createMock(MutatorInterface::class); + $mutator = self::createStub(MutatorInterface::class); $processor = new Processor( - $this->createMock(ValueEncoderInterface::class), - $this->createMock(ValueDecoderInterface::class), - $mutator + self::createStub(ValueEncoderInterface::class), + self::createStub(ValueDecoderInterface::class), + $mutator, ); $parent = new NodeObjectValue( (object) [], - $this->createMock(PathInterface::class), - $this->createMock(NodeValueFactoryInterface::class) + self::createStub(PathInterface::class), + self::createStub(NodeValueFactoryInterface::class), ); $queryResult = new QueryResult( '', null, $parent, - $this->createMock(ReferenceInterface::class) + self::createStub(ReferenceInterface::class), ); - $query = $this->createMock(QueryInterface::class); + $query = self::createStub(QueryInterface::class); $query ->method('__invoke') ->willReturn($queryResult); $mutator ->method('mutate') - ->willReturn($this->createMock(NodeValueInterface::class)); + ->willReturn(self::createStub(NodeValueInterface::class)); $result = $processor->add( $query, - $this->createMock(NodeValueInterface::class), - $this->createMock(NodeValueInterface::class) + self::createStub(NodeValueInterface::class), + self::createStub(NodeValueInterface::class), ); self::assertTrue($result->exists()); } diff --git a/tests/Processor/Result/Exception/ResultNotFoundExceptionTest.php b/tests/Processor/Result/Exception/ResultNotFoundExceptionTest.php index 5510332..2dc7c91 100644 --- a/tests/Processor/Result/Exception/ResultNotFoundExceptionTest.php +++ b/tests/Processor/Result/Exception/ResultNotFoundExceptionTest.php @@ -5,12 +5,11 @@ namespace Remorhaz\JSON\Pointer\Test\Processor\Result\Exception; use Exception; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Remorhaz\JSON\Pointer\Processor\Result\Exception\ResultNotFoundException; -/** - * @covers \Remorhaz\JSON\Pointer\Processor\Result\Exception\ResultNotFoundException - */ +#[CoversClass(ResultNotFoundException::class)] class ResultNotFoundExceptionTest extends TestCase { public function testGetMessage_Constructed_ReturnsMatchingValue(): void @@ -25,12 +24,6 @@ public function testGetSource_ConstructedWithSource_ReturnsSameValue(): void self::assertSame('a', $exception->getSource()); } - public function testGetCode_Always_ReturnsZero(): void - { - $exception = new ResultNotFoundException('a'); - self::assertSame(0, $exception->getCode()); - } - public function testGetPrevious_PreviousNotSet_ReturnsNull(): void { $exception = new ResultNotFoundException('a'); diff --git a/tests/Processor/Result/ExistingResultTest.php b/tests/Processor/Result/ExistingResultTest.php index b360a7c..d5458c4 100644 --- a/tests/Processor/Result/ExistingResultTest.php +++ b/tests/Processor/Result/ExistingResultTest.php @@ -4,23 +4,22 @@ namespace Remorhaz\JSON\Pointer\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\NodeValueInterface; use Remorhaz\JSON\Pointer\Processor\Result\ExistingResult; -/** - * @covers \Remorhaz\JSON\Pointer\Processor\Result\ExistingResult - */ +#[CoversClass(ExistingResult::class)] class ExistingResultTest extends TestCase { public function testExists_Always_ReturnsTrue(): void { $result = new ExistingResult( - $this->createMock(ValueEncoderInterface::class), - $this->createMock(ValueDecoderInterface::class), - $this->createMock(NodeValueInterface::class), + self::createStub(ValueEncoderInterface::class), + self::createStub(ValueDecoderInterface::class), + self::createStub(NodeValueInterface::class), ); self::assertTrue($result->exists()); } @@ -28,10 +27,10 @@ public function testExists_Always_ReturnsTrue(): void public function testEncode_ConstructedWithValue_PassesSameInstanceToEncoder(): void { $encoder = $this->createMock(ValueEncoderInterface::class); - $value = $this->createMock(NodeValueInterface::class); + $value = self::createStub(NodeValueInterface::class); $result = new ExistingResult( $encoder, - $this->createMock(ValueDecoderInterface::class), + self::createStub(ValueDecoderInterface::class), $value, ); @@ -44,11 +43,11 @@ public function testEncode_ConstructedWithValue_PassesSameInstanceToEncoder(): v public function testEncode_EncoderExportsValue_ReturnsSameValue(): void { - $encoder = $this->createMock(ValueEncoderInterface::class); - $value = $this->createMock(NodeValueInterface::class); + $encoder = self::createStub(ValueEncoderInterface::class); + $value = self::createStub(NodeValueInterface::class); $result = new ExistingResult( $encoder, - $this->createMock(ValueDecoderInterface::class), + self::createStub(ValueDecoderInterface::class), $value, ); @@ -61,9 +60,9 @@ public function testEncode_EncoderExportsValue_ReturnsSameValue(): void public function testDecode_ConstructedWithValue_PassesSameInstanceToDecoder(): void { $decoder = $this->createMock(ValueDecoderInterface::class); - $value = $this->createMock(NodeValueInterface::class); + $value = self::createStub(NodeValueInterface::class); $result = new ExistingResult( - $this->createMock(ValueEncoderInterface::class), + self::createStub(ValueEncoderInterface::class), $decoder, $value, ); @@ -77,10 +76,10 @@ public function testDecode_ConstructedWithValue_PassesSameInstanceToDecoder(): v public function testDecode_DecoderExportsValue_ReturnsSameValue(): void { - $decoder = $this->createMock(ValueDecoderInterface::class); - $value = $this->createMock(NodeValueInterface::class); + $decoder = self::createStub(ValueDecoderInterface::class); + $value = self::createStub(NodeValueInterface::class); $result = new ExistingResult( - $this->createMock(ValueEncoderInterface::class), + self::createStub(ValueEncoderInterface::class), $decoder, $value, ); @@ -93,11 +92,11 @@ public function testDecode_DecoderExportsValue_ReturnsSameValue(): void public function testGet_ConstructedWithValue_ReturnsSameInstance(): void { - $value = $this->createMock(NodeValueInterface::class); + $value = self::createStub(NodeValueInterface::class); $result = new ExistingResult( - $this->createMock(ValueEncoderInterface::class), - $this->createMock(ValueDecoderInterface::class), - $value + self::createStub(ValueEncoderInterface::class), + self::createStub(ValueDecoderInterface::class), + $value, ); self::assertSame($value, $result->get()); } diff --git a/tests/Processor/Result/NonExistingResultTest.php b/tests/Processor/Result/NonExistingResultTest.php index fd199a5..e9aac83 100644 --- a/tests/Processor/Result/NonExistingResultTest.php +++ b/tests/Processor/Result/NonExistingResultTest.php @@ -4,13 +4,12 @@ namespace Remorhaz\JSON\Pointer\Test\Processor\Result; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Remorhaz\JSON\Pointer\Processor\Result\Exception\ResultNotFoundException; use Remorhaz\JSON\Pointer\Processor\Result\NonExistingResult; -/** - * @covers \Remorhaz\JSON\Pointer\Processor\Result\NonExistingResult - */ +#[CoversClass(NonExistingResult::class)] class NonExistingResultTest extends TestCase { public function testExists_Always_ReturnsFalse(): void diff --git a/tests/Query/Exception/LastReferenceNotFoundExceptionTest.php b/tests/Query/Exception/LastReferenceNotFoundExceptionTest.php index 087c4f6..3880ee5 100644 --- a/tests/Query/Exception/LastReferenceNotFoundExceptionTest.php +++ b/tests/Query/Exception/LastReferenceNotFoundExceptionTest.php @@ -5,12 +5,11 @@ namespace Remorhaz\JSON\Pointer\Test\Query\Exception; use Exception; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Remorhaz\JSON\Pointer\Query\Exception\LastReferenceNotFoundException; -/** - * @covers \Remorhaz\JSON\Pointer\Query\Exception\LastReferenceNotFoundException - */ +#[CoversClass(LastReferenceNotFoundException::class)] class LastReferenceNotFoundExceptionTest extends TestCase { public function testGetMessage_Constructed_ReturnsMatchingValue(): void @@ -25,12 +24,6 @@ public function testGetSource_ConstructedWithSource_ReturnsSameValue(): void self::assertSame('a', $exception->getSource()); } - public function testGetCode_Always_ReturnsZero(): void - { - $exception = new LastReferenceNotFoundException('a'); - self::assertSame(0, $exception->getCode()); - } - public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void { $exception = new LastReferenceNotFoundException('a'); diff --git a/tests/Query/Exception/ParentNotFoundExceptionTest.php b/tests/Query/Exception/ParentNotFoundExceptionTest.php index 8c27608..8a2e8d9 100644 --- a/tests/Query/Exception/ParentNotFoundExceptionTest.php +++ b/tests/Query/Exception/ParentNotFoundExceptionTest.php @@ -5,12 +5,11 @@ namespace Remorhaz\JSON\Pointer\Test\Query\Exception; use Exception; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Remorhaz\JSON\Pointer\Query\Exception\ParentNotFoundException; -/** - * @covers \Remorhaz\JSON\Pointer\Query\Exception\ParentNotFoundException - */ +#[CoversClass(ParentNotFoundException::class)] class ParentNotFoundExceptionTest extends TestCase { public function testGetMessage_Constructed_ReturnsMatchingValue(): void @@ -25,12 +24,6 @@ public function testGetSource_ConstructedWithSource_ReturnsSameValue(): void self::assertSame('a', $exception->getSource()); } - public function testGetCode_Always_ReturnsZero(): void - { - $exception = new ParentNotFoundException('a'); - self::assertSame(0, $exception->getCode()); - } - public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void { $exception = new ParentNotFoundException('a'); diff --git a/tests/Query/Exception/SelectionNotFoundExceptionTest.php b/tests/Query/Exception/SelectionNotFoundExceptionTest.php index 288de32..45148bd 100644 --- a/tests/Query/Exception/SelectionNotFoundExceptionTest.php +++ b/tests/Query/Exception/SelectionNotFoundExceptionTest.php @@ -5,12 +5,11 @@ namespace Remorhaz\JSON\Pointer\Test\Query\Exception; use Exception; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Remorhaz\JSON\Pointer\Query\Exception\SelectionNotFoundException; -/** - * @covers \Remorhaz\JSON\Pointer\Query\Exception\SelectionNotFoundException - */ +#[CoversClass(SelectionNotFoundException::class)] class SelectionNotFoundExceptionTest extends TestCase { public function testGetMessage_Constructed_ReturnsMatchingValue(): void @@ -25,12 +24,6 @@ public function testGetSource_ConstructedWithSource_ReturnsSameValue(): void self::assertSame('a', $exception->getSource()); } - public function testGetCode_Always_ReturnsZero(): void - { - $exception = new SelectionNotFoundException('a'); - self::assertSame(0, $exception->getCode()); - } - public function testGetPrevious_ConstructedWithoutPrevious_ReturnsNull(): void { $exception = new SelectionNotFoundException('a'); diff --git a/tests/Query/LazyQueryTest.php b/tests/Query/LazyQueryTest.php index d5f8521..98157df 100644 --- a/tests/Query/LazyQueryTest.php +++ b/tests/Query/LazyQueryTest.php @@ -4,20 +4,19 @@ namespace Remorhaz\JSON\Pointer\Query; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Remorhaz\JSON\Data\Value\NodeValueInterface; use Remorhaz\JSON\Pointer\Parser\ParserInterface; -/** - * @covers \Remorhaz\JSON\Pointer\Query\LazyQuery - */ +#[CoversClass(LazyQuery::class)] class LazyQueryTest extends TestCase { public function testGetSource_ConstructedWithSource_ReturnsSameValue(): void { $query = new LazyQuery( 'a', - $this->createMock(ParserInterface::class), + self::createStub(ParserInterface::class), ); self::assertSame('a', $query->getSource()); } @@ -26,7 +25,7 @@ public function testInvoke_CalledTwice_InvokesParserOnce(): void { $parser = $this->createMock(ParserInterface::class); $query = new LazyQuery('', $parser); - $value = $this->createMock(NodeValueInterface::class); + $value = self::createStub(NodeValueInterface::class); $parser ->expects(self::once()) ->method('buildLocator'); @@ -38,7 +37,7 @@ public function testInvoke_ConstructedWithSource_ParserSameSource(): void { $parser = $this->createMock(ParserInterface::class); $query = new LazyQuery('a', $parser); - $value = $this->createMock(NodeValueInterface::class); + $value = self::createStub(NodeValueInterface::class); $parser ->expects(self::once()) ->method('buildLocator') diff --git a/tests/Query/QueryFactoryTest.php b/tests/Query/QueryFactoryTest.php index ae703f3..7608e59 100644 --- a/tests/Query/QueryFactoryTest.php +++ b/tests/Query/QueryFactoryTest.php @@ -4,6 +4,7 @@ namespace Remorhaz\JSON\Pointer\Test\Query; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Remorhaz\JSON\Data\Value\NodeValueInterface; use Remorhaz\JSON\Pointer\Locator\LocatorInterface; @@ -11,9 +12,7 @@ use Remorhaz\JSON\Pointer\Query\LazyQuery; use Remorhaz\JSON\Pointer\Query\QueryFactory; -/** - * @covers \Remorhaz\JSON\Pointer\Query\QueryFactory - */ +#[CoversClass(QueryFactory::class)] class QueryFactoryTest extends TestCase { public function testCreate_Always_ReturnsQueryFactoryInstance(): void @@ -32,7 +31,7 @@ public function testCreateQuery_ConstructedWithParser_ResultCallsSameParserInsta $parser = $this->createMock(ParserInterface::class); $factory = new QueryFactory($parser); $query = $factory->createQuery('a'); - $nodeValue = $this->createMock(NodeValueInterface::class); + $nodeValue = self::createStub(NodeValueInterface::class); $parser ->expects(self::once()) @@ -43,10 +42,10 @@ public function testCreateQuery_ConstructedWithParser_ResultCallsSameParserInsta public function testCreateQuery_ConstructedWithParser_ResultUsesLocatorCreatedByParserOnExecution(): void { - $parser = $this->createMock(ParserInterface::class); + $parser = self::createStub(ParserInterface::class); $factory = new QueryFactory($parser); $query = $factory->createQuery('a'); - $nodeValue = $this->createMock(NodeValueInterface::class); + $nodeValue = self::createStub(NodeValueInterface::class); $locator = $this->createMock(LocatorInterface::class); $parser diff --git a/tests/Query/QueryResultTest.php b/tests/Query/QueryResultTest.php index de37ad7..8bf77fd 100644 --- a/tests/Query/QueryResultTest.php +++ b/tests/Query/QueryResultTest.php @@ -4,6 +4,7 @@ namespace Remorhaz\JSON\Pointer\Test\Query; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Remorhaz\JSON\Data\Value\NodeValueInterface; use Remorhaz\JSON\Pointer\Locator\ReferenceInterface; @@ -12,12 +13,10 @@ use Remorhaz\JSON\Pointer\Query\Exception\SelectionNotFoundException; use Remorhaz\JSON\Pointer\Query\QueryResult; -/** - * @covers \Remorhaz\JSON\Pointer\Query\QueryResult - */ +#[CoversClass(QueryResult::class)] class QueryResultTest extends TestCase { - public function testGetSource_ConstructedWithSource_ReturnsSameInstance(): void + public function testGetSource_ConstructedWithSource_ReturnsSameValue(): void { $result = new QueryResult('a'); self::assertSame('a', $result->getSource()); @@ -33,7 +32,7 @@ public function testHasSelection_ConstructedWithSelection_ReturnsFalse(): void { $result = new QueryResult( 'a', - $this->createMock(NodeValueInterface::class) + self::createStub(NodeValueInterface::class), ); self::assertTrue($result->hasSelection()); } @@ -47,7 +46,7 @@ public function testGetSelection_ConstructedWithoutSelection_ThrowsException(): public function testGetSelection_ConstructedWithSelection_ReturnsSameInstance(): void { - $selection = $this->createMock(NodeValueInterface::class); + $selection = self::createStub(NodeValueInterface::class); $result = new QueryResult('a', $selection); self::assertSame($selection, $result->getSelection()); } @@ -60,7 +59,7 @@ public function testHasParent_ConstructedWithoutParent_ReturnsFalse(): void public function testHasParent_ConstructedWithParent_ReturnsTrue(): void { - $parent = $this->createMock(NodeValueInterface::class); + $parent = self::createStub(NodeValueInterface::class); $result = new QueryResult('a', null, $parent); self::assertTrue($result->hasParent()); } @@ -74,7 +73,7 @@ public function testGetParent_ConstructedWithoutParent_ThrowsException(): void public function testGetParent_ConstructedWithParent_ReturnsSameInstance(): void { - $parent = $this->createMock(NodeValueInterface::class); + $parent = self::createStub(NodeValueInterface::class); $result = new QueryResult('a', null, $parent); self::assertSame($parent, $result->getParent()); } @@ -87,7 +86,7 @@ public function testHasLastReference_ConstructedWithoutLastReference_ReturnsFals public function testHasLastReference_ConstructedWithLastReference_ReturnsTrue(): void { - $reference = $this->createMock(ReferenceInterface::class); + $reference = self::createStub(ReferenceInterface::class); $result = new QueryResult('a', null, null, $reference); self::assertTrue($result->hasLastReference()); } @@ -101,7 +100,7 @@ public function testGetLastReference_ConstructedWithoutLastReference_ThrowsExcep public function testGetLastReference_ConstructedWithLastReference_ReturnsSameInstance(): void { - $reference = $this->createMock(ReferenceInterface::class); + $reference = self::createStub(ReferenceInterface::class); $result = new QueryResult('a', null, null, $reference); self::assertSame($reference, $result->getLastReference()); } diff --git a/tests/Query/QueryTest.php b/tests/Query/QueryTest.php index a9d9a74..8a19aff 100644 --- a/tests/Query/QueryTest.php +++ b/tests/Query/QueryTest.php @@ -4,6 +4,7 @@ namespace Remorhaz\JSON\Pointer\Test\Query; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Remorhaz\JSON\Data\Export\ValueDecoder; use Remorhaz\JSON\Data\Export\ValueEncoder; @@ -13,16 +14,14 @@ use Remorhaz\JSON\Pointer\Locator\PropertyReference; use Remorhaz\JSON\Pointer\Query\Query; -/** - * @covers \Remorhaz\JSON\Pointer\Query\Query - */ +#[CoversClass(Query::class)] class QueryTest extends TestCase { public function testGetSource_ConstructedWithSource_ReturnsSameValue(): void { $query = new Query( 'a', - $this->createMock(LocatorInterface::class), + self::createStub(LocatorInterface::class), ); self::assertSame('a', $query->getSource()); } diff --git a/tests/TokenMatcherTest.php b/tests/TokenMatcherTest.php index 77791f8..2d6988f 100644 --- a/tests/TokenMatcherTest.php +++ b/tests/TokenMatcherTest.php @@ -4,6 +4,8 @@ namespace Remorhaz\JSON\Pointer\Test; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Remorhaz\JSON\Pointer\Parser\TokenType; use Remorhaz\JSON\Pointer\TokenMatcher; @@ -11,21 +13,19 @@ use Remorhaz\UniLex\Lexer\TokenFactoryInterface; use Remorhaz\UniLex\Unicode\CharBufferFactory; -/** - * @covers \Remorhaz\JSON\Pointer\TokenMatcher - */ +#[CoversClass(TokenMatcher::class)] class TokenMatcherTest extends TestCase { /** * @param list $data - * @dataProvider providerInvalidData */ + #[DataProvider('providerInvalidData')] public function testMatch_InvalidDataInBuffer_ReturnsFalse(array $data): void { $matcher = new TokenMatcher(); $actualValue = $matcher->match( new CharBuffer(...$data), - $this->createMock(TokenFactoryInterface::class), + self::createStub(TokenFactoryInterface::class), ); self::assertFalse($actualValue); } @@ -41,9 +41,7 @@ public static function providerInvalidData(): iterable ]; } - /** - * @dataProvider providerValidData - */ + #[DataProvider('providerValidData')] public function testMatch_ValidDataInBuffer_ReturnsMatchingTokens(string $data, int $token): void { $tokenFactory = $this->createMock(TokenFactoryInterface::class); @@ -55,7 +53,7 @@ public function testMatch_ValidDataInBuffer_ReturnsMatchingTokens(string $data, ->with($token); $matcher->match( CharBufferFactory::createFromString($data), - $tokenFactory + $tokenFactory, ); } diff --git a/vendor-bin/cs/composer.json b/vendor-bin/cs/composer.json new file mode 100644 index 0000000..17c21c0 --- /dev/null +++ b/vendor-bin/cs/composer.json @@ -0,0 +1,5 @@ +{ + "require-dev": { + "squizlabs/php_codesniffer": "^3.9" + } +}