From a7c522dd3c1b59cd8d3215893f36bfb82017d0f8 Mon Sep 17 00:00:00 2001 From: Mokhtar Tlili Date: Mon, 9 Mar 2026 00:08:36 +0100 Subject: [PATCH 1/2] Support Symfony 8 --- .gitattributes | 0 .github/workflows/ci.yml | 7 +- .gitignore | 3 +- .php-cs-fixer.dist.php | 30 + CHANGELOG.md | 8 + LICENSE.md | 0 README.md | 2 +- composer.json | 20 +- flake.lock | 607 +++++------------- flake.nix | 4 +- phpunit.xml.dist | 0 src/Attribute/Input.php | 6 +- src/DependencyInjection/Configuration.php | 48 +- .../RequestInputExtension.php | 10 +- src/EventListener/ExceptionListener.php | 6 +- src/EventListener/ReadInputListener.php | 4 +- src/Exception/DeserializationException.php | 0 src/Exception/ExceptionInterface.php | 4 +- src/Exception/UnexpectedFormatException.php | 4 +- src/Exception/ValidationException.php | 0 src/Factory/InputFactory.php | 16 +- src/Factory/InputFactoryInterface.php | 1 - src/InputInterface.php | 4 +- src/Metadata/InputMetadataFactory.php | 4 +- .../InputMetadataFactoryInterface.php | 2 +- src/RequestInputBundle.php | 4 +- src/ValueResolver/InputValueResolver.php | 6 +- tests/Attribute/InputTest.php | 5 + .../DependencyInjection/ConfigurationTest.php | 21 +- .../RequestInputExtensionTest.php | 23 +- tests/EventListener/ExceptionListenerTest.php | 9 +- tests/EventListener/ReadInputListenerTest.php | 7 + tests/Factory/InputFactoryTest.php | 129 +--- tests/Fixtures/Controller/TestController.php | 16 +- tests/Fixtures/Input/DummyInput.php | 2 +- tests/Metadata/InputMetadataFactoryTest.php | 21 +- .../ValueResolver/InputValueResolverTest.php | 8 +- 37 files changed, 373 insertions(+), 668 deletions(-) mode change 100644 => 100755 .gitattributes mode change 100644 => 100755 .github/workflows/ci.yml mode change 100644 => 100755 .gitignore create mode 100644 .php-cs-fixer.dist.php mode change 100644 => 100755 CHANGELOG.md mode change 100644 => 100755 LICENSE.md mode change 100644 => 100755 README.md mode change 100644 => 100755 composer.json mode change 100644 => 100755 flake.nix mode change 100644 => 100755 phpunit.xml.dist mode change 100644 => 100755 src/Attribute/Input.php mode change 100644 => 100755 src/DependencyInjection/RequestInputExtension.php mode change 100644 => 100755 src/EventListener/ExceptionListener.php mode change 100644 => 100755 src/EventListener/ReadInputListener.php mode change 100644 => 100755 src/Exception/DeserializationException.php mode change 100644 => 100755 src/Exception/ExceptionInterface.php mode change 100644 => 100755 src/Exception/UnexpectedFormatException.php mode change 100644 => 100755 src/Exception/ValidationException.php mode change 100644 => 100755 src/Factory/InputFactory.php mode change 100644 => 100755 src/Factory/InputFactoryInterface.php mode change 100644 => 100755 src/InputInterface.php mode change 100644 => 100755 src/Metadata/InputMetadataFactory.php mode change 100644 => 100755 src/Metadata/InputMetadataFactoryInterface.php mode change 100644 => 100755 src/RequestInputBundle.php mode change 100644 => 100755 src/ValueResolver/InputValueResolver.php mode change 100644 => 100755 tests/Attribute/InputTest.php mode change 100644 => 100755 tests/DependencyInjection/ConfigurationTest.php mode change 100644 => 100755 tests/DependencyInjection/RequestInputExtensionTest.php mode change 100644 => 100755 tests/EventListener/ExceptionListenerTest.php mode change 100644 => 100755 tests/EventListener/ReadInputListenerTest.php mode change 100644 => 100755 tests/Factory/InputFactoryTest.php mode change 100644 => 100755 tests/Fixtures/Controller/TestController.php mode change 100644 => 100755 tests/Fixtures/Input/DummyInput.php mode change 100644 => 100755 tests/Metadata/InputMetadataFactoryTest.php mode change 100644 => 100755 tests/ValueResolver/InputValueResolverTest.php diff --git a/.gitattributes b/.gitattributes old mode 100644 new mode 100755 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml old mode 100644 new mode 100755 index fab42f3..025ec75 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,8 +17,7 @@ jobs: fail-fast: false matrix: php-version: - - "8.1" - - "8.2" + - "8.4" dependencies: - "highest" stability: @@ -27,11 +26,11 @@ jobs: # Tests the lowest set of dependencies - dependencies: "lowest" stability: "stable" - php-version: "8.1" + php-version: "8.4" # Tests the highest set of dependencies - dependencies: "highest" stability: "dev" - php-version: "8.2" + php-version: "8.4" steps: - name: "Checkout" diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 index 2a88ee6..95377c5 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ .php-cs-fixer.cache .phpunit.result.cache coverage.xml -.result \ No newline at end of file +.result +/flake.lock \ No newline at end of file diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..a112ab3 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,30 @@ +setRiskyAllowed(false) + ->setRules([ + '@auto' => true, + '@PhpCsFixer' => true, + 'php_unit_test_class_requires_covers' => false, + ]) + // 💡 by default, Fixer looks for `*.php` files excluding `./vendor/` - here, you can groom this config + ->setFinder( + (new Finder()) + // 💡 root folder to check + ->in(__DIR__) + // 💡 additional files, eg bin entry file + // ->append([__DIR__.'/bin-entry-file']) + // 💡 folders to exclude, if any + // ->exclude([/* ... */]) + // 💡 path patterns to exclude, if any + // ->notPath([/* ... */]) + // 💡 extra configs + // ->ignoreDotFiles(false) // true by default in v3, false in v4 or future mode + // ->ignoreVCS(true) // true by default + ) +; diff --git a/CHANGELOG.md b/CHANGELOG.md old mode 100644 new mode 100755 index 4ac6a1c..b1a5b96 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 2.0.0 +- Support Symfony v8. +- Upgrade PHPunit to v12. +- Fix Symfony and PHPUnit deprecations. +- Remove `form` format deprecations. +- Fix [#22](https://github.com/sfmok/request-input-bundle/issues/22) +- Fix [#21](https://github.com/sfmok/request-input-bundle/issues/21) + ## 1.2.6 - Support symfony 7 & fix deprecation. - Deprecate `form` request input data. diff --git a/LICENSE.md b/LICENSE.md old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 index a439e06..149ed84 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ **RequestInputBundle** converts request data into DTO inputs objects with validation. -- Request data supported: `json`, `xml` and `form` based on `Content-Type` header. +- Request data supported: `json` and `xml` based on `Content-Type` header. - Resolve inputs arguments for controllers actions. - Create DTO inputs outside controllers - Validate DTO inputs objects. diff --git a/composer.json b/composer.json old mode 100644 new mode 100755 index dd2bc78..9f47fff --- a/composer.json +++ b/composer.json @@ -18,19 +18,19 @@ ], "license": "MIT", "require": { - "php": ">=8.1", - "symfony/http-kernel": "^6.2|^7.0", - "symfony/http-foundation": "^6.2|^7.0", - "symfony/serializer": "^6.2|^7.0", - "symfony/validator": "^6.2|^7.0", - "symfony/dependency-injection": "^6.2|^7.0", - "symfony/property-access": "^6.2|^7.0" + "php": ">=8.4", + "symfony/http-kernel": "^8.0", + "symfony/http-foundation": "^8.0", + "symfony/serializer": "^8.0", + "symfony/validator": "^8.0", + "symfony/dependency-injection": "^8.0", + "symfony/property-access": "^8.0" }, "require-dev": { - "phpunit/phpunit": "^10.5", - "symfony/framework-bundle": "^6.2|^7.0", + "phpunit/phpunit": "^12.0", + "symfony/framework-bundle": "^8.0", "friendsofphp/php-cs-fixer": "^3.5", - "phpstan/phpstan": "^1.9" + "phpstan/phpstan": "^2.0" }, "autoload": { "psr-4": { diff --git a/flake.lock b/flake.lock index add9bcf..22329c3 100644 --- a/flake.lock +++ b/flake.lock @@ -2,24 +2,33 @@ "nodes": { "cachix": { "inputs": { - "devenv": "devenv_2", - "flake-compat": "flake-compat_2", + "devenv": [ + "devenv" + ], + "flake-compat": [ + "devenv", + "flake-compat" + ], + "git-hooks": [ + "devenv", + "git-hooks" + ], "nixpkgs": [ "devenv", "nixpkgs" - ], - "pre-commit-hooks": "pre-commit-hooks" + ] }, "locked": { - "lastModified": 1710475558, - "narHash": "sha256-egKrPCKjy/cE+NqCj4hg2fNX/NwLCf0bRDInraYXDgs=", + "lastModified": 1767714506, + "narHash": "sha256-WaTs0t1CxhgxbIuvQ97OFhDTVUGd1HA+KzLZUZBhe0s=", "owner": "cachix", "repo": "cachix", - "rev": "661bbb7f8b55722a0406456b15267b5426a3bda6", + "rev": "894c649f0daaa38bbcfb21de64be47dfa7cd0ec9", "type": "github" }, "original": { "owner": "cachix", + "ref": "latest", "repo": "cachix", "type": "github" } @@ -27,52 +36,23 @@ "devenv": { "inputs": { "cachix": "cachix", - "flake-compat": "flake-compat_4", - "nix": "nix_2", - "nixpkgs": "nixpkgs_2", - "pre-commit-hooks": "pre-commit-hooks_2" - }, - "locked": { - "lastModified": 1711019207, - "narHash": "sha256-9LnGe0KWqXj18IV+A1panzXQuTamrH/QcasaqnuqiE0=", - "owner": "cachix", - "repo": "devenv", - "rev": "a7ba6766c0cc351b8656c63560c6b19c3788455f", - "type": "github" - }, - "original": { - "owner": "cachix", - "repo": "devenv", - "type": "github" - } - }, - "devenv_2": { - "inputs": { - "flake-compat": [ - "devenv", - "cachix", - "flake-compat" - ], + "flake-compat": "flake-compat", + "flake-parts": "flake-parts", + "git-hooks": "git-hooks", "nix": "nix", - "nixpkgs": "nixpkgs", - "poetry2nix": "poetry2nix", - "pre-commit-hooks": [ - "devenv", - "cachix", - "pre-commit-hooks" - ] + "nixd": "nixd", + "nixpkgs": "nixpkgs" }, "locked": { - "lastModified": 1708704632, - "narHash": "sha256-w+dOIW60FKMaHI1q5714CSibk99JfYxm0CzTinYWr+Q=", + "lastModified": 1772989822, + "narHash": "sha256-3TQjDm5pXTpmsc7T48hlAxgm6G5INqZHyw8Rk9zYTG0=", "owner": "cachix", "repo": "devenv", - "rev": "2ee4450b0f4b95a1b90f2eb5ffea98b90e48c196", + "rev": "f8846599708f5c6ba69c156d4becaaab2218e184", "type": "github" }, "original": { "owner": "cachix", - "ref": "python-rewrite", "repo": "devenv", "type": "github" } @@ -80,11 +60,11 @@ "flake-compat": { "flake": false, "locked": { - "lastModified": 1673956053, - "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "lastModified": 1767039857, + "narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=", "owner": "edolstra", "repo": "flake-compat", - "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab", "type": "github" }, "original": { @@ -96,93 +76,50 @@ "flake-compat_2": { "flake": false, "locked": { - "lastModified": 1696426674, - "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", - "type": "github" - }, - "original": { - "owner": "edolstra", - "repo": "flake-compat", - "type": "github" - } - }, - "flake-compat_3": { - "flake": false, - "locked": { - "lastModified": 1696426674, - "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", - "type": "github" - }, - "original": { - "owner": "edolstra", - "repo": "flake-compat", - "type": "github" - } - }, - "flake-compat_4": { - "flake": false, - "locked": { - "lastModified": 1696426674, - "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", - "owner": "edolstra", + "lastModified": 1767039857, + "narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=", + "owner": "NixOS", "repo": "flake-compat", - "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab", "type": "github" }, "original": { - "owner": "edolstra", + "owner": "NixOS", "repo": "flake-compat", "type": "github" } }, - "flake-compat_5": { - "flake": false, - "locked": { - "lastModified": 1673956053, - "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", - "type": "github" + "flake-parts": { + "inputs": { + "nixpkgs-lib": [ + "devenv", + "nixpkgs" + ] }, - "original": { - "owner": "edolstra", - "repo": "flake-compat", - "type": "github" - } - }, - "flake-compat_6": { - "flake": false, "locked": { - "lastModified": 1696426674, - "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "lastModified": 1772408722, + "narHash": "sha256-rHuJtdcOjK7rAHpHphUb1iCvgkU3GpfvicLMwwnfMT0=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "f20dc5d9b8027381c474144ecabc9034d6a839a3", "type": "github" }, "original": { - "owner": "edolstra", - "repo": "flake-compat", + "owner": "hercules-ci", + "repo": "flake-parts", "type": "github" } }, - "flake-parts": { + "flake-parts_2": { "inputs": { "nixpkgs-lib": "nixpkgs-lib" }, "locked": { - "lastModified": 1709336216, - "narHash": "sha256-Dt/wOWeW6Sqm11Yh+2+t0dfEWxoMxGBvv3JpIocFl9E=", + "lastModified": 1772408722, + "narHash": "sha256-rHuJtdcOjK7rAHpHphUb1iCvgkU3GpfvicLMwwnfMT0=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "f7b3c975cf067e56e7cda6cb098ebe3fb4d74ca2", + "rev": "f20dc5d9b8027381c474144ecabc9034d6a839a3", "type": "github" }, "original": { @@ -190,97 +127,61 @@ "type": "indirect" } }, - "flake-utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1689068808, - "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_2": { - "inputs": { - "systems": "systems_2" - }, - "locked": { - "lastModified": 1701680307, - "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_3": { - "inputs": { - "systems": "systems_3" - }, + "flake-root": { "locked": { - "lastModified": 1701680307, - "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", + "lastModified": 1723604017, + "narHash": "sha256-rBtQ8gg+Dn4Sx/s+pvjdq3CB2wQNzx9XGFq/JVGCB6k=", + "owner": "srid", + "repo": "flake-root", + "rev": "b759a56851e10cb13f6b8e5698af7b59c44be26e", "type": "github" }, "original": { - "owner": "numtide", - "repo": "flake-utils", + "owner": "srid", + "repo": "flake-root", "type": "github" } }, - "gitignore": { + "git-hooks": { "inputs": { + "flake-compat": [ + "devenv", + "flake-compat" + ], + "gitignore": "gitignore", "nixpkgs": [ "devenv", - "cachix", - "pre-commit-hooks", "nixpkgs" ] }, "locked": { - "lastModified": 1703887061, - "narHash": "sha256-gGPa9qWNc6eCXT/+Z5/zMkyYOuRZqeFZBDbopNZQkuY=", - "owner": "hercules-ci", - "repo": "gitignore.nix", - "rev": "43e1aa1308018f37118e34d3a9cb4f5e75dc11d5", + "lastModified": 1772665116, + "narHash": "sha256-XmjUDG/J8Z8lY5DVNVUf5aoZGc400FxcjsNCqHKiKtc=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "39f53203a8458c330f61cc0759fe243f0ac0d198", "type": "github" }, "original": { - "owner": "hercules-ci", - "repo": "gitignore.nix", + "owner": "cachix", + "repo": "git-hooks.nix", "type": "github" } }, - "gitignore_2": { + "gitignore": { "inputs": { "nixpkgs": [ "devenv", - "pre-commit-hooks", + "git-hooks", "nixpkgs" ] }, "locked": { - "lastModified": 1703887061, - "narHash": "sha256-gGPa9qWNc6eCXT/+Z5/zMkyYOuRZqeFZBDbopNZQkuY=", + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", "owner": "hercules-ci", "repo": "gitignore.nix", - "rev": "43e1aa1308018f37118e34d3a9cb4f5e75dc11d5", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", "type": "github" }, "original": { @@ -291,199 +192,129 @@ }, "nix": { "inputs": { - "flake-compat": "flake-compat", - "nixpkgs": [ + "flake-compat": [ "devenv", - "cachix", + "flake-compat" + ], + "flake-parts": [ + "devenv", + "flake-parts" + ], + "git-hooks-nix": [ + "devenv", + "git-hooks" + ], + "nixpkgs": [ "devenv", "nixpkgs" ], - "nixpkgs-regression": "nixpkgs-regression" + "nixpkgs-23-11": [ + "devenv" + ], + "nixpkgs-regression": [ + "devenv" + ] }, "locked": { - "lastModified": 1708577783, - "narHash": "sha256-92xq7eXlxIT5zFNccLpjiP7sdQqQI30Gyui2p/PfKZM=", - "owner": "domenkozar", + "lastModified": 1772748357, + "narHash": "sha256-vtf03lfgQKNkPH9FdXdboBDS5DtFkXB8xRw5EBpuDas=", + "owner": "cachix", "repo": "nix", - "rev": "ecd0af0c1f56de32cbad14daa1d82a132bf298f8", + "rev": "41eee9d3b1f611b1b90d51caa858b6d83834c44a", "type": "github" }, "original": { - "owner": "domenkozar", - "ref": "devenv-2.21", + "owner": "cachix", + "ref": "devenv-2.32", "repo": "nix", "type": "github" } }, - "nix-github-actions": { + "nixd": { "inputs": { - "nixpkgs": [ + "flake-parts": [ "devenv", - "cachix", + "flake-parts" + ], + "flake-root": "flake-root", + "nixpkgs": [ "devenv", - "poetry2nix", "nixpkgs" - ] + ], + "treefmt-nix": "treefmt-nix" }, "locked": { - "lastModified": 1688870561, - "narHash": "sha256-4UYkifnPEw1nAzqqPOTL2MvWtm3sNGw1UTYTalkTcGY=", + "lastModified": 1772441848, + "narHash": "sha256-H3W5PSJQTh8Yp51PGU3GUoGCcrD+y7nCsxYHQr+Orvw=", "owner": "nix-community", - "repo": "nix-github-actions", - "rev": "165b1650b753316aa7f1787f3005a8d2da0f5301", + "repo": "nixd", + "rev": "c896f916addae5b133ee0f4f01f9cd93906f62ea", "type": "github" }, "original": { "owner": "nix-community", - "repo": "nix-github-actions", + "repo": "nixd", "type": "github" } }, - "nix_2": { + "nixpkgs": { "inputs": { - "flake-compat": "flake-compat_5", - "nixpkgs": [ - "devenv", - "nixpkgs" - ], - "nixpkgs-regression": "nixpkgs-regression_2" + "nixpkgs-src": "nixpkgs-src" }, "locked": { - "lastModified": 1710500156, - "narHash": "sha256-zvCqeUO2GLOm7jnU23G4EzTZR7eylcJN+HJ5svjmubI=", - "owner": "domenkozar", - "repo": "nix", - "rev": "c5bbf14ecbd692eeabf4184cc8d50f79c2446549", - "type": "github" - }, - "original": { - "owner": "domenkozar", - "ref": "devenv-2.21", - "repo": "nix", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1692808169, - "narHash": "sha256-x9Opq06rIiwdwGeK2Ykj69dNc2IvUH1fY55Wm7atwrE=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "9201b5ff357e781bf014d0330d18555695df7ba8", + "lastModified": 1772749504, + "narHash": "sha256-eqtQIz0alxkQPym+Zh/33gdDjkkch9o6eHnMPnXFXN0=", + "owner": "cachix", + "repo": "devenv-nixpkgs", + "rev": "08543693199362c1fddb8f52126030d0d374ba2e", "type": "github" }, "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", + "owner": "cachix", + "ref": "rolling", + "repo": "devenv-nixpkgs", "type": "github" } }, "nixpkgs-lib": { "locked": { - "dir": "lib", - "lastModified": 1709237383, - "narHash": "sha256-cy6ArO4k5qTx+l5o+0mL9f5fa86tYUX3ozE1S+Txlds=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "1536926ef5621b09bba54035ae2bb6d806d72ac8", - "type": "github" - }, - "original": { - "dir": "lib", - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs-regression": { - "locked": { - "lastModified": 1643052045, - "narHash": "sha256-uGJ0VXIhWKGXxkeNnq4TvV3CIOkUJ3PAoLZ3HMzNVMw=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", - "type": "github" - }, - "original": { - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", - "type": "github" - } - }, - "nixpkgs-regression_2": { - "locked": { - "lastModified": 1643052045, - "narHash": "sha256-uGJ0VXIhWKGXxkeNnq4TvV3CIOkUJ3PAoLZ3HMzNVMw=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", - "type": "github" - }, - "original": { - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", - "type": "github" - } - }, - "nixpkgs-stable": { - "locked": { - "lastModified": 1704874635, - "narHash": "sha256-YWuCrtsty5vVZvu+7BchAxmcYzTMfolSPP5io8+WYCg=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "3dc440faeee9e889fe2d1b4d25ad0f430d449356", + "lastModified": 1772328832, + "narHash": "sha256-e+/T/pmEkLP6BHhYjx6GmwP5ivonQQn0bJdH9YrRB+Q=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "c185c7a5e5dd8f9add5b2f8ebeff00888b070742", "type": "github" }, "original": { - "owner": "NixOS", - "ref": "nixos-23.11", - "repo": "nixpkgs", + "owner": "nix-community", + "repo": "nixpkgs.lib", "type": "github" } }, - "nixpkgs-stable_2": { + "nixpkgs-src": { + "flake": false, "locked": { - "lastModified": 1704874635, - "narHash": "sha256-YWuCrtsty5vVZvu+7BchAxmcYzTMfolSPP5io8+WYCg=", + "lastModified": 1772173633, + "narHash": "sha256-MOH58F4AIbCkh6qlQcwMycyk5SWvsqnS/TCfnqDlpj4=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "3dc440faeee9e889fe2d1b4d25ad0f430d449356", + "rev": "c0f3d81a7ddbc2b1332be0d8481a672b4f6004d6", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixos-23.11", + "ref": "nixpkgs-unstable", "repo": "nixpkgs", "type": "github" } }, "nixpkgs_2": { "locked": { - "lastModified": 1710236354, - "narHash": "sha256-vWrciFdq49vve43g4pbi7NjmL4cwG1ifXnQx+dU3T5E=", - "owner": "cachix", - "repo": "devenv-nixpkgs", - "rev": "829e73affeadfb4198a7105cbe3a03153d13edc9", - "type": "github" - }, - "original": { - "owner": "cachix", - "ref": "rolling", - "repo": "devenv-nixpkgs", - "type": "github" - } - }, - "nixpkgs_3": { - "locked": { - "lastModified": 1710889954, - "narHash": "sha256-Pr6F5Pmd7JnNEMHHmspZ0qVqIBVxyZ13ik1pJtm2QXk=", + "lastModified": 1772771118, + "narHash": "sha256-xWzaTvmmACR/SRWtABgI/Z97lcqwJAeoSd5QW1KdK1s=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "7872526e9c5332274ea5932a0c3270d6e4724f3b", + "rev": "e38213b91d3786389a446dfce4ff5a8aaf6012f2", "type": "github" }, "original": { @@ -493,13 +324,13 @@ "type": "github" } }, - "nixpkgs_4": { + "nixpkgs_3": { "locked": { - "lastModified": 1710534455, - "narHash": "sha256-huQT4Xs0y4EeFKn2BTBVYgEwJSv8SDlm82uWgMnCMmI=", + "lastModified": 1772173633, + "narHash": "sha256-MOH58F4AIbCkh6qlQcwMycyk5SWvsqnS/TCfnqDlpj4=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "9af9c1c87ed3e3ed271934cb896e0cdd33dae212", + "rev": "c0f3d81a7ddbc2b1332be0d8481a672b4f6004d6", "type": "github" }, "original": { @@ -511,16 +342,16 @@ }, "phps": { "inputs": { - "flake-compat": "flake-compat_6", - "nixpkgs": "nixpkgs_4", + "flake-compat": "flake-compat_2", + "nixpkgs": "nixpkgs_3", "utils": "utils" }, "locked": { - "lastModified": 1710655046, - "narHash": "sha256-trKsOhL4F+Zqel/Twj5KTUsYrWpQ39RryCXqqB92Pm8=", + "lastModified": 1772365008, + "narHash": "sha256-/ynkWKeZ1dyRIUkQas0AB35semWAwCbTKXu+/q+8MGg=", "owner": "fossar", "repo": "nix-phps", - "rev": "3d37e59865d77328ee23e0c93a25187bf7924568", + "rev": "f47eb877bf1c219809e4357eec2fdab8e3263b7b", "type": "github" }, "original": { @@ -529,92 +360,13 @@ "type": "github" } }, - "poetry2nix": { - "inputs": { - "flake-utils": "flake-utils", - "nix-github-actions": "nix-github-actions", - "nixpkgs": [ - "devenv", - "cachix", - "devenv", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1692876271, - "narHash": "sha256-IXfZEkI0Mal5y1jr6IRWMqK8GW2/f28xJenZIPQqkY0=", - "owner": "nix-community", - "repo": "poetry2nix", - "rev": "d5006be9c2c2417dafb2e2e5034d83fabd207ee3", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "poetry2nix", - "type": "github" - } - }, - "pre-commit-hooks": { - "inputs": { - "flake-compat": "flake-compat_3", - "flake-utils": "flake-utils_2", - "gitignore": "gitignore", - "nixpkgs": [ - "devenv", - "cachix", - "nixpkgs" - ], - "nixpkgs-stable": "nixpkgs-stable" - }, - "locked": { - "lastModified": 1708018599, - "narHash": "sha256-M+Ng6+SePmA8g06CmUZWi1AjG2tFBX9WCXElBHEKnyM=", - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "rev": "5df5a70ad7575f6601d91f0efec95dd9bc619431", - "type": "github" - }, - "original": { - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "type": "github" - } - }, - "pre-commit-hooks_2": { - "inputs": { - "flake-compat": [ - "devenv", - "flake-compat" - ], - "flake-utils": "flake-utils_3", - "gitignore": "gitignore_2", - "nixpkgs": [ - "devenv", - "nixpkgs" - ], - "nixpkgs-stable": "nixpkgs-stable_2" - }, - "locked": { - "lastModified": 1708018599, - "narHash": "sha256-M+Ng6+SePmA8g06CmUZWi1AjG2tFBX9WCXElBHEKnyM=", - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "rev": "5df5a70ad7575f6601d91f0efec95dd9bc619431", - "type": "github" - }, - "original": { - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "type": "github" - } - }, "root": { "inputs": { "devenv": "devenv", - "flake-parts": "flake-parts", - "nixpkgs": "nixpkgs_3", + "flake-parts": "flake-parts_2", + "nixpkgs": "nixpkgs_2", "phps": "phps", - "systems": "systems_5" + "systems": "systems_2" } }, "systems": { @@ -647,61 +399,38 @@ "type": "github" } }, - "systems_3": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - }, - "systems_4": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "devenv", + "nixd", + "nixpkgs" + ] }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - }, - "systems_5": { "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "lastModified": 1734704479, + "narHash": "sha256-MMi74+WckoyEWBRcg/oaGRvXC9BVVxDZNRMpL+72wBI=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "65712f5af67234dad91a5a4baee986a8b62dbf8f", "type": "github" }, "original": { - "owner": "nix-systems", - "repo": "default", + "owner": "numtide", + "repo": "treefmt-nix", "type": "github" } }, "utils": { "inputs": { - "systems": "systems_4" + "systems": "systems" }, "locked": { - "lastModified": 1710146030, - "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", "owner": "numtide", "repo": "flake-utils", - "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix old mode 100644 new mode 100755 index 65a6884..3e128a4 --- a/flake.nix +++ b/flake.nix @@ -25,8 +25,8 @@ name = "php-dev-env"; packages = [ - pkgs.php82 - pkgs.php82.packages.composer + pkgs.php84 + pkgs.php84.packages.composer ]; }; }; diff --git a/phpunit.xml.dist b/phpunit.xml.dist old mode 100644 new mode 100755 diff --git a/src/Attribute/Input.php b/src/Attribute/Input.php old mode 100644 new mode 100755 index 8df7ed7..64ec61c --- a/src/Attribute/Input.php +++ b/src/Attribute/Input.php @@ -9,15 +9,13 @@ class Input { public const INPUT_JSON_FORMAT = 'json'; public const INPUT_XML_FORMAT = 'xml'; - public const INPUT_FORM_FORMAT = 'form'; - public const INPUT_SUPPORTED_FORMATS = [self::INPUT_JSON_FORMAT, self::INPUT_XML_FORMAT, self::INPUT_FORM_FORMAT]; + public const INPUT_SUPPORTED_FORMATS = [self::INPUT_JSON_FORMAT, self::INPUT_XML_FORMAT]; public function __construct( private string $format = 'json', private array $groups = ['Default'], private array $context = [] - ) { - } + ) {} public function getFormat(): string { diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 9167d11..f18ae19 100755 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -24,29 +24,31 @@ public function getConfigTreeBuilder(): TreeBuilder ->fixXmlConfig('format', 'formats') ->addDefaultsIfNotSet() ->children() - ->booleanNode('enabled') - ->defaultTrue() - ->end() - ->arrayNode('formats') - ->defaultValue(Input::INPUT_SUPPORTED_FORMATS) - ->requiresAtLeastOneElement() - ->scalarPrototype()->end() - ->validate() - ->ifTrue(function ($values) { - foreach ($values as $value) { - if (!\in_array($value, Input::INPUT_SUPPORTED_FORMATS)) { - return true; - } - } - return false; - }) - ->thenInvalid(sprintf('Only the formats [%s] are supported. Got %s.', implode(', ', Input::INPUT_SUPPORTED_FORMATS), '%s')) - ->end() - ->end() - ->booleanNode('skip_validation') - ->defaultFalse() - ->end() - ->end(); + ->booleanNode('enabled') + ->defaultTrue() + ->end() + ->arrayNode('formats') + ->defaultValue(Input::INPUT_SUPPORTED_FORMATS) + ->requiresAtLeastOneElement() + ->scalarPrototype()->end() + ->validate() + ->ifTrue(function ($values) { + foreach ($values as $value) { + if (!\in_array($value, Input::INPUT_SUPPORTED_FORMATS)) { + return true; + } + } + + return false; + }) + ->thenInvalid(sprintf('Only the formats [%s] are supported. Got %s.', implode(', ', Input::INPUT_SUPPORTED_FORMATS), '%s')) + ->end() + ->end() + ->booleanNode('skip_validation') + ->defaultFalse() + ->end() + ->end() + ; return $treeBuilder; } diff --git a/src/DependencyInjection/RequestInputExtension.php b/src/DependencyInjection/RequestInputExtension.php old mode 100644 new mode 100755 index cb36b54..c2552c0 --- a/src/DependencyInjection/RequestInputExtension.php +++ b/src/DependencyInjection/RequestInputExtension.php @@ -4,22 +4,22 @@ namespace Sfmok\RequestInput\DependencyInjection; +use Sfmok\RequestInput\EventListener\ExceptionListener; +use Sfmok\RequestInput\EventListener\ReadInputListener; use Sfmok\RequestInput\Factory\InputFactory; use Sfmok\RequestInput\Factory\InputFactoryInterface; use Sfmok\RequestInput\Metadata\InputMetadataFactory; use Sfmok\RequestInput\Metadata\InputMetadataFactoryInterface; -use Sfmok\RequestInput\EventListener\ReadInputListener; -use Sfmok\RequestInput\EventListener\ExceptionListener; use Sfmok\RequestInput\ValueResolver\InputValueResolver; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Extension\Extension; use Symfony\Component\DependencyInjection\Reference; -use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\Serializer\SerializerInterface; use Symfony\Component\Validator\Validator\ValidatorInterface; /** -* @internal -*/ + * @internal + */ class RequestInputExtension extends Extension { public function load(array $configs, ContainerBuilder $container): void diff --git a/src/EventListener/ExceptionListener.php b/src/EventListener/ExceptionListener.php old mode 100644 new mode 100755 index 82d544b..b4bcb1d --- a/src/EventListener/ExceptionListener.php +++ b/src/EventListener/ExceptionListener.php @@ -13,9 +13,7 @@ class ExceptionListener { - public function __construct(private SerializerInterface $serializer) - { - } + public function __construct(private SerializerInterface $serializer) {} public function onKernelException(ExceptionEvent $event): void { @@ -55,7 +53,7 @@ public function onKernelException(ExceptionEvent $event): void $data = json_encode([ 'title' => $exception->getMessage(), 'detail' => empty($violations) ? $detail : 'Data error', - 'violations' => $violations + 'violations' => $violations, ]); $event->setResponse(new Response($data, $exception->getStatusCode(), $headers)); diff --git a/src/EventListener/ReadInputListener.php b/src/EventListener/ReadInputListener.php old mode 100644 new mode 100755 index cbfc984..b441593 --- a/src/EventListener/ReadInputListener.php +++ b/src/EventListener/ReadInputListener.php @@ -11,9 +11,7 @@ class ReadInputListener { - public function __construct(private InputMetadataFactoryInterface $inputMetadataFactory) - { - } + public function __construct(private InputMetadataFactoryInterface $inputMetadataFactory) {} public function onKernelController(ControllerEvent $event): void { diff --git a/src/Exception/DeserializationException.php b/src/Exception/DeserializationException.php old mode 100644 new mode 100755 diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php old mode 100644 new mode 100755 index 2b966a4..f5b88ca --- a/src/Exception/ExceptionInterface.php +++ b/src/Exception/ExceptionInterface.php @@ -4,6 +4,4 @@ namespace Sfmok\RequestInput\Exception; -interface ExceptionInterface extends \Throwable -{ -} +interface ExceptionInterface extends \Throwable {} diff --git a/src/Exception/UnexpectedFormatException.php b/src/Exception/UnexpectedFormatException.php old mode 100644 new mode 100755 index 6311b8b..3e73eff --- a/src/Exception/UnexpectedFormatException.php +++ b/src/Exception/UnexpectedFormatException.php @@ -6,6 +6,4 @@ use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; -class UnexpectedFormatException extends BadRequestHttpException -{ -} +class UnexpectedFormatException extends BadRequestHttpException {} diff --git a/src/Exception/ValidationException.php b/src/Exception/ValidationException.php old mode 100644 new mode 100755 diff --git a/src/Factory/InputFactory.php b/src/Factory/InputFactory.php old mode 100644 new mode 100755 index 7cb1136..19d6a7d --- a/src/Factory/InputFactory.php +++ b/src/Factory/InputFactory.php @@ -4,10 +4,9 @@ namespace Sfmok\RequestInput\Factory; -use Sfmok\RequestInput\Attribute\Input; use Sfmok\RequestInput\Exception\DeserializationException; -use Sfmok\RequestInput\InputInterface; use Sfmok\RequestInput\Exception\ValidationException; +use Sfmok\RequestInput\InputInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException; use Symfony\Component\Serializer\Exception\UnexpectedValueException; @@ -24,8 +23,7 @@ public function __construct( private ValidatorInterface $validator, private bool $skipValidation, private array $inputFormats - ) { - } + ) {} public function createFromRequest(Request $request, string $type): iterable { @@ -33,10 +31,6 @@ public function createFromRequest(Request $request, string $type): iterable return []; } - if (!is_subclass_of($type, InputInterface::class)) { - return []; - } - $contentType = $request->headers->get('CONTENT_TYPE'); if (null === $contentType || '' === $contentType) { throw new UnsupportedMediaTypeHttpException('The "Content-Type" header must exist and not empty.'); @@ -52,11 +46,6 @@ public function createFromRequest(Request $request, string $type): iterable $data = $request->getContent(); $format = $request->getContentTypeFormat(); - if (Input::INPUT_FORM_FORMAT === $format) { - @trigger_error("The format 'form' is deprecated and will be removed in version 2.0. Use 'symfony/form' component instead.", \E_USER_DEPRECATED); - $data = json_encode($request->request->all()); - $format = Input::INPUT_JSON_FORMAT; - } try { $input = $this->serializer->deserialize($data, $type, $format, $inputMetadata?->getContext() ?? []); @@ -64,7 +53,6 @@ public function createFromRequest(Request $request, string $type): iterable throw new DeserializationException('Deserialization Failed', $exception); } - if (!$this->skipValidation) { $violations = $this->validator->validate($input, null, $inputMetadata?->getGroups() ?? ['Default']); diff --git a/src/Factory/InputFactoryInterface.php b/src/Factory/InputFactoryInterface.php old mode 100644 new mode 100755 index ad7da8d..680d123 --- a/src/Factory/InputFactoryInterface.php +++ b/src/Factory/InputFactoryInterface.php @@ -4,7 +4,6 @@ namespace Sfmok\RequestInput\Factory; -use Sfmok\RequestInput\InputInterface; use Symfony\Component\HttpFoundation\Request; interface InputFactoryInterface diff --git a/src/InputInterface.php b/src/InputInterface.php old mode 100644 new mode 100755 index de3df4e..3f286e6 --- a/src/InputInterface.php +++ b/src/InputInterface.php @@ -4,6 +4,4 @@ namespace Sfmok\RequestInput; -interface InputInterface -{ -} +interface InputInterface {} diff --git a/src/Metadata/InputMetadataFactory.php b/src/Metadata/InputMetadataFactory.php old mode 100644 new mode 100755 index c84b152..50df05c --- a/src/Metadata/InputMetadataFactory.php +++ b/src/Metadata/InputMetadataFactory.php @@ -8,14 +8,14 @@ final class InputMetadataFactory implements InputMetadataFactoryInterface { - public function createInputMetadata(string|object|array $controller): ?Input + public function createInputMetadata(array|object|string $controller): ?Input { if (\is_array($controller)) { $reflection = new \ReflectionMethod($controller[0], $controller[1]); } elseif (\is_object($controller) && !$controller instanceof \Closure) { $reflection = new \ReflectionMethod($controller, '__invoke'); } elseif (\is_string($controller) && \str_contains($controller, '::')) { - $reflection = new \ReflectionMethod($controller); + $reflection = \ReflectionMethod::createFromMethodName($controller); } else { return null; } diff --git a/src/Metadata/InputMetadataFactoryInterface.php b/src/Metadata/InputMetadataFactoryInterface.php old mode 100644 new mode 100755 index 2fe61a5..3d2fa22 --- a/src/Metadata/InputMetadataFactoryInterface.php +++ b/src/Metadata/InputMetadataFactoryInterface.php @@ -8,5 +8,5 @@ interface InputMetadataFactoryInterface { - public function createInputMetadata(string|object|array $controller): ?Input; + public function createInputMetadata(array|object|string $controller): ?Input; } diff --git a/src/RequestInputBundle.php b/src/RequestInputBundle.php old mode 100644 new mode 100755 index 69f054c..6b30dfd --- a/src/RequestInputBundle.php +++ b/src/RequestInputBundle.php @@ -6,6 +6,4 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; -class RequestInputBundle extends Bundle -{ -} +class RequestInputBundle extends Bundle {} diff --git a/src/ValueResolver/InputValueResolver.php b/src/ValueResolver/InputValueResolver.php old mode 100644 new mode 100755 index 943890e..54e1987 --- a/src/ValueResolver/InputValueResolver.php +++ b/src/ValueResolver/InputValueResolver.php @@ -4,16 +4,14 @@ namespace Sfmok\RequestInput\ValueResolver; -use Symfony\Component\HttpFoundation\Request; use Sfmok\RequestInput\Factory\InputFactoryInterface; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Controller\ValueResolverInterface; use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata; class InputValueResolver implements ValueResolverInterface { - public function __construct(private InputFactoryInterface $inputFactory) - { - } + public function __construct(private InputFactoryInterface $inputFactory) {} public function resolve(Request $request, ArgumentMetadata $argument): iterable { diff --git a/tests/Attribute/InputTest.php b/tests/Attribute/InputTest.php old mode 100644 new mode 100755 index 45ea7aa..105af8c --- a/tests/Attribute/InputTest.php +++ b/tests/Attribute/InputTest.php @@ -4,9 +4,14 @@ namespace Sfmok\RequestInput\Tests\Attribute; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Sfmok\RequestInput\Attribute\Input; +/** + * @internal + */ +#[CoversClass(Input::class)] class InputTest extends TestCase { public function testDefaultValues() diff --git a/tests/DependencyInjection/ConfigurationTest.php b/tests/DependencyInjection/ConfigurationTest.php old mode 100644 new mode 100755 index 9c08244..3cad930 --- a/tests/DependencyInjection/ConfigurationTest.php +++ b/tests/DependencyInjection/ConfigurationTest.php @@ -4,6 +4,7 @@ namespace Sfmok\RequestInput\Tests\DependencyInjection; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Sfmok\RequestInput\DependencyInjection\Configuration; @@ -12,22 +13,25 @@ use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; use Symfony\Component\Config\Definition\Processor; +/** + * @internal + */ +#[CoversClass(Configuration::class)] class ConfigurationTest extends TestCase { public function testDefaultConfig(): void { $configuration = new Configuration(); $treeBuilder = $configuration->getConfigTreeBuilder(); - $config = (new Processor())->processConfiguration($configuration, []); + $config = new Processor()->processConfiguration($configuration, []); $this->assertInstanceOf(ConfigurationInterface::class, $configuration); $this->assertInstanceOf(TreeBuilder::class, $treeBuilder); $this->assertEquals([ 'enabled' => true, - 'formats' => ['json', 'xml', 'form'], - 'skip_validation' => false + 'formats' => ['json', 'xml'], + 'skip_validation' => false, ], $config); - } #[DataProvider('invalidFormatsProvider')] @@ -36,18 +40,21 @@ public function testInvalidFormatsConfig(array $formats): void self::expectException(InvalidConfigurationException::class); self::expectExceptionMessageMatches('/Only the formats .+ are supported. Got .+./'); - (new Processor())->processConfiguration((new Configuration()), [ + new Processor()->processConfiguration(new Configuration(), [ 'request_input' => [ - 'formats' => $formats - ] + 'formats' => $formats, + ], ]); } public static function invalidFormatsProvider(): iterable { yield [['js']]; + yield [['html']]; + yield [['json', 'xml', 'form', 'txt']]; + yield [['form', 'pdf']]; } } diff --git a/tests/DependencyInjection/RequestInputExtensionTest.php b/tests/DependencyInjection/RequestInputExtensionTest.php old mode 100644 new mode 100755 index 2283f84..ba7742d --- a/tests/DependencyInjection/RequestInputExtensionTest.php +++ b/tests/DependencyInjection/RequestInputExtensionTest.php @@ -4,8 +4,8 @@ namespace Sfmok\RequestInput\Tests\DependencyInjection; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -use Sfmok\RequestInput\ValueResolver\InputValueResolver; use Sfmok\RequestInput\DependencyInjection\RequestInputExtension; use Sfmok\RequestInput\EventListener\ExceptionListener; use Sfmok\RequestInput\EventListener\ReadInputListener; @@ -13,16 +13,21 @@ use Sfmok\RequestInput\Factory\InputFactoryInterface; use Sfmok\RequestInput\Metadata\InputMetadataFactory; use Sfmok\RequestInput\Metadata\InputMetadataFactoryInterface; +use Sfmok\RequestInput\ValueResolver\InputValueResolver; use Symfony\Component\DependencyInjection\ContainerBuilder; +/** + * @internal + */ +#[CoversClass(RequestInputExtension::class)] class RequestInputExtensionTest extends TestCase { public const DEFAULT_CONFIG = [ 'request_input' => [ 'enabled' => true, - 'formats' => ['json', 'xml', 'form'], - 'skip_validation' => false - ] + 'formats' => ['json', 'xml'], + 'skip_validation' => false, + ], ]; private ContainerBuilder $container; @@ -35,19 +40,19 @@ protected function setUp(): void public function testLoadConfiguration(): void { $config = self::DEFAULT_CONFIG; - (new RequestInputExtension())->load($config, $this->container); + new RequestInputExtension()->load($config, $this->container); $services = [ InputValueResolver::class, ExceptionListener::class, ReadInputListener::class, InputFactory::class, - InputMetadataFactory::class + InputMetadataFactory::class, ]; $aliases = [ InputFactoryInterface::class, - InputMetadataFactoryInterface::class + InputMetadataFactoryInterface::class, ]; $this->assertContainerHas($services, $aliases); @@ -59,14 +64,14 @@ public function testLoadConfiguration(): void public function testLoadConfigurationWithDisabledOption(): void { - (new RequestInputExtension())->load(['request_input' => ['enabled' => false]], $this->container); + new RequestInputExtension()->load(['request_input' => ['enabled' => false]], $this->container); $services = [ InputValueResolver::class, ExceptionListener::class, ReadInputListener::class, InputFactory::class, - InputMetadataFactory::class + InputMetadataFactory::class, ]; foreach ($services as $service) { diff --git a/tests/EventListener/ExceptionListenerTest.php b/tests/EventListener/ExceptionListenerTest.php old mode 100644 new mode 100755 index 6a91380..14891e5 --- a/tests/EventListener/ExceptionListenerTest.php +++ b/tests/EventListener/ExceptionListenerTest.php @@ -4,6 +4,8 @@ namespace Sfmok\RequestInput\Tests\EventListener; +use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Sfmok\RequestInput\EventListener\ExceptionListener; use Sfmok\RequestInput\Exception\DeserializationException; @@ -17,6 +19,11 @@ use Symfony\Component\Serializer\SerializerInterface; use Symfony\Component\Validator\ConstraintViolationList; +/** + * @internal + */ +#[CoversClass(ExceptionListener::class)] +#[AllowMockObjectsWithoutExpectations] class ExceptionListenerTest extends TestCase { private SerializerInterface $serializer; @@ -79,7 +86,7 @@ public function testOnKernelExceptionWithDenormalizationExceptionDataError(): vo 'violations' => [[ 'propertyPath' => 'foo', 'message' => 'This value should be of type string', - 'currentType' => 'array' + 'currentType' => 'array', ]], ]), $response->getContent()); } diff --git a/tests/EventListener/ReadInputListenerTest.php b/tests/EventListener/ReadInputListenerTest.php old mode 100644 new mode 100755 index d268d8b..8d0b2ca --- a/tests/EventListener/ReadInputListenerTest.php +++ b/tests/EventListener/ReadInputListenerTest.php @@ -4,6 +4,8 @@ namespace Sfmok\RequestInput\Tests\EventListener; +use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Sfmok\RequestInput\Attribute\Input; use Sfmok\RequestInput\EventListener\ReadInputListener; @@ -14,6 +16,11 @@ use Symfony\Component\HttpKernel\Event\ControllerEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; +/** + * @internal + */ +#[CoversClass(ReadInputListener::class)] +#[AllowMockObjectsWithoutExpectations] class ReadInputListenerTest extends TestCase { public function testOnKernelController(): void diff --git a/tests/Factory/InputFactoryTest.php b/tests/Factory/InputFactoryTest.php old mode 100644 new mode 100755 index b2b4db3..c20283d --- a/tests/Factory/InputFactoryTest.php +++ b/tests/Factory/InputFactoryTest.php @@ -4,22 +4,23 @@ namespace Sfmok\RequestInput\Tests\Factory; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Sfmok\RequestInput\Attribute\Input; -use Sfmok\RequestInput\Exception\DeserializationException; -use Sfmok\RequestInput\Exception\ValidationException; use Sfmok\RequestInput\Factory\InputFactory; use Sfmok\RequestInput\Factory\InputFactoryInterface; use Sfmok\RequestInput\Tests\Fixtures\Input\DummyInput; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException; -use Symfony\Component\Serializer\Exception\UnexpectedValueException; use Symfony\Component\Serializer\SerializerInterface; -use Symfony\Component\Validator\ConstraintViolation; use Symfony\Component\Validator\ConstraintViolationList; use Symfony\Component\Validator\Validator\ValidatorInterface; +/** + * @internal + */ +#[CoversClass(InputFactory::class)] class InputFactoryTest extends TestCase { private ValidatorInterface $validator; @@ -54,30 +55,6 @@ public function testCreateFromRequestWithContent(Request $request): void $this->assertEquals([$input], $inputFactory->createFromRequest($request, $input::class)); } - #[DataProvider('provideDataRequestWithForm')] - public function testCreateFromRequestWithForm(Request $request): void - { - $input = $this->getDummyInput(); - $data = json_encode($request->request->all()); - - $this->serializer - ->expects(self::once()) - ->method('deserialize') - ->with($data, $input::class, Input::INPUT_JSON_FORMAT) - ->willReturn($input) - ; - - $this->validator - ->expects(self::once()) - ->method('validate') - ->with($input, null, ['Default']) - ->willReturn(new ConstraintViolationList([])) - ; - - $inputFactory = $this->createInputFactory(false); - $this->assertEquals([$input], $inputFactory->createFromRequest($request, $input::class)); - } - #[DataProvider('provideDataUnsupportedContentType')] public function testCreateFromRequestWithUnsupportedContentType(Request $request): void { @@ -92,6 +69,23 @@ public function testCreateFromRequestWithUnsupportedContentType(Request $request $inputFactory->createFromRequest($request, DummyInput::class); } + public static function provideDataUnsupportedContentType(): iterable + { + yield [new Request(server: ['CONTENT_TYPE' => 'application/xhtml+xml'])]; + + yield [new Request(server: ['CONTENT_TYPE' => 'text/plain'])]; + + yield [new Request(server: ['CONTENT_TYPE' => 'application/javascript'])]; + + yield [new Request(server: ['CONTENT_TYPE' => 'text/css'])]; + + yield [new Request(server: ['CONTENT_TYPE' => 'application/ld+json'])]; + + yield [new Request(server: ['CONTENT_TYPE' => 'application/rdf+xml'])]; + + yield [new Request(server: ['CONTENT_TYPE' => 'application/rss+xml'])]; + } + #[DataProvider('provideDataEmptyContentType')] public function testCreateFromRequestWithEmptyContentType(Request $request): void { @@ -104,6 +98,13 @@ public function testCreateFromRequestWithEmptyContentType(Request $request): voi $inputFactory->createFromRequest($request, DummyInput::class); } + public static function provideDataEmptyContentType(): iterable + { + yield [new Request()]; + + yield [new Request(server: ['CONTENT_TYPE' => ''])]; + } + #[DataProvider('provideDataRequestWithContent')] public function testCreateFromRequestWithSkipValidation(Request $request): void { @@ -146,81 +147,11 @@ public function testCreateFromRequestWithInputMetadata(Request $request): void $this->assertEquals([$input], $inputFactory->createFromRequest($request, $input::class)); } - #[DataProvider('provideDataRequestWithForm')] - public function testCreateFromRequestWithDeserializationException(Request $request): void - { - $this->expectException(DeserializationException::class); - $data = json_encode($request->request->all()); - - $this->serializer - ->expects(self::once()) - ->method('deserialize') - ->with($data, DummyInput::class, 'json', []) - ->willThrowException(new UnexpectedValueException()) - ; - - $this->validator->expects(self::never())->method('validate'); - - $inputFactory = $this->createInputFactory(false); - $inputFactory->createFromRequest($request, DummyInput::class); - } - - /** - * @dataProvider provideDataRequestWithForm - */ - #[DataProvider('provideDataRequestWithForm')] - public function testCreateFromRequestWithValidationException(Request $request): void - { - $this->expectException(ValidationException::class); - - $input = $this->getDummyInput(); - $data = json_encode($request->request->all()); - - $this->serializer - ->expects(self::once()) - ->method('deserialize') - ->with($data, $input::class, 'json', []) - ->willReturn($input) - ; - - $this->validator - ->expects(self::once()) - ->method('validate') - ->with($input, null, ['Default']) - ->willReturn(new ConstraintViolationList([new ConstraintViolation('foo', null, [], null, null, null)])) - ; - - $inputFactory = $this->createInputFactory(false); - $inputFactory->createFromRequest($request, $input::class); - } - public static function provideDataRequestWithContent(): iterable { yield [new Request(server: ['CONTENT_TYPE' => 'application/json'])]; - yield [new Request(server: ['CONTENT_TYPE' => 'application/x-json'])]; - } - - public static function provideDataRequestWithForm(): iterable - { - yield [new Request(server: ['CONTENT_TYPE' => 'application/x-www-form-urlencoded'])]; - yield [new Request(server: ['CONTENT_TYPE' => 'multipart/form-data'])]; - } - - public static function provideDataUnsupportedContentType(): iterable - { - yield [new Request(server: ['CONTENT_TYPE' => 'application/xhtml+xml'])]; - yield [new Request(server: ['CONTENT_TYPE' => 'text/plain'])]; - yield [new Request(server: ['CONTENT_TYPE' => 'application/javascript'])]; - yield [new Request(server: ['CONTENT_TYPE' => 'text/css'])]; - yield [new Request(server: ['CONTENT_TYPE' => 'application/ld+json'])]; - yield [new Request(server: ['CONTENT_TYPE' => 'application/rdf+xml'])]; - yield [new Request(server: ['CONTENT_TYPE' => 'application/rss+xml'])]; - } - public static function provideDataEmptyContentType(): iterable - { - yield [new Request()]; - yield [new Request(server: ['CONTENT_TYPE' => ''])]; + yield [new Request(server: ['CONTENT_TYPE' => 'application/x-json'])]; } private function createInputFactory(bool $skipValidation): InputFactoryInterface diff --git a/tests/Fixtures/Controller/TestController.php b/tests/Fixtures/Controller/TestController.php old mode 100644 new mode 100755 index 365326f..5393181 --- a/tests/Fixtures/Controller/TestController.php +++ b/tests/Fixtures/Controller/TestController.php @@ -9,21 +9,13 @@ class TestController { #[Input(format: 'json', groups: ['bar'], context: ['groups' => ['bar']])] - public function __invoke(): void - { - } + public function __invoke(): void {} #[Input(format: 'json', groups: ['foo'], context: ['groups' => ['foo']])] - public function testWithInput(): void - { - } + public function testWithInput(): void {} - public function testWithoutInput(): void - { - } + public function testWithoutInput(): void {} #[Input(format: 'unsupported')] - public function testWithInputUnsupportedFormat(): void - { - } + public function testWithInputUnsupportedFormat(): void {} } diff --git a/tests/Fixtures/Input/DummyInput.php b/tests/Fixtures/Input/DummyInput.php old mode 100644 new mode 100755 index f751881..cd621c0 --- a/tests/Fixtures/Input/DummyInput.php +++ b/tests/Fixtures/Input/DummyInput.php @@ -5,8 +5,8 @@ namespace Sfmok\RequestInput\Tests\Fixtures\Input; use Sfmok\RequestInput\InputInterface; -use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Serializer\Annotation\SerializedName; +use Symfony\Component\Validator\Constraints as Assert; class DummyInput implements InputInterface { diff --git a/tests/Metadata/InputMetadataFactoryTest.php b/tests/Metadata/InputMetadataFactoryTest.php old mode 100644 new mode 100755 index 64d0f5c..e06773f --- a/tests/Metadata/InputMetadataFactoryTest.php +++ b/tests/Metadata/InputMetadataFactoryTest.php @@ -4,38 +4,43 @@ namespace Sfmok\RequestInput\Tests\Metadata; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Sfmok\RequestInput\Attribute\Input; use Sfmok\RequestInput\Metadata\InputMetadataFactory; use Sfmok\RequestInput\Tests\Fixtures\Controller\TestController; +/** + * @internal + */ +#[CoversClass(InputMetadataFactory::class)] class InputMetadataFactoryTest extends TestCase { public function testCreateInputMetadataWithInput() { - $input = (new InputMetadataFactory())->createInputMetadata([new TestController(), 'testWithInput']); + $input = new InputMetadataFactory()->createInputMetadata([new TestController(), 'testWithInput']); $this->assertEquals(new Input('json', ['foo'], ['groups' => ['foo']]), $input); - $input = (new InputMetadataFactory())->createInputMetadata(TestController::class.'::testWithInput'); + $input = new InputMetadataFactory()->createInputMetadata(TestController::class.'::testWithInput'); $this->assertEquals(new Input('json', ['foo'], ['groups' => ['foo']]), $input); - $input = (new InputMetadataFactory())->createInputMetadata(new TestController()); + $input = new InputMetadataFactory()->createInputMetadata(new TestController()); $this->assertEquals(new Input('json', ['bar'], ['groups' => ['bar']]), $input); } public function testCreateInputMetadataWithoutInput() { - $input = (new InputMetadataFactory())->createInputMetadata([new TestController(), 'testWithoutInput']); + $input = new InputMetadataFactory()->createInputMetadata([new TestController(), 'testWithoutInput']); $this->assertNull($input); - $input = (new InputMetadataFactory())->createInputMetadata(\Closure::fromCallable([new TestController(), 'testWithoutInput'])); + $input = new InputMetadataFactory()->createInputMetadata(\Closure::fromCallable([new TestController(), 'testWithoutInput'])); $this->assertNull($input); - # this will be null because attribute is not supported on closure function - $input = (new InputMetadataFactory())->createInputMetadata(\Closure::fromCallable([new TestController(), 'testWithInput'])); + // this will be null because attribute is not supported on closure function + $input = new InputMetadataFactory()->createInputMetadata(\Closure::fromCallable([new TestController(), 'testWithInput'])); $this->assertNull($input); - $input = (new InputMetadataFactory())->createInputMetadata(TestController::class.'::testWithoutInput'); + $input = new InputMetadataFactory()->createInputMetadata(TestController::class.'::testWithoutInput'); $this->assertNull($input); } } diff --git a/tests/ValueResolver/InputValueResolverTest.php b/tests/ValueResolver/InputValueResolverTest.php old mode 100644 new mode 100755 index 5eba590..a391344 --- a/tests/ValueResolver/InputValueResolverTest.php +++ b/tests/ValueResolver/InputValueResolverTest.php @@ -4,6 +4,7 @@ namespace Sfmok\RequestInput\Tests\ValueResolver; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Sfmok\RequestInput\Factory\InputFactoryInterface; use Sfmok\RequestInput\Tests\Fixtures\Input\DummyInput; @@ -11,6 +12,10 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata; +/** + * @internal + */ +#[CoversClass(InputValueResolver::class)] class InputValueResolverTest extends TestCase { public function testResolve(): void @@ -23,7 +28,8 @@ public function testResolve(): void $factory->expects(self::once()) ->method('createFromRequest') ->with($request, $dummyInput::class) - ->willReturn([$dummyInput]); + ->willReturn([$dummyInput]) + ; $this->assertEquals([$dummyInput], $resolver->resolve($request, $argument)); } } From 4bfbc4b22058b4eea5f07ac071859bc49c8c0598 Mon Sep 17 00:00:00 2001 From: Mokhtar Tlili Date: Mon, 9 Mar 2026 20:08:13 +0100 Subject: [PATCH 2/2] Fix runner label deprecation --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 025ec75..25d0b90 100755 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ on: jobs: phpunit: name: "PHPUnit" - runs-on: "ubuntu-20.04" + runs-on: "ubuntu-22.04" strategy: fail-fast: false @@ -65,7 +65,7 @@ jobs: upload_coverage: name: "Upload coverage to Codecov" - runs-on: "ubuntu-20.04" + runs-on: "ubuntu-22.04" needs: - "phpunit"