From 56949c0aca6f23512b6a9496f707c10fa7237ef7 Mon Sep 17 00:00:00 2001 From: Daniel Jakob Date: Tue, 19 Nov 2024 20:54:58 +0100 Subject: [PATCH] Replace mockery by phpunit --- .php-cs-fixer.dist.php | 31 +- composer.json | 2 - composer.lock | 370 +++++------------- phpstan.neon | 1 - phpunit.xml.dist | 3 +- src/Contract/ApiMethodInterface.php | 2 +- src/Contract/MethodProviderInterface.php | 2 +- src/Dispatch/MethodDispatcher.php | 14 +- src/Dispatch/MethodDispatcherInterface.php | 4 +- src/Dispatch/MethodValidator.php | 16 +- src/Dispatch/MethodValidatorInterface.php | 4 +- src/Dispatch/RequestValidator.php | 14 +- src/Dispatch/RequestValidatorInterface.php | 6 +- src/Dispatch/SchemaLoader.php | 12 +- src/Dispatch/SchemaLoaderInterface.php | 4 +- src/Endpoint.php | 28 +- src/Exception/InternalException.php | 2 +- src/Response/ResponseBuilder.php | 8 +- src/Response/ResponseBuilderInterface.php | 2 +- tests/Dispatch/MethodDispatcherTest.php | 108 +++-- tests/Dispatch/MethodValidatorTest.php | 113 +++--- tests/Dispatch/RequestValidatorTest.php | 123 +++--- tests/Dispatch/SchemaLoaderTest.php | 10 +- tests/EndpointTest.php | 311 +++++++-------- .../ResponseMalformedExceptionTest.php | 8 +- tests/Response/ResponseBuilderTest.php | 22 +- tests/bootstrap.php | 7 - 27 files changed, 508 insertions(+), 719 deletions(-) delete mode 100644 tests/bootstrap.php diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index fa9c001..e4eb243 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -1,16 +1,27 @@ in(['src', 'tests']) -; -$config = new PhpCsFixer\Config(); -$config->setRules( - [ +declare(strict_types=1); + +return (new PhpCsFixer\Config()) + ->setRules([ '@PSR12' => true, 'array_syntax' => ['syntax' => 'short'], 'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline', 'keep_multiple_spaces_after_comma' => false], - ] -)->setFinder($finder) + 'no_unused_imports' => true, + 'ordered_imports' => [ + 'sort_algorithm' => 'alpha', + 'imports_order' => ['const', 'class', 'function'], + ], + 'fully_qualified_strict_types' => [ + 'import_symbols' => true, + ], + 'trailing_comma_in_multiline' => [ + 'after_heredoc' => true, + 'elements' => ['array_destructuring', 'arrays', 'parameters', 'arguments'], + ], + ]) + ->setFinder( + PhpCsFixer\Finder::create() + ->in(['src', 'tests']) + ) ; - -return $config; \ No newline at end of file diff --git a/composer.json b/composer.json index 58d5ec8..6a8d2b9 100644 --- a/composer.json +++ b/composer.json @@ -35,9 +35,7 @@ "friendsofphp/php-cs-fixer": "^3.0", "laminas/laminas-diactoros": "^3", "mikey179/vfsstream": "^1.6", - "mockery/mockery": "^1.4", "phpstan/phpstan": "^1", - "phpstan/phpstan-mockery": "^1", "phpstan/phpstan-strict-rules": "^1", "phpunit/phpunit": "^11", "rector/rector": "^1" diff --git a/composer.lock b/composer.lock index 7a05d13..1b34471 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ef74def478f90a875a8ac48419145279", + "content-hash": "be721add78f3a8dede464e302dbcf127", "packages": [ { "name": "brick/math", @@ -851,16 +851,16 @@ }, { "name": "composer/pcre", - "version": "3.3.1", + "version": "3.3.2", "source": { "type": "git", "url": "https://github.com/composer/pcre.git", - "reference": "63aaeac21d7e775ff9bc9d45021e1745c97521c4" + "reference": "b2bed4734f0cc156ee1fe9c0da2550420d99a21e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/pcre/zipball/63aaeac21d7e775ff9bc9d45021e1745c97521c4", - "reference": "63aaeac21d7e775ff9bc9d45021e1745c97521c4", + "url": "https://api.github.com/repos/composer/pcre/zipball/b2bed4734f0cc156ee1fe9c0da2550420d99a21e", + "reference": "b2bed4734f0cc156ee1fe9c0da2550420d99a21e", "shasum": "" }, "require": { @@ -870,8 +870,8 @@ "phpstan/phpstan": "<1.11.10" }, "require-dev": { - "phpstan/phpstan": "^1.11.10", - "phpstan/phpstan-strict-rules": "^1.1", + "phpstan/phpstan": "^1.12 || ^2", + "phpstan/phpstan-strict-rules": "^1 || ^2", "phpunit/phpunit": "^8 || ^9" }, "type": "library", @@ -910,7 +910,7 @@ ], "support": { "issues": "https://github.com/composer/pcre/issues", - "source": "https://github.com/composer/pcre/tree/3.3.1" + "source": "https://github.com/composer/pcre/tree/3.3.2" }, "funding": [ { @@ -926,7 +926,7 @@ "type": "tidelift" } ], - "time": "2024-08-27T18:44:43+00:00" + "time": "2024-11-12T16:29:46+00:00" }, { "name": "composer/semver", @@ -1286,57 +1286,6 @@ ], "time": "2024-08-30T23:09:38+00:00" }, - { - "name": "hamcrest/hamcrest-php", - "version": "v2.0.1", - "source": { - "type": "git", - "url": "https://github.com/hamcrest/hamcrest-php.git", - "reference": "8c3d0a3f6af734494ad8f6fbbee0ba92422859f3" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/hamcrest/hamcrest-php/zipball/8c3d0a3f6af734494ad8f6fbbee0ba92422859f3", - "reference": "8c3d0a3f6af734494ad8f6fbbee0ba92422859f3", - "shasum": "" - }, - "require": { - "php": "^5.3|^7.0|^8.0" - }, - "replace": { - "cordoval/hamcrest-php": "*", - "davedevelopment/hamcrest-php": "*", - "kodova/hamcrest-php": "*" - }, - "require-dev": { - "phpunit/php-file-iterator": "^1.4 || ^2.0", - "phpunit/phpunit": "^4.8.36 || ^5.7 || ^6.5 || ^7.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - }, - "autoload": { - "classmap": [ - "hamcrest" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "description": "This is the PHP port of Hamcrest Matchers", - "keywords": [ - "test" - ], - "support": { - "issues": "https://github.com/hamcrest/hamcrest-php/issues", - "source": "https://github.com/hamcrest/hamcrest-php/tree/v2.0.1" - }, - "time": "2020-07-09T08:09:16+00:00" - }, { "name": "laminas/laminas-diactoros", "version": "3.5.0", @@ -1477,101 +1426,18 @@ }, "time": "2024-08-29T18:43:31+00:00" }, - { - "name": "mockery/mockery", - "version": "1.6.12", - "source": { - "type": "git", - "url": "https://github.com/mockery/mockery.git", - "reference": "1f4efdd7d3beafe9807b08156dfcb176d18f1699" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/mockery/mockery/zipball/1f4efdd7d3beafe9807b08156dfcb176d18f1699", - "reference": "1f4efdd7d3beafe9807b08156dfcb176d18f1699", - "shasum": "" - }, - "require": { - "hamcrest/hamcrest-php": "^2.0.1", - "lib-pcre": ">=7.0", - "php": ">=7.3" - }, - "conflict": { - "phpunit/phpunit": "<8.0" - }, - "require-dev": { - "phpunit/phpunit": "^8.5 || ^9.6.17", - "symplify/easy-coding-standard": "^12.1.14" - }, - "type": "library", - "autoload": { - "files": [ - "library/helpers.php", - "library/Mockery.php" - ], - "psr-4": { - "Mockery\\": "library/Mockery" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Pádraic Brady", - "email": "padraic.brady@gmail.com", - "homepage": "https://github.com/padraic", - "role": "Author" - }, - { - "name": "Dave Marshall", - "email": "dave.marshall@atstsolutions.co.uk", - "homepage": "https://davedevelopment.co.uk", - "role": "Developer" - }, - { - "name": "Nathanael Esayeas", - "email": "nathanael.esayeas@protonmail.com", - "homepage": "https://github.com/ghostwriter", - "role": "Lead Developer" - } - ], - "description": "Mockery is a simple yet flexible PHP mock object framework", - "homepage": "https://github.com/mockery/mockery", - "keywords": [ - "BDD", - "TDD", - "library", - "mock", - "mock objects", - "mockery", - "stub", - "test", - "test double", - "testing" - ], - "support": { - "docs": "https://docs.mockery.io/", - "issues": "https://github.com/mockery/mockery/issues", - "rss": "https://github.com/mockery/mockery/releases.atom", - "security": "https://github.com/mockery/mockery/security/advisories", - "source": "https://github.com/mockery/mockery" - }, - "time": "2024-05-16T03:13:13+00:00" - }, { "name": "myclabs/deep-copy", - "version": "1.12.0", + "version": "1.12.1", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c" + "reference": "123267b2c49fbf30d78a7b2d333f6be754b94845" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c", - "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/123267b2c49fbf30d78a7b2d333f6be754b94845", + "reference": "123267b2c49fbf30d78a7b2d333f6be754b94845", "shasum": "" }, "require": { @@ -1610,7 +1476,7 @@ ], "support": { "issues": "https://github.com/myclabs/DeepCopy/issues", - "source": "https://github.com/myclabs/DeepCopy/tree/1.12.0" + "source": "https://github.com/myclabs/DeepCopy/tree/1.12.1" }, "funding": [ { @@ -1618,7 +1484,7 @@ "type": "tidelift" } ], - "time": "2024-06-12T14:39:25+00:00" + "time": "2024-11-08T17:47:46+00:00" }, { "name": "nikic/php-parser", @@ -1798,16 +1664,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.12.6", + "version": "1.12.11", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "dc4d2f145a88ea7141ae698effd64d9df46527ae" + "reference": "0d1fc20a962a91be578bcfe7cf939e6e1a2ff733" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/dc4d2f145a88ea7141ae698effd64d9df46527ae", - "reference": "dc4d2f145a88ea7141ae698effd64d9df46527ae", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/0d1fc20a962a91be578bcfe7cf939e6e1a2ff733", + "reference": "0d1fc20a962a91be578bcfe7cf939e6e1a2ff733", "shasum": "" }, "require": { @@ -1852,57 +1718,7 @@ "type": "github" } ], - "time": "2024-10-06T15:03:59+00:00" - }, - { - "name": "phpstan/phpstan-mockery", - "version": "1.1.3", - "source": { - "type": "git", - "url": "https://github.com/phpstan/phpstan-mockery.git", - "reference": "98cac6e256b4ee60fdeb26a7dd81bb271b454e80" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-mockery/zipball/98cac6e256b4ee60fdeb26a7dd81bb271b454e80", - "reference": "98cac6e256b4ee60fdeb26a7dd81bb271b454e80", - "shasum": "" - }, - "require": { - "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.12" - }, - "require-dev": { - "mockery/mockery": "^1.6.11", - "nikic/php-parser": "^4.13.0", - "php-parallel-lint/php-parallel-lint": "^1.2", - "phpstan/phpstan-phpunit": "^1.4", - "phpstan/phpstan-strict-rules": "^1.6", - "phpunit/phpunit": "^9.5" - }, - "type": "phpstan-extension", - "extra": { - "phpstan": { - "includes": [ - "extension.neon" - ] - } - }, - "autoload": { - "psr-4": { - "PHPStan\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "PHPStan Mockery extension", - "support": { - "issues": "https://github.com/phpstan/phpstan-mockery/issues", - "source": "https://github.com/phpstan/phpstan-mockery/tree/1.1.3" - }, - "time": "2024-09-11T15:47:29+00:00" + "time": "2024-11-17T14:08:01+00:00" }, { "name": "phpstan/phpstan-strict-rules", @@ -2278,16 +2094,16 @@ }, { "name": "phpunit/phpunit", - "version": "11.4.1", + "version": "11.4.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "7875627f15f4da7e7f0823d1f323f7295a77334e" + "reference": "e8e8ed1854de5d36c088ec1833beae40d2dedd76" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/7875627f15f4da7e7f0823d1f323f7295a77334e", - "reference": "7875627f15f4da7e7f0823d1f323f7295a77334e", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/e8e8ed1854de5d36c088ec1833beae40d2dedd76", + "reference": "e8e8ed1854de5d36c088ec1833beae40d2dedd76", "shasum": "" }, "require": { @@ -2301,21 +2117,21 @@ "phar-io/manifest": "^2.0.4", "phar-io/version": "^3.2.1", "php": ">=8.2", - "phpunit/php-code-coverage": "^11.0.6", + "phpunit/php-code-coverage": "^11.0.7", "phpunit/php-file-iterator": "^5.1.0", "phpunit/php-invoker": "^5.0.1", "phpunit/php-text-template": "^4.0.1", "phpunit/php-timer": "^7.0.1", "sebastian/cli-parser": "^3.0.2", "sebastian/code-unit": "^3.0.1", - "sebastian/comparator": "^6.1.0", + "sebastian/comparator": "^6.1.1", "sebastian/diff": "^6.0.2", "sebastian/environment": "^7.2.0", "sebastian/exporter": "^6.1.3", "sebastian/global-state": "^7.0.2", "sebastian/object-enumerator": "^6.0.1", "sebastian/type": "^5.1.0", - "sebastian/version": "^5.0.1" + "sebastian/version": "^5.0.2" }, "suggest": { "ext-soap": "To be able to generate mocks based on WSDL files" @@ -2358,7 +2174,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/11.4.1" + "source": "https://github.com/sebastianbergmann/phpunit/tree/11.4.3" }, "funding": [ { @@ -2374,7 +2190,7 @@ "type": "tidelift" } ], - "time": "2024-10-08T15:38:37+00:00" + "time": "2024-10-28T13:07:50+00:00" }, { "name": "psr/container", @@ -3011,16 +2827,16 @@ }, { "name": "rector/rector", - "version": "1.2.7", + "version": "1.2.10", "source": { "type": "git", "url": "https://github.com/rectorphp/rector.git", - "reference": "5b33bdd871895276e2c18e5410a4a57df9233ee0" + "reference": "40f9cf38c05296bd32f444121336a521a293fa61" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/rectorphp/rector/zipball/5b33bdd871895276e2c18e5410a4a57df9233ee0", - "reference": "5b33bdd871895276e2c18e5410a4a57df9233ee0", + "url": "https://api.github.com/repos/rectorphp/rector/zipball/40f9cf38c05296bd32f444121336a521a293fa61", + "reference": "40f9cf38c05296bd32f444121336a521a293fa61", "shasum": "" }, "require": { @@ -3058,7 +2874,7 @@ ], "support": { "issues": "https://github.com/rectorphp/rector/issues", - "source": "https://github.com/rectorphp/rector/tree/1.2.7" + "source": "https://github.com/rectorphp/rector/tree/1.2.10" }, "funding": [ { @@ -3066,7 +2882,7 @@ "type": "github" } ], - "time": "2024-10-12T11:12:46+00:00" + "time": "2024-11-08T13:59:10+00:00" }, { "name": "sebastian/cli-parser", @@ -3240,16 +3056,16 @@ }, { "name": "sebastian/comparator", - "version": "6.1.0", + "version": "6.2.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "fa37b9e2ca618cb051d71b60120952ee8ca8b03d" + "reference": "43d129d6a0f81c78bee378b46688293eb7ea3739" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/fa37b9e2ca618cb051d71b60120952ee8ca8b03d", - "reference": "fa37b9e2ca618cb051d71b60120952ee8ca8b03d", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/43d129d6a0f81c78bee378b46688293eb7ea3739", + "reference": "43d129d6a0f81c78bee378b46688293eb7ea3739", "shasum": "" }, "require": { @@ -3260,12 +3076,12 @@ "sebastian/exporter": "^6.0" }, "require-dev": { - "phpunit/phpunit": "^11.3" + "phpunit/phpunit": "^11.4" }, "type": "library", "extra": { "branch-alias": { - "dev-main": "6.1-dev" + "dev-main": "6.2-dev" } }, "autoload": { @@ -3305,7 +3121,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/comparator/issues", "security": "https://github.com/sebastianbergmann/comparator/security/policy", - "source": "https://github.com/sebastianbergmann/comparator/tree/6.1.0" + "source": "https://github.com/sebastianbergmann/comparator/tree/6.2.1" }, "funding": [ { @@ -3313,7 +3129,7 @@ "type": "github" } ], - "time": "2024-09-11T15:42:56+00:00" + "time": "2024-10-31T05:30:08+00:00" }, { "name": "sebastian/complexity", @@ -3993,16 +3809,16 @@ }, { "name": "symfony/console", - "version": "v7.1.5", + "version": "v7.1.8", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "0fa539d12b3ccf068a722bbbffa07ca7079af9ee" + "reference": "ff04e5b5ba043d2badfb308197b9e6b42883fcd5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/0fa539d12b3ccf068a722bbbffa07ca7079af9ee", - "reference": "0fa539d12b3ccf068a722bbbffa07ca7079af9ee", + "url": "https://api.github.com/repos/symfony/console/zipball/ff04e5b5ba043d2badfb308197b9e6b42883fcd5", + "reference": "ff04e5b5ba043d2badfb308197b9e6b42883fcd5", "shasum": "" }, "require": { @@ -4066,7 +3882,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v7.1.5" + "source": "https://github.com/symfony/console/tree/v7.1.8" }, "funding": [ { @@ -4082,7 +3898,7 @@ "type": "tidelift" } ], - "time": "2024-09-20T08:28:38+00:00" + "time": "2024-11-06T14:23:19+00:00" }, { "name": "symfony/deprecation-contracts", @@ -4153,16 +3969,16 @@ }, { "name": "symfony/event-dispatcher", - "version": "v7.1.1", + "version": "v7.1.6", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "9fa7f7a21beb22a39a8f3f28618b29e50d7a55a7" + "reference": "87254c78dd50721cfd015b62277a8281c5589702" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/9fa7f7a21beb22a39a8f3f28618b29e50d7a55a7", - "reference": "9fa7f7a21beb22a39a8f3f28618b29e50d7a55a7", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/87254c78dd50721cfd015b62277a8281c5589702", + "reference": "87254c78dd50721cfd015b62277a8281c5589702", "shasum": "" }, "require": { @@ -4213,7 +4029,7 @@ "description": "Provides tools that allow your application components to communicate with each other by dispatching events and listening to them", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/event-dispatcher/tree/v7.1.1" + "source": "https://github.com/symfony/event-dispatcher/tree/v7.1.6" }, "funding": [ { @@ -4229,7 +4045,7 @@ "type": "tidelift" } ], - "time": "2024-05-31T14:57:53+00:00" + "time": "2024-09-25T14:20:29+00:00" }, { "name": "symfony/event-dispatcher-contracts", @@ -4309,16 +4125,16 @@ }, { "name": "symfony/filesystem", - "version": "v7.1.5", + "version": "v7.1.6", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "61fe0566189bf32e8cfee78335d8776f64a66f5a" + "reference": "c835867b3c62bb05c7fe3d637c871c7ae52024d4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/61fe0566189bf32e8cfee78335d8776f64a66f5a", - "reference": "61fe0566189bf32e8cfee78335d8776f64a66f5a", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/c835867b3c62bb05c7fe3d637c871c7ae52024d4", + "reference": "c835867b3c62bb05c7fe3d637c871c7ae52024d4", "shasum": "" }, "require": { @@ -4355,7 +4171,7 @@ "description": "Provides basic utilities for the filesystem", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/filesystem/tree/v7.1.5" + "source": "https://github.com/symfony/filesystem/tree/v7.1.6" }, "funding": [ { @@ -4371,20 +4187,20 @@ "type": "tidelift" } ], - "time": "2024-09-17T09:16:35+00:00" + "time": "2024-10-25T15:11:02+00:00" }, { "name": "symfony/finder", - "version": "v7.1.4", + "version": "v7.1.6", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "d95bbf319f7d052082fb7af147e0f835a695e823" + "reference": "2cb89664897be33f78c65d3d2845954c8d7a43b8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/d95bbf319f7d052082fb7af147e0f835a695e823", - "reference": "d95bbf319f7d052082fb7af147e0f835a695e823", + "url": "https://api.github.com/repos/symfony/finder/zipball/2cb89664897be33f78c65d3d2845954c8d7a43b8", + "reference": "2cb89664897be33f78c65d3d2845954c8d7a43b8", "shasum": "" }, "require": { @@ -4419,7 +4235,7 @@ "description": "Finds files and directories via an intuitive fluent interface", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/finder/tree/v7.1.4" + "source": "https://github.com/symfony/finder/tree/v7.1.6" }, "funding": [ { @@ -4435,20 +4251,20 @@ "type": "tidelift" } ], - "time": "2024-08-13T14:28:19+00:00" + "time": "2024-10-01T08:31:23+00:00" }, { "name": "symfony/options-resolver", - "version": "v7.1.1", + "version": "v7.1.6", "source": { "type": "git", "url": "https://github.com/symfony/options-resolver.git", - "reference": "47aa818121ed3950acd2b58d1d37d08a94f9bf55" + "reference": "85e95eeede2d41cd146146e98c9c81d9214cae85" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/options-resolver/zipball/47aa818121ed3950acd2b58d1d37d08a94f9bf55", - "reference": "47aa818121ed3950acd2b58d1d37d08a94f9bf55", + "url": "https://api.github.com/repos/symfony/options-resolver/zipball/85e95eeede2d41cd146146e98c9c81d9214cae85", + "reference": "85e95eeede2d41cd146146e98c9c81d9214cae85", "shasum": "" }, "require": { @@ -4486,7 +4302,7 @@ "options" ], "support": { - "source": "https://github.com/symfony/options-resolver/tree/v7.1.1" + "source": "https://github.com/symfony/options-resolver/tree/v7.1.6" }, "funding": [ { @@ -4502,7 +4318,7 @@ "type": "tidelift" } ], - "time": "2024-05-31T14:57:53+00:00" + "time": "2024-09-25T14:20:29+00:00" }, { "name": "symfony/polyfill-ctype", @@ -4980,16 +4796,16 @@ }, { "name": "symfony/process", - "version": "v7.1.5", + "version": "v7.1.8", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "5c03ee6369281177f07f7c68252a280beccba847" + "reference": "42783370fda6e538771f7c7a36e9fa2ee3a84892" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/5c03ee6369281177f07f7c68252a280beccba847", - "reference": "5c03ee6369281177f07f7c68252a280beccba847", + "url": "https://api.github.com/repos/symfony/process/zipball/42783370fda6e538771f7c7a36e9fa2ee3a84892", + "reference": "42783370fda6e538771f7c7a36e9fa2ee3a84892", "shasum": "" }, "require": { @@ -5021,7 +4837,7 @@ "description": "Executes commands in sub-processes", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/process/tree/v7.1.5" + "source": "https://github.com/symfony/process/tree/v7.1.8" }, "funding": [ { @@ -5037,7 +4853,7 @@ "type": "tidelift" } ], - "time": "2024-09-19T21:48:23+00:00" + "time": "2024-11-06T14:23:19+00:00" }, { "name": "symfony/service-contracts", @@ -5124,16 +4940,16 @@ }, { "name": "symfony/stopwatch", - "version": "v7.1.1", + "version": "v7.1.6", "source": { "type": "git", "url": "https://github.com/symfony/stopwatch.git", - "reference": "5b75bb1ac2ba1b9d05c47fc4b3046a625377d23d" + "reference": "8b4a434e6e7faf6adedffb48783a5c75409a1a05" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/stopwatch/zipball/5b75bb1ac2ba1b9d05c47fc4b3046a625377d23d", - "reference": "5b75bb1ac2ba1b9d05c47fc4b3046a625377d23d", + "url": "https://api.github.com/repos/symfony/stopwatch/zipball/8b4a434e6e7faf6adedffb48783a5c75409a1a05", + "reference": "8b4a434e6e7faf6adedffb48783a5c75409a1a05", "shasum": "" }, "require": { @@ -5166,7 +4982,7 @@ "description": "Provides a way to profile code", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/stopwatch/tree/v7.1.1" + "source": "https://github.com/symfony/stopwatch/tree/v7.1.6" }, "funding": [ { @@ -5182,20 +4998,20 @@ "type": "tidelift" } ], - "time": "2024-05-31T14:57:53+00:00" + "time": "2024-09-25T14:20:29+00:00" }, { "name": "symfony/string", - "version": "v7.1.5", + "version": "v7.1.8", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "d66f9c343fa894ec2037cc928381df90a7ad4306" + "reference": "591ebd41565f356fcd8b090fe64dbb5878f50281" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/d66f9c343fa894ec2037cc928381df90a7ad4306", - "reference": "d66f9c343fa894ec2037cc928381df90a7ad4306", + "url": "https://api.github.com/repos/symfony/string/zipball/591ebd41565f356fcd8b090fe64dbb5878f50281", + "reference": "591ebd41565f356fcd8b090fe64dbb5878f50281", "shasum": "" }, "require": { @@ -5253,7 +5069,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v7.1.5" + "source": "https://github.com/symfony/string/tree/v7.1.8" }, "funding": [ { @@ -5269,7 +5085,7 @@ "type": "tidelift" } ], - "time": "2024-09-20T08:28:38+00:00" + "time": "2024-11-13T13:31:21+00:00" }, { "name": "theseer/tokenizer", @@ -5324,13 +5140,13 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": {}, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { "php": "~8.3", "ext-json": "*" }, - "platform-dev": {}, + "platform-dev": [], "plugin-api-version": "2.6.0" } diff --git a/phpstan.neon b/phpstan.neon index fef7554..881934c 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -4,5 +4,4 @@ parameters: - src includes: - - vendor/phpstan/phpstan-mockery/extension.neon - vendor/phpstan/phpstan-strict-rules/rules.neon diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 29346ae..7e10413 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,8 +1,7 @@ > */ public function lookup( - string $methodName + string $methodName, ): ?ApiMethodInterface; } diff --git a/src/Dispatch/MethodDispatcher.php b/src/Dispatch/MethodDispatcher.php index 08843d1..5a8fb02 100644 --- a/src/Dispatch/MethodDispatcher.php +++ b/src/Dispatch/MethodDispatcher.php @@ -31,7 +31,7 @@ public function __construct( private SchemaLoaderInterface $schemaLoader, private MethodValidatorInterface $methodValidator, private MethodProviderInterface $methodProvider, - private ?LoggerInterface $logger + private ?LoggerInterface $logger, ) { } @@ -48,7 +48,7 @@ public function __construct( */ public function dispatch( ServerRequestInterface $request, - stdClass $input + stdClass $input, ): array { // Get the method from the request and perform lookup $methodName = $input->method; @@ -57,15 +57,15 @@ public function dispatch( 'Api method call', [ 'method' => $methodName, - 'input' => $input->parameter - ] + 'input' => $input->parameter, + ], ); $handler = $this->methodProvider->lookup($methodName); if (!$handler instanceof ApiMethodInterface) { throw new MethodNotFoundException( 'Method not found', - Http::BAD_REQUEST + Http::BAD_REQUEST, ); } @@ -77,14 +77,14 @@ public function dispatch( 'Api method call', [ 'method' => $methodName, - ] + ], ); $response = $handler->handle($request, $input->parameter); $this->methodValidator->validateOutput( $schemaContent, - $response + $response, ); return $response; diff --git a/src/Dispatch/MethodDispatcherInterface.php b/src/Dispatch/MethodDispatcherInterface.php index 1e69160..bf8c4f2 100644 --- a/src/Dispatch/MethodDispatcherInterface.php +++ b/src/Dispatch/MethodDispatcherInterface.php @@ -5,11 +5,11 @@ use Psr\Http\Message\ServerRequestInterface; use stdClass; use Usox\JsonSchemaApi\Dispatch\Exception\SchemaInvalidException; +use Usox\JsonSchemaApi\Dispatch\Exception\SchemaNotFoundException; use Usox\JsonSchemaApi\Exception\ApiMethodException; use Usox\JsonSchemaApi\Exception\MethodNotFoundException; use Usox\JsonSchemaApi\Exception\RequestMalformedException; use Usox\JsonSchemaApi\Exception\ResponseMalformedException; -use Usox\JsonSchemaApi\Dispatch\Exception\SchemaNotFoundException; interface MethodDispatcherInterface { @@ -25,6 +25,6 @@ interface MethodDispatcherInterface */ public function dispatch( ServerRequestInterface $request, - stdClass $input + stdClass $input, ): array; } diff --git a/src/Dispatch/MethodValidator.php b/src/Dispatch/MethodValidator.php index 3633d70..b268cdc 100644 --- a/src/Dispatch/MethodValidator.php +++ b/src/Dispatch/MethodValidator.php @@ -19,7 +19,7 @@ { public function __construct( private Validator $schemaValidator, - private ErrorFormatter $errorFormatter + private ErrorFormatter $errorFormatter, ) { } @@ -28,19 +28,19 @@ public function __construct( */ public function validateInput( stdClass $methodSchemaContent, - stdClass $input + stdClass $input, ): void { // Validate the input parameter against the parameter definition in method schema $validationResult = $this->schemaValidator->validate( $input->parameter, - $methodSchemaContent->properties->parameter + $methodSchemaContent->properties->parameter, ); // Throw exception if the input does not validate against the basic request schema if (!$validationResult->isValid()) { throw new RequestMalformedException( 'Bad Request', - Http::BAD_REQUEST + Http::BAD_REQUEST, ); } } @@ -52,7 +52,7 @@ public function validateInput( */ public function validateOutput( stdClass $methodSchemaContent, - array $output + array $output, ): void { if (property_exists($methodSchemaContent->properties, 'response')) { $data = new stdClass(); @@ -64,13 +64,13 @@ public function validateOutput( 'properties' => (object) [ 'data' => $methodSchemaContent->properties->response, ], - 'required' => ['data'] + 'required' => ['data'], ]; // Validate the response against the response definition in method schema $validationResult = $this->schemaValidator->validate( $data, - $response + $response, ); $error = $validationResult->error(); @@ -80,7 +80,7 @@ public function validateOutput( 'Internal Server Error', Http::INTERNAL_SERVER_ERROR, null, - $this->errorFormatter->format($error) + $this->errorFormatter->format($error), ); } } diff --git a/src/Dispatch/MethodValidatorInterface.php b/src/Dispatch/MethodValidatorInterface.php index 6308b9d..d726a6c 100644 --- a/src/Dispatch/MethodValidatorInterface.php +++ b/src/Dispatch/MethodValidatorInterface.php @@ -13,7 +13,7 @@ interface MethodValidatorInterface */ public function validateInput( stdClass $methodSchemaContent, - stdClass $input + stdClass $input, ): void; /** @@ -23,6 +23,6 @@ public function validateInput( */ public function validateOutput( stdClass $methodSchemaContent, - array $output + array $output, ): void; } diff --git a/src/Dispatch/RequestValidator.php b/src/Dispatch/RequestValidator.php index 18aa6e0..b0ed5b4 100644 --- a/src/Dispatch/RequestValidator.php +++ b/src/Dispatch/RequestValidator.php @@ -4,14 +4,14 @@ namespace Usox\JsonSchemaApi\Dispatch; -use Teapot\StatusCode\Http; -use Usox\JsonSchemaApi\Dispatch\Exception\SchemaInvalidException; -use Usox\JsonSchemaApi\Dispatch\Exception\SchemaNotFoundException; -use Usox\JsonSchemaApi\Dispatch\Exception\SchemaNotLoadableException; use Opis\JsonSchema\Validator; use Psr\Http\Message\ServerRequestInterface; use stdClass; +use Teapot\StatusCode\Http; use Usox\JsonSchemaApi\Dispatch\Exception\JsonInvalidException; +use Usox\JsonSchemaApi\Dispatch\Exception\SchemaInvalidException; +use Usox\JsonSchemaApi\Dispatch\Exception\SchemaNotFoundException; +use Usox\JsonSchemaApi\Dispatch\Exception\SchemaNotLoadableException; use Usox\JsonSchemaApi\Exception\RequestMalformedException; /** @@ -40,7 +40,7 @@ public function validate(ServerRequestInterface $request): stdClass if (json_last_error() !== JSON_ERROR_NONE) { throw new JsonInvalidException( sprintf('Input is no valid json (%s)', json_last_error_msg()), - Http::BAD_REQUEST + Http::BAD_REQUEST, ); } @@ -50,14 +50,14 @@ public function validate(ServerRequestInterface $request): stdClass // First, validate the input against the basic request schema $validationResult = $this->schemaValidator->validate( $decodedInput, - $fileContent + $fileContent, ); // Throw exception if the input does not validate against the basic request schema if (!$validationResult->isValid()) { throw new RequestMalformedException( 'Request is invalid', - Http::BAD_REQUEST + Http::BAD_REQUEST, ); } diff --git a/src/Dispatch/RequestValidatorInterface.php b/src/Dispatch/RequestValidatorInterface.php index a6eea7f..31fe182 100644 --- a/src/Dispatch/RequestValidatorInterface.php +++ b/src/Dispatch/RequestValidatorInterface.php @@ -2,12 +2,12 @@ namespace Usox\JsonSchemaApi\Dispatch; -use Usox\JsonSchemaApi\Dispatch\Exception\SchemaInvalidException; -use Usox\JsonSchemaApi\Dispatch\Exception\SchemaNotFoundException; -use Usox\JsonSchemaApi\Dispatch\Exception\SchemaNotLoadableException; use Psr\Http\Message\ServerRequestInterface; use stdClass; use Usox\JsonSchemaApi\Dispatch\Exception\JsonInvalidException; +use Usox\JsonSchemaApi\Dispatch\Exception\SchemaInvalidException; +use Usox\JsonSchemaApi\Dispatch\Exception\SchemaNotFoundException; +use Usox\JsonSchemaApi\Dispatch\Exception\SchemaNotLoadableException; use Usox\JsonSchemaApi\Exception\RequestMalformedException; interface RequestValidatorInterface diff --git a/src/Dispatch/SchemaLoader.php b/src/Dispatch/SchemaLoader.php index 84b5f7c..10bad0d 100644 --- a/src/Dispatch/SchemaLoader.php +++ b/src/Dispatch/SchemaLoader.php @@ -4,11 +4,11 @@ namespace Usox\JsonSchemaApi\Dispatch; +use stdClass; use Teapot\StatusCode\Http; +use Usox\JsonSchemaApi\Dispatch\Exception\SchemaInvalidException; use Usox\JsonSchemaApi\Dispatch\Exception\SchemaNotFoundException; use Usox\JsonSchemaApi\Dispatch\Exception\SchemaNotLoadableException; -use stdClass; -use Usox\JsonSchemaApi\Dispatch\Exception\SchemaInvalidException; /** * Lookup the schema and load its contents @@ -23,12 +23,12 @@ final class SchemaLoader implements SchemaLoaderInterface * @throws SchemaNotLoadableException */ public function load( - string $schemaFilePath + string $schemaFilePath, ): stdClass { if (!file_exists($schemaFilePath)) { throw new SchemaNotFoundException( sprintf('Schema file `%s` not found', $schemaFilePath), - Http::INTERNAL_SERVER_ERROR + Http::INTERNAL_SERVER_ERROR, ); } @@ -37,7 +37,7 @@ public function load( if ($fileContent === false) { throw new SchemaNotLoadableException( sprintf('Schema file `%s` not loadable', $schemaFilePath), - Http::INTERNAL_SERVER_ERROR + Http::INTERNAL_SERVER_ERROR, ); } @@ -47,7 +47,7 @@ public function load( if (json_last_error() !== JSON_ERROR_NONE) { throw new SchemaInvalidException( sprintf('Schema does not contain valid json (%s)', json_last_error_msg()), - Http::INTERNAL_SERVER_ERROR + Http::INTERNAL_SERVER_ERROR, ); } diff --git a/src/Dispatch/SchemaLoaderInterface.php b/src/Dispatch/SchemaLoaderInterface.php index 1c398d3..c305ad9 100644 --- a/src/Dispatch/SchemaLoaderInterface.php +++ b/src/Dispatch/SchemaLoaderInterface.php @@ -2,10 +2,10 @@ namespace Usox\JsonSchemaApi\Dispatch; +use stdClass; use Usox\JsonSchemaApi\Dispatch\Exception\SchemaInvalidException; use Usox\JsonSchemaApi\Dispatch\Exception\SchemaNotFoundException; use Usox\JsonSchemaApi\Dispatch\Exception\SchemaNotLoadableException; -use stdClass; interface SchemaLoaderInterface { @@ -17,6 +17,6 @@ interface SchemaLoaderInterface * @throws SchemaNotLoadableException */ public function load( - string $schemaFilePath + string $schemaFilePath, ): stdClass; } diff --git a/src/Endpoint.php b/src/Endpoint.php index 1b45d9d..96162b9 100644 --- a/src/Endpoint.php +++ b/src/Endpoint.php @@ -42,7 +42,7 @@ public function __construct( private UuidFactoryInterface $uuidFactory, private StreamFactoryInterface $streamFactory, private ResponseFactoryInterface $responseFactory, - private ?LoggerInterface $logger = null + private ?LoggerInterface $logger = null, ) { } @@ -60,8 +60,8 @@ public function serve( $responseData = $this->responseBuilder->buildResponse( $this->methodRetriever->dispatch( $request, - $this->inputValidator->validate($request) - ) + $this->inputValidator->validate($request), + ), ); } catch (ApiException $e) { $uuid = $this->uuidFactory->uuid4(); @@ -76,14 +76,14 @@ public function serve( $this->logError( $e, $this->uuidFactory->uuid4(), - $e->getContext() + $e->getContext(), ); $statusCode = Http::INTERNAL_SERVER_ERROR; } catch (Throwable $e) { $this->logError( $e, - $this->uuidFactory->uuid4() + $this->uuidFactory->uuid4(), ); $statusCode = Http::INTERNAL_SERVER_ERROR; @@ -94,8 +94,8 @@ public function serve( if ($responseData !== null) { $response = $response->withBody( $this->streamFactory->createStream( - (string) json_encode($responseData) - ) + (string) json_encode($responseData), + ), ); } @@ -110,7 +110,7 @@ public function serve( private function logError( Throwable $e, UuidInterface $uuid, - array $context = [] + array $context = [], ): void { $this->logger?->error( sprintf('%s (%d)', $e->getMessage(), $e->getCode()), @@ -118,8 +118,8 @@ private function logError( 'id' => $uuid->toString(), 'file' => $e->getFile(), 'line' => $e->getLine(), - 'context' => $context - ] + 'context' => $context, + ], ); } @@ -132,7 +132,7 @@ public static function factory( MethodProviderInterface $methodProvider, ?StreamFactoryInterface $streamFactory = null, ?ResponseFactoryInterface $responseFactory = null, - ?LoggerInterface $logger = null + ?LoggerInterface $logger = null, ): EndpointInterface { $schemaValidator = new Validator(); $schemaLoader = new SchemaLoader(); @@ -148,13 +148,13 @@ public static function factory( return new self( new RequestValidator( $schemaLoader, - $schemaValidator + $schemaValidator, ), new MethodDispatcher( $schemaLoader, new MethodValidator( $schemaValidator, - new ErrorFormatter() + new ErrorFormatter(), ), $methodProvider, $logger, @@ -163,7 +163,7 @@ public static function factory( new UuidFactory(), $streamFactory, $responseFactory, - $logger + $logger, ); } diff --git a/src/Exception/InternalException.php b/src/Exception/InternalException.php index feccbff..d16bf81 100644 --- a/src/Exception/InternalException.php +++ b/src/Exception/InternalException.php @@ -16,7 +16,7 @@ public function __construct( string $message, int $code, null|Throwable $previous = null, - private readonly array $context = [] + private readonly array $context = [], ) { parent::__construct($message, $code, $previous); } diff --git a/src/Response/ResponseBuilder.php b/src/Response/ResponseBuilder.php index a80566b..732a332 100644 --- a/src/Response/ResponseBuilder.php +++ b/src/Response/ResponseBuilder.php @@ -14,14 +14,14 @@ final class ResponseBuilder implements ResponseBuilderInterface */ public function buildErrorResponse( Throwable $e, - UuidInterface $uuid + UuidInterface $uuid, ): array { return [ 'error' => [ 'message' => $e->getMessage(), 'code' => $e->getCode(), - 'id' => $uuid->toString() - ] + 'id' => $uuid->toString(), + ], ]; } @@ -33,7 +33,7 @@ public function buildErrorResponse( public function buildResponse(array $data): array { return [ - 'data' => $data + 'data' => $data, ]; } } diff --git a/src/Response/ResponseBuilderInterface.php b/src/Response/ResponseBuilderInterface.php index f1074db..4a6fbfa 100644 --- a/src/Response/ResponseBuilderInterface.php +++ b/src/Response/ResponseBuilderInterface.php @@ -14,7 +14,7 @@ interface ResponseBuilderInterface */ public function buildErrorResponse( Throwable $e, - UuidInterface $uuid + UuidInterface $uuid, ): array; /** diff --git a/tests/Dispatch/MethodDispatcherTest.php b/tests/Dispatch/MethodDispatcherTest.php index 17820e6..b6b7d31 100644 --- a/tests/Dispatch/MethodDispatcherTest.php +++ b/tests/Dispatch/MethodDispatcherTest.php @@ -4,9 +4,8 @@ namespace Usox\JsonSchemaApi\Dispatch; -use Mockery; -use Mockery\Adapter\Phpunit\MockeryTestCase; -use Mockery\MockInterface; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; use Psr\Http\Message\ServerRequestInterface; use Psr\Log\LoggerInterface; use Teapot\StatusCode\Http; @@ -14,36 +13,36 @@ use Usox\JsonSchemaApi\Contract\MethodProviderInterface; use Usox\JsonSchemaApi\Exception\MethodNotFoundException; -class MethodDispatcherTest extends MockeryTestCase +class MethodDispatcherTest extends TestCase { - private MockInterface&SchemaLoaderInterface $schemaLoader; + private MockObject&SchemaLoaderInterface $schemaLoader; - private MockInterface&MethodValidatorInterface $methodValidator; + private MockObject&MethodValidatorInterface $methodValidator; - private MockInterface&MethodProviderInterface $methodProvider; + private MockObject&MethodProviderInterface $methodProvider; - private MockInterface&LoggerInterface $logger; + private MockObject&LoggerInterface $logger; private MethodDispatcher $subject; protected function setUp(): void { - $this->schemaLoader = Mockery::mock(SchemaLoaderInterface::class); - $this->methodValidator = Mockery::mock(MethodValidatorInterface::class); - $this->methodProvider = Mockery::mock(MethodProviderInterface::class); - $this->logger = Mockery::mock(LoggerInterface::class); + $this->schemaLoader = $this->createMock(SchemaLoaderInterface::class); + $this->methodValidator = $this->createMock(MethodValidatorInterface::class); + $this->methodProvider = $this->createMock(MethodProviderInterface::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->subject = new MethodDispatcher( $this->schemaLoader, $this->methodValidator, $this->methodProvider, - $this->logger + $this->logger, ); } public function testDispatchThrowsExceptionIfMethodDoesNotExist(): void { - $request = Mockery::mock(ServerRequestInterface::class); + $request = $this->createMock(ServerRequestInterface::class); $this->expectException(MethodNotFoundException::class); $this->expectExceptionMessage('Method not found'); @@ -54,24 +53,24 @@ public function testDispatchThrowsExceptionIfMethodDoesNotExist(): void $input = ['method' => $method, 'parameter' => $parameter]; - $this->methodProvider->shouldReceive('lookup') + $this->methodProvider->expects(static::once()) + ->method('lookup') ->with($method) - ->once() - ->andReturnNull(); + ->willReturn(null); - $this->logger->shouldReceive('debug') + $this->logger->expects(static::once()) + ->method('debug') ->with( 'Api method call', [ 'method' => $method, - 'input' => $parameter - ] - ) - ->once(); + 'input' => $parameter, + ], + ); $this->subject->dispatch( $request, - (object) $input + (object) $input, ); } @@ -85,60 +84,59 @@ public function testDispatchReturnsHandler(): void $input = (object) ['method' => $method, 'parameter' => $parameter]; - $request = Mockery::mock(ServerRequestInterface::class); - $handler = Mockery::mock(ApiMethodInterface::class); + $request = $this->createMock(ServerRequestInterface::class); + $handler = $this->createMock(ApiMethodInterface::class); - $handler->shouldReceive('getSchemaFile') - ->withNoArgs() - ->once() - ->andReturn($schemaFilePath); + $handler->expects(static::once()) + ->method('getSchemaFile') + ->willReturn($schemaFilePath); - $this->schemaLoader->shouldReceive('load') + $this->schemaLoader->expects(static::once()) + ->method('load') ->with($schemaFilePath) - ->once() - ->andReturn($schemaContent); + ->willReturn($schemaContent); - $this->methodProvider->shouldReceive('lookup') + $this->methodProvider->expects(static::once()) + ->method('lookup') ->with($method) - ->once() - ->andReturn($handler); + ->willReturn($handler); - $this->methodValidator->shouldReceive('validateInput') - ->with($schemaContent, $input) - ->once(); - $this->methodValidator->shouldReceive('validateOutput') + $this->methodValidator->expects(static::once()) + ->method('validateInput') + ->with($schemaContent, $input); + $this->methodValidator->expects(static::once()) + ->method('validateOutput') ->with( $schemaContent, - Mockery::on(static fn ($param): bool => (array) $param == $result) - ) - ->once(); + $this->callback(static fn ($param): bool => (array) $param == $result), + ); - $this->logger->shouldReceive('info') + $this->logger->expects(static::once()) + ->method('info') ->with( 'Api method call', [ 'method' => $method, - ] - ) - ->once(); - $this->logger->shouldReceive('debug') + ], + ); + $this->logger->expects(static::once()) + ->method('debug') ->with( 'Api method call', [ 'method' => $method, - 'input' => $input->parameter - ] - ) - ->once(); + 'input' => $input->parameter, + ], + ); - $handler->shouldReceive('handle') + $handler->expects(static::once()) + ->method('handle') ->with($request, $parameter) - ->once() - ->andReturn($result); + ->willReturn($result); static::assertSame( $result, - $this->subject->dispatch($request, $input) + $this->subject->dispatch($request, $input), ); } } diff --git a/tests/Dispatch/MethodValidatorTest.php b/tests/Dispatch/MethodValidatorTest.php index d82827e..7acfe34 100644 --- a/tests/Dispatch/MethodValidatorTest.php +++ b/tests/Dispatch/MethodValidatorTest.php @@ -4,33 +4,32 @@ namespace Usox\JsonSchemaApi\Dispatch; -use Mockery; -use Mockery\Adapter\Phpunit\MockeryTestCase; -use Mockery\MockInterface; use Opis\JsonSchema\Errors\ErrorFormatter; use Opis\JsonSchema\Errors\ValidationError; use Opis\JsonSchema\ValidationResult; use Opis\JsonSchema\Validator; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; use Teapot\StatusCode\Http; use Usox\JsonSchemaApi\Exception\RequestMalformedException; use Usox\JsonSchemaApi\Exception\ResponseMalformedException; -class MethodValidatorTest extends MockeryTestCase +class MethodValidatorTest extends TestCase { - private MockInterface&Validator $schemaValidator; + private MockObject&Validator $schemaValidator; - private MockInterface&ErrorFormatter $errorFormatter; + private MockObject&ErrorFormatter $errorFormatter; private MethodValidator $subject; protected function setUp(): void { - $this->schemaValidator = Mockery::mock(Validator::class); - $this->errorFormatter = Mockery::mock(ErrorFormatter::class); + $this->schemaValidator = $this->createMock(Validator::class); + $this->errorFormatter = $this->createMock(ErrorFormatter::class); $this->subject = new MethodValidator( $this->schemaValidator, - $this->errorFormatter + $this->errorFormatter, ); } @@ -41,28 +40,27 @@ public function testValidateInputThrowsExceptionIfInputDoesNotValidate(): void $input = (object) ['parameter' => $parameter]; $content = (object) ['properties' => (object) ['parameter' => $schemaParameter]]; - $validationResult = Mockery::mock(ValidationResult::class); + $validationResult = $this->createMock(ValidationResult::class); $this->expectException(RequestMalformedException::class); $this->expectExceptionMessage('Bad Request'); $this->expectExceptionCode(Http::BAD_REQUEST); - $this->schemaValidator->shouldReceive('validate') + $this->schemaValidator->expects(static::once()) + ->method('validate') ->with( $parameter, - Mockery::on(static fn ($value): bool => json_encode($value) === json_encode($schemaParameter)) + $this->callback(static fn ($value): bool => json_encode($value) === json_encode($schemaParameter)), ) - ->once() - ->andReturn($validationResult); + ->willReturn($validationResult); - $validationResult->shouldReceive('isValid') - ->withNoArgs() - ->once() - ->andReturnFalse(); + $validationResult->expects(static::once()) + ->method('isValid') + ->willReturn(false); $this->subject->validateInput( $content, - $input + $input, ); } @@ -73,24 +71,23 @@ public function testValidateInputValidates(): void $input = (object) ['parameter' => $parameter]; $content = (object) ['properties' => (object) ['parameter' => $schemaParameter]]; - $result = Mockery::mock(ValidationResult::class); + $result = $this->createMock(ValidationResult::class); - $this->schemaValidator->shouldReceive('validate') + $this->schemaValidator->expects(static::once()) + ->method('validate') ->with( $parameter, - Mockery::on(static fn ($value): bool => (array) $value === $schemaParameter) + $this->callback(static fn ($value): bool => (array) $value === $schemaParameter), ) - ->once() - ->andReturn($result); + ->willReturn($result); - $result->shouldReceive('isValid') - ->withNoArgs() - ->once() - ->andReturnTrue(); + $result->expects(static::once()) + ->method('isValid') + ->willReturn(true); $this->subject->validateInput( $content, - $input + $input, ); } @@ -101,44 +98,43 @@ public function testValidateOutputThrowsExceptionIfOutputDoesNotValidate(): void $content = (object) ['properties' => (object) ['response' => $schemaParameter]]; $error = ['some' => 'error']; - $validationResult = Mockery::mock(ValidationResult::class); - $validationError = Mockery::mock(ValidationError::class); + $validationResult = $this->createMock(ValidationResult::class); + $validationError = $this->createMock(ValidationError::class); $this->expectException(ResponseMalformedException::class); $this->expectExceptionMessage('Internal Server Error'); $this->expectExceptionCode(Http::INTERNAL_SERVER_ERROR); - $this->schemaValidator->shouldReceive('validate') + $this->schemaValidator->expects(static::once()) + ->method('validate') ->with( - Mockery::on(static fn ($value): bool => json_encode($value) === json_encode(['data' => $output])), - Mockery::on(static function ($value) use ($schemaParameter): bool { + $this->callback(static fn ($value): bool => json_encode($value) === json_encode(['data' => $output])), + $this->callback(static function ($value) use ($schemaParameter): bool { $schemaParameter = [ 'type' => 'object', 'properties' => [ 'data' => $schemaParameter, ], - 'required' => ['data'] + 'required' => ['data'], ]; return json_encode($value) === json_encode($schemaParameter); - }) + }), ) - ->once() - ->andReturn($validationResult); + ->willReturn($validationResult); - $validationResult->shouldReceive('error') - ->withNoArgs() - ->once() - ->andReturn($validationError); + $validationResult->expects(static::once()) + ->method('error') + ->willReturn($validationError); - $this->errorFormatter->shouldReceive('format') + $this->errorFormatter->expects(static::once()) + ->method('format') ->with($validationError) - ->once() - ->andReturn($error); + ->willReturn($error); $this->subject->validateOutput( $content, - $output + $output, ); } @@ -148,34 +144,33 @@ public function testValidateOutputValidates(): void $schemaParameter = ['schema' => 'param']; $content = (object) ['properties' => (object) ['response' => $schemaParameter]]; - $validationResult = Mockery::mock(ValidationResult::class); + $validationResult = $this->createMock(ValidationResult::class); - $this->schemaValidator->shouldReceive('validate') + $this->schemaValidator->expects(static::once()) + ->method('validate') ->with( - Mockery::on(static fn ($value): bool => json_encode($value) === json_encode(['data' => $output])), - Mockery::on(static function ($value) use ($schemaParameter): bool { + $this->callback(static fn ($value): bool => json_encode($value) === json_encode(['data' => $output])), + $this->callback(static function ($value) use ($schemaParameter): bool { $schemaParameter = [ 'type' => 'object', 'properties' => [ 'data' => $schemaParameter, ], - 'required' => ['data'] + 'required' => ['data'], ]; return json_encode($value) === json_encode($schemaParameter); - }) + }), ) - ->once() - ->andReturn($validationResult); + ->willReturn($validationResult); - $validationResult->shouldReceive('error') - ->withNoArgs() - ->once() - ->andReturnNull(); + $validationResult->expects(static::once()) + ->method('error') + ->willReturn(null); $this->subject->validateOutput( $content, - $output + $output, ); } } diff --git a/tests/Dispatch/RequestValidatorTest.php b/tests/Dispatch/RequestValidatorTest.php index 0449ef3..28c9d76 100644 --- a/tests/Dispatch/RequestValidatorTest.php +++ b/tests/Dispatch/RequestValidatorTest.php @@ -4,33 +4,32 @@ namespace Usox\JsonSchemaApi\Dispatch; -use Mockery; -use Mockery\Adapter\Phpunit\MockeryTestCase; -use Mockery\MockInterface; use Opis\JsonSchema\ValidationResult; use Opis\JsonSchema\Validator; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\StreamInterface; use Teapot\StatusCode\Http; use Usox\JsonSchemaApi\Dispatch\Exception\JsonInvalidException; use Usox\JsonSchemaApi\Exception\RequestMalformedException; -class RequestValidatorTest extends MockeryTestCase +class RequestValidatorTest extends TestCase { - private MockInterface&SchemaLoaderInterface $schemaLoader; + private MockObject&SchemaLoaderInterface $schemaLoader; - private MockInterface&Validator $validator; + private MockObject&Validator $validator; private RequestValidator $subject; protected function setUp(): void { - $this->schemaLoader = Mockery::mock(SchemaLoaderInterface::class); - $this->validator = Mockery::mock(Validator::class); + $this->schemaLoader = $this->createMock(SchemaLoaderInterface::class); + $this->validator = $this->createMock(Validator::class); $this->subject = new RequestValidator( $this->schemaLoader, - $this->validator + $this->validator, ); } @@ -40,20 +39,18 @@ public function testValidateThrowsExceptionIfInputIsInvalid(): void $this->expectExceptionMessage('Input is no valid json (Syntax error)'); $this->expectExceptionCode(Http::BAD_REQUEST); - $stream = Mockery::mock(StreamInterface::class); - $request = Mockery::mock(ServerRequestInterface::class); + $stream = $this->createMock(StreamInterface::class); + $request = $this->createMock(ServerRequestInterface::class); $input = 'some-input' . PHP_EOL . 'errors'; - $request->shouldReceive('getBody') - ->withNoArgs() - ->once() - ->andReturn($stream); + $request->expects(static::once()) + ->method('getBody') + ->willReturn($stream); - $stream->shouldReceive('getContents') - ->withNoArgs() - ->once() - ->andReturn($input); + $stream->expects(static::once()) + ->method('getContents') + ->willReturn($input); $this->subject->validate($request); } @@ -64,82 +61,76 @@ public function testValidateThrowsExceptionIfInputDoesNotValidate(): void $this->expectExceptionMessage('Request is invalid'); $this->expectExceptionCode(Http::BAD_REQUEST); - $stream = Mockery::mock(StreamInterface::class); - $request = Mockery::mock(ServerRequestInterface::class); - $validationResult = Mockery::mock(ValidationResult::class); + $stream = $this->createMock(StreamInterface::class); + $request = $this->createMock(ServerRequestInterface::class); + $validationResult = $this->createMock(ValidationResult::class); $input = ['some' => 'input']; $schemaContent = (object) ['some' => 'schema-content']; - $this->schemaLoader->shouldReceive('load') - ->once() - ->andReturn($schemaContent); + $this->schemaLoader->expects(static::once()) + ->method('load') + ->willReturn($schemaContent); - $this->validator->shouldReceive('validate') + $this->validator->expects(static::once()) + ->method('validate') ->with( - Mockery::on(static fn ($value): bool => (array) $value === $input), - Mockery::on(static fn ($value): bool => $value == $schemaContent) + $this->callback(static fn ($value): bool => (array) $value === $input), + $this->callback(static fn ($value): bool => $value == $schemaContent), ) - ->once() - ->andReturn($validationResult); + ->willReturn($validationResult); - $validationResult->shouldReceive('isValid') - ->withNoArgs() - ->once() - ->andReturnFalse(); + $validationResult->expects(static::once()) + ->method('isValid') + ->willReturn(false); - $request->shouldReceive('getBody') - ->withNoArgs() - ->once() - ->andReturn($stream); + $request->expects(static::once()) + ->method('getBody') + ->willReturn($stream); - $stream->shouldReceive('getContents') - ->withNoArgs() - ->once() - ->andReturn(json_encode($input)); + $stream->expects(static::once()) + ->method('getContents') + ->willReturn(json_encode($input)); $this->subject->validate($request); } public function testValidateReturnsValidatedInput(): void { - $stream = Mockery::mock(StreamInterface::class); - $request = Mockery::mock(ServerRequestInterface::class); - $validationResult = Mockery::mock(ValidationResult::class); + $stream = $this->createMock(StreamInterface::class); + $request = $this->createMock(ServerRequestInterface::class); + $validationResult = $this->createMock(ValidationResult::class); $input = ['some' => 'input']; $schemaContent = (object) ['some' => 'schema-content']; - $this->schemaLoader->shouldReceive('load') - ->once() - ->andReturn($schemaContent); + $this->schemaLoader->expects(static::once()) + ->method('load') + ->willReturn($schemaContent); - $this->validator->shouldReceive('validate') + $this->validator->expects(static::once()) + ->method('validate') ->with( - Mockery::on(static fn ($value): bool => (array) $value === $input), - Mockery::on(static fn ($value): bool => $value == $schemaContent) + $this->callback(static fn ($value): bool => (array) $value === $input), + $this->callback(static fn ($value): bool => $value == $schemaContent), ) - ->once() - ->andReturn($validationResult); + ->willReturn($validationResult); - $validationResult->shouldReceive('isValid') - ->withNoArgs() - ->once() - ->andReturnTrue(); + $validationResult->expects(static::once()) + ->method('isValid') + ->willReturn(true); - $request->shouldReceive('getBody') - ->withNoArgs() - ->once() - ->andReturn($stream); + $request->expects(static::once()) + ->method('getBody') + ->willReturn($stream); - $stream->shouldReceive('getContents') - ->withNoArgs() - ->once() - ->andReturn(json_encode($input)); + $stream->expects(static::once()) + ->method('getContents') + ->willReturn(json_encode($input)); static::assertEquals( (object) $input, - $this->subject->validate($request) + $this->subject->validate($request), ); } } diff --git a/tests/Dispatch/SchemaLoaderTest.php b/tests/Dispatch/SchemaLoaderTest.php index 907b728..520cf6f 100644 --- a/tests/Dispatch/SchemaLoaderTest.php +++ b/tests/Dispatch/SchemaLoaderTest.php @@ -4,14 +4,14 @@ namespace Usox\JsonSchemaApi\Dispatch; -use Mockery\Adapter\Phpunit\MockeryTestCase; use org\bovigo\vfs\vfsStream; +use PHPUnit\Framework\TestCase; use Teapot\StatusCode\Http; use Usox\JsonSchemaApi\Dispatch\Exception\SchemaInvalidException; use Usox\JsonSchemaApi\Dispatch\Exception\SchemaNotFoundException; use Usox\JsonSchemaApi\Dispatch\Exception\SchemaNotLoadableException; -class SchemaLoaderTest extends MockeryTestCase +class SchemaLoaderTest extends TestCase { private SchemaLoader $subject; @@ -27,7 +27,7 @@ public function testLoadThrowsExceptionIfSchemaWasNotFound(): void $this->expectException(SchemaNotFoundException::class); $this->expectExceptionMessage( - sprintf('Schema file `%s` not found', $path) + sprintf('Schema file `%s` not found', $path), ); $this->expectExceptionCode(Http::INTERNAL_SERVER_ERROR); @@ -44,7 +44,7 @@ public function testLoadThrowsExceptionIfSchemaDoesNotContainValidJson(): void $this->expectException(SchemaInvalidException::class); $this->expectExceptionMessage( - 'Schema does not contain valid json (Syntax error)' + 'Schema does not contain valid json (Syntax error)', ); $this->expectExceptionCode(Http::INTERNAL_SERVER_ERROR); @@ -76,7 +76,7 @@ public function testLoadReturnsData(): void static::assertSame( $content, - (array) $this->subject->load($path) + (array) $this->subject->load($path), ); } } diff --git a/tests/EndpointTest.php b/tests/EndpointTest.php index 487db3d..0cabb73 100644 --- a/tests/EndpointTest.php +++ b/tests/EndpointTest.php @@ -5,9 +5,8 @@ namespace Usox\JsonSchemaApi; use Exception; -use Mockery; -use Mockery\Adapter\Phpunit\MockeryTestCase; -use Mockery\MockInterface; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; @@ -26,33 +25,33 @@ use Usox\JsonSchemaApi\Exception\ResponseMalformedException; use Usox\JsonSchemaApi\Response\ResponseBuilderInterface; -class EndpointTest extends MockeryTestCase +class EndpointTest extends TestCase { - private MockInterface&RequestValidatorInterface $requestValidator; + private MockObject&RequestValidatorInterface $requestValidator; - private MockInterface&MethodDispatcherInterface $methodDispatcher; + private MockObject&MethodDispatcherInterface $methodDispatcher; - private MockInterface&ResponseBuilderInterface $responseBuilder; + private MockObject&ResponseBuilderInterface $responseBuilder; - private MockInterface&UuidFactoryInterface $uuidFactory; + private MockObject&UuidFactoryInterface $uuidFactory; - private MockInterface&StreamFactoryInterface $streamFactory; + private MockObject&StreamFactoryInterface $streamFactory; - private MockInterface&ResponseFactoryInterface $responseFactory; + private MockObject&ResponseFactoryInterface $responseFactory; - private MockInterface&LoggerInterface $logger; + private MockObject&LoggerInterface $logger; private Endpoint $subject; protected function setUp(): void { - $this->requestValidator = Mockery::mock(RequestValidatorInterface::class); - $this->methodDispatcher = Mockery::mock(MethodDispatcherInterface::class); - $this->responseBuilder = Mockery::mock(ResponseBuilderInterface::class); - $this->uuidFactory = Mockery::mock(UuidFactoryInterface::class); - $this->streamFactory = Mockery::mock(StreamFactoryInterface::class); - $this->responseFactory = Mockery::mock(ResponseFactoryInterface::class); - $this->logger = Mockery::mock(LoggerInterface::class); + $this->requestValidator = $this->createMock(RequestValidatorInterface::class); + $this->methodDispatcher = $this->createMock(MethodDispatcherInterface::class); + $this->responseBuilder = $this->createMock(ResponseBuilderInterface::class); + $this->uuidFactory = $this->createMock(UuidFactoryInterface::class); + $this->streamFactory = $this->createMock(StreamFactoryInterface::class); + $this->responseFactory = $this->createMock(ResponseFactoryInterface::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->subject = new Endpoint( $this->requestValidator, @@ -61,14 +60,14 @@ protected function setUp(): void $this->uuidFactory, $this->streamFactory, $this->responseFactory, - $this->logger + $this->logger, ); } public function testServeReturnsHandlerOutput(): void { - $request = Mockery::mock(ServerRequestInterface::class); - $response = Mockery::mock(ResponseInterface::class); + $request = $this->createMock(ServerRequestInterface::class); + $response = $this->createMock(ResponseInterface::class); $parameter = new stdClass(); $decodedInput = new stdClass(); @@ -76,25 +75,25 @@ public function testServeReturnsHandlerOutput(): void $responseData = ['some-response']; $processedResponse = ['some-processed-response']; - $this->requestValidator->shouldReceive('validate') + $this->requestValidator->expects(static::once()) + ->method('validate') ->with($request) - ->once() - ->andReturn($decodedInput); + ->willReturn($decodedInput); - $this->methodDispatcher->shouldReceive('dispatch') + $this->methodDispatcher->expects(static::once()) + ->method('dispatch') ->with($request, $decodedInput) - ->once() - ->andReturn($responseData); + ->willReturn($responseData); - $this->responseBuilder->shouldReceive('buildResponse') + $this->responseBuilder->expects(static::once()) + ->method('buildResponse') ->with($responseData) - ->once() - ->andReturn($processedResponse); + ->willReturn($processedResponse); - $this->responseFactory->shouldReceive('createResponse') + $this->responseFactory->expects(static::once()) + ->method('createResponse') ->with(Http::OK) - ->once() - ->andReturn($response); + ->willReturn($response); $this->createResponseExpectations( $response, @@ -103,15 +102,15 @@ public function testServeReturnsHandlerOutput(): void static::assertSame( $response, - $this->subject->serve($request) + $this->subject->serve($request), ); } public function testServeCatchesApiMethodException(): void { - $request = Mockery::mock(ServerRequestInterface::class); - $response = Mockery::mock(ResponseInterface::class); - $uuid = Mockery::mock(UuidInterface::class); + $request = $this->createMock(ServerRequestInterface::class); + $response = $this->createMock(ResponseInterface::class); + $uuid = $this->createMock(UuidInterface::class); $errorMessage = 'some-error'; $errorCode = 666; @@ -121,54 +120,52 @@ public function testServeCatchesApiMethodException(): void $error = new class ($errorMessage, $errorCode) extends ApiMethodException { }; - $this->requestValidator->shouldReceive('validate') + $this->requestValidator->expects(static::once()) + ->method('validate') ->with($request) - ->once() - ->andThrow($error); + ->willThrowException($error); - $this->responseBuilder->shouldReceive('buildErrorResponse') + $this->responseBuilder->expects(static::once()) + ->method('buildErrorResponse') ->with($error, $uuid) - ->once() - ->andReturn($processedResponse); + ->willReturn($processedResponse); - $this->uuidFactory->shouldReceive('uuid4') - ->withNoArgs() - ->once() - ->andReturn($uuid); + $this->uuidFactory->expects(static::once()) + ->method('uuid4') + ->willReturn($uuid); - $uuid->shouldReceive('toString') - ->withNoArgs() - ->once() - ->andReturn($uuidValue); + $uuid->expects(static::once()) + ->method('toString') + ->willReturn($uuidValue); - $this->responseFactory->shouldReceive('createResponse') + $this->responseFactory->expects(static::once()) + ->method('createResponse') ->with(Http::BAD_REQUEST) - ->once() - ->andReturn($response); + ->willReturn($response); $this->createResponseExpectations( $response, $processedResponse, ); - $this->logger->shouldReceive('error') + $this->logger->expects(static::once()) + ->method('error') ->with( sprintf('%s (%d)', $errorMessage, $errorCode), - Mockery::type('array') - ) - ->once(); + self::isType('array'), + ); static::assertSame( $response, - $this->subject->serve($request) + $this->subject->serve($request), ); } public function testServeCatchesApiException(): void { - $request = Mockery::mock(ServerRequestInterface::class); - $response = Mockery::mock(ResponseInterface::class); - $uuid = Mockery::mock(UuidInterface::class); + $request = $this->createMock(ServerRequestInterface::class); + $response = $this->createMock(ResponseInterface::class); + $uuid = $this->createMock(UuidInterface::class); $errorMessage = 'some-error'; $errorCode = 666; @@ -178,54 +175,52 @@ public function testServeCatchesApiException(): void $error = new class ($errorMessage, $errorCode) extends ApiException { }; - $this->requestValidator->shouldReceive('validate') + $this->requestValidator->expects(static::once()) + ->method('validate') ->with($request) - ->once() - ->andThrow($error); + ->willThrowException($error); - $this->responseBuilder->shouldReceive('buildErrorResponse') + $this->responseBuilder->expects(static::once()) + ->method('buildErrorResponse') ->with($error, $uuid) - ->once() - ->andReturn($processedResponse); + ->willReturn($processedResponse); - $this->uuidFactory->shouldReceive('uuid4') - ->withNoArgs() - ->once() - ->andReturn($uuid); + $this->uuidFactory->expects(static::once()) + ->method('uuid4') + ->willReturn($uuid); - $uuid->shouldReceive('toString') - ->withNoArgs() - ->once() - ->andReturn($uuidValue); + $uuid->expects(static::once()) + ->method('toString') + ->willReturn($uuidValue); - $this->responseFactory->shouldReceive('createResponse') + $this->responseFactory->expects(static::once()) + ->method('createResponse') ->with(Http::BAD_REQUEST) - ->once() - ->andReturn($response); + ->willReturn($response); $this->createResponseExpectations( $response, $processedResponse, ); - $this->logger->shouldReceive('error') + $this->logger->expects(static::once()) + ->method('error') ->with( sprintf('%s (%d)', $errorMessage, $errorCode), - Mockery::type('array') - ) - ->once(); + static::isType('array'), + ); static::assertSame( $response, - $this->subject->serve($request) + $this->subject->serve($request), ); } public function testServeCatchesGenericException(): void { - $request = Mockery::mock(ServerRequestInterface::class); - $response = Mockery::mock(ResponseInterface::class); - $uuid = Mockery::mock(UuidInterface::class); + $request = $this->createMock(ServerRequestInterface::class); + $response = $this->createMock(ResponseInterface::class); + $uuid = $this->createMock(UuidInterface::class); $errorMessage = 'some-error'; $errorCode = 666; @@ -233,49 +228,47 @@ public function testServeCatchesGenericException(): void $error = new Exception($errorMessage, $errorCode); - $this->requestValidator->shouldReceive('validate') + $this->requestValidator->expects(static::once()) + ->method('validate') ->with($request) - ->once() - ->andThrow($error); + ->willThrowException($error); - $this->uuidFactory->shouldReceive('uuid4') - ->withNoArgs() - ->once() - ->andReturn($uuid); + $this->uuidFactory->expects(static::once()) + ->method('uuid4') + ->willReturn($uuid); - $uuid->shouldReceive('toString') - ->withNoArgs() - ->once() - ->andReturn($uuidValue); + $uuid->expects(static::once()) + ->method('toString') + ->willReturn($uuidValue); - $this->responseFactory->shouldReceive('createResponse') + $this->responseFactory->expects(static::once()) + ->method('createResponse') ->with(Http::INTERNAL_SERVER_ERROR) - ->once() - ->andReturn($response); + ->willReturn($response); $this->createResponseExpectations( $response, null, ); - $this->logger->shouldReceive('error') + $this->logger->expects(static::once()) + ->method('error') ->with( sprintf('%s (%d)', $errorMessage, $errorCode), - Mockery::type('array') - ) - ->once(); + static::isType('array'), + ); static::assertSame( $response, - $this->subject->serve($request) + $this->subject->serve($request), ); } public function testServeCatchesInternalException(): void { - $request = Mockery::mock(ServerRequestInterface::class); - $response = Mockery::mock(ResponseInterface::class); - $uuid = Mockery::mock(UuidInterface::class); + $request = $this->createMock(ServerRequestInterface::class); + $response = $this->createMock(ResponseInterface::class); + $uuid = $this->createMock(UuidInterface::class); $errorMessage = 'some-error'; $errorCode = 666; @@ -284,41 +277,39 @@ public function testServeCatchesInternalException(): void $error = new ResponseMalformedException($errorMessage, $errorCode, null, $context); - $this->requestValidator->shouldReceive('validate') + $this->requestValidator->expects(static::once()) + ->method('validate') ->with($request) - ->once() - ->andThrow($error); + ->willThrowException($error); - $this->uuidFactory->shouldReceive('uuid4') - ->withNoArgs() - ->once() - ->andReturn($uuid); + $this->uuidFactory->expects(static::once()) + ->method('uuid4') + ->willReturn($uuid); - $uuid->shouldReceive('toString') - ->withNoArgs() - ->once() - ->andReturn($uuidValue); + $uuid->expects(static::once()) + ->method('toString') + ->willReturn($uuidValue); - $this->responseFactory->shouldReceive('createResponse') + $this->responseFactory->expects(static::once()) + ->method('createResponse') ->with(Http::INTERNAL_SERVER_ERROR) - ->once() - ->andReturn($response); + ->willReturn($response); $this->createResponseExpectations( $response, null, ); - $this->logger->shouldReceive('error') + $this->logger->expects(static::once()) + ->method('error') ->with( sprintf('%s (%d)', $errorMessage, $errorCode), - Mockery::type('array') - ) - ->once(); + static::isType('array'), + ); static::assertSame( $response, - $this->subject->serve($request) + $this->subject->serve($request), ); } @@ -327,10 +318,10 @@ public function testFactoryReturnsInstance(): void static::assertInstanceOf( Endpoint::class, Endpoint::factory( - Mockery::mock(MethodProviderInterface::class), - Mockery::mock(StreamFactoryInterface::class), - Mockery::mock(ResponseFactoryInterface::class), - ) + $this->createMock(MethodProviderInterface::class), + $this->createMock(StreamFactoryInterface::class), + $this->createMock(ResponseFactoryInterface::class), + ), ); } @@ -339,15 +330,15 @@ public function testFactoryReturnsInstanceUsingAutoDetection(): void static::assertInstanceOf( Endpoint::class, Endpoint::factory( - Mockery::mock(MethodProviderInterface::class), - ) + $this->createMock(MethodProviderInterface::class), + ), ); } public function testHandleWorks(): void { - $request = Mockery::mock(ServerRequestInterface::class); - $response = Mockery::mock(ResponseInterface::class); + $request = $this->createMock(ServerRequestInterface::class); + $response = $this->createMock(ResponseInterface::class); $parameter = new stdClass(); $decodedInput = new stdClass(); @@ -355,25 +346,25 @@ public function testHandleWorks(): void $responseData = ['some-response']; $processedResponse = ['some-processed-response']; - $this->requestValidator->shouldReceive('validate') + $this->requestValidator->expects(static::once()) + ->method('validate') ->with($request) - ->once() - ->andReturn($decodedInput); + ->willReturn($decodedInput); - $this->methodDispatcher->shouldReceive('dispatch') + $this->methodDispatcher->expects(static::once()) + ->method('dispatch') ->with($request, $decodedInput) - ->once() - ->andReturn($responseData); + ->willReturn($responseData); - $this->responseBuilder->shouldReceive('buildResponse') + $this->responseBuilder->expects(static::once()) + ->method('buildResponse') ->with($responseData) - ->once() - ->andReturn($processedResponse); + ->willReturn($processedResponse); - $this->responseFactory->shouldReceive('createResponse') + $this->responseFactory->expects(static::once()) + ->method('createResponse') ->with(Http::OK) - ->once() - ->andReturn($response); + ->willReturn($response); $this->createResponseExpectations( $response, @@ -382,31 +373,31 @@ public function testHandleWorks(): void static::assertSame( $response, - $this->subject->handle($request) + $this->subject->handle($request), ); } private function createResponseExpectations( - MockInterface $response, + MockObject&ResponseInterface $response, string|array|null $responseData, ): void { if ($responseData !== null) { - $stream = Mockery::mock(StreamInterface::class); + $stream = $this->createMock(StreamInterface::class); - $this->streamFactory->shouldReceive('createStream') + $this->streamFactory->expects(static::once()) + ->method('createStream') ->with(json_encode($responseData)) - ->once() - ->andReturn($stream); + ->willReturn($stream); - $response->shouldReceive('withBody') + $response->expects(static::once()) + ->method('withBody') ->with($stream) - ->once() - ->andReturnSelf(); + ->willReturnSelf(); } - $response->shouldReceive('withHeader') + $response->expects(static::once()) + ->method('withHeader') ->with('Content-Type', 'application/json') - ->once() - ->andReturnSelf(); + ->willReturnSelf(); } } diff --git a/tests/Exception/ResponseMalformedExceptionTest.php b/tests/Exception/ResponseMalformedExceptionTest.php index 40d0baf..33e6028 100644 --- a/tests/Exception/ResponseMalformedExceptionTest.php +++ b/tests/Exception/ResponseMalformedExceptionTest.php @@ -4,9 +4,9 @@ namespace Usox\JsonSchemaApi\Exception; -use Mockery\Adapter\Phpunit\MockeryTestCase; +use PHPUnit\Framework\TestCase; -class ResponseMalformedExceptionTest extends MockeryTestCase +class ResponseMalformedExceptionTest extends TestCase { /** @var array */ private array $context = ['some' => 'context']; @@ -19,7 +19,7 @@ protected function setUp(): void '', 0, null, - $this->context + $this->context, ); } @@ -27,7 +27,7 @@ public function testGetContextReturnsData(): void { static::assertSame( $this->context, - $this->subject->getContext() + $this->subject->getContext(), ); } } diff --git a/tests/Response/ResponseBuilderTest.php b/tests/Response/ResponseBuilderTest.php index 69e84ed..5a1a00d 100644 --- a/tests/Response/ResponseBuilderTest.php +++ b/tests/Response/ResponseBuilderTest.php @@ -5,11 +5,10 @@ namespace Usox\JsonSchemaApi\Response; use Exception; -use Mockery; -use Mockery\Adapter\Phpunit\MockeryTestCase; +use PHPUnit\Framework\TestCase; use Ramsey\Uuid\UuidInterface; -class ResponseBuilderTest extends MockeryTestCase +class ResponseBuilderTest extends TestCase { private ResponseBuilder $subject; @@ -25,22 +24,21 @@ public function testBuildErrorResponseReturnsData(): void $uuidValue = 'some-uuid'; $error = new Exception($message, $code); - $uuid = Mockery::mock(UuidInterface::class); + $uuid = $this->createMock(UuidInterface::class); - $uuid->shouldReceive('toString') - ->withNoArgs() - ->once() - ->andReturn($uuidValue); + $uuid->expects(static::once()) + ->method('toString') + ->willReturn($uuidValue); $this->assertSame( [ 'error' => [ 'message' => $message, 'code' => $code, - 'id' => $uuidValue - ] + 'id' => $uuidValue, + ], ], - $this->subject->buildErrorResponse($error, $uuid) + $this->subject->buildErrorResponse($error, $uuid), ); } @@ -50,7 +48,7 @@ public function testBuildResponseReturnsResponse(): void $this->assertSame( ['data' => $data], - $this->subject->buildResponse($data) + $this->subject->buildResponse($data), ); } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php deleted file mode 100644 index 6e149bc..0000000 --- a/tests/bootstrap.php +++ /dev/null @@ -1,7 +0,0 @@ -allowMockingNonExistentMethods(false);