diff --git a/.coveralls.yml b/.coveralls.yml deleted file mode 100644 index bc71b62f..00000000 --- a/.coveralls.yml +++ /dev/null @@ -1,2 +0,0 @@ -coverage_clover: clover.xml -json_path: coveralls-upload.json diff --git a/.gitattributes b/.gitattributes index 70b009d9..17ba94b9 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,10 +1,13 @@ -/.coveralls.yml export-ignore /.gitattributes export-ignore /.github/ export-ignore /.gitignore export-ignore -/.travis.yml export-ignore /docs/ export-ignore /mkdocs.yml export-ignore /phpcs.xml export-ignore /phpunit.xml.dist export-ignore /test/ export-ignore +/psalm.xml export-ignore +/psalm-baseline.xml export-ignore +/renovate.json export-ignore +/.laminas-ci.json export-ignore +/composer.lock export-ignore diff --git a/.laminas-ci.json b/.laminas-ci.json index 15cc043d..c703c5a8 100644 --- a/.laminas-ci.json +++ b/.laminas-ci.json @@ -3,6 +3,6 @@ "pdo-sqlite" ], "ignore_php_platform_requirements": { - "8.0": false + "8.2": true } } diff --git a/composer.json b/composer.json index cb5bb8da..cd282adf 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "dealerdirect/phpcodesniffer-composer-installer": true }, "platform": { - "php": "7.4.99" + "php": "8.0.99" } }, "extra": { @@ -35,8 +35,8 @@ } }, "require": { - "php": "^7.4 || ~8.0.0 || ~8.1.0", - "league/oauth2-server": "^8.3.3", + "php": "~8.0.0 || ~8.1.0 || ~8.2.0", + "league/oauth2-server": "^8.3.5", "mezzio/mezzio-authentication": "^1.0", "psr/container": "^1.0 || ^2.0", "psr/http-factory": "^1.0", @@ -46,15 +46,15 @@ }, "require-dev": { "laminas/laminas-coding-standard": "~2.4.0", - "laminas/laminas-diactoros": "^2.17", - "laminas/laminas-servicemanager": "^3.16.0", - "phpspec/prophecy-phpunit": "^2.0", - "phpunit/phpunit": "^9.5.11", + "laminas/laminas-diactoros": "^2.19", + "laminas/laminas-servicemanager": "^3.19", + "phpunit/phpunit": "^9.5.25", "psalm/plugin-phpunit": "^0.17.0", - "vimeo/psalm": "^4.27.0" + "vimeo/psalm": "^4.29" }, "conflict": { "container-interop/container-interop": "<1.2.0", + "lcobucci/jwt": "<4", "zendframework/zend-expressive-authentication-oauth2": "*" }, "autoload": { diff --git a/composer.lock b/composer.lock index 620863d5..fd8c6d56 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": "3971330e0fc11bd7b26a9bc89c3d7eee", + "content-hash": "e5690a8c827b401dc70e983789a7f3fc", "packages": [ { "name": "defuse/php-encryption", @@ -74,31 +74,31 @@ }, { "name": "lcobucci/clock", - "version": "2.0.0", + "version": "2.2.0", "source": { "type": "git", "url": "https://github.com/lcobucci/clock.git", - "reference": "353d83fe2e6ae95745b16b3d911813df6a05bfb3" + "reference": "fb533e093fd61321bfcbac08b131ce805fe183d3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/lcobucci/clock/zipball/353d83fe2e6ae95745b16b3d911813df6a05bfb3", - "reference": "353d83fe2e6ae95745b16b3d911813df6a05bfb3", + "url": "https://api.github.com/repos/lcobucci/clock/zipball/fb533e093fd61321bfcbac08b131ce805fe183d3", + "reference": "fb533e093fd61321bfcbac08b131ce805fe183d3", "shasum": "" }, "require": { - "php": "^7.4 || ^8.0" + "php": "^8.0", + "stella-maris/clock": "^0.1.4" }, "require-dev": { - "infection/infection": "^0.17", - "lcobucci/coding-standard": "^6.0", - "phpstan/extension-installer": "^1.0", + "infection/infection": "^0.26", + "lcobucci/coding-standard": "^8.0", + "phpstan/extension-installer": "^1.1", "phpstan/phpstan": "^0.12", "phpstan/phpstan-deprecation-rules": "^0.12", "phpstan/phpstan-phpunit": "^0.12", "phpstan/phpstan-strict-rules": "^0.12", - "phpunit/php-code-coverage": "9.1.4", - "phpunit/phpunit": "9.3.7" + "phpunit/phpunit": "^9.5" }, "type": "library", "autoload": { @@ -119,7 +119,7 @@ "description": "Yet another clock abstraction", "support": { "issues": "https://github.com/lcobucci/clock/issues", - "source": "https://github.com/lcobucci/clock/tree/2.0.x" + "source": "https://github.com/lcobucci/clock/tree/2.2.0" }, "funding": [ { @@ -131,7 +131,7 @@ "type": "patreon" } ], - "time": "2020-08-27T18:56:02+00:00" + "time": "2022-04-19T19:34:17+00:00" }, { "name": "lcobucci/jwt", @@ -521,20 +521,20 @@ }, { "name": "mezzio/mezzio-authentication", - "version": "1.6.0", + "version": "1.7.0", "source": { "type": "git", "url": "https://github.com/mezzio/mezzio-authentication.git", - "reference": "9c5608bc6a1ce653bc6d2bb93abc5014777304aa" + "reference": "001b081a514f495b711fe44ae4e2be30a1c75181" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/mezzio/mezzio-authentication/zipball/9c5608bc6a1ce653bc6d2bb93abc5014777304aa", - "reference": "9c5608bc6a1ce653bc6d2bb93abc5014777304aa", + "url": "https://api.github.com/repos/mezzio/mezzio-authentication/zipball/001b081a514f495b711fe44ae4e2be30a1c75181", + "reference": "001b081a514f495b711fe44ae4e2be30a1c75181", "shasum": "" }, "require": { - "php": "^7.4 || ~8.0.0 || ~8.1.0", + "php": "~8.0.0 || ~8.1.0 || ~8.2.0", "psr/container": "^1.0 || ^2.0", "psr/http-message": "^1.0.1", "psr/http-server-middleware": "^1.0", @@ -547,11 +547,9 @@ "require-dev": { "ext-sqlite3": "*", "laminas/laminas-coding-standard": "~2.4.0", - "phpspec/prophecy": "^1.14", - "phpspec/prophecy-phpunit": "^v2.0.1", - "phpunit/phpunit": "^9.5.24", + "phpunit/phpunit": "^9.5.25", "psalm/plugin-phpunit": "^0.17.0", - "vimeo/psalm": "^4.27.0" + "vimeo/psalm": "^4.29" }, "suggest": { "ext-pdo": "*: for use with the PDO-backed UserRepositoryInterface implementation", @@ -599,7 +597,7 @@ "type": "community_bridge" } ], - "time": "2022-09-18T15:02:36+00:00" + "time": "2022-10-14T15:54:13+00:00" }, { "name": "paragonie/random_compat", @@ -921,6 +919,53 @@ }, "time": "2018-10-30T17:12:04+00:00" }, + { + "name": "stella-maris/clock", + "version": "0.1.6", + "source": { + "type": "git", + "url": "https://github.com/stella-maris-solutions/clock.git", + "reference": "a94228dac03c9a8411198ce8c8dacbbe99c930c3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/stella-maris-solutions/clock/zipball/a94228dac03c9a8411198ce8c8dacbbe99c930c3", + "reference": "a94228dac03c9a8411198ce8c8dacbbe99c930c3", + "shasum": "" + }, + "require": { + "php": "^7.0|^8.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "StellaMaris\\Clock\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Andreas Heigl", + "role": "Maintainer" + } + ], + "description": "A pre-release of the proposed PSR-20 Clock-Interface", + "homepage": "https://gitlab.com/stella-maris/clock", + "keywords": [ + "clock", + "datetime", + "point in time", + "psr20" + ], + "support": { + "issues": "https://github.com/stella-maris-solutions/clock/issues", + "source": "https://github.com/stella-maris-solutions/clock/tree/0.1.6" + }, + "time": "2022-09-27T15:03:11+00:00" + }, { "name": "webmozart/assert", "version": "1.11.0", @@ -1779,20 +1824,20 @@ }, { "name": "laminas/laminas-diactoros", - "version": "2.17.0", + "version": "2.19.0", "source": { "type": "git", "url": "https://github.com/laminas/laminas-diactoros.git", - "reference": "5b32597aa46b83c8b85bb1cf9a6ed4fe7dd980c5" + "reference": "b3c7e9262b4fbec801d8df2370cdebb4f5d3a0ae" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-diactoros/zipball/5b32597aa46b83c8b85bb1cf9a6ed4fe7dd980c5", - "reference": "5b32597aa46b83c8b85bb1cf9a6ed4fe7dd980c5", + "url": "https://api.github.com/repos/laminas/laminas-diactoros/zipball/b3c7e9262b4fbec801d8df2370cdebb4f5d3a0ae", + "reference": "b3c7e9262b4fbec801d8df2370cdebb4f5d3a0ae", "shasum": "" }, "require": { - "php": "^7.4 || ~8.0.0 || ~8.1.0", + "php": "~8.0.0 || ~8.1.0 || ~8.2.0", "psr/http-factory": "^1.0", "psr/http-message": "^1.0" }, @@ -1811,9 +1856,9 @@ "http-interop/http-factory-tests": "^0.9.0", "laminas/laminas-coding-standard": "^2.4.0", "php-http/psr7-integration-tests": "^1.1.1", - "phpunit/phpunit": "^9.5.23", + "phpunit/phpunit": "^9.5.25", "psalm/plugin-phpunit": "^0.17.0", - "vimeo/psalm": "^4.24.0" + "vimeo/psalm": "^4.28" }, "type": "library", "extra": { @@ -1872,25 +1917,25 @@ "type": "community_bridge" } ], - "time": "2022-08-30T17:01:46+00:00" + "time": "2022-10-10T21:28:03+00:00" }, { "name": "laminas/laminas-servicemanager", - "version": "3.17.0", + "version": "3.19.0", "source": { "type": "git", "url": "https://github.com/laminas/laminas-servicemanager.git", - "reference": "360be5f16955dd1edbcce1cfaa98ed82a17f02ec" + "reference": "ed160729bb8721127efdaac799f9a298963345b1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-servicemanager/zipball/360be5f16955dd1edbcce1cfaa98ed82a17f02ec", - "reference": "360be5f16955dd1edbcce1cfaa98ed82a17f02ec", + "url": "https://api.github.com/repos/laminas/laminas-servicemanager/zipball/ed160729bb8721127efdaac799f9a298963345b1", + "reference": "ed160729bb8721127efdaac799f9a298963345b1", "shasum": "" }, "require": { "laminas/laminas-stdlib": "^3.2.1", - "php": "~7.4.0 || ~8.0.0 || ~8.1.0", + "php": "~8.0.0 || ~8.1.0 || ~8.2.0", "psr/container": "^1.0" }, "conflict": { @@ -1906,17 +1951,16 @@ "container-interop/container-interop": "^1.2.0" }, "require-dev": { - "composer/package-versions-deprecated": "^1.0", + "composer/package-versions-deprecated": "^1.11.99.5", "laminas/laminas-coding-standard": "~2.4.0", "laminas/laminas-container-config-test": "^0.7", - "laminas/laminas-dependency-plugin": "^2.1.2", - "mikey179/vfsstream": "^1.6.10@alpha", - "ocramius/proxy-manager": "^2.11", - "phpbench/phpbench": "^1.1", - "phpspec/prophecy-phpunit": "^2.0", - "phpunit/phpunit": "^9.5.5", + "laminas/laminas-dependency-plugin": "^2.2", + "mikey179/vfsstream": "^1.6.11@alpha", + "ocramius/proxy-manager": "^2.14.1", + "phpbench/phpbench": "^1.2.6", + "phpunit/phpunit": "^9.5.25", "psalm/plugin-phpunit": "^0.17.0", - "vimeo/psalm": "^4.8" + "vimeo/psalm": "^4.28" }, "suggest": { "ocramius/proxy-manager": "ProxyManager ^2.1.1 to handle lazy initialization of services" @@ -1963,35 +2007,34 @@ "type": "community_bridge" } ], - "time": "2022-09-22T11:33:46+00:00" + "time": "2022-10-10T20:59:22+00:00" }, { "name": "laminas/laminas-stdlib", - "version": "3.13.0", + "version": "3.15.0", "source": { "type": "git", "url": "https://github.com/laminas/laminas-stdlib.git", - "reference": "66a6d03c381f6c9f1dd988bf8244f9afb9380d76" + "reference": "63b66bd4b696f024f42616b9d95cdb10e5109c27" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-stdlib/zipball/66a6d03c381f6c9f1dd988bf8244f9afb9380d76", - "reference": "66a6d03c381f6c9f1dd988bf8244f9afb9380d76", + "url": "https://api.github.com/repos/laminas/laminas-stdlib/zipball/63b66bd4b696f024f42616b9d95cdb10e5109c27", + "reference": "63b66bd4b696f024f42616b9d95cdb10e5109c27", "shasum": "" }, "require": { - "php": "^7.4 || ~8.0.0 || ~8.1.0" + "php": "~8.0.0 || ~8.1.0 || ~8.2.0" }, "conflict": { "zendframework/zend-stdlib": "*" }, "require-dev": { - "laminas/laminas-coding-standard": "~2.3.0", + "laminas/laminas-coding-standard": "^2.4.0", "phpbench/phpbench": "^1.2.6", - "phpstan/phpdoc-parser": "^0.5.4", - "phpunit/phpunit": "^9.5.23", + "phpunit/phpunit": "^9.5.25", "psalm/plugin-phpunit": "^0.17.0", - "vimeo/psalm": "^4.26" + "vimeo/psalm": "^4.28" }, "type": "library", "autoload": { @@ -2023,7 +2066,7 @@ "type": "community_bridge" } ], - "time": "2022-08-24T13:56:50+00:00" + "time": "2022-10-10T19:10:24+00:00" }, { "name": "myclabs/deep-copy", @@ -2467,25 +2510,30 @@ }, { "name": "phpdocumentor/type-resolver", - "version": "1.6.1", + "version": "1.6.2", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "77a32518733312af16a44300404e945338981de3" + "reference": "48f445a408c131e38cab1c235aa6d2bb7a0bb20d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/77a32518733312af16a44300404e945338981de3", - "reference": "77a32518733312af16a44300404e945338981de3", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/48f445a408c131e38cab1c235aa6d2bb7a0bb20d", + "reference": "48f445a408c131e38cab1c235aa6d2bb7a0bb20d", "shasum": "" }, "require": { - "php": "^7.2 || ^8.0", + "php": "^7.4 || ^8.0", "phpdocumentor/reflection-common": "^2.0" }, "require-dev": { "ext-tokenizer": "*", - "psalm/phar": "^4.8" + "phpstan/extension-installer": "^1.1", + "phpstan/phpstan": "^1.8", + "phpstan/phpstan-phpunit": "^1.1", + "phpunit/phpunit": "^9.5", + "rector/rector": "^0.13.9", + "vimeo/psalm": "^4.25" }, "type": "library", "extra": { @@ -2511,128 +2559,9 @@ "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", "support": { "issues": "https://github.com/phpDocumentor/TypeResolver/issues", - "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.6.1" - }, - "time": "2022-03-15T21:29:03+00:00" - }, - { - "name": "phpspec/prophecy", - "version": "v1.15.0", - "source": { - "type": "git", - "url": "https://github.com/phpspec/prophecy.git", - "reference": "bbcd7380b0ebf3961ee21409db7b38bc31d69a13" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/bbcd7380b0ebf3961ee21409db7b38bc31d69a13", - "reference": "bbcd7380b0ebf3961ee21409db7b38bc31d69a13", - "shasum": "" - }, - "require": { - "doctrine/instantiator": "^1.2", - "php": "^7.2 || ~8.0, <8.2", - "phpdocumentor/reflection-docblock": "^5.2", - "sebastian/comparator": "^3.0 || ^4.0", - "sebastian/recursion-context": "^3.0 || ^4.0" - }, - "require-dev": { - "phpspec/phpspec": "^6.0 || ^7.0", - "phpunit/phpunit": "^8.0 || ^9.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.x-dev" - } - }, - "autoload": { - "psr-4": { - "Prophecy\\": "src/Prophecy" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Konstantin Kudryashov", - "email": "ever.zet@gmail.com", - "homepage": "http://everzet.com" - }, - { - "name": "Marcello Duarte", - "email": "marcello.duarte@gmail.com" - } - ], - "description": "Highly opinionated mocking framework for PHP 5.3+", - "homepage": "https://github.com/phpspec/prophecy", - "keywords": [ - "Double", - "Dummy", - "fake", - "mock", - "spy", - "stub" - ], - "support": { - "issues": "https://github.com/phpspec/prophecy/issues", - "source": "https://github.com/phpspec/prophecy/tree/v1.15.0" - }, - "time": "2021-12-08T12:19:24+00:00" - }, - { - "name": "phpspec/prophecy-phpunit", - "version": "v2.0.1", - "source": { - "type": "git", - "url": "https://github.com/phpspec/prophecy-phpunit.git", - "reference": "2d7a9df55f257d2cba9b1d0c0963a54960657177" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy-phpunit/zipball/2d7a9df55f257d2cba9b1d0c0963a54960657177", - "reference": "2d7a9df55f257d2cba9b1d0c0963a54960657177", - "shasum": "" - }, - "require": { - "php": "^7.3 || ^8", - "phpspec/prophecy": "^1.3", - "phpunit/phpunit": "^9.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0-dev" - } - }, - "autoload": { - "psr-4": { - "Prophecy\\PhpUnit\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Christophe Coevoet", - "email": "stof@notk.org" - } - ], - "description": "Integrating the Prophecy mocking library in PHPUnit test cases", - "homepage": "http://phpspec.net", - "keywords": [ - "phpunit", - "prophecy" - ], - "support": { - "issues": "https://github.com/phpspec/prophecy-phpunit/issues", - "source": "https://github.com/phpspec/prophecy-phpunit/tree/v2.0.1" + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.6.2" }, - "time": "2020-07-09T08:33:42+00:00" + "time": "2022-10-14T12:47:21+00:00" }, { "name": "phpstan/phpdoc-parser", @@ -3160,30 +3089,30 @@ }, { "name": "psr/log", - "version": "1.1.4", + "version": "3.0.0", "source": { "type": "git", "url": "https://github.com/php-fig/log.git", - "reference": "d49695b909c3b7628b6289db5479a1c204601f11" + "reference": "fe5ea303b0887d5caefd3d431c3e61ad47037001" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/d49695b909c3b7628b6289db5479a1c204601f11", - "reference": "d49695b909c3b7628b6289db5479a1c204601f11", + "url": "https://api.github.com/repos/php-fig/log/zipball/fe5ea303b0887d5caefd3d431c3e61ad47037001", + "reference": "fe5ea303b0887d5caefd3d431c3e61ad47037001", "shasum": "" }, "require": { - "php": ">=5.3.0" + "php": ">=8.0.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.1.x-dev" + "dev-master": "3.x-dev" } }, "autoload": { "psr-4": { - "Psr\\Log\\": "Psr/Log/" + "Psr\\Log\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -3204,9 +3133,9 @@ "psr-3" ], "support": { - "source": "https://github.com/php-fig/log/tree/1.1.4" + "source": "https://github.com/php-fig/log/tree/3.0.0" }, - "time": "2021-05-03T11:20:27+00:00" + "time": "2021-07-14T16:46:02+00:00" }, { "name": "sebastian/cli-parser", @@ -4291,46 +4220,42 @@ }, { "name": "symfony/console", - "version": "v5.4.14", + "version": "v6.0.14", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "984ea2c0f45f42dfed01d2f3987b187467c4b16d" + "reference": "1f89cab8d52c84424f798495b3f10342a7b1a070" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/984ea2c0f45f42dfed01d2f3987b187467c4b16d", - "reference": "984ea2c0f45f42dfed01d2f3987b187467c4b16d", + "url": "https://api.github.com/repos/symfony/console/zipball/1f89cab8d52c84424f798495b3f10342a7b1a070", + "reference": "1f89cab8d52c84424f798495b3f10342a7b1a070", "shasum": "" }, "require": { - "php": ">=7.2.5", - "symfony/deprecation-contracts": "^2.1|^3", + "php": ">=8.0.2", "symfony/polyfill-mbstring": "~1.0", - "symfony/polyfill-php73": "^1.9", - "symfony/polyfill-php80": "^1.16", "symfony/service-contracts": "^1.1|^2|^3", - "symfony/string": "^5.1|^6.0" + "symfony/string": "^5.4|^6.0" }, "conflict": { - "psr/log": ">=3", - "symfony/dependency-injection": "<4.4", - "symfony/dotenv": "<5.1", - "symfony/event-dispatcher": "<4.4", - "symfony/lock": "<4.4", - "symfony/process": "<4.4" + "symfony/dependency-injection": "<5.4", + "symfony/dotenv": "<5.4", + "symfony/event-dispatcher": "<5.4", + "symfony/lock": "<5.4", + "symfony/process": "<5.4" }, "provide": { - "psr/log-implementation": "1.0|2.0" + "psr/log-implementation": "1.0|2.0|3.0" }, "require-dev": { - "psr/log": "^1|^2", - "symfony/config": "^4.4|^5.0|^6.0", - "symfony/dependency-injection": "^4.4|^5.0|^6.0", - "symfony/event-dispatcher": "^4.4|^5.0|^6.0", - "symfony/lock": "^4.4|^5.0|^6.0", - "symfony/process": "^4.4|^5.0|^6.0", - "symfony/var-dumper": "^4.4|^5.0|^6.0" + "psr/log": "^1|^2|^3", + "symfony/config": "^5.4|^6.0", + "symfony/dependency-injection": "^5.4|^6.0", + "symfony/event-dispatcher": "^5.4|^6.0", + "symfony/lock": "^5.4|^6.0", + "symfony/process": "^5.4|^6.0", + "symfony/var-dumper": "^5.4|^6.0" }, "suggest": { "psr/log": "For using the console logger", @@ -4370,7 +4295,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v5.4.14" + "source": "https://github.com/symfony/console/tree/v6.0.14" }, "funding": [ { @@ -4386,29 +4311,29 @@ "type": "tidelift" } ], - "time": "2022-10-07T08:01:20+00:00" + "time": "2022-10-07T08:02:12+00:00" }, { "name": "symfony/deprecation-contracts", - "version": "v2.5.2", + "version": "v3.0.2", "source": { "type": "git", "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "e8b495ea28c1d97b5e0c121748d6f9b53d075c66" + "reference": "26954b3d62a6c5fd0ea8a2a00c0353a14978d05c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/e8b495ea28c1d97b5e0c121748d6f9b53d075c66", - "reference": "e8b495ea28c1d97b5e0c121748d6f9b53d075c66", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/26954b3d62a6c5fd0ea8a2a00c0353a14978d05c", + "reference": "26954b3d62a6c5fd0ea8a2a00c0353a14978d05c", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=8.0.2" }, "type": "library", "extra": { "branch-alias": { - "dev-main": "2.5-dev" + "dev-main": "3.0-dev" }, "thanks": { "name": "symfony/contracts", @@ -4437,7 +4362,7 @@ "description": "A generic function and convention to trigger deprecation notices", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v2.5.2" + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.0.2" }, "funding": [ { @@ -4453,7 +4378,7 @@ "type": "tidelift" } ], - "time": "2022-01-02T09:53:40+00:00" + "time": "2022-01-02T09:55:41+00:00" }, { "name": "symfony/polyfill-ctype", @@ -4785,85 +4710,6 @@ ], "time": "2022-05-24T11:49:31+00:00" }, - { - "name": "symfony/polyfill-php73", - "version": "v1.26.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-php73.git", - "reference": "e440d35fa0286f77fb45b79a03fedbeda9307e85" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/e440d35fa0286f77fb45b79a03fedbeda9307e85", - "reference": "e440d35fa0286f77fb45b79a03fedbeda9307e85", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.26-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "files": [ - "bootstrap.php" - ], - "psr-4": { - "Symfony\\Polyfill\\Php73\\": "" - }, - "classmap": [ - "Resources/stubs" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "polyfill", - "portable", - "shim" - ], - "support": { - "source": "https://github.com/symfony/polyfill-php73/tree/v1.26.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2022-05-24T11:49:31+00:00" - }, { "name": "symfony/polyfill-php80", "version": "v1.26.0", @@ -5032,34 +4878,33 @@ }, { "name": "symfony/string", - "version": "v5.4.14", + "version": "v6.0.14", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "089e7237497fae7a9c404d0c3aeb8db3254733e4" + "reference": "3db7da820a6e4a584b714b3933c34c6a7db4d86c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/089e7237497fae7a9c404d0c3aeb8db3254733e4", - "reference": "089e7237497fae7a9c404d0c3aeb8db3254733e4", + "url": "https://api.github.com/repos/symfony/string/zipball/3db7da820a6e4a584b714b3933c34c6a7db4d86c", + "reference": "3db7da820a6e4a584b714b3933c34c6a7db4d86c", "shasum": "" }, "require": { - "php": ">=7.2.5", + "php": ">=8.0.2", "symfony/polyfill-ctype": "~1.8", "symfony/polyfill-intl-grapheme": "~1.0", "symfony/polyfill-intl-normalizer": "~1.0", - "symfony/polyfill-mbstring": "~1.0", - "symfony/polyfill-php80": "~1.15" + "symfony/polyfill-mbstring": "~1.0" }, "conflict": { - "symfony/translation-contracts": ">=3.0" + "symfony/translation-contracts": "<2.0" }, "require-dev": { - "symfony/error-handler": "^4.4|^5.0|^6.0", - "symfony/http-client": "^4.4|^5.0|^6.0", - "symfony/translation-contracts": "^1.1|^2", - "symfony/var-exporter": "^4.4|^5.0|^6.0" + "symfony/error-handler": "^5.4|^6.0", + "symfony/http-client": "^5.4|^6.0", + "symfony/translation-contracts": "^2.0|^3.0", + "symfony/var-exporter": "^5.4|^6.0" }, "type": "library", "autoload": { @@ -5098,7 +4943,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v5.4.14" + "source": "https://github.com/symfony/string/tree/v6.0.14" }, "funding": [ { @@ -5114,7 +4959,7 @@ "type": "tidelift" } ], - "time": "2022-10-05T15:16:54+00:00" + "time": "2022-10-10T09:34:08+00:00" }, { "name": "theseer/tokenizer", @@ -5387,11 +5232,11 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": "^7.4 || ~8.0.0 || ~8.1.0" + "php": "~8.0.0 || ~8.1.0 || ~8.2.0" }, "platform-dev": [], "platform-overrides": { - "php": "7.4.99" + "php": "8.0.99" }, "plugin-api-version": "2.3.0" } diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 778cbea6..928d8a08 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + $config['encryption_key'] @@ -113,7 +113,8 @@ - + + $revoked $revoked $revoked $revoked @@ -124,19 +125,11 @@ ! $this->createdAt $this->createdAt - + $createdAt - $updatedAt - new DateTimeImmutable('now', new DateTimeZone($this->getTimezone()->getValue())) - new DateTimeImmutable() - - - DateTimeInterface - DateTimeInterface - - $createdAt $updatedAt + $updatedAt $this->getTimezone()->getValue() @@ -144,10 +137,6 @@ getValue - - DateTime - DateTime - @@ -365,188 +354,16 @@ - - function () { - - - testConfigProvider - testConstructor - testFactoryRaisesTypeErrorForNonCallableResponseFactory - testFactoryRaisesTypeErrorWhenResponseServiceProvidesResponseInstance - testFactoryReturnsInstanceWhenAppropriateDependenciesArePresentInContainer - testRaisesTypeErrorForInvalidAuthorizationServer - - - $this->container->reveal() - $this->container->reveal() - $this->container->reveal() - $this->container->reveal() - (new ConfigProvider())->getDependencies() - - shouldBeCalled - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - - - reveal - reveal - reveal - reveal - reveal - reveal - reveal - - - - - - testInvalidResponseFactoryThrowsTypeError - - - - - testConstructor - testFactoryRaisesTypeErrorForNonCallableResponseFactory - testFactoryRaisesTypeErrorWhenResponseServiceProvidesResponseInstance - testFactoryReturnsInstanceWhenAppropriateDependenciesArePresentInContainer - testRaisesTypeErrorForInvalidAuthorizationServer - - - $this->container->reveal() - $this->container->reveal() - $this->container->reveal() - $this->container->reveal() - - - shouldBeCalled - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - - - reveal - reveal - reveal - reveal - reveal - reveal - reveal - - - - - Argument::any() - - - $this->prophesize(AuthorizationRequest::class) - $this->prophesize(AuthorizationServer::class) - $this->prophesize(RequestHandlerInterface::class) - $this->prophesize(ServerRequestInterface::class) - - - function () { - - - testAuthorizationRequestRaisingOAuthServerExceptionGeneratesResponseFromException - testAuthorizationRequestRaisingUnknownExceptionGeneratesResponseFromException - testConstructor - testProcess - - - $this->authServer->reveal() - $this->authServer->reveal() - $this->authServer->reveal() - $this->authServer->reveal() - $this->handler->reveal() - $this->handler->reveal() - $this->handler->reveal() - $this->serverRequest->reveal() - $this->serverRequest->reveal() - $this->serverRequest->reveal() - $this->serverRequest->reveal() - $this->serverRequest->reveal() - $this->serverRequest->reveal() - - - $this->responseFactory - $this->responseFactory - $this->responseFactory - $this->responseFactory - - - function (RequestEvent $event) { - - - testInvoke - testInvokeWithListenerConfig - testInvokeWithListenerConfigMissingServiceThrowsException - testInvokeWithListenerProviderConfig - testInvokeWithListenerProviderConfigMissingServiceThrowsException - testInvokeWithNullGrant - - - $mockContainer->reveal() - $mockContainer->reveal() - $mockContainer->reveal() - $mockContainer->reveal() - $mockContainer->reveal() - $event - - $mockListener - $mockProvider - $result - - - testGetAccessTokenExpire - testGetAccessTokenExpireNoConfig - testGetAuthCodeExpire - testGetAuthCodeExpireNoConfig - testGetEncryptionKey - testGetEncryptionKeyNoConfig - testGetGrantsConfig - testGetGrantsConfigNoArrayValue - testGetGrantsConfigNoConfig - testGetListenerProvidersConfig - testGetListenerProvidersConfigNoArrayValue - testGetListenerProvidersConfigNoConfig - testGetListenersConfig - testGetListenersConfigNoArrayValue - testGetListenersConfigNoConfig - testGetPrivateKey - testGetPrivateKeyArray - testGetPrivateKeyWhenNoConfigPresentWillResultInAnException - testGetRefreshTokenExpire - testGetRefreshTokenExpireNoConfig - - - $this->config['authentication'] - $this->config['authentication'] - $this->config['authentication'] - $this->config['authentication'] - $this->config['authentication'] - $this->config['authentication'] - $result $result @@ -561,21 +378,7 @@ array|string - - get - get - get - get - get - get - get - get - get - get - get - get - get - get + proxy proxy proxy @@ -596,224 +399,12 @@ proxy proxy proxy - reveal - reveal - reveal - reveal - reveal - reveal - reveal - reveal - reveal - reveal - reveal - reveal - reveal - reveal - reveal - reveal - reveal - reveal - reveal - reveal - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn $this->$name($container) - - $this->config - $this->container - $this->trait - - - $this->config - $this->config - $this->config - $this->config - $this->config - $this->config - $this->container - $this->container - $this->container - $this->container - $this->container - $this->container - $this->container - $this->container - $this->container - $this->container - $this->container - $this->container - $this->container - $this->container - $this->container - $this->container - $this->container - $this->container - $this->container - $this->container - $this->trait - $this->trait - $this->trait - $this->trait - $this->trait - $this->trait - $this->trait - $this->trait - $this->trait - $this->trait - $this->trait - $this->trait - $this->trait - $this->trait - $this->trait - $this->trait - $this->trait - $this->trait - $this->trait - $this->trait - - - $trait - - - - - testImplementsInstanceAccessTokenEntityInterface - - - - - testImplementsInstanceAuthCodeEntityInterface - - - - - testConstructorSetsIdentifier - testConstructorSetsName - testConstructorSetsRedirectUri - testImplementsAuthCodeEntityInterface - testPasswordClient - testPersonalAccessClient - testSecret - - - getIdentifier - getName - getRedirectUri - getSecret - hasPasswordClient - hasPasswordClient - hasPersonalAccessClient - hasPersonalAccessClient - setPasswordClient - setPasswordClient - setPersonalAccessClient - setPersonalAccessClient - setSecret - - - $this->entity - - - $this->entity - $this->entity - $this->entity - $this->entity - $this->entity - $this->entity - $this->entity - - - - - testImplementsRefreshTokenEntityInterface - - - - - RevokableTrait::class - - - testSetRevokedToFalse - testSetRevokedToTrue - - - isRevoked - isRevoked - setRevoked - setRevoked - - - $this->trait - - - $this->trait - $this->trait - - - - - testEntityIsJsonSerializable - testImplementsScopeEntityInterface - - - setIdentifier - - - $this->entity - - - $this->entity - $this->entity - - - - - TimestampableTrait::class - - - testCreatedAt - testTimestampOnCreate - testUpdatedAt - - - getCreatedAt - getCreatedAt - getUpdatedAt - setCreatedAt - setUpdatedAt - timestampOnCreate - - - $this->trait - - - $this->trait - $this->trait - $this->trait - - - testConstructorWithoutParamWillResultInAnException - testGetIdentifier - testImplementsUserEntityInterface - new UserEntity() @@ -821,150 +412,17 @@ $entity - - - testInvoke - - - - - testInvoke - - - - - testInvoke - - - - - testInvoke - - - - - testInvoke - - - - - fn() - - - testConstructor - testFactoryRaisesTypeErrorForNonCallableResponseFactory - testFactoryRaisesTypeErrorWhenResponseServiceProvidesResponseInstance - testFactoryReturnsInstanceWhenAppropriateDependenciesArePresentInContainer - testInvokeWithEmptyContainer - - - $this->container->reveal() - $this->container->reveal() - $this->container->reveal() - $this->container->reveal() - - - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - - - willReturn - willReturn - willReturn - willReturn - willReturn - - - reveal - reveal - reveal - reveal - reveal - reveal - reveal - reveal - - - $identity - $roles - $details - - - - Argument::that([$request, 'reveal']) - Argument::that([$request, 'reveal']) - Argument::that([$request, 'reveal']) - Argument::that([$request, 'reveal']) - - - function ( - - - testAuthenticateReturnsAUserIfTheResourceServerProducesAUserId - testAuthenticateReturnsNullIfResourceServerDoesNotProduceAUserIdOrClientId - testAuthenticateReturnsNullIfTheResourceServerProducesAClientIdOnly - testConstructor - testOAuthServerExceptionRaisedDuringAuthenticateResultsInInvalidAuthentication - testUnauthorizedResponseProducesAResponseWithAWwwAuthenticateHeader - - - $this->resourceServer->reveal() - $this->resourceServer->reveal() - $this->resourceServer->reveal() - $this->resourceServer->reveal() - $this->resourceServer->reveal() - $this->resourceServer->reveal() - - + $details $roles - $this->responseFactory - $this->responseFactory - $this->responseFactory - $this->responseFactory - $this->responseFactory - $this->responseFactory - [$request, 'reveal'] - [$request, 'reveal'] - [$request, 'reveal'] - [$request, 'reveal'] - - reveal - reveal - reveal - reveal - reveal - reveal - will - will - will - willThrow - $consumerHandler $consumerHandler - - function () { - - - testProcessClientCredentialGrantConfidential - testProcessClientCredentialGrantNotConfidential - testProcessImplicitGrant - testProcessPasswordGrant - testProcessRefreshTokenGrant - $data['token_type'] @@ -1022,498 +480,11 @@ ResponseFactoryFactory - - - testConstructor - testScopesToStringWithEmptyArray - - - $this->pdo->reveal() - $this->pdo->reveal() - - - reveal - reveal - - - $this->pdo - - - $this->pdo - $this->pdo - - - - - $this->prophesize(ContainerInterface::class) - - - testFactory - - - $this->container->reveal() - - - reveal - willReturn - - - reveal - - - $this->pdo - - - $this->pdo - - - - - testGetNewToken - testGetNewTokenWithScopeAndIndentifier - testIsAccessTokenRevokedReturnsFalseWhenRowDoesNotContainRevokedFlag - testIsAccessTokenRevokedReturnsFalseWhenRowRevokedFlagIsFalse - testIsAccessTokenRevokedReturnsFalseWhenStatementFailsExecution - testIsAccessTokenRevokedReturnsTrueWhenRowRevokedFlagIsTrue - testIsAcessTokenRevokedRaisesExceptionWhenTokenIdDontExists - testPersistNewAccessTokenRaisesExceptionWhenStatementExecutionFails - testRevokeAccessToken - - - prepare - prepare - prepare - prepare - prepare - prepare - prepare - will - will - will - will - will - will - will - - - $this->pdo - - - $this->pdo - $this->pdo - $this->pdo - $this->pdo - $this->pdo - $this->pdo - $this->pdo - - - - - $this->prophesize(ContainerInterface::class) - - - testFactory - - - $this->container->reveal() - - - reveal - willReturn - - - reveal - - - $this->pdo - - - $this->pdo - - - - - testIsAuthCodeRevokedReturnsFalseForStatementExecutionFailure - testIsAuthCodeRevokedReturnsTrue - testNewAuthCode - testPersistNewAuthCodeRaisesExceptionWhenStatementExecutionFails - testRevokeAuthCode - - - getNewAuthCode - isAuthCodeRevoked - isAuthCodeRevoked - persistNewAuthCode - prepare - prepare - prepare - prepare - revokeAuthCode - will - will - will - will - - - $this->pdo - $this->repo - - - $this->pdo - $this->pdo - $this->pdo - $this->pdo - $this->repo - $this->repo - $this->repo - $this->repo - $this->repo - - - - - $this->prophesize(ContainerInterface::class) - - - testFactory - - - $this->container->reveal() - - - reveal - willReturn - - - reveal - - - $this->pdo - - - $this->pdo - - - - - testGetClientEntityReturnsCorrectEntity - testGetClientEntityReturnsNullIfNoRowReturned - testGetClientEntityReturnsNullIfStatementExecutionReturnsFalse - testValidateClientReturnsFalseForEmptyClientSecret - testValidateClientReturnsFalseForNonMatchingClientSecret - testValidateClientReturnsFalseIfRowIndicatesNotGranted - - - array - - - getClientEntity - getClientEntity - getClientEntity - prepare - prepare - prepare - prepare - prepare - prepare - prepare - validateClient - validateClient - validateClient - validateClient - will - will - will - will - will - will - will - - - $this->pdo - $this->repo - - - $this->pdo - $this->pdo - $this->pdo - $this->pdo - $this->pdo - $this->pdo - $this->pdo - $this->repo - $this->repo - $this->repo - $this->repo - $this->repo - $this->repo - $this->repo - - - $client - $client - $client - - - - - testRaisesExceptionIfPdoConfigurationIsMissing - testRaisesExceptionIfPdoServiceIsInvalid - testValidConfigurationResultsInReturnedPdoServiceInstance - testValidServiceInConfigurationReturnsPdoService - - - ($this->factory)($this->container->reveal()) - ($this->factory)($this->container->reveal()) - ($this->factory)($this->container->reveal()) - ($this->factory)($this->container->reveal()) - - - array - - - get - get - get - get - get - get - has - has - has - has - has - has - reveal - reveal - reveal - reveal - shouldBeCalled - shouldNotBeCalled - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - - - $this->container - $this->factory - - - $this->container - $this->container - $this->container - $this->container - $this->factory - $this->factory - $this->factory - $this->factory - - - - - $this->prophesize(ContainerInterface::class) - - - testFactory - - - $this->container->reveal() - - - reveal - willReturn - - - reveal - - - $this->pdo - - - $this->pdo - - - - - testGetNewRefreshToken - testIsRefreshTokenRevokedReturnsFalseWhenStatementFailsExecution - testIsRefreshTokenRevokedReturnsTrue - testPersistNewRefreshTokenRaisesExceptionWhenStatementExecutionFails - testRevokeRefreshToken - - - getNewRefreshToken - isRefreshTokenRevoked - isRefreshTokenRevoked - persistNewRefreshToken - prepare - prepare - prepare - prepare - revokeRefreshToken - will - will - will - will - - - $this->pdo - $this->repo - - - $this->pdo - $this->pdo - $this->pdo - $this->pdo - $this->repo - $this->repo - $this->repo - $this->repo - $this->repo - - - - - $this->prophesize(ContainerInterface::class) - - - testFactory - - - $this->container->reveal() - - - reveal - willReturn - - - reveal - - - $this->pdo - - - $this->pdo - - - - - testFinalizeScopesWithEmptyScopes - testGetScopeEntityByIdentifierReturnsNullWhenReturnedRowDoesNotHaveIdentifier - testGetScopeEntityByIdentifierReturnsNullWhenStatementExecutionFails - testGetScopeEntityByIndentifierReturnsScopes - - - $scopes - - - finalizeScopes - getScopeEntityByIdentifier - getScopeEntityByIdentifier - getScopeEntityByIdentifier - prepare - prepare - prepare - will - will - will - - - $this->pdo - $this->repo - - - $this->pdo - $this->pdo - $this->pdo - $this->repo - $this->repo - $this->repo - $this->repo - - - - - testGetUserEntityByCredentialsReturnsEntity - testGetUserEntityByCredentialsReturnsNullIfPasswordVerificationFails - testGetUserEntityByCredentialsReturnsNullIfStatementExecutionReturnsFalse - testGetUserEntityByCredentialsReturnsNullIfUserIsNotFound - - - getUserEntityByUserCredentials - getUserEntityByUserCredentials - getUserEntityByUserCredentials - getUserEntityByUserCredentials - prepare - prepare - prepare - prepare - will - will - will - will - - - $this->pdo - $this->repo - - - $this->pdo - $this->pdo - $this->pdo - $this->pdo - $this->repo - $this->repo - $this->repo - $this->repo - - - - testGetAccessTokenRepository - testGetAccessTokenRepositoryWithoutService - testGetAuthCodeRepository - testGetAuthCodeRepositoryWithoutService - testGetClientRepository - testGetClientRepositoryWithoutService - testGetRefreshTokenRepository - testGetRefreshTokenRepositoryWithoutService - testGetScopeRepository - testGetScopeRepositoryWithoutService - testGetUserRepository - testGetUserRepositoryWithoutService - RepositoryInterface - - get - get - get - get - get - get - has - has - has - has - has - has - has - has - has - has - has - has + proxy proxy proxy @@ -1526,171 +497,14 @@ proxy proxy proxy - reveal - reveal - reveal - reveal - reveal - reveal - reveal - reveal - reveal - reveal - reveal - reveal - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn $this->$name($container) - - $this->container - $this->trait - - - $this->container - $this->container - $this->container - $this->container - $this->container - $this->container - $this->container - $this->container - $this->container - $this->container - $this->container - $this->container - $this->trait - $this->trait - $this->trait - $this->trait - $this->trait - $this->trait - $this->trait - $this->trait - $this->trait - $this->trait - $this->trait - $this->trait - - - - - testConstructor - testInvokeWithConfigAndRepository - testInvokeWithConfigWithoutRepository - testInvokeWithEmptyConfig - testInvokeWithInvalidExtendedKey - testInvokeWithValidExtendedKey - - - $this->container->reveal() - $this->container->reveal() - $this->container->reveal() - $this->container->reveal() - $this->container->reveal() - - - Generator - Generator - - - get - get - get - get - get - get - get - get - has - has - has - has - has - has - has - has - has - reveal - reveal - reveal - reveal - reveal - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - willReturn - - - $this->container - - - $this->container - $this->container - $this->container - $this->container - $this->container - Psr17ResponseFactoryTrait - - - $container - - - function () { - - - testCreatesTokenEndpointHandler - testDirectResponseInstanceFromContainerThrowsTypeError - testEmptyContainerThrowsTypeError - - - - - testGenericExceptionsFallsThrough - testHandleUsesAuthorizationServer - testOAuthExceptionProducesResult - - - $this->createResponseFactory($expectedResponse) - $this->createResponseFactory($expectedResponse) - $this->createResponseFactory() - - diff --git a/src/Entity/TimestampableTrait.php b/src/Entity/TimestampableTrait.php index b9e79ca8..13c79668 100644 --- a/src/Entity/TimestampableTrait.php +++ b/src/Entity/TimestampableTrait.php @@ -12,10 +12,10 @@ trait TimestampableTrait { - /** @var DateTime */ + /** @var DateTimeInterface */ protected $createdAt; - /** @var DateTime */ + /** @var DateTimeInterface */ protected $updatedAt; public function getCreatedAt(): DateTimeInterface diff --git a/test/AuthorizationHandlerFactoryTest.php b/test/AuthorizationHandlerFactoryTest.php index 0307b043..eadf269b 100644 --- a/test/AuthorizationHandlerFactoryTest.php +++ b/test/AuthorizationHandlerFactoryTest.php @@ -11,8 +11,6 @@ use Mezzio\Authentication\OAuth2\ConfigProvider; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Psr\Container\ContainerInterface; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface; @@ -24,102 +22,99 @@ */ class AuthorizationHandlerFactoryTest extends TestCase { - use ProphecyTrait; + /** @var AuthorizationServer&MockObject */ + private AuthorizationServer $authServer; - /** @var AuthorizationServer|ObjectProphecy */ - private $authServer; - - /** @var ContainerInterface|ObjectProphecy */ - private $container; + /** @var ContainerInterface&MockObject */ + private ContainerInterface $container; /** @var ResponseInterface&MockObject */ - private $response; + private ResponseInterface $response; protected function setUp(): void { - $this->container = $this->prophesize(ContainerInterface::class); + $this->container = $this->createMock(ContainerInterface::class); $this->container - ->has(ResponseFactoryInterface::class) + ->method('has') + ->with(ResponseFactoryInterface::class) ->willReturn(false); - $this->authServer = $this->prophesize(AuthorizationServer::class); + $this->authServer = $this->createMock(AuthorizationServer::class); $this->response = $this->createMock(ResponseInterface::class); } - public function testConstructor() + public function testConstructor(): void { $factory = new AuthorizationHandlerFactory(); - $this->assertInstanceOf(AuthorizationHandlerFactory::class, $factory); + self::assertInstanceOf(AuthorizationHandlerFactory::class, $factory); } - public function testRaisesTypeErrorForInvalidAuthorizationServer() + public function testRaisesTypeErrorForInvalidAuthorizationServer(): void { - $this->container - ->get(AuthorizationServer::class) - ->willReturn(new stdClass()); - $this->container - ->get(ResponseInterface::class) - ->willReturn(static function (): void { - }); + $this->container->expects(self::exactly(2)) + ->method('get') + ->willReturnMap([ + [AuthorizationServer::class, new stdClass()], + [ResponseInterface::class, fn () => null], + ]); $factory = new AuthorizationHandlerFactory(); $this->expectException(TypeError::class); - $factory($this->container->reveal()); + $factory($this->container); } - public function testFactoryRaisesTypeErrorForNonCallableResponseFactory() + public function testFactoryRaisesTypeErrorForNonCallableResponseFactory(): void { - $this->container - ->get(AuthorizationServer::class) - ->willReturn($this->authServer->reveal()); - $this->container - ->get(ResponseInterface::class) - ->willReturn(new stdClass()); + $this->container->expects(self::exactly(2)) + ->method('get') + ->willReturnMap([ + [AuthorizationServer::class, $this->authServer], + [ResponseInterface::class, new stdClass()], + ]); $factory = new AuthorizationHandlerFactory(); $this->expectException(TypeError::class); - $factory($this->container->reveal()); + $factory($this->container); } - public function testFactoryRaisesTypeErrorWhenResponseServiceProvidesResponseInstance() + public function testFactoryRaisesTypeErrorWhenResponseServiceProvidesResponseInstance(): void { - $this->container - ->get(AuthorizationServer::class) - ->willReturn($this->authServer->reveal()); - $this->container - ->get(ResponseInterface::class) - ->willReturn($this->response); + $this->container->expects(self::exactly(2)) + ->method('get') + ->willReturnMap([ + [AuthorizationServer::class, $this->authServer], + [ResponseInterface::class, $this->response], + ]); $factory = new AuthorizationHandlerFactory(); $this->expectException(TypeError::class); - $factory($this->container->reveal()); + $factory($this->container); } - public function testFactoryReturnsInstanceWhenAppropriateDependenciesArePresentInContainer() + public function testFactoryReturnsInstanceWhenAppropriateDependenciesArePresentInContainer(): void { - $this->container - ->get(AuthorizationServer::class) - ->willReturn($this->authServer->reveal()); - $this->container - ->get(ResponseInterface::class) - ->willReturn(fn(): MockObject => $this->response)->shouldBeCalled(); + $this->container->expects(self::exactly(2)) + ->method('get') + ->willReturnMap([ + [AuthorizationServer::class, $this->authServer], + [ResponseInterface::class, fn (): ResponseInterface => $this->response], + ]); $factory = new AuthorizationHandlerFactory(); - $factory($this->container->reveal()); + $factory($this->container); } - public function testConfigProvider() + public function testConfigProvider(): void { - $authServer = $this->prophesize(AuthorizationServer::class)->reveal(); - $responseFactory = fn(): object => $this->prophesize(ResponseInterface::class)->reveal(); + $responseFactory = fn(): ResponseInterface => $this->response; $container = new ServiceManager((new ConfigProvider())->getDependencies()); - $container->setService(AuthorizationServer::class, $authServer); + $container->setService(AuthorizationServer::class, $this->authServer); $container->setService(ResponseInterface::class, $responseFactory); $authHandler = $container->get(AuthorizationHandler::class); - $this->assertInstanceOf(AuthorizationHandler::class, $authHandler); + self::assertInstanceOf(AuthorizationHandler::class, $authHandler); } } diff --git a/test/AuthorizationHandlerTest.php b/test/AuthorizationHandlerTest.php index 33c9eb93..979ba4e7 100644 --- a/test/AuthorizationHandlerTest.php +++ b/test/AuthorizationHandlerTest.php @@ -2,13 +2,12 @@ declare(strict_types=1); -namespace Mezzio\Authentication\OAuth2; +namespace MezzioTest\Authentication\OAuth2; use League\OAuth2\Server\AuthorizationServer; use League\OAuth2\Server\RequestTypes\AuthorizationRequest; +use Mezzio\Authentication\OAuth2\AuthorizationHandler; use PHPUnit\Framework\TestCase; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use stdClass; @@ -19,46 +18,48 @@ */ class AuthorizationHandlerTest extends TestCase { - use ProphecyTrait; - public function testHandleUsesAuthorizationServerService(): void { - $server = $this->prophesize(AuthorizationServer::class); + $server = $this->createMock(AuthorizationServer::class); $response = $this->createMock(ResponseInterface::class); - $authRequest = $this->prophesize(AuthorizationRequest::class); - $request = $this->prophesize(ServerRequestInterface::class); + $authRequest = $this->createMock(AuthorizationRequest::class); + $request = $this->createMock(ServerRequestInterface::class); $expectedResponse = $response; $response ->method('withStatus') ->willReturnSelf(); - $request->getAttribute(AuthorizationRequest::class) - ->willReturn($authRequest->reveal()); + $request->method('getAttribute') + ->with(AuthorizationRequest::class) + ->willReturn($authRequest); - $server->completeAuthorizationRequest($authRequest->reveal(), $expectedResponse) - ->shouldBeCalled() + $server->expects(self::once()) + ->method('completeAuthorizationRequest') + ->with($authRequest, $expectedResponse) ->willReturn($expectedResponse); - $subject = new AuthorizationHandler($server->reveal(), static fn(): ResponseInterface => $expectedResponse); + $subject = new AuthorizationHandler($server, static fn(): ResponseInterface => $expectedResponse); - self::assertSame($expectedResponse, $subject->handle($request->reveal())); + self::assertSame($expectedResponse, $subject->handle($request)); } - public function testInvalidResponseFactoryThrowsTypeError() + public function testInvalidResponseFactoryThrowsTypeError(): void { - $server = $this->prophesize(AuthorizationServer::class); - $authRequest = $this->prophesize(AuthorizationRequest::class); - $request = $this->prophesize(ServerRequestInterface::class); + $server = $this->createMock(AuthorizationServer::class); + $authRequest = $this->createMock(AuthorizationRequest::class); + $request = $this->createMock(ServerRequestInterface::class); - $request->getAttribute(AuthorizationRequest::class) - ->willReturn($authRequest->reveal()); + $request->method('getAttribute') + ->with(AuthorizationRequest::class) + ->willReturn($authRequest); - $server->completeAuthorizationRequest(Argument::any()) - ->shouldNotBeCalled(); + $server->expects(self::never()) + ->method('completeAuthorizationRequest'); - $subject = new AuthorizationHandler($server->reveal(), static fn(): stdClass => new stdClass()); + /** @psalm-suppress InvalidArgument */ + $subject = new AuthorizationHandler($server, static fn(): stdClass => new stdClass()); $this->expectException(TypeError::class); - $subject->handle($request->reveal()); + $subject->handle($request); } } diff --git a/test/AuthorizationMiddlewareFactoryTest.php b/test/AuthorizationMiddlewareFactoryTest.php index 7c7240d6..f8d132d2 100644 --- a/test/AuthorizationMiddlewareFactoryTest.php +++ b/test/AuthorizationMiddlewareFactoryTest.php @@ -8,8 +8,6 @@ use Mezzio\Authentication\OAuth2\AuthorizationMiddlewareFactory; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Psr\Container\ContainerInterface; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface; @@ -21,90 +19,86 @@ */ class AuthorizationMiddlewareFactoryTest extends TestCase { - use ProphecyTrait; + /** @var AuthorizationServer&MockObject */ + private AuthorizationServer $authServer; - /** @var AuthorizationServer|ObjectProphecy */ - private $authServer; - - /** @var ContainerInterface|ObjectProphecy */ - private $container; + /** @var ContainerInterface&MockObject */ + private ContainerInterface $container; /** @var ResponseInterface&MockObject */ - private $response; + private ResponseInterface $response; protected function setUp(): void { - $this->container = $this->prophesize(ContainerInterface::class); - $this->authServer = $this->prophesize(AuthorizationServer::class); + $this->container = $this->createMock(ContainerInterface::class); + $this->authServer = $this->createMock(AuthorizationServer::class); $this->response = $this->createMock(ResponseInterface::class); - $this->container - ->has(ResponseFactoryInterface::class) + $this->container->method('has') + ->with(ResponseFactoryInterface::class) ->willReturn(false); } - public function testConstructor() + public function testConstructor(): void { $factory = new AuthorizationMiddlewareFactory(); - $this->assertInstanceOf(AuthorizationMiddlewareFactory::class, $factory); + self::assertInstanceOf(AuthorizationMiddlewareFactory::class, $factory); } - public function testRaisesTypeErrorForInvalidAuthorizationServer() + public function testRaisesTypeErrorForInvalidAuthorizationServer(): void { - $this->container - ->get(AuthorizationServer::class) - ->willReturn(new stdClass()); - $this->container - ->get(ResponseInterface::class) - ->willReturn(static function (): void { - }); + $this->container->expects(self::exactly(2)) + ->method('get') + ->willReturnMap([ + [AuthorizationServer::class, new stdClass()], + [ResponseInterface::class, fn () => null], + ]); $factory = new AuthorizationMiddlewareFactory(); $this->expectException(TypeError::class); - $factory($this->container->reveal()); + $factory($this->container); } - public function testFactoryRaisesTypeErrorForNonCallableResponseFactory() + public function testFactoryRaisesTypeErrorForNonCallableResponseFactory(): void { - $this->container - ->get(AuthorizationServer::class) - ->willReturn($this->authServer->reveal()); - $this->container - ->get(ResponseInterface::class) - ->willReturn(new stdClass()); + $this->container->expects(self::exactly(2)) + ->method('get') + ->willReturnMap([ + [AuthorizationServer::class, $this->authServer], + [ResponseInterface::class, new stdClass()], + ]); $factory = new AuthorizationMiddlewareFactory(); $this->expectException(TypeError::class); - $factory($this->container->reveal()); + $factory($this->container); } - public function testFactoryRaisesTypeErrorWhenResponseServiceProvidesResponseInstance() + public function testFactoryRaisesTypeErrorWhenResponseServiceProvidesResponseInstance(): void { - $this->container - ->get(AuthorizationServer::class) - ->willReturn($this->authServer->reveal()); - $this->container - ->get(ResponseInterface::class) - ->willReturn($this->response); + $this->container->expects(self::exactly(2)) + ->method('get') + ->willReturnMap([ + [AuthorizationServer::class, $this->authServer], + [ResponseInterface::class, $this->response], + ]); $factory = new AuthorizationMiddlewareFactory(); $this->expectException(TypeError::class); - $factory($this->container->reveal()); + $factory($this->container); } - public function testFactoryReturnsInstanceWhenAppropriateDependenciesArePresentInContainer() + public function testFactoryReturnsInstanceWhenAppropriateDependenciesArePresentInContainer(): void { - $this->container - ->get(AuthorizationServer::class) - ->willReturn($this->authServer->reveal()); - $this->container - ->get(ResponseInterface::class) - ->willReturn(fn(): MockObject => $this->response) - ->shouldBeCalled(); + $this->container->expects(self::exactly(2)) + ->method('get') + ->willReturnMap([ + [AuthorizationServer::class, $this->authServer], + [ResponseInterface::class, fn (): ResponseInterface => $this->response], + ]); $factory = new AuthorizationMiddlewareFactory(); - $factory($this->container->reveal()); + $factory($this->container); } } diff --git a/test/AuthorizationMiddlewareTest.php b/test/AuthorizationMiddlewareTest.php index 25421cd0..36219a71 100644 --- a/test/AuthorizationMiddlewareTest.php +++ b/test/AuthorizationMiddlewareTest.php @@ -10,9 +10,6 @@ use Mezzio\Authentication\OAuth2\AuthorizationMiddleware; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\StreamInterface; @@ -22,101 +19,103 @@ class AuthorizationMiddlewareTest extends TestCase { - use ProphecyTrait; + /** @var AuthorizationRequest&MockObject */ + private AuthorizationRequest $authRequest; - /** @var AuthorizationRequest&ObjectProphecy */ - private $authRequest; + /** @var AuthorizationServer&MockObject */ + private AuthorizationServer $authServer; - /** @var AuthorizationServer&ObjectProphecy */ - private $authServer; - - /** @var RequestHandlerInterface&ObjectProphecy */ - private $handler; + /** @var RequestHandlerInterface&MockObject */ + private RequestHandlerInterface $handler; /** @var ResponseInterface&MockObject */ - private $response; + private ResponseInterface $response; - /** @var callable */ + /** @var callable(): ResponseInterface */ private $responseFactory; - /** @var ServerRequestInterface&ObjectProphecy */ - private $serverRequest; + /** @var ServerRequestInterface&MockObject */ + private ServerRequestInterface $serverRequest; protected function setUp(): void { - $this->authServer = $this->prophesize(AuthorizationServer::class); + $this->authServer = $this->createMock(AuthorizationServer::class); $this->response = $this->createMock(ResponseInterface::class); - $this->serverRequest = $this->prophesize(ServerRequestInterface::class); - $this->authRequest = $this->prophesize(AuthorizationRequest::class); - $this->handler = $this->prophesize(RequestHandlerInterface::class); - $this->responseFactory = fn(): MockObject => $this->response; + $this->serverRequest = $this->createMock(ServerRequestInterface::class); + $this->authRequest = $this->createMock(AuthorizationRequest::class); + $this->handler = $this->createMock(RequestHandlerInterface::class); + $this->responseFactory = fn(): ResponseInterface => $this->response; } - public function testConstructor() + public function testConstructor(): void { $middleware = new AuthorizationMiddleware( - $this->authServer->reveal(), + $this->authServer, $this->responseFactory ); - $this->assertInstanceOf(AuthorizationMiddleware::class, $middleware); - $this->assertInstanceOf(MiddlewareInterface::class, $middleware); + self::assertInstanceOf(AuthorizationMiddleware::class, $middleware); + self::assertInstanceOf(MiddlewareInterface::class, $middleware); } - public function testProcess() + public function testProcess(): void { - $this->authRequest - ->setUser(Argument::any()) - ->shouldNotBeCalled(); // Ths middleware must not provide a user entity - $this->authRequest - ->setAuthorizationApproved(false) // Expect approval to be set to false only - ->willReturn(null); + $this->authRequest->expects(self::never()) + ->method('setUser'); // Ths middleware must not provide a user entity + + $this->authRequest->expects(self::once()) + ->method('setAuthorizationApproved') + ->with(false); // Expect approval to be set to false only // Mock a valid authorization request - $this->authServer - ->validateAuthorizationRequest($this->serverRequest->reveal()) - ->willReturn($this->authRequest->reveal()); + $this->authServer->expects(self::once()) + ->method('validateAuthorizationRequest') + ->with($this->serverRequest) + ->willReturn($this->authRequest); // Mock a instance immutability when the authorization request // is populated - $newRequest = $this->prophesize(ServerRequestInterface::class); - $this->serverRequest - ->withAttribute(AuthorizationRequest::class, $this->authRequest->reveal()) - ->willReturn($newRequest->reveal()); + $newRequest = $this->createMock(ServerRequestInterface::class); + $this->serverRequest->expects(self::once()) + ->method('withAttribute') + ->with(AuthorizationRequest::class, $this->authRequest) + ->willReturn($newRequest); // Expect the handler to be called with the new modified request, // that contains the auth request attribute $handlerResponse = $this->createMock(ResponseInterface::class); - $this->handler - ->handle($newRequest->reveal()) + $this->handler->expects(self::once()) + ->method('handle') + ->with($newRequest) ->willReturn($handlerResponse); $middleware = new AuthorizationMiddleware( - $this->authServer->reveal(), + $this->authServer, $this->responseFactory ); $response = $middleware->process( - $this->serverRequest->reveal(), - $this->handler->reveal() + $this->serverRequest, + $this->handler ); - $this->assertSame($handlerResponse, $response); + self::assertSame($handlerResponse, $response); } - public function testAuthorizationRequestRaisingOAuthServerExceptionGeneratesResponseFromException() + public function testAuthorizationRequestRaisingOAuthServerExceptionGeneratesResponseFromException(): void { $oauthServerException = $this->createMock(OAuthServerException::class); - $oauthServerException + $oauthServerException->expects(self::once()) ->method('generateHttpResponse') ->with($this->response) ->willReturnArgument(0); - $this->authServer - ->validateAuthorizationRequest($this->serverRequest->reveal()) - ->willThrow($oauthServerException); + $this->authServer->expects(self::once()) + ->method('validateAuthorizationRequest') + ->with($this->serverRequest) + ->willThrowException($oauthServerException); $middleware = new AuthorizationMiddleware( - $this->authServer->reveal(), + $this->authServer, $this->responseFactory ); @@ -125,24 +124,24 @@ public function testAuthorizationRequestRaisingOAuthServerExceptionGeneratesResp ->willReturnSelf(); $result = $middleware->process( - $this->serverRequest->reveal(), - $this->handler->reveal() + $this->serverRequest, + $this->handler ); - $this->assertSame($this->response, $result); + self::assertSame($this->response, $result); } - public function testAuthorizationRequestRaisingUnknownExceptionGeneratesResponseFromException() + public function testAuthorizationRequestRaisingUnknownExceptionGeneratesResponseFromException(): void { - $body = $this->prophesize(StreamInterface::class); - $body - ->write(Argument::containingString('oauth2 server error')) - ->shouldBeCalled(); + $body = $this->createMock(StreamInterface::class); + $body->expects(self::once()) + ->method('write') + ->with(self::stringContains('oauth2 server error')); $this->response ->expects(self::once()) ->method('getBody') - ->willReturn($body->reveal()); + ->willReturn($body); $this->response ->expects(self::once()) ->method('withHeader') @@ -156,20 +155,21 @@ public function testAuthorizationRequestRaisingUnknownExceptionGeneratesResponse $exception = new RuntimeException('oauth2 server error'); - $this->authServer - ->validateAuthorizationRequest($this->serverRequest->reveal()) - ->willThrow($exception); + $this->authServer->expects(self::once()) + ->method('validateAuthorizationRequest') + ->with($this->serverRequest) + ->willThrowException($exception); $middleware = new AuthorizationMiddleware( - $this->authServer->reveal(), + $this->authServer, $this->responseFactory ); $response = $middleware->process( - $this->serverRequest->reveal(), - $this->handler->reveal() + $this->serverRequest, + $this->handler ); - $this->assertSame($this->response, $response); + self::assertSame($this->response, $response); } } diff --git a/test/AuthorizationServerFactoryTest.php b/test/AuthorizationServerFactoryTest.php index 47beac93..5c65c212 100644 --- a/test/AuthorizationServerFactoryTest.php +++ b/test/AuthorizationServerFactoryTest.php @@ -16,22 +16,17 @@ use Mezzio\Authentication\OAuth2\AuthorizationServerFactory; use Mezzio\Authentication\OAuth2\Exception\InvalidConfigException; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; -use Psr\Container\ContainerInterface; class AuthorizationServerFactoryTest extends TestCase { - use ProphecyTrait; - - public function testInvoke() + public function testInvoke(): void { - $mockContainer = $this->prophesize(ContainerInterface::class); - $mockClientRepo = $this->prophesize(ClientRepositoryInterface::class); - $mockAccessTokenRepo = $this->prophesize(AccessTokenRepositoryInterface::class); - $mockScopeRepo = $this->prophesize(ScopeRepositoryInterface::class); - $mockClientGrant = $this->prophesize(ClientCredentialsGrant::class); - $mockPasswordGrant = $this->prophesize(PasswordGrant::class); + $container = new InMemoryContainer(); + $mockClientRepo = $this->createMock(ClientRepositoryInterface::class); + $mockAccessTokenRepo = $this->createMock(AccessTokenRepositoryInterface::class); + $mockScopeRepo = $this->createMock(ScopeRepositoryInterface::class); + $mockClientGrant = $this->createMock(ClientCredentialsGrant::class); + $mockPasswordGrant = $this->createMock(PasswordGrant::class); $config = [ 'authentication' => [ @@ -45,47 +40,39 @@ public function testInvoke() ], ]; - $mockContainer->has(ClientRepositoryInterface::class)->willReturn(true); - $mockContainer->has(AccessTokenRepositoryInterface::class)->willReturn(true); - $mockContainer->has(ScopeRepositoryInterface::class)->willReturn(true); - - $mockContainer->get(ClientRepositoryInterface::class)->willReturn($mockClientRepo->reveal()); - $mockContainer->get(AccessTokenRepositoryInterface::class)->willReturn($mockAccessTokenRepo->reveal()); - $mockContainer->get(ScopeRepositoryInterface::class)->willReturn($mockScopeRepo->reveal()); - $mockContainer->get(ClientCredentialsGrant::class)->willReturn($mockClientGrant->reveal()); - $mockContainer->get(PasswordGrant::class)->willReturn($mockPasswordGrant->reveal()); - $mockContainer->get('config')->willReturn($config); + $container->set(ClientRepositoryInterface::class, $mockClientRepo); + $container->set(AccessTokenRepositoryInterface::class, $mockAccessTokenRepo); + $container->set(ScopeRepositoryInterface::class, $mockScopeRepo); + $container->set(ClientCredentialsGrant::class, $mockClientGrant); + $container->set(PasswordGrant::class, $mockPasswordGrant); + $container->set('config', $config); $factory = new AuthorizationServerFactory(); - $result = $factory($mockContainer->reveal()); + $result = $factory($container); - $this->assertInstanceOf(AuthorizationServer::class, $result); + self::assertInstanceOf(AuthorizationServer::class, $result); } - private function getContainerMock(): ObjectProphecy + private function getContainerMock(): InMemoryContainer { - $mockContainer = $this->prophesize(ContainerInterface::class); - $mockClientRepo = $this->prophesize(ClientRepositoryInterface::class); - $mockAccessTokenRepo = $this->prophesize(AccessTokenRepositoryInterface::class); - $mockScopeRepo = $this->prophesize(ScopeRepositoryInterface::class); - $mockClientGrant = $this->prophesize(ClientCredentialsGrant::class); - $mockPasswordGrant = $this->prophesize(PasswordGrant::class); - - $mockContainer->has(ClientRepositoryInterface::class)->willReturn(true); - $mockContainer->has(AccessTokenRepositoryInterface::class)->willReturn(true); - $mockContainer->has(ScopeRepositoryInterface::class)->willReturn(true); - - $mockContainer->get(ClientRepositoryInterface::class)->willReturn($mockClientRepo->reveal()); - $mockContainer->get(AccessTokenRepositoryInterface::class)->willReturn($mockAccessTokenRepo->reveal()); - $mockContainer->get(ScopeRepositoryInterface::class)->willReturn($mockScopeRepo->reveal()); - $mockContainer->get(ClientCredentialsGrant::class)->willReturn($mockClientGrant->reveal()); - $mockContainer->get(PasswordGrant::class)->willReturn($mockPasswordGrant->reveal()); - - return $mockContainer; + $container = new InMemoryContainer(); + $mockClientRepo = $this->createMock(ClientRepositoryInterface::class); + $mockAccessTokenRepo = $this->createMock(AccessTokenRepositoryInterface::class); + $mockScopeRepo = $this->createMock(ScopeRepositoryInterface::class); + $mockClientGrant = $this->createMock(ClientCredentialsGrant::class); + $mockPasswordGrant = $this->createMock(PasswordGrant::class); + + $container->set(ClientRepositoryInterface::class, $mockClientRepo); + $container->set(AccessTokenRepositoryInterface::class, $mockAccessTokenRepo); + $container->set(ScopeRepositoryInterface::class, $mockScopeRepo); + $container->set(ClientCredentialsGrant::class, $mockClientGrant); + $container->set(PasswordGrant::class, $mockPasswordGrant); + + return $container; } - public function testInvokeWithNullGrant() + public function testInvokeWithNullGrant(): void { $mockContainer = $this->getContainerMock(); @@ -101,21 +88,20 @@ public function testInvokeWithNullGrant() ], ]; - $mockContainer->get('config')->willReturn($config); + $mockContainer->set('config', $config); $factory = new AuthorizationServerFactory(); - $result = $factory($mockContainer->reveal()); + $result = $factory($mockContainer); - $this->assertInstanceOf(AuthorizationServer::class, $result); + self::assertInstanceOf(AuthorizationServer::class, $result); } - public function testInvokeWithListenerConfig() + public function testInvokeWithListenerConfig(): void { $mockContainer = $this->getContainerMock(); - $mockListener = $this->prophesize(ListenerInterface::class); - $mockContainer->has(ListenerInterface::class)->willReturn(true); - $mockContainer->get(ListenerInterface::class)->willReturn($mockListener->reveal()); + $mockListener = $this->createMock(ListenerInterface::class); + $mockContainer->set(ListenerInterface::class, $mockListener); $config = [ 'authentication' => [ @@ -140,20 +126,18 @@ static function (RequestEvent $event): void { ], ]; - $mockContainer->get('config')->willReturn($config); + $mockContainer->set('config', $config); $factory = new AuthorizationServerFactory(); - $result = $factory($mockContainer->reveal()); + $result = $factory($mockContainer); - $this->assertInstanceOf(AuthorizationServer::class, $result); + self::assertInstanceOf(AuthorizationServer::class, $result); } - public function testInvokeWithListenerConfigMissingServiceThrowsException() + public function testInvokeWithListenerConfigMissingServiceThrowsException(): void { $mockContainer = $this->getContainerMock(); - $mockListener = $this->prophesize(ListenerInterface::class); - $mockContainer->has(ListenerInterface::class)->willReturn(false); $config = [ 'authentication' => [ @@ -172,21 +156,20 @@ public function testInvokeWithListenerConfigMissingServiceThrowsException() ], ]; - $mockContainer->get('config')->willReturn($config); + $mockContainer->set('config', $config); $factory = new AuthorizationServerFactory(); $this->expectException(InvalidConfigException::class); - $result = $factory($mockContainer->reveal()); + $factory($mockContainer); } - public function testInvokeWithListenerProviderConfig() + public function testInvokeWithListenerProviderConfig(): void { $mockContainer = $this->getContainerMock(); - $mockProvider = $this->prophesize(ListenerProviderInterface::class); - $mockContainer->has(ListenerProviderInterface::class)->willReturn(true); - $mockContainer->get(ListenerProviderInterface::class)->willReturn($mockProvider->reveal()); + $mockProvider = $this->createMock(ListenerProviderInterface::class); + $mockContainer->set(ListenerProviderInterface::class, $mockProvider); $config = [ 'authentication' => [ @@ -202,20 +185,18 @@ public function testInvokeWithListenerProviderConfig() ], ]; - $mockContainer->get('config')->willReturn($config); + $mockContainer->set('config', $config); $factory = new AuthorizationServerFactory(); - $result = $factory($mockContainer->reveal()); + $result = $factory($mockContainer); - $this->assertInstanceOf(AuthorizationServer::class, $result); + self::assertInstanceOf(AuthorizationServer::class, $result); } - public function testInvokeWithListenerProviderConfigMissingServiceThrowsException() + public function testInvokeWithListenerProviderConfigMissingServiceThrowsException(): void { $mockContainer = $this->getContainerMock(); - $mockProvider = $this->prophesize(ListenerProviderInterface::class); - $mockContainer->has(ListenerProviderInterface::class)->willReturn(false); $config = [ 'authentication' => [ @@ -231,11 +212,11 @@ public function testInvokeWithListenerProviderConfigMissingServiceThrowsExceptio ], ]; - $mockContainer->get('config')->willReturn($config); + $mockContainer->set('config', $config); $factory = new AuthorizationServerFactory(); $this->expectException(InvalidConfigException::class); - $factory($mockContainer->reveal()); + $factory($mockContainer); } } diff --git a/test/ConfigTraitTest.php b/test/ConfigTraitTest.php index 6de9b6c9..4f4256b2 100644 --- a/test/ConfigTraitTest.php +++ b/test/ConfigTraitTest.php @@ -6,17 +6,21 @@ use Mezzio\Authentication\OAuth2\ConfigTrait; use Mezzio\Authentication\OAuth2\Exception; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; use Psr\Container\ContainerInterface; class ConfigTraitTest extends TestCase { - use ProphecyTrait; + private object $trait; + /** @var array{authentication: array} */ + private array $config; + /** @var ContainerInterface&MockObject */ + private ContainerInterface $container; protected function setUp(): void { - $this->trait = $trait = new class { + $this->trait = new class { use ConfigTrait; /** @@ -37,29 +41,33 @@ public function proxy(string $name, ContainerInterface $container) 'grants' => ['xxx'], ], ]; - $this->container = $this->prophesize(ContainerInterface::class); - $this->container - ->get('config') - ->willReturn($this->config); + $this->container = $this->createMock(ContainerInterface::class); } - public function testGetPrivateKeyWhenNoConfigPresentWillResultInAnException() + private function containerHasConfig(array $config): void { - $this->container - ->get('config') - ->willReturn([]); + $this->container->expects(self::once()) + ->method('get') + ->with('config') + ->willReturn($config); + } + + public function testGetPrivateKeyWhenNoConfigPresentWillResultInAnException(): void + { + $this->containerHasConfig([]); $this->expectException(Exception\InvalidConfigException::class); - $this->trait->proxy('getPrivateKey', $this->container->reveal()); + $this->trait->proxy('getPrivateKey', $this->container); } - public function testGetPrivateKey() + public function testGetPrivateKey(): void { - $result = $this->trait->proxy('getPrivateKey', $this->container->reveal()); - $this->assertEquals($this->config['authentication']['private_key'], $result); + $this->containerHasConfig($this->config); + $result = $this->trait->proxy('getPrivateKey', $this->container); + self::assertEquals($this->config['authentication']['private_key'], $result); } - public function testGetPrivateKeyArray() + public function testGetPrivateKeyArray(): void { $config = [ 'authentication' => [ @@ -71,181 +79,165 @@ public function testGetPrivateKeyArray() ], ]; - $this->container - ->get('config') - ->willReturn($config); + $this->containerHasConfig($config); - $result = $this->trait->proxy('getPrivateKey', $this->container->reveal()); - $this->assertEquals($config['authentication']['private_key'], $result); + $result = $this->trait->proxy('getPrivateKey', $this->container); + self::assertEquals($config['authentication']['private_key'], $result); } - public function testGetEncryptionKeyNoConfig() + public function testGetEncryptionKeyNoConfig(): void { - $this->container - ->get('config') - ->willReturn([]); + $this->containerHasConfig([]); $this->expectException(Exception\InvalidConfigException::class); - $this->trait->proxy('getEncryptionKey', $this->container->reveal()); + $this->trait->proxy('getEncryptionKey', $this->container); } - public function testGetEncryptionKey() + public function testGetEncryptionKey(): void { - $result = $this->trait->proxy('getEncryptionKey', $this->container->reveal()); - $this->assertEquals($this->config['authentication']['encryption_key'], $result); + $this->containerHasConfig($this->config); + $result = $this->trait->proxy('getEncryptionKey', $this->container); + self::assertEquals($this->config['authentication']['encryption_key'], $result); } - public function testGetAccessTokenExpireNoConfig() + public function testGetAccessTokenExpireNoConfig(): void { - $this->container - ->get('config') - ->willReturn([]); + $this->containerHasConfig([]); $this->expectException(Exception\InvalidConfigException::class); - $this->trait->proxy('getAccessTokenExpire', $this->container->reveal()); + $this->trait->proxy('getAccessTokenExpire', $this->container); } - public function testGetAccessTokenExpire() + public function testGetAccessTokenExpire(): void { - $result = $this->trait->proxy('getAccessTokenExpire', $this->container->reveal()); - $this->assertEquals($this->config['authentication']['access_token_expire'], $result); + $this->containerHasConfig($this->config); + + $result = $this->trait->proxy('getAccessTokenExpire', $this->container); + self::assertEquals($this->config['authentication']['access_token_expire'], $result); } - public function testGetRefreshTokenExpireNoConfig() + public function testGetRefreshTokenExpireNoConfig(): void { - $this->container - ->get('config') - ->willReturn([]); + $this->containerHasConfig([]); $this->expectException(Exception\InvalidConfigException::class); - $this->trait->proxy('getRefreshTokenExpire', $this->container->reveal()); + $this->trait->proxy('getRefreshTokenExpire', $this->container); } - public function testGetRefreshTokenExpire() + public function testGetRefreshTokenExpire(): void { - $result = $this->trait->proxy('getRefreshTokenExpire', $this->container->reveal()); - $this->assertEquals($this->config['authentication']['refresh_token_expire'], $result); + $this->containerHasConfig($this->config); + + $result = $this->trait->proxy('getRefreshTokenExpire', $this->container); + self::assertEquals($this->config['authentication']['refresh_token_expire'], $result); } - public function testGetAuthCodeExpireNoConfig() + public function testGetAuthCodeExpireNoConfig(): void { - $this->container - ->get('config') - ->willReturn([]); + $this->containerHasConfig([]); $this->expectException(Exception\InvalidConfigException::class); - $this->trait->proxy('getAuthCodeExpire', $this->container->reveal()); + $this->trait->proxy('getAuthCodeExpire', $this->container); } - public function testGetAuthCodeExpire() + public function testGetAuthCodeExpire(): void { - $result = $this->trait->proxy('getAuthCodeExpire', $this->container->reveal()); - $this->assertEquals($this->config['authentication']['auth_code_expire'], $result); + $this->containerHasConfig($this->config); + + $result = $this->trait->proxy('getAuthCodeExpire', $this->container); + self::assertEquals($this->config['authentication']['auth_code_expire'], $result); } - public function testGetGrantsConfigNoConfig() + public function testGetGrantsConfigNoConfig(): void { - $this->container - ->get('config') - ->willReturn([]); + $this->containerHasConfig([]); $this->expectException(Exception\InvalidConfigException::class); - $this->trait->proxy('getGrantsConfig', $this->container->reveal()); + $this->trait->proxy('getGrantsConfig', $this->container); } - public function testGetGrantsConfigNoArrayValue() + public function testGetGrantsConfigNoArrayValue(): void { - $this->container - ->get('config') - ->willReturn([ - 'authentication' => [ - 'grants' => 'xxx', - ], - ]); + $this->containerHasConfig([ + 'authentication' => [ + 'grants' => 'xxx', + ], + ]); $this->expectException(Exception\InvalidConfigException::class); - $this->trait->proxy('getGrantsConfig', $this->container->reveal()); + $this->trait->proxy('getGrantsConfig', $this->container); } - public function testGetGrantsConfig() + public function testGetGrantsConfig(): void { - $result = $this->trait->proxy('getGrantsConfig', $this->container->reveal()); - $this->assertEquals($this->config['authentication']['grants'], $result); + $this->containerHasConfig($this->config); + + $result = $this->trait->proxy('getGrantsConfig', $this->container); + self::assertEquals($this->config['authentication']['grants'], $result); } - public function testGetListenersConfigNoConfig() + public function testGetListenersConfigNoConfig(): void { - $this->container - ->get('config') - ->willReturn([]); + $this->containerHasConfig([]); + $result = $this->trait - ->proxy('getListenersConfig', $this->container->reveal()); - $this->assertIsArray($result); + ->proxy('getListenersConfig', $this->container); + self::assertIsArray($result); } - public function testGetListenersConfigNoArrayValue() + public function testGetListenersConfigNoArrayValue(): void { $this->expectException(Exception\InvalidConfigException::class); - $this->container - ->get('config') - ->willReturn([ - 'authentication' => [ - 'event_listeners' => 'xxx', - ], - ]); + $this->containerHasConfig([ + 'authentication' => [ + 'event_listeners' => 'xxx', + ], + ]); - $this->trait->proxy('getListenersConfig', $this->container->reveal()); + $this->trait->proxy('getListenersConfig', $this->container); } - public function testGetListenersConfig() + public function testGetListenersConfig(): void { - $this->container->get('config') - ->willReturn([ - 'authentication' => [ - 'event_listeners' => $expected = [['xxx']], - ], - ]); - $result = $this->trait - ->proxy('getListenersConfig', $this->container->reveal()); - $this->assertEquals($expected, $result); + $this->containerHasConfig([ + 'authentication' => [ + 'event_listeners' => $expected = [['xxx']], + ], + ]); + $result = $this->trait->proxy('getListenersConfig', $this->container); + self::assertEquals($expected, $result); } - public function testGetListenerProvidersConfigNoConfig() + public function testGetListenerProvidersConfigNoConfig(): void { - $this->container - ->get('config') - ->willReturn([]); - $result = $this->trait - ->proxy('getListenerProvidersConfig', $this->container->reveal()); - $this->assertIsArray($result); + $this->containerHasConfig([]); + + $result = $this->trait->proxy('getListenerProvidersConfig', $this->container); + self::assertIsArray($result); } - public function testGetListenerProvidersConfigNoArrayValue() + public function testGetListenerProvidersConfigNoArrayValue(): void { $this->expectException(Exception\InvalidConfigException::class); - $this->container - ->get('config') - ->willReturn([ - 'authentication' => [ - 'event_listener_providers' => 'xxx', - ], - ]); + $this->containerHasConfig([ + 'authentication' => [ + 'event_listener_providers' => 'xxx', + ], + ]); - $this->trait->proxy('getListenerProvidersConfig', $this->container->reveal()); + $this->trait->proxy('getListenerProvidersConfig', $this->container); } - public function testGetListenerProvidersConfig() + public function testGetListenerProvidersConfig(): void { - $this->container->get('config') - ->willReturn([ - 'authentication' => [ - 'event_listener_providers' => $expected = ['xxx'], - ], - ]); - $result = $this->trait - ->proxy('getListenerProvidersConfig', $this->container->reveal()); - $this->assertEquals($expected, $result); + $this->containerHasConfig([ + 'authentication' => [ + 'event_listener_providers' => $expected = ['xxx'], + ], + ]); + $result = $this->trait->proxy('getListenerProvidersConfig', $this->container); + self::assertEquals($expected, $result); } } diff --git a/test/Entity/AccessTokenEntityTest.php b/test/Entity/AccessTokenEntityTest.php index a17d89f9..fc9e0fb6 100644 --- a/test/Entity/AccessTokenEntityTest.php +++ b/test/Entity/AccessTokenEntityTest.php @@ -10,7 +10,7 @@ class AccessTokenEntityTest extends TestCase { - public function testImplementsInstanceAccessTokenEntityInterface() + public function testImplementsInstanceAccessTokenEntityInterface(): void { $entity = new AccessTokenEntity(); $this->assertInstanceOf(AccessTokenEntityInterface::class, $entity); diff --git a/test/Entity/AuthCodeEntityTest.php b/test/Entity/AuthCodeEntityTest.php index 8a1cdc6b..40d2d66c 100644 --- a/test/Entity/AuthCodeEntityTest.php +++ b/test/Entity/AuthCodeEntityTest.php @@ -10,7 +10,7 @@ class AuthCodeEntityTest extends TestCase { - public function testImplementsInstanceAuthCodeEntityInterface() + public function testImplementsInstanceAuthCodeEntityInterface(): void { $entity = new AuthCodeEntity(); $this->assertInstanceOf(AuthCodeEntityInterface::class, $entity); diff --git a/test/Entity/ClientEntityTest.php b/test/Entity/ClientEntityTest.php index 0aef4b8a..7287f6a0 100644 --- a/test/Entity/ClientEntityTest.php +++ b/test/Entity/ClientEntityTest.php @@ -10,38 +10,40 @@ class ClientEntityTest extends TestCase { + private ClientEntity $entity; + protected function setUp(): void { $this->entity = new ClientEntity('foo', 'bar', 'http://localhost'); } - public function testImplementsAuthCodeEntityInterface() + public function testImplementsAuthCodeEntityInterface(): void { $this->assertInstanceOf(ClientEntityInterface::class, $this->entity); } - public function testConstructorSetsIdentifier() + public function testConstructorSetsIdentifier(): void { $this->assertSame('foo', $this->entity->getIdentifier()); } - public function testConstructorSetsName() + public function testConstructorSetsName(): void { $this->assertSame('bar', $this->entity->getName()); } - public function testConstructorSetsRedirectUri() + public function testConstructorSetsRedirectUri(): void { $this->assertSame(['http://localhost'], $this->entity->getRedirectUri()); } - public function testSecret() + public function testSecret(): void { $this->entity->setSecret('secret'); $this->assertEquals('secret', $this->entity->getSecret()); } - public function testPersonalAccessClient() + public function testPersonalAccessClient(): void { $this->entity->setPersonalAccessClient(true); $this->assertTrue($this->entity->hasPersonalAccessClient()); @@ -50,7 +52,7 @@ public function testPersonalAccessClient() $this->assertFalse($this->entity->hasPersonalAccessClient()); } - public function testPasswordClient() + public function testPasswordClient(): void { $this->entity->setPasswordClient(true); $this->assertTrue($this->entity->hasPasswordClient()); diff --git a/test/Entity/RefreshTokenEntityTest.php b/test/Entity/RefreshTokenEntityTest.php index 8465d138..598f2b3d 100644 --- a/test/Entity/RefreshTokenEntityTest.php +++ b/test/Entity/RefreshTokenEntityTest.php @@ -10,7 +10,7 @@ class RefreshTokenEntityTest extends TestCase { - public function testImplementsRefreshTokenEntityInterface() + public function testImplementsRefreshTokenEntityInterface(): void { $entity = new RefreshTokenEntity(); $this->assertInstanceOf(RefreshTokenEntityInterface::class, $entity); diff --git a/test/Entity/RevokableTraitStub.php b/test/Entity/RevokableTraitStub.php new file mode 100644 index 00000000..d4cb6f2d --- /dev/null +++ b/test/Entity/RevokableTraitStub.php @@ -0,0 +1,12 @@ +trait = $this->getMockForTrait(RevokableTrait::class); + $this->trait = new RevokableTraitStub(); } - public function testSetRevokedToTrue() + public function testSetRevokedToTrue(): void { $this->trait->setRevoked(true); $this->assertTrue($this->trait->isRevoked()); } - public function testSetRevokedToFalse() + public function testSetRevokedToFalse(): void { $this->trait->setRevoked(false); $this->assertFalse($this->trait->isRevoked()); diff --git a/test/Entity/ScopeEntityTest.php b/test/Entity/ScopeEntityTest.php index 65c99ea9..4974924b 100644 --- a/test/Entity/ScopeEntityTest.php +++ b/test/Entity/ScopeEntityTest.php @@ -12,17 +12,19 @@ class ScopeEntityTest extends TestCase { + private ScopeEntity $entity; + protected function setUp(): void { $this->entity = new ScopeEntity(); } - public function testImplementsScopeEntityInterface() + public function testImplementsScopeEntityInterface(): void { $this->assertInstanceOf(ScopeEntityInterface::class, $this->entity); } - public function testEntityIsJsonSerializable() + public function testEntityIsJsonSerializable(): void { $this->entity->setIdentifier('foo'); $this->assertEquals('"foo"', json_encode($this->entity)); diff --git a/test/Entity/TimestampableTraitStub.php b/test/Entity/TimestampableTraitStub.php new file mode 100644 index 00000000..8da13e29 --- /dev/null +++ b/test/Entity/TimestampableTraitStub.php @@ -0,0 +1,12 @@ +trait = $this->getMockForTrait(TimestampableTrait::class); + $this->trait = new TimestampableTraitStub(); } - public function testCreatedAt() + public function testCreatedAt(): void { $now = new DateTimeImmutable(); $this->trait->setCreatedAt($now); $this->assertEquals($now, $this->trait->getCreatedAt()); } - public function testUpdatedAt() + public function testUpdatedAt(): void { $now = new DateTimeImmutable(); $this->trait->setUpdatedAt($now); $this->assertEquals($now, $this->trait->getUpdatedAt()); } - public function testTimestampOnCreate() + public function testTimestampOnCreate(): void { $this->trait->timestampOnCreate(); $this->assertNotEmpty($this->trait->getCreatedAt()); diff --git a/test/Entity/UserEntityTest.php b/test/Entity/UserEntityTest.php index 53dc81d4..8e42cf36 100644 --- a/test/Entity/UserEntityTest.php +++ b/test/Entity/UserEntityTest.php @@ -18,18 +18,18 @@ protected function setUp(): void $this->entity = new UserEntity('foo'); } - public function testConstructorWithoutParamWillResultInAnException() + public function testConstructorWithoutParamWillResultInAnException(): void { $this->expectException(ArgumentCountError::class); $entity = new UserEntity(); } - public function testImplementsUserEntityInterface() + public function testImplementsUserEntityInterface(): void { $this->assertInstanceOf(UserEntityInterface::class, $this->entity); } - public function testGetIdentifier() + public function testGetIdentifier(): void { $this->assertEquals('foo', $this->entity->getIdentifier()); } diff --git a/test/Grant/AuthCodeGrantFactoryTest.php b/test/Grant/AuthCodeGrantFactoryTest.php index fb89daf1..236a997d 100644 --- a/test/Grant/AuthCodeGrantFactoryTest.php +++ b/test/Grant/AuthCodeGrantFactoryTest.php @@ -9,18 +9,15 @@ use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface; use Mezzio\Authentication\OAuth2\Grant\AuthCodeGrantFactory; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; use Psr\Container\ContainerInterface; class AuthCodeGrantFactoryTest extends TestCase { - use ProphecyTrait; - - public function testInvoke() + public function testInvoke(): void { - $mockContainer = $this->prophesize(ContainerInterface::class); - $mockAuthRepo = $this->prophesize(AuthCodeRepositoryInterface::class); - $mockRefreshTokenRepo = $this->prophesize(RefreshTokenRepositoryInterface::class); + $mockContainer = $this->createMock(ContainerInterface::class); + $mockAuthRepo = $this->createMock(AuthCodeRepositoryInterface::class); + $mockRefreshTokenRepo = $this->createMock(RefreshTokenRepositoryInterface::class); $config = [ 'authentication' => [ @@ -29,16 +26,25 @@ public function testInvoke() ], ]; - $mockContainer->has(AuthCodeRepositoryInterface::class)->willReturn(true); - $mockContainer->has(RefreshTokenRepositoryInterface::class)->willReturn(true); - $mockContainer->get('config')->willReturn($config); - $mockContainer->get(AuthCodeRepositoryInterface::class)->willReturn($mockAuthRepo->reveal()); - $mockContainer->get(RefreshTokenRepositoryInterface::class)->willReturn($mockRefreshTokenRepo->reveal()); + $mockContainer->expects(self::exactly(2)) + ->method('has') + ->willReturnMap([ + [AuthCodeRepositoryInterface::class, true], + [RefreshTokenRepositoryInterface::class, true], + ]); + + $mockContainer->expects(self::atLeast(3)) + ->method('get') + ->willReturnMap([ + ['config', $config], + [AuthCodeRepositoryInterface::class, $mockAuthRepo], + [RefreshTokenRepositoryInterface::class, $mockRefreshTokenRepo], + ]); $factory = new AuthCodeGrantFactory(); - $result = $factory($mockContainer->reveal()); + $result = $factory($mockContainer); - $this->assertInstanceOf(AuthCodeGrant::class, $result); + self::assertInstanceOf(AuthCodeGrant::class, $result); } } diff --git a/test/Grant/ClientCredentialsGrantFactoryTest.php b/test/Grant/ClientCredentialsGrantFactoryTest.php index d309cf9b..06603f89 100644 --- a/test/Grant/ClientCredentialsGrantFactoryTest.php +++ b/test/Grant/ClientCredentialsGrantFactoryTest.php @@ -7,21 +7,18 @@ use League\OAuth2\Server\Grant\ClientCredentialsGrant; use Mezzio\Authentication\OAuth2\Grant\ClientCredentialsGrantFactory; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; use Psr\Container\ContainerInterface; class ClientCredentialsGrantFactoryTest extends TestCase { - use ProphecyTrait; - - public function testInvoke() + public function testInvoke(): void { - $mockContainer = $this->prophesize(ContainerInterface::class); + $mockContainer = $this->createMock(ContainerInterface::class); $factory = new ClientCredentialsGrantFactory(); - $result = $factory($mockContainer->reveal()); + $result = $factory($mockContainer); - $this->assertInstanceOf(ClientCredentialsGrant::class, $result); + self::assertInstanceOf(ClientCredentialsGrant::class, $result); } } diff --git a/test/Grant/ImplicitGrantFactoryTest.php b/test/Grant/ImplicitGrantFactoryTest.php index 15a77e7e..93e90a36 100644 --- a/test/Grant/ImplicitGrantFactoryTest.php +++ b/test/Grant/ImplicitGrantFactoryTest.php @@ -7,16 +7,13 @@ use League\OAuth2\Server\Grant\ImplicitGrant; use Mezzio\Authentication\OAuth2\Grant\ImplicitGrantFactory; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; use Psr\Container\ContainerInterface; class ImplicitGrantFactoryTest extends TestCase { - use ProphecyTrait; - - public function testInvoke() + public function testInvoke(): void { - $mockContainer = $this->prophesize(ContainerInterface::class); + $mockContainer = $this->createMock(ContainerInterface::class); $config = [ 'authentication' => [ @@ -24,12 +21,15 @@ public function testInvoke() ], ]; - $mockContainer->get('config')->willReturn($config); + $mockContainer->expects(self::once()) + ->method('get') + ->with('config') + ->willReturn($config); $factory = new ImplicitGrantFactory(); - $result = $factory($mockContainer->reveal()); + $result = $factory($mockContainer); - $this->assertInstanceOf(ImplicitGrant::class, $result); + self::assertInstanceOf(ImplicitGrant::class, $result); } } diff --git a/test/Grant/PasswordGrantFactoryTest.php b/test/Grant/PasswordGrantFactoryTest.php index 78f7196b..0593abe6 100644 --- a/test/Grant/PasswordGrantFactoryTest.php +++ b/test/Grant/PasswordGrantFactoryTest.php @@ -9,18 +9,15 @@ use League\OAuth2\Server\Repositories\UserRepositoryInterface; use Mezzio\Authentication\OAuth2\Grant\PasswordGrantFactory; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; use Psr\Container\ContainerInterface; class PasswordGrantFactoryTest extends TestCase { - use ProphecyTrait; - - public function testInvoke() + public function testInvoke(): void { - $mockContainer = $this->prophesize(ContainerInterface::class); - $mockUserRepo = $this->prophesize(UserRepositoryInterface::class); - $mockRefreshTokenRepo = $this->prophesize(RefreshTokenRepositoryInterface::class); + $mockContainer = $this->createMock(ContainerInterface::class); + $mockUserRepo = $this->createMock(UserRepositoryInterface::class); + $mockRefreshTokenRepo = $this->createMock(RefreshTokenRepositoryInterface::class); $config = [ 'authentication' => [ @@ -28,16 +25,24 @@ public function testInvoke() ], ]; - $mockContainer->has(UserRepositoryInterface::class)->willReturn(true); - $mockContainer->has(RefreshTokenRepositoryInterface::class)->willReturn(true); - $mockContainer->get(UserRepositoryInterface::class)->willReturn($mockUserRepo->reveal()); - $mockContainer->get(RefreshTokenRepositoryInterface::class)->willReturn($mockRefreshTokenRepo->reveal()); - $mockContainer->get('config')->willReturn($config); + $mockContainer->expects(self::exactly(2)) + ->method('has') + ->willReturnMap([ + [UserRepositoryInterface::class, true], + [RefreshTokenRepositoryInterface::class, true], + ]); + $mockContainer->expects(self::exactly(3)) + ->method('get') + ->willReturnMap([ + [UserRepositoryInterface::class, $mockUserRepo], + [RefreshTokenRepositoryInterface::class, $mockRefreshTokenRepo], + ['config', $config], + ]); $factory = new PasswordGrantFactory(); - $result = $factory($mockContainer->reveal()); + $result = $factory($mockContainer); - $this->assertInstanceOf(PasswordGrant::class, $result); + self::assertInstanceOf(PasswordGrant::class, $result); } } diff --git a/test/Grant/RefreshTokenGrantFactoryTest.php b/test/Grant/RefreshTokenGrantFactoryTest.php index ba19177f..b5cae2b2 100644 --- a/test/Grant/RefreshTokenGrantFactoryTest.php +++ b/test/Grant/RefreshTokenGrantFactoryTest.php @@ -8,17 +8,14 @@ use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface; use Mezzio\Authentication\OAuth2\Grant\RefreshTokenGrantFactory; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; use Psr\Container\ContainerInterface; class RefreshTokenGrantFactoryTest extends TestCase { - use ProphecyTrait; - - public function testInvoke() + public function testInvoke(): void { - $mockContainer = $this->prophesize(ContainerInterface::class); - $mockRefreshTokenRepo = $this->prophesize(RefreshTokenRepositoryInterface::class); + $mockContainer = $this->createMock(ContainerInterface::class); + $mockRefreshTokenRepo = $this->createMock(RefreshTokenRepositoryInterface::class); $config = [ 'authentication' => [ @@ -26,14 +23,21 @@ public function testInvoke() ], ]; - $mockContainer->has(RefreshTokenRepositoryInterface::class)->willReturn(true); - $mockContainer->get(RefreshTokenRepositoryInterface::class)->willReturn($mockRefreshTokenRepo->reveal()); - $mockContainer->get('config')->willReturn($config); + $mockContainer->expects(self::once()) + ->method('has') + ->with(RefreshTokenRepositoryInterface::class) + ->willReturn(true); - $factory = new RefreshTokenGrantFactory(); + $mockContainer->expects(self::atLeast(2)) + ->method('get') + ->willReturnMap([ + [RefreshTokenRepositoryInterface::class, $mockRefreshTokenRepo], + ['config', $config], + ]); - $result = $factory($mockContainer->reveal()); + $factory = new RefreshTokenGrantFactory(); + $result = $factory($mockContainer); - $this->assertInstanceOf(RefreshTokenGrant::class, $result); + self::assertInstanceOf(RefreshTokenGrant::class, $result); } } diff --git a/test/OAuth2AdapterFactoryTest.php b/test/OAuth2AdapterFactoryTest.php index 280c3345..16dfac5b 100644 --- a/test/OAuth2AdapterFactoryTest.php +++ b/test/OAuth2AdapterFactoryTest.php @@ -12,137 +12,79 @@ use Mezzio\Authentication\UserInterface; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; -use Psr\Container\ContainerInterface; -use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface; use stdClass; use TypeError; class OAuth2AdapterFactoryTest extends TestCase { - use ProphecyTrait; + private InMemoryContainer $container; - /** @var ContainerInterface|ObjectProphecy */ - private $container; - - /** @var ResourceServer|ObjectProphecy */ - private $resourceServer; + /** @var ResourceServer&MockObject */ + private ResourceServer $resourceServer; /** @var ResponseInterface&MockObject */ - private $response; + private ResponseInterface $response; - /** @var callable */ + /** @var callable(): ResponseInterface */ private $responseFactory; - /** @var UserInterface|ObjectProphecy */ - private $user; + /** @var UserInterface&MockObject */ + private UserInterface $user; - /** @var Closure */ - private $userFactory; + /** @var Closure(): UserInterface */ + private Closure $userFactory; protected function setUp(): void { - $this->container = $this->prophesize(ContainerInterface::class); - $this->container - ->has(ResponseFactoryInterface::class) - ->willReturn(false); - - $this->resourceServer = $this->prophesize(ResourceServer::class); + $this->container = new InMemoryContainer(); + $this->resourceServer = $this->createMock(ResourceServer::class); $this->response = $this->createMock(ResponseInterface::class); $this->responseFactory = fn(): MockObject => $this->response; - $this->user = $this->prophesize(UserInterface::class); - $this->userFactory = fn(string $identity, array $roles = [], array $details = []) => $this->user->reveal(); - } - - public function testConstructor() - { - $factory = new OAuth2AdapterFactory(); - $this->assertInstanceOf(OAuth2AdapterFactory::class, $factory); + $this->user = $this->createMock(UserInterface::class); + $this->userFactory = fn(): UserInterface => $this->user; } - public function testInvokeWithEmptyContainer() + public function testInvokeWithEmptyContainer(): void { $factory = new OAuth2AdapterFactory(); - $this->container - ->has(ResourceServer::class) - ->willReturn(false); - $this->expectException(Exception\InvalidConfigException::class); - $factory($this->container->reveal()); + $factory($this->container); } - public function testFactoryRaisesTypeErrorForNonCallableResponseFactory() + public function testFactoryRaisesTypeErrorForNonCallableResponseFactory(): void { - $this->container - ->has(ResourceServer::class) - ->willReturn(true); - $this->container - ->get(ResourceServer::class) - ->willReturn($this->resourceServer->reveal()); - - $this->container - ->get(ResponseInterface::class) - ->willReturn(new stdClass()); - - $this->container - ->get(UserInterface::class) - ->willReturn($this->userFactory); + $this->container->set(ResourceServer::class, $this->resourceServer); + $this->container->set(ResponseInterface::class, new stdClass()); + $this->container->set(UserInterface::class, $this->userFactory); $factory = new OAuth2AdapterFactory(); - $this->expectException(TypeError::class); - $factory($this->container->reveal()); + $factory($this->container); } - public function testFactoryRaisesTypeErrorWhenResponseServiceProvidesResponseInstance() + public function testFactoryRaisesTypeErrorWhenResponseServiceProvidesResponseInstance(): void { - $this->container - ->has(ResourceServer::class) - ->willReturn(true); - $this->container - ->get(ResourceServer::class) - ->willReturn($this->resourceServer->reveal()); - - $this->container - ->get(ResponseInterface::class) - ->willReturn($this->response); - - $this->container - ->get(UserInterface::class) - ->willReturn($this->userFactory); + $this->container->set(ResourceServer::class, $this->resourceServer); + $this->container->set(ResponseInterface::class, $this->response); + $this->container->set(UserInterface::class, $this->userFactory); $factory = new OAuth2AdapterFactory(); $this->expectException(TypeError::class); - $factory($this->container->reveal()); + $factory($this->container); } - public function testFactoryReturnsInstanceWhenAppropriateDependenciesArePresentInContainer() + public function testFactoryReturnsInstanceWhenAppropriateDependenciesArePresentInContainer(): void { - $this->container - ->has(ResourceServer::class) - ->willReturn(true); - $this->container - ->get(ResourceServer::class) - ->willReturn($this->resourceServer->reveal()); - - $this->container - ->has(ResponseInterface::class) - ->willReturn(true); - $this->container - ->get(ResponseInterface::class) - ->willReturn($this->responseFactory); - - $this->container - ->get(UserInterface::class) - ->willReturn($this->userFactory); + $this->container->set(ResourceServer::class, $this->resourceServer); + $this->container->set(ResponseInterface::class, $this->responseFactory); + $this->container->set(UserInterface::class, $this->userFactory); $factory = new OAuth2AdapterFactory(); - $adapter = $factory($this->container->reveal()); + $adapter = $factory($this->container); - $this->assertInstanceOf(AuthenticationInterface::class, $adapter); + self::assertInstanceOf(AuthenticationInterface::class, $adapter); } } diff --git a/test/OAuth2AdapterTest.php b/test/OAuth2AdapterTest.php index bc468250..526b86e6 100644 --- a/test/OAuth2AdapterTest.php +++ b/test/OAuth2AdapterTest.php @@ -4,6 +4,7 @@ namespace MezzioTest\Authentication\OAuth2; +use Laminas\Diactoros\ServerRequest; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\ResourceServer; use Mezzio\Authentication\AuthenticationInterface; @@ -12,136 +13,123 @@ use Mezzio\Authentication\UserInterface; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; class OAuth2AdapterTest extends TestCase { - use ProphecyTrait; - - /** @var ResourceServer|ObjectProphecy */ - private $resourceServer; + /** @var ResourceServer&MockObject */ + private ResourceServer $resourceServer; /** @var ResponseInterface&MockObject */ - private $response; + private ResponseInterface $response; - /** @var callable */ + /** @var callable(): ResponseInterface */ private $responseFactory; - /** @var callable */ + /** @var callable(string, array, array): DefaultUser */ private $userFactory; protected function setUp(): void { - $this->resourceServer = $this->prophesize(ResourceServer::class); + $this->resourceServer = $this->createMock(ResourceServer::class); $this->response = $this->createMock(ResponseInterface::class); $this->responseFactory = fn(): ResponseInterface => $this->response; $this->userFactory = static fn(string $identity, array $roles = [], array $details = []): DefaultUser => new DefaultUser($identity, $roles, $details); } - public function testConstructor() + public function testConstructor(): void { $adapter = new OAuth2Adapter( - $this->resourceServer->reveal(), + $this->resourceServer, $this->responseFactory, $this->userFactory ); - $this->assertInstanceOf(OAuth2Adapter::class, $adapter); - $this->assertInstanceOf(AuthenticationInterface::class, $adapter); + self::assertInstanceOf(OAuth2Adapter::class, $adapter); + self::assertInstanceOf(AuthenticationInterface::class, $adapter); } - public function testOAuthServerExceptionRaisedDuringAuthenticateResultsInInvalidAuthentication() + public function testOAuthServerExceptionRaisedDuringAuthenticateResultsInInvalidAuthentication(): void { - $request = $this->prophesize(ServerRequestInterface::class); - - $exception = $this->prophesize(OAuthServerException::class); + $request = $this->createMock(ServerRequestInterface::class); + $exception = $this->createMock(OAuthServerException::class); - $this->resourceServer - ->validateAuthenticatedRequest(Argument::that([$request, 'reveal'])) - ->willThrow($exception->reveal()); + $this->resourceServer->expects(self::once()) + ->method('validateAuthenticatedRequest') + ->with($request) + ->willThrowException($exception); $adapter = new OAuth2Adapter( - $this->resourceServer->reveal(), + $this->resourceServer, $this->responseFactory, $this->userFactory ); - $this->assertNull($adapter->authenticate($request->reveal())); + self::assertNull($adapter->authenticate($request)); } - public function testAuthenticateReturnsNullIfResourceServerDoesNotProduceAUserIdOrClientId() + public function testAuthenticateReturnsNullIfResourceServerDoesNotProduceAUserIdOrClientId(): void { - $request = $this->prophesize(ServerRequestInterface::class); - $request->getAttribute('oauth_user_id', null)->willReturn(null); - $request->getAttribute('oauth_client_id', null)->willReturn(null); - - $this->resourceServer - ->validateAuthenticatedRequest(Argument::that([$request, 'reveal'])) - ->will([$request, 'reveal']); + $request = new ServerRequest(); + $this->resourceServer->expects(self::once()) + ->method('validateAuthenticatedRequest') + ->with($request) + ->willReturn($request); $adapter = new OAuth2Adapter( - $this->resourceServer->reveal(), + $this->resourceServer, $this->responseFactory, $this->userFactory ); - $this->assertNull($adapter->authenticate($request->reveal())); + self::assertNull($adapter->authenticate($request)); } - public function testAuthenticateReturnsAUserIfTheResourceServerProducesAUserId() + public function testAuthenticateReturnsAUserIfTheResourceServerProducesAUserId(): void { - $request = $this->prophesize(ServerRequestInterface::class); - $request->getAttribute('oauth_user_id', null)->willReturn('some-identifier'); - $request->getAttribute('oauth_client_id', null)->willReturn(null); - $request->getAttribute('oauth_access_token_id', null)->willReturn(null); - $request->getAttribute('oauth_scopes', null)->willReturn(null); + $request = (new ServerRequest())->withAttribute('oauth_user_id', 'some-identifier'); - $this->resourceServer - ->validateAuthenticatedRequest(Argument::that([$request, 'reveal'])) - ->will([$request, 'reveal']); + $this->resourceServer->expects(self::once()) + ->method('validateAuthenticatedRequest') + ->with($request) + ->willReturn($request); $adapter = new OAuth2Adapter( - $this->resourceServer->reveal(), + $this->resourceServer, $this->responseFactory, $this->userFactory ); - $user = $adapter->authenticate($request->reveal()); + $user = $adapter->authenticate($request); - $this->assertInstanceOf(UserInterface::class, $user); - $this->assertSame('some-identifier', $user->getIdentity()); - $this->assertSame([], $user->getRoles()); + self::assertInstanceOf(UserInterface::class, $user); + self::assertSame('some-identifier', $user->getIdentity()); + self::assertSame([], $user->getRoles()); } - public function testAuthenticateReturnsNullIfTheResourceServerProducesAClientIdOnly() + public function testAuthenticateReturnsNullIfTheResourceServerProducesAClientIdOnly(): void { - $request = $this->prophesize(ServerRequestInterface::class); - $request->getAttribute('oauth_user_id', null)->willReturn(null); - $request->getAttribute('oauth_client_id', null)->willReturn('some-identifier'); - $request->getAttribute('oauth_access_token_id', null)->willReturn(null); - $request->getAttribute('oauth_scopes', null)->willReturn(null); + $request = (new ServerRequest())->withAttribute('oauth_client_id', 'some-identifier'); - $this->resourceServer - ->validateAuthenticatedRequest(Argument::that([$request, 'reveal'])) - ->will([$request, 'reveal']); + $this->resourceServer->expects(self::once()) + ->method('validateAuthenticatedRequest') + ->with($request) + ->willReturn($request); $adapter = new OAuth2Adapter( - $this->resourceServer->reveal(), + $this->resourceServer, $this->responseFactory, $this->userFactory ); - $user = $adapter->authenticate($request->reveal()); - $this->assertNull($user); + $user = $adapter->authenticate($request); + self::assertNull($user); } - public function testUnauthorizedResponseProducesAResponseWithAWwwAuthenticateHeader() + public function testUnauthorizedResponseProducesAResponseWithAWwwAuthenticateHeader(): void { - $request = $this->prophesize(ServerRequestInterface::class)->reveal(); + $request = $this->createMock(ServerRequestInterface::class); $this->response ->expects(self::once()) @@ -155,12 +143,12 @@ public function testUnauthorizedResponseProducesAResponseWithAWwwAuthenticateHea ->willReturnSelf(); $adapter = new OAuth2Adapter( - $this->resourceServer->reveal(), + $this->resourceServer, $this->responseFactory, $this->userFactory ); - $this->assertSame( + self::assertSame( $this->response, $adapter->unauthorizedResponse($request) ); diff --git a/test/Pdo/OAuth2PdoMiddlewareTest.php b/test/Pdo/OAuth2PdoMiddlewareTest.php index 590fd8a7..fa429384 100644 --- a/test/Pdo/OAuth2PdoMiddlewareTest.php +++ b/test/Pdo/OAuth2PdoMiddlewareTest.php @@ -29,9 +29,8 @@ use Mezzio\Authentication\OAuth2\Repository\Pdo\UserRepository; use Mezzio\Authentication\OAuth2\TokenEndpointHandler; use PDO; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; @@ -60,8 +59,6 @@ */ class OAuth2PdoMiddlewareTest extends TestCase { - use ProphecyTrait; - private const DB_FILE = __DIR__ . '/TestAsset/test_oauth2.sq3'; private const DB_SCHEMA = __DIR__ . '/../../data/oauth2.sql'; private const DB_DATA = __DIR__ . '/TestAsset/test_data.sql'; @@ -78,8 +75,8 @@ class OAuth2PdoMiddlewareTest extends TestCase private ClientRepository $clientRepository; - /** @var RequestHandlerInterface|ObjectProphecy */ - private $handler; + /** @var RequestHandlerInterface&MockObject */ + private RequestHandlerInterface $handler; private PdoService $pdoService; @@ -141,7 +138,7 @@ protected function setUp(): void self::ENCRYPTION_KEY ); - $this->handler = $this->prophesize(RequestHandlerInterface::class); + $this->handler = $this->createMock(RequestHandlerInterface::class); $this->responseFactory = fn(): Response => $this->response; } @@ -150,7 +147,7 @@ protected function setUp(): void * * @see https://oauth2.thephpleague.com/authorization-server/client-credentials-grant/ */ - public function testProcessClientCredentialGrantNotConfidential() + public function testProcessClientCredentialGrantNotConfidential(): void { // Enable the client credentials grant on the server $this->authServer->enableGrantType( @@ -180,7 +177,7 @@ public function testProcessClientCredentialGrantNotConfidential() $response = $handler->handle($request); - $this->assertEquals(401, $response->getStatusCode()); + self::assertEquals(401, $response->getStatusCode()); } /** @@ -188,7 +185,7 @@ public function testProcessClientCredentialGrantNotConfidential() * * @see https://oauth2.thephpleague.com/authorization-server/client-credentials-grant/ */ - public function testProcessClientCredentialGrantConfidential() + public function testProcessClientCredentialGrantConfidential(): void { // Enable the client credentials grant on the server $this->authServer->enableGrantType( @@ -218,11 +215,11 @@ public function testProcessClientCredentialGrantConfidential() $response = $handler->handle($request); - $this->assertEquals(200, $response->getStatusCode()); + self::assertEquals(200, $response->getStatusCode()); $content = json_decode((string) $response->getBody()); - $this->assertEquals('Bearer', $content->token_type); - $this->assertIsInt($content->expires_in); - $this->assertNotEmpty($content->access_token); + self::assertEquals('Bearer', $content->token_type); + self::assertIsInt($content->expires_in); + self::assertNotEmpty($content->access_token); } /** @@ -230,7 +227,7 @@ public function testProcessClientCredentialGrantConfidential() * * @see https://oauth2.thephpleague.com/authorization-server/resource-owner-password-credentials-grant/ */ - public function testProcessPasswordGrant() + public function testProcessPasswordGrant(): void { $grant = new PasswordGrant( $this->userRepository, @@ -266,12 +263,12 @@ public function testProcessPasswordGrant() $response = $handler->handle($request); - $this->assertEquals(200, $response->getStatusCode()); + self::assertEquals(200, $response->getStatusCode()); $content = json_decode((string) $response->getBody()); - $this->assertEquals('Bearer', $content->token_type); - $this->assertIsInt($content->expires_in); - $this->assertNotEmpty($content->access_token); - $this->assertNotEmpty($content->refresh_token); + self::assertEquals('Bearer', $content->token_type); + self::assertIsInt($content->expires_in); + self::assertNotEmpty($content->access_token); + self::assertNotEmpty($content->refresh_token); } /** @@ -329,14 +326,14 @@ public function testProcessGetAuthorizationCode(): string $response = $authMiddleware->process($request, $consumerHandler); - $this->assertEquals(302, $response->getStatusCode()); - $this->assertTrue($response->hasHeader('Location')); + self::assertEquals(302, $response->getStatusCode()); + self::assertTrue($response->hasHeader('Location')); [$url, $queryString] = explode('?', $response->getHeader('Location')[0]); - $this->assertEquals($params['redirect_uri'], $url); + self::assertEquals($params['redirect_uri'], $url); parse_str($queryString, $data); - $this->assertTrue(isset($data['code'])); - $this->assertTrue(isset($data['state'])); - $this->assertEquals($state, $data['state']); + self::assertTrue(isset($data['code'])); + self::assertTrue(isset($data['state'])); + self::assertEquals($state, $data['state']); return $data['code']; } @@ -388,12 +385,12 @@ public function testProcessFromAuthorizationCode(string $code): string $response = $handler->handle($request); - $this->assertEquals(200, $response->getStatusCode()); + self::assertEquals(200, $response->getStatusCode()); $content = json_decode((string) $response->getBody()); - $this->assertEquals('Bearer', $content->token_type); - $this->assertIsInt($content->expires_in); - $this->assertNotEmpty($content->access_token); - $this->assertNotEmpty($content->refresh_token); + self::assertEquals('Bearer', $content->token_type); + self::assertIsInt($content->expires_in); + self::assertNotEmpty($content->access_token); + self::assertNotEmpty($content->refresh_token); return $content->refresh_token; } @@ -403,7 +400,7 @@ public function testProcessFromAuthorizationCode(string $code): string * * @see https://oauth2.thephpleague.com/authorization-server/implicit-grant/ */ - public function testProcessImplicitGrant() + public function testProcessImplicitGrant(): void { // Enable the implicit grant on the server $this->authServer->enableGrantType( @@ -434,18 +431,18 @@ public function testProcessImplicitGrant() $response = $authMiddleware->process($request, $consumerHandler); - $this->assertEquals(302, $response->getStatusCode()); - $this->assertTrue($response->hasHeader('Location')); + self::assertEquals(302, $response->getStatusCode()); + self::assertTrue($response->hasHeader('Location')); [$url, $fragment] = explode('#', $response->getHeader('Location')[0]); - $this->assertEquals($params['redirect_uri'], $url); + self::assertEquals($params['redirect_uri'], $url); parse_str($fragment, $data); - $this->assertTrue(isset($data['access_token'])); - $this->assertTrue(isset($data['expires_in'])); - $this->assertTrue(isset($data['token_type'])); - $this->assertEquals('bearer', strtolower($data['token_type'])); - $this->assertFalse(isset($data['refresh_token'])); - $this->assertTrue(isset($data['state'])); - $this->assertEquals($state, $data['state']); + self::assertTrue(isset($data['access_token'])); + self::assertTrue(isset($data['expires_in'])); + self::assertTrue(isset($data['token_type'])); + self::assertEquals('bearer', strtolower($data['token_type'])); + self::assertFalse(isset($data['refresh_token'])); + self::assertTrue(isset($data['state'])); + self::assertEquals($state, $data['state']); } /** @@ -455,7 +452,7 @@ public function testProcessImplicitGrant() * * @depends testProcessFromAuthorizationCode */ - public function testProcessRefreshTokenGrant(string $refreshToken) + public function testProcessRefreshTokenGrant(string $refreshToken): void { $grant = new RefreshTokenGrant($this->refreshTokenRepository); $grant->setRefreshTokenTTL(new DateInterval('P1M')); // new refresh tokens will expire after 1 month @@ -488,12 +485,12 @@ public function testProcessRefreshTokenGrant(string $refreshToken) $response = $handler->handle($request); - $this->assertEquals(200, $response->getStatusCode()); + self::assertEquals(200, $response->getStatusCode()); $content = json_decode((string) $response->getBody()); - $this->assertEquals('Bearer', $content->token_type); - $this->assertIsInt($content->expires_in); - $this->assertNotEmpty($content->access_token); - $this->assertNotEmpty($content->refresh_token); + self::assertEquals('Bearer', $content->token_type); + self::assertIsInt($content->expires_in); + self::assertNotEmpty($content->access_token); + self::assertNotEmpty($content->refresh_token); } private function buildConsumerAuthMiddleware(AuthorizationHandler $authHandler): object diff --git a/test/Repository/Pdo/AbstractRepositoryTest.php b/test/Repository/Pdo/AbstractRepositoryTest.php index c47a93ce..4753855c 100644 --- a/test/Repository/Pdo/AbstractRepositoryTest.php +++ b/test/Repository/Pdo/AbstractRepositoryTest.php @@ -6,27 +6,28 @@ use Mezzio\Authentication\OAuth2\Repository\Pdo\AbstractRepository; use Mezzio\Authentication\OAuth2\Repository\Pdo\PdoService; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; class AbstractRepositoryTest extends TestCase { - use ProphecyTrait; + /** @var PdoService&MockObject */ + private PdoService|MockObject $pdo; protected function setUp(): void { - $this->pdo = $this->prophesize(PdoService::class); + $this->pdo = $this->createMock(PdoService::class); } - public function testConstructor() + public function testConstructor(): void { - $abstract = new AbstractRepository($this->pdo->reveal()); + $abstract = new AbstractRepository($this->pdo); $this->assertInstanceOf(AbstractRepository::class, $abstract); } - public function testScopesToStringWithEmptyArray() + public function testScopesToStringWithEmptyArray(): void { - $proxy = new class ($this->pdo->reveal()) extends AbstractRepository { + $proxy = new class ($this->pdo) extends AbstractRepository { public function scopesToString(array $scopes): string { return parent::scopesToString($scopes); diff --git a/test/Repository/Pdo/AccessTokenRepositoryFactoryTest.php b/test/Repository/Pdo/AccessTokenRepositoryFactoryTest.php index 0295f190..545a8f51 100644 --- a/test/Repository/Pdo/AccessTokenRepositoryFactoryTest.php +++ b/test/Repository/Pdo/AccessTokenRepositoryFactoryTest.php @@ -7,30 +7,31 @@ use Mezzio\Authentication\OAuth2\Repository\Pdo\AccessTokenRepository; use Mezzio\Authentication\OAuth2\Repository\Pdo\AccessTokenRepositoryFactory; use Mezzio\Authentication\OAuth2\Repository\Pdo\PdoService; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Psr\Container\ContainerInterface; class AccessTokenRepositoryFactoryTest extends TestCase { - use ProphecyTrait; - - private ObjectProphecy $container; + /** @var ContainerInterface&MockObject */ + private ContainerInterface $container; + /** @var PdoService&MockObject */ + private PdoService $pdo; protected function setUp(): void { - $this->container = $this->prophesize(ContainerInterface::class); - $this->pdo = $this->prophesize(PdoService::class); + $this->container = $this->createMock(ContainerInterface::class); + $this->pdo = $this->createMock(PdoService::class); } - public function testFactory() + public function testFactory(): void { - $this->container - ->get(PdoService::class) - ->willReturn($this->pdo->reveal()); + $this->container->expects(self::once()) + ->method('get') + ->with(PdoService::class) + ->willReturn($this->pdo); - $factory = (new AccessTokenRepositoryFactory())($this->container->reveal()); - $this->assertInstanceOf(AccessTokenRepository::class, $factory); + $factory = (new AccessTokenRepositoryFactory())($this->container); + self::assertInstanceOf(AccessTokenRepository::class, $factory); } } diff --git a/test/Repository/Pdo/AccessTokenRepositoryTest.php b/test/Repository/Pdo/AccessTokenRepositoryTest.php index 61546907..5deb264b 100644 --- a/test/Repository/Pdo/AccessTokenRepositoryTest.php +++ b/test/Repository/Pdo/AccessTokenRepositoryTest.php @@ -14,47 +14,50 @@ use Mezzio\Authentication\OAuth2\Repository\Pdo\AccessTokenRepository; use Mezzio\Authentication\OAuth2\Repository\Pdo\PdoService; use PDOStatement; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; use function date; use function time; class AccessTokenRepositoryTest extends TestCase { - use ProphecyTrait; - private AccessTokenRepository $repo; + /** @var PdoService&MockObject */ + private PdoService $pdo; protected function setUp(): void { - $this->pdo = $this->prophesize(PdoService::class); - $this->repo = new AccessTokenRepository($this->pdo->reveal()); + $this->pdo = $this->createMock(PdoService::class); + $this->repo = new AccessTokenRepository($this->pdo); } - public function testPersistNewAccessTokenRaisesExceptionWhenStatementExecutionFails() + public function testPersistNewAccessTokenRaisesExceptionWhenStatementExecutionFails(): void { - $client = $this->prophesize(ClientEntityInterface::class); - $client->getIdentifier()->willReturn('client_id'); + $client = $this->createMock(ClientEntityInterface::class); + $client->expects(self::once()) + ->method('getIdentifier') + ->willReturn('client_id'); - $scope = $this->prophesize(ScopeEntityInterface::class); - $scope->getIdentifier()->willReturn('authentication'); + $scope = $this->createMock(ScopeEntityInterface::class); + $scope->expects(self::once()) + ->method('getIdentifier') + ->willReturn('authentication'); $time = time(); - $date = $this->prophesize(DateTime::class); - $date->getTimestamp()->willReturn($time); - - $accessToken = $this->prophesize(AccessTokenEntityInterface::class); - $accessToken->getIdentifier()->willReturn('id'); - $accessToken->getUserIdentifier()->willReturn('user_id'); - $accessToken->getClient()->will([$client, 'reveal']); - $accessToken->getScopes()->willReturn([$scope->reveal()]); - $accessToken->getExpiryDateTime()->will([$date, 'reveal']); - - $statement = $this->prophesize(PDOStatement::class); - $statement - ->execute([ + $date = DateTime::createFromFormat('U', (string) $time); + + $accessToken = $this->createMock(AccessTokenEntityInterface::class); + $accessToken->method('getIdentifier')->willReturn('id'); + $accessToken->method('getUserIdentifier')->willReturn('user_id'); + $accessToken->method('getClient')->willReturn($client); + $accessToken->method('getScopes')->willReturn([$scope]); + $accessToken->method('getExpiryDateTime')->willReturn($date); + + $statement = $this->createMock(PDOStatement::class); + $statement->expects(self::once()) + ->method('execute') + ->with([ ':id' => 'id', ':user_id' => 'user_id', ':client_id' => 'client_id', @@ -64,112 +67,176 @@ public function testPersistNewAccessTokenRaisesExceptionWhenStatementExecutionFa ]) ->willReturn(false); - $this->pdo - ->prepare(Argument::containingString('INSERT INTO oauth_access_tokens')) - ->will([$statement, 'reveal']); + $this->pdo->expects(self::once()) + ->method('prepare') + ->with(self::callback(function (string $arg): bool { + self::assertStringContainsString('INSERT INTO oauth_access_tokens', $arg); + + return true; + })) + ->willReturn($statement); $this->expectException(UniqueTokenIdentifierConstraintViolationException::class); - $this->repo->persistNewAccessToken($accessToken->reveal()); + $this->repo->persistNewAccessToken($accessToken); } - public function testIsAccessTokenRevokedReturnsFalseWhenStatementFailsExecution() + public function testIsAccessTokenRevokedReturnsFalseWhenStatementFailsExecution(): void { - $statement = $this->prophesize(PDOStatement::class); - $statement->bindParam(':tokenId', 'token_id')->shouldBeCalled(); - $statement->execute()->willReturn(false)->shouldBeCalled(); - $statement->fetch()->shouldNotBeCalled(); + $statement = $this->createMock(PDOStatement::class); + $statement->expects(self::once()) + ->method('bindParam') + ->with(':tokenId', 'token_id'); + $statement->expects(self::once()) + ->method('execute') + ->willReturn(false); + $statement->expects(self::never()) + ->method('fetch'); - $this->pdo - ->prepare(Argument::containingString('SELECT revoked FROM oauth_access_tokens')) - ->will([$statement, 'reveal']); + $this->pdo->expects(self::once()) + ->method('prepare') + ->with(self::callback(function (string $sql): bool { + self::assertStringContainsString('SELECT revoked FROM oauth_access_tokens', $sql); + + return true; + }))->willReturn($statement); $this->assertFalse($this->repo->isAccessTokenRevoked('token_id')); } - public function testIsAccessTokenRevokedReturnsFalseWhenRowDoesNotContainRevokedFlag() + public function testIsAccessTokenRevokedReturnsFalseWhenRowDoesNotContainRevokedFlag(): void { - $statement = $this->prophesize(PDOStatement::class); - $statement->bindParam(':tokenId', 'token_id')->shouldBeCalled(); - $statement->execute()->willReturn(true)->shouldBeCalled(); - $statement->fetch()->willReturn([])->shouldBeCalled(); - - $this->pdo - ->prepare(Argument::containingString('SELECT revoked FROM oauth_access_tokens')) - ->will([$statement, 'reveal']); + $statement = $this->createMock(PDOStatement::class); + $statement->expects(self::once()) + ->method('bindParam') + ->with(':tokenId', 'token_id'); + $statement->expects(self::once()) + ->method('execute') + ->willReturn(true); + $statement->expects(self::once()) + ->method('fetch') + ->willReturn([]); + + $this->pdo->expects(self::once()) + ->method('prepare') + ->with(self::callback(function (string $sql): bool { + self::assertStringContainsString('SELECT revoked FROM oauth_access_tokens', $sql); + + return true; + }))->willReturn($statement); $this->assertFalse($this->repo->isAccessTokenRevoked('token_id')); } - public function testIsAccessTokenRevokedReturnsFalseWhenRowRevokedFlagIsFalse() + public function testIsAccessTokenRevokedReturnsFalseWhenRowRevokedFlagIsFalse(): void { - $statement = $this->prophesize(PDOStatement::class); - $statement->bindParam(':tokenId', 'token_id')->shouldBeCalled(); - $statement->execute()->willReturn(true)->shouldBeCalled(); - $statement->fetch()->willReturn(['revoked' => 0])->shouldBeCalled(); - - $this->pdo - ->prepare(Argument::containingString('SELECT revoked FROM oauth_access_tokens')) - ->will([$statement, 'reveal']); + $statement = $this->createMock(PDOStatement::class); + $statement->expects(self::once()) + ->method('bindParam') + ->with(':tokenId', 'token_id'); + $statement->expects(self::once()) + ->method('execute') + ->willReturn(true); + $statement->expects(self::once()) + ->method('fetch') + ->willReturn(['revoked' => 0]); + + $this->pdo->expects(self::once()) + ->method('prepare') + ->with(self::callback(function (string $sql): bool { + self::assertStringContainsString('SELECT revoked FROM oauth_access_tokens', $sql); + + return true; + }))->willReturn($statement); $this->assertFalse($this->repo->isAccessTokenRevoked('token_id')); } - public function testIsAccessTokenRevokedReturnsTrueWhenRowRevokedFlagIsTrue() + public function testIsAccessTokenRevokedReturnsTrueWhenRowRevokedFlagIsTrue(): void { - $statement = $this->prophesize(PDOStatement::class); - $statement->bindParam(':tokenId', 'token_id')->shouldBeCalled(); - $statement->execute()->willReturn(true)->shouldBeCalled(); - $statement->fetch()->willReturn(['revoked' => 1])->shouldBeCalled(); - - $this->pdo - ->prepare(Argument::containingString('SELECT revoked FROM oauth_access_tokens')) - ->will([$statement, 'reveal']); + $statement = $this->createMock(PDOStatement::class); + $statement->expects(self::once()) + ->method('bindParam') + ->with(':tokenId', 'token_id'); + $statement->expects(self::once()) + ->method('execute') + ->willReturn(true); + $statement->expects(self::once()) + ->method('fetch') + ->willReturn(['revoked' => 1]); + + $this->pdo->expects(self::once()) + ->method('prepare') + ->with(self::callback(function (string $sql): bool { + self::assertStringContainsString('SELECT revoked FROM oauth_access_tokens', $sql); + + return true; + }))->willReturn($statement); $this->assertTrue($this->repo->isAccessTokenRevoked('token_id')); } - public function testIsAcessTokenRevokedRaisesExceptionWhenTokenIdDontExists() + public function testIsAcessTokenRevokedRaisesExceptionWhenTokenIdDontExists(): void { - $statement = $this->prophesize(PDOStatement::class); - $statement->bindParam(':tokenId', 'token_id')->shouldBeCalled(); - $statement->execute()->willReturn(true)->shouldBeCalled(); - $statement->fetch()->willReturn(false)->shouldBeCalled(); + $statement = $this->createMock(PDOStatement::class); + $statement->expects(self::once()) + ->method('bindParam') + ->with(':tokenId', 'token_id'); + $statement->expects(self::once()) + ->method('execute') + ->willReturn(true); + $statement->expects(self::once()) + ->method('fetch') + ->willReturn(false); - $this->pdo - ->prepare(Argument::containingString('SELECT revoked FROM oauth_access_tokens')) - ->will([$statement, 'reveal']); + $this->pdo->expects(self::once()) + ->method('prepare') + ->with(self::callback(function (string $sql): bool { + self::assertStringContainsString('SELECT revoked FROM oauth_access_tokens', $sql); + + return true; + }))->willReturn($statement); $this->expectException(OAuthServerException::class); $this->repo->isAccessTokenRevoked('token_id'); } - public function testRevokeAccessToken() + public function testRevokeAccessToken(): void { - $statement = $this->prophesize(PDOStatement::class); - $statement->bindParam(':tokenId', 'token_id')->shouldBeCalled(); - $statement->bindValue(':revoked', 1)->shouldBeCalled(); - $statement->execute()->willReturn(true)->shouldBeCalled(); - - $this->pdo - ->prepare(Argument::containingString('UPDATE oauth_access_tokens SET revoked=:revoked')) - ->will([$statement, 'reveal']); + $statement = $this->createMock(PDOStatement::class); + $statement->expects(self::once()) + ->method('bindParam') + ->with(':tokenId', 'token_id'); + $statement->expects(self::once()) + ->method('bindValue') + ->with(':revoked', 1); + $statement->expects(self::once()) + ->method('execute') + ->willReturn(true); + + $this->pdo->expects(self::once()) + ->method('prepare') + ->with(self::callback(function (string $sql): bool { + self::assertStringContainsString('UPDATE oauth_access_tokens SET revoked=:revoked', $sql); + + return true; + }))->willReturn($statement); $this->repo->revokeAccessToken('token_id'); } - public function testGetNewToken() + public function testGetNewToken(): void { - $client = $this->prophesize(ClientEntityInterface::class)->reveal(); + $client = $this->createMock(ClientEntityInterface::class); $accessToken = $this->repo->getNewToken($client, []); $this->assertInstanceOf(AccessTokenEntity::class, $accessToken); $this->assertEquals($client, $accessToken->getClient()); $this->assertEquals([], $accessToken->getScopes()); } - public function testGetNewTokenWithScopeAndIndentifier() + public function testGetNewTokenWithScopeAndIndentifier(): void { - $client = $this->prophesize(ClientEntityInterface::class)->reveal(); - $scopes = [$this->prophesize(ScopeEntityInterface::class)->reveal()]; + $client = $this->createMock(ClientEntityInterface::class); + $scopes = [$this->createMock(ScopeEntityInterface::class)]; $userIdentifier = 'foo'; $accessToken = $this->repo->getNewToken($client, $scopes, $userIdentifier); diff --git a/test/Repository/Pdo/AuthCodeRepositoryFactoryTest.php b/test/Repository/Pdo/AuthCodeRepositoryFactoryTest.php index 85d41a77..5e6a0120 100644 --- a/test/Repository/Pdo/AuthCodeRepositoryFactoryTest.php +++ b/test/Repository/Pdo/AuthCodeRepositoryFactoryTest.php @@ -8,29 +8,19 @@ use Mezzio\Authentication\OAuth2\Repository\Pdo\AuthCodeRepositoryFactory; use Mezzio\Authentication\OAuth2\Repository\Pdo\PdoService; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Psr\Container\ContainerInterface; class AuthCodeRepositoryFactoryTest extends TestCase { - use ProphecyTrait; - - private ObjectProphecy $container; - - protected function setUp(): void - { - $this->container = $this->prophesize(ContainerInterface::class); - $this->pdo = $this->prophesize(PdoService::class); - } - - public function testFactory() + public function testFactory(): void { - $this->container - ->get(PdoService::class) - ->willReturn($this->pdo->reveal()); - - $factory = (new AuthCodeRepositoryFactory())($this->container->reveal()); - $this->assertInstanceOf(AuthCodeRepository::class, $factory); + $container = $this->createMock(ContainerInterface::class); + $container->expects(self::once()) + ->method('get') + ->with(PdoService::class) + ->willReturn($this->createMock(PdoService::class)); + + $factory = (new AuthCodeRepositoryFactory())($container); + self::assertInstanceOf(AuthCodeRepository::class, $factory); } } diff --git a/test/Repository/Pdo/AuthCodeRepositoryTest.php b/test/Repository/Pdo/AuthCodeRepositoryTest.php index dfcecc3d..a513f188 100644 --- a/test/Repository/Pdo/AuthCodeRepositoryTest.php +++ b/test/Repository/Pdo/AuthCodeRepositoryTest.php @@ -12,104 +12,136 @@ use Mezzio\Authentication\OAuth2\Repository\Pdo\AuthCodeRepository; use Mezzio\Authentication\OAuth2\Repository\Pdo\PdoService; use PDOStatement; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; use function date; use function time; class AuthCodeRepositoryTest extends TestCase { - use ProphecyTrait; + /** @var PdoService&MockObject */ + private PdoService $pdo; + private AuthCodeRepository $repo; protected function setUp(): void { - $this->pdo = $this->prophesize(PdoService::class); - $this->repo = new AuthCodeRepository($this->pdo->reveal()); + $this->pdo = $this->createMock(PdoService::class); + $this->repo = new AuthCodeRepository($this->pdo); } - public function testPersistNewAuthCodeRaisesExceptionWhenStatementExecutionFails() + public function testPersistNewAuthCodeRaisesExceptionWhenStatementExecutionFails(): void { - $client = $this->prophesize(ClientEntityInterface::class); - $client->getIdentifier()->willReturn('client_id'); + $client = $this->createMock(ClientEntityInterface::class); + $client->expects(self::once()) + ->method('getIdentifier') + ->willReturn('client_id'); - $scope = $this->prophesize(ScopeEntityInterface::class); - $scope->getIdentifier()->willReturn('authentication'); + $scope = $this->createMock(ScopeEntityInterface::class); + $scope->expects(self::once()) + ->method('getIdentifier') + ->willReturn('authentication'); $time = time(); - $date = $this->prophesize(DateTime::class); - $date->getTimestamp()->willReturn($time); - - $authCode = $this->prophesize(AuthCodeEntity::class); - $authCode->getIdentifier()->willReturn('id'); - $authCode->getUserIdentifier()->willReturn('user_id'); - $authCode->getClient()->will([$client, 'reveal']); - $authCode->getScopes()->willReturn([$scope->reveal()]); - $authCode->getExpiryDateTime()->will([$date, 'reveal']); - - $statement = $this->prophesize(PDOStatement::class); - $statement->bindValue(':id', 'id')->shouldBeCalled(); - $statement->bindValue(':user_id', 'user_id')->shouldBeCalled(); - $statement->bindValue(':client_id', 'client_id')->shouldBeCalled(); - $statement->bindValue(':scopes', 'authentication')->shouldBeCalled(); - $statement->bindValue(':revoked', 0)->shouldBeCalled(); - $statement->bindValue(':expires_at', date('Y-m-d H:i:s', $time)) - ->shouldBeCalled(); - $statement->execute()->willReturn(false); - - $this->pdo - ->prepare(Argument::containingString('INSERT INTO oauth_auth_codes')) - ->will([$statement, 'reveal']); + $date = DateTime::createFromFormat('U', (string) $time); + + $authCode = $this->createMock(AuthCodeEntity::class); + $authCode->method('getIdentifier')->willReturn('id'); + $authCode->method('getUserIdentifier')->willReturn('user_id'); + $authCode->method('getClient')->willReturn($client); + $authCode->method('getScopes')->willReturn([$scope]); + $authCode->method('getExpiryDateTime')->willReturn($date); + + $statement = $this->createMock(PDOStatement::class); + $statement->method('bindValue') + ->withConsecutive( + [':id', 'id'], + [':user_id', 'user_id'], + [':client_id', 'client_id'], + [':scopes', 'authentication'], + [':revoked', 0], + [':expires_at', date('Y-m-d H:i:s', $time)], + ); + + $statement->expects(self::once()) + ->method('execute') + ->willReturn(false); + + $this->pdo->expects(self::once()) + ->method('prepare') + ->with(self::stringContains('INSERT INTO oauth_auth_codes')) + ->willReturn($statement); $this->expectException(UniqueTokenIdentifierConstraintViolationException::class); - $this->repo->persistNewAuthCode($authCode->reveal()); + $this->repo->persistNewAuthCode($authCode); } - public function testIsAuthCodeRevokedReturnsFalseForStatementExecutionFailure() + public function testIsAuthCodeRevokedReturnsFalseForStatementExecutionFailure(): void { - $statement = $this->prophesize(PDOStatement::class); - $statement->bindParam(':codeId', 'code_identifier')->shouldBeCalled(); - $statement->execute()->willReturn(false); - $statement->fetch()->shouldNotBeCalled(); + $statement = $this->createMock(PDOStatement::class); + $statement->expects(self::once()) + ->method('bindParam') + ->with(':codeId', 'code_identifier'); - $this->pdo - ->prepare(Argument::containingString('SELECT revoked FROM oauth_auth_codes')) - ->will([$statement, 'reveal']); + $statement->expects(self::once()) + ->method('execute') + ->willReturn(false); - $this->assertFalse($this->repo->isAuthCodeRevoked('code_identifier')); - } + $statement->expects(self::never()) + ->method('fetch'); - public function testIsAuthCodeRevokedReturnsTrue() - { - $statement = $this->prophesize(PDOStatement::class); - $statement->bindParam(':codeId', 'code_identifier')->shouldBeCalled(); - $statement->execute()->willReturn(true); - $statement->fetch()->willReturn(['revoked' => true]); + $this->pdo->expects(self::once()) + ->method('prepare') + ->with(self::stringContains('SELECT revoked FROM oauth_auth_codes')) + ->willReturn($statement); - $this->pdo - ->prepare(Argument::containingString('SELECT revoked FROM oauth_auth_codes')) - ->will([$statement, 'reveal']); + self::assertFalse($this->repo->isAuthCodeRevoked('code_identifier')); + } - $this->assertTrue($this->repo->isAuthCodeRevoked('code_identifier')); + public function testIsAuthCodeRevokedReturnsTrue(): void + { + $statement = $this->createMock(PDOStatement::class); + $statement->expects(self::once()) + ->method('bindParam') + ->with(':codeId', 'code_identifier'); + $statement->expects(self::once()) + ->method('execute') + ->willReturn(true); + $statement->expects(self::once()) + ->method('fetch') + ->willReturn(['revoked' => true]); + + $this->pdo->expects(self::once()) + ->method('prepare') + ->with(self::stringContains('SELECT revoked FROM oauth_auth_codes')) + ->willReturn($statement); + + self::assertTrue($this->repo->isAuthCodeRevoked('code_identifier')); } - public function testNewAuthCode() + public function testNewAuthCode(): void { $result = $this->repo->getNewAuthCode(); - $this->assertInstanceOf(AuthCodeEntity::class, $result); + self::assertInstanceOf(AuthCodeEntity::class, $result); } - public function testRevokeAuthCode() + public function testRevokeAuthCode(): void { - $statement = $this->prophesize(PDOStatement::class); - $statement->bindParam(':codeId', 'code_identifier')->shouldBeCalled(); - $statement->bindValue(':revoked', 1)->shouldBeCalled(); - $statement->execute()->willReturn(true); - - $this->pdo - ->prepare(Argument::containingString('UPDATE oauth_auth_codes SET revoked=:revoked WHERE id = :codeId')) - ->will([$statement, 'reveal']); + $statement = $this->createMock(PDOStatement::class); + $statement->expects(self::once()) + ->method('bindParam') + ->with(':codeId', 'code_identifier'); + $statement->expects(self::once()) + ->method('bindValue') + ->with(':revoked', 1); + $statement->expects(self::once()) + ->method('execute') + ->willReturn(true); + + $this->pdo->expects(self::once()) + ->method('prepare') + ->with(self::stringContains('UPDATE oauth_auth_codes SET revoked=:revoked WHERE id = :codeId')) + ->willReturn($statement); $this->repo->revokeAuthCode('code_identifier'); } diff --git a/test/Repository/Pdo/ClientRepositoryFactoryTest.php b/test/Repository/Pdo/ClientRepositoryFactoryTest.php index 130ef244..c9a0ef72 100644 --- a/test/Repository/Pdo/ClientRepositoryFactoryTest.php +++ b/test/Repository/Pdo/ClientRepositoryFactoryTest.php @@ -8,29 +8,19 @@ use Mezzio\Authentication\OAuth2\Repository\Pdo\ClientRepositoryFactory; use Mezzio\Authentication\OAuth2\Repository\Pdo\PdoService; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Psr\Container\ContainerInterface; class ClientRepositoryFactoryTest extends TestCase { - use ProphecyTrait; - - private ObjectProphecy $container; - - protected function setUp(): void - { - $this->container = $this->prophesize(ContainerInterface::class); - $this->pdo = $this->prophesize(PdoService::class); - } - - public function testFactory() + public function testFactory(): void { - $this->container - ->get(PdoService::class) - ->willReturn($this->pdo->reveal()); - - $factory = (new ClientRepositoryFactory())($this->container->reveal()); - $this->assertInstanceOf(ClientRepository::class, $factory); + $container = $this->createMock(ContainerInterface::class); + $container->expects(self::once()) + ->method('get') + ->with(PdoService::class) + ->willReturn($this->createMock(PdoService::class)); + + $factory = (new ClientRepositoryFactory())($container); + self::assertInstanceOf(ClientRepository::class, $factory); } } diff --git a/test/Repository/Pdo/ClientRepositoryTest.php b/test/Repository/Pdo/ClientRepositoryTest.php index 48426e92..04fea43c 100644 --- a/test/Repository/Pdo/ClientRepositoryTest.php +++ b/test/Repository/Pdo/ClientRepositoryTest.php @@ -8,91 +8,106 @@ use Mezzio\Authentication\OAuth2\Repository\Pdo\ClientRepository; use Mezzio\Authentication\OAuth2\Repository\Pdo\PdoService; use PDOStatement; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; class ClientRepositoryTest extends TestCase { - use ProphecyTrait; + /** @var PdoService&MockObject */ + private PdoService $pdo; + private ClientRepository $repo; protected function setUp(): void { - $this->pdo = $this->prophesize(PdoService::class); - $this->repo = new ClientRepository($this->pdo->reveal()); + $this->pdo = $this->createMock(PdoService::class); + $this->repo = new ClientRepository($this->pdo); } - public function testGetClientEntityReturnsNullIfStatementExecutionReturnsFalse() + public function testGetClientEntityReturnsNullIfStatementExecutionReturnsFalse(): void { - $statement = $this->prophesize(PDOStatement::class); - $statement->bindParam(':clientIdentifier', 'client_id')->shouldBeCalled(); - $statement->execute()->willReturn(false); - - $this->pdo - ->prepare(Argument::containingString('SELECT * FROM oauth_clients')) - ->will([$statement, 'reveal']); - - $this->assertNull( + $statement = $this->createMock(PDOStatement::class); + $statement->expects(self::once()) + ->method('bindParam') + ->with(':clientIdentifier', 'client_id'); + $statement->expects(self::once()) + ->method('execute') + ->willReturn(false); + + $this->pdo->expects(self::once()) + ->method('prepare') + ->with(self::stringContains('SELECT * FROM oauth_clients')) + ->willReturn($statement); + + self::assertNull( $this->repo->getClientEntity('client_id') ); } - public function testGetClientEntityReturnsNullIfNoRowReturned() + public function testGetClientEntityReturnsNullIfNoRowReturned(): void { - $statement = $this->prophesize(PDOStatement::class); - $statement->bindParam(':clientIdentifier', 'client_id')->shouldBeCalled(); - $statement->execute()->will(function () use ($statement): bool { - $statement->fetch()->willReturn([]); - return true; - }); - - $this->pdo - ->prepare(Argument::containingString('SELECT * FROM oauth_clients')) - ->will([$statement, 'reveal']); - - $this->assertNull( + $statement = $this->createMock(PDOStatement::class); + $statement->expects(self::once()) + ->method('bindParam') + ->with(':clientIdentifier', 'client_id'); + $statement->expects(self::once()) + ->method('execute') + ->willReturn(true); + $statement->expects(self::once()) + ->method('fetch') + ->willReturn([]); + + $this->pdo->expects(self::once()) + ->method('prepare') + ->with(self::stringContains('SELECT * FROM oauth_clients')) + ->willReturn($statement); + + self::assertNull( $this->repo->getClientEntity('client_id') ); } - public function testGetClientEntityReturnsCorrectEntity() + public function testGetClientEntityReturnsCorrectEntity(): void { $name = 'foo'; $redirect = 'bar'; - $statement = $this->prophesize(PDOStatement::class); - $statement->bindParam(':clientIdentifier', 'client_id')->shouldBeCalled(); - $statement->execute()->will(function () use ($statement, $name, $redirect): bool { - $statement->fetch()->willReturn([ + $statement = $this->createMock(PDOStatement::class); + $statement->expects(self::once()) + ->method('bindParam') + ->with(':clientIdentifier', 'client_id'); + $statement->expects(self::once()) + ->method('execute') + ->willReturn(true); + $statement->expects(self::once()) + ->method('fetch') + ->willReturn([ 'name' => $name, 'redirect' => $redirect, ]); - return true; - }); - $this->pdo - ->prepare(Argument::containingString('SELECT * FROM oauth_clients')) - ->will([$statement, 'reveal']); - - $this->prophesize(ClientEntityInterface::class); + $this->pdo->expects(self::once()) + ->method('prepare') + ->with(self::stringContains('SELECT * FROM oauth_clients')) + ->willReturn($statement); /** @var ClientEntityInterface $client */ $client = $this->repo->getClientEntity('client_id'); - $this->assertInstanceOf( + self::assertInstanceOf( ClientEntityInterface::class, $client ); - $this->assertEquals( + self::assertEquals( $name, $client->getName() ); - $this->assertEquals( + self::assertEquals( [$redirect], $client->getRedirectUri() ); } + /** @return array */ public function invalidGrants(): array { return [ @@ -120,20 +135,23 @@ public function invalidGrants(): array public function testValidateClientReturnsFalseIfNoRowReturned(): void { - $statement = $this->prophesize(PDOStatement::class); - $statement->bindParam(':clientIdentifier', 'client_id')->shouldBeCalled(); - $statement->execute()->will(function () use ($statement): bool { - $statement->fetch()->willReturn([]); - return true; - }); - - $this->pdo - ->prepare(Argument::containingString('SELECT * FROM oauth_clients')) - ->will([$statement, 'reveal']); - - $client = $this->prophesize(ClientEntityInterface::class); - - $this->assertFalse( + $statement = $this->createMock(PDOStatement::class); + $statement->expects(self::once()) + ->method('bindParam') + ->with(':clientIdentifier', 'client_id'); + $statement->expects(self::once()) + ->method('execute') + ->willReturn(true); + $statement->expects(self::once()) + ->method('fetch') + ->willReturn([]); + + $this->pdo->expects(self::once()) + ->method('prepare') + ->with(self::stringContains('SELECT * FROM oauth_clients')) + ->willReturn($statement); + + self::assertFalse( $this->repo->validateClient( 'client_id', '', @@ -145,20 +163,25 @@ public function testValidateClientReturnsFalseIfNoRowReturned(): void /** * @dataProvider invalidGrants */ - public function testValidateClientReturnsFalseIfRowIndicatesNotGranted(string $grantType, array $rowReturned) + public function testValidateClientReturnsFalseIfRowIndicatesNotGranted(string $grantType, array $rowReturned): void { - $statement = $this->prophesize(PDOStatement::class); - $statement->bindParam(':clientIdentifier', 'client_id')->shouldBeCalled(); - $statement->execute()->will(function () use ($statement, $rowReturned): bool { - $statement->fetch()->willReturn($rowReturned); - return true; - }); - - $this->pdo - ->prepare(Argument::containingString('SELECT * FROM oauth_clients')) - ->will([$statement, 'reveal']); - - $this->assertFalse( + $statement = $this->createMock(PDOStatement::class); + $statement->expects(self::once()) + ->method('bindParam') + ->with(':clientIdentifier', 'client_id'); + $statement->expects(self::once()) + ->method('execute') + ->willReturn(true); + $statement->expects(self::once()) + ->method('fetch') + ->willReturn($rowReturned); + + $this->pdo->expects(self::once()) + ->method('prepare') + ->with(self::stringContains('SELECT * FROM oauth_clients')) + ->willReturn($statement); + + self::assertFalse( $this->repo->validateClient( 'client_id', '', @@ -167,25 +190,28 @@ public function testValidateClientReturnsFalseIfRowIndicatesNotGranted(string $g ); } - public function testValidateClientReturnsFalseForNonMatchingClientSecret() + public function testValidateClientReturnsFalseForNonMatchingClientSecret(): void { - $statement = $this->prophesize(PDOStatement::class); - $statement->bindParam(':clientIdentifier', 'client_id')->shouldBeCalled(); - $statement->execute()->will(function () use ($statement): bool { - $statement->fetch()->willReturn([ + $statement = $this->createMock(PDOStatement::class); + $statement->expects(self::once()) + ->method('bindParam') + ->with(':clientIdentifier', 'client_id'); + $statement->expects(self::once()) + ->method('execute') + ->willReturn(true); + $statement->expects(self::once()) + ->method('fetch') + ->willReturn([ 'password_client' => true, 'secret' => 'bar', ]); - return true; - }); - $this->pdo - ->prepare(Argument::containingString('SELECT * FROM oauth_clients')) - ->will([$statement, 'reveal']); + $this->pdo->expects(self::once()) + ->method('prepare') + ->with(self::stringContains('SELECT * FROM oauth_clients')) + ->willReturn($statement); - $client = $this->prophesize(ClientEntityInterface::class); - - $this->assertFalse( + self::assertFalse( $this->repo->validateClient( 'client_id', 'foo', @@ -194,25 +220,28 @@ public function testValidateClientReturnsFalseForNonMatchingClientSecret() ); } - public function testValidateClientReturnsFalseForEmptyClientSecret() + public function testValidateClientReturnsFalseForEmptyClientSecret(): void { - $statement = $this->prophesize(PDOStatement::class); - $statement->bindParam(':clientIdentifier', 'client_id')->shouldBeCalled(); - $statement->execute()->will(function () use ($statement): bool { - $statement->fetch()->willReturn([ + $statement = $this->createMock(PDOStatement::class); + $statement->expects(self::once()) + ->method('bindParam') + ->with(':clientIdentifier', 'client_id'); + $statement->expects(self::once()) + ->method('execute') + ->willReturn(true); + $statement->expects(self::once()) + ->method('fetch') + ->willReturn([ 'password_client' => true, 'secret' => null, ]); - return true; - }); - - $this->pdo - ->prepare(Argument::containingString('SELECT * FROM oauth_clients')) - ->will([$statement, 'reveal']); - $client = $this->prophesize(ClientEntityInterface::class); + $this->pdo->expects(self::once()) + ->method('prepare') + ->with(self::stringContains('SELECT * FROM oauth_clients')) + ->willReturn($statement); - $this->assertFalse( + self::assertFalse( $this->repo->validateClient( 'client_id', 'foo', diff --git a/test/Repository/Pdo/PdoServiceFactoryTest.php b/test/Repository/Pdo/PdoServiceFactoryTest.php index b415973d..3c1cb66f 100644 --- a/test/Repository/Pdo/PdoServiceFactoryTest.php +++ b/test/Repository/Pdo/PdoServiceFactoryTest.php @@ -7,21 +7,22 @@ use Mezzio\Authentication\OAuth2\Exception; use Mezzio\Authentication\OAuth2\Repository\Pdo\PdoService; use Mezzio\Authentication\OAuth2\Repository\Pdo\PdoServiceFactory; +use MezzioTest\Authentication\OAuth2\InMemoryContainer; use PDO; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; -use Psr\Container\ContainerInterface; class PdoServiceFactoryTest extends TestCase { - use ProphecyTrait; + private InMemoryContainer $container; + private PdoServiceFactory $factory; protected function setUp(): void { - $this->container = $this->prophesize(ContainerInterface::class); + $this->container = new InMemoryContainer(); $this->factory = new PdoServiceFactory(); } + /** @return array */ public function invalidConfiguration(): array { // phpcs:disable @@ -42,24 +43,20 @@ public function testRaisesExceptionIfPdoConfigurationIsMissing( bool $hasConfig, array $config, string $expectedMessage - ) { - $this->container->has('config')->willReturn($hasConfig); + ): void { if ($hasConfig) { - $this->container->get('config')->willReturn($config)->shouldBeCalled(); - } else { - $this->container->get('config')->shouldNotBeCalled(); + $this->container->set('config', $config); } $this->expectException(Exception\InvalidConfigException::class); $this->expectExceptionMessage($expectedMessage); - ($this->factory)($this->container->reveal()); + ($this->factory)($this->container); } - public function testValidConfigurationResultsInReturnedPdoServiceInstance() + public function testValidConfigurationResultsInReturnedPdoServiceInstance(): void { - $this->container->has('config')->willReturn(true); - $this->container->get('config')->willReturn([ + $this->container->set('config', [ 'authentication' => [ 'pdo' => [ 'dsn' => 'sqlite::memory:', @@ -67,43 +64,38 @@ public function testValidConfigurationResultsInReturnedPdoServiceInstance() ], ]); - $pdo = ($this->factory)($this->container->reveal()); + $pdo = ($this->factory)($this->container); - $this->assertInstanceOf(PdoService::class, $pdo); + self::assertInstanceOf(PdoService::class, $pdo); } - public function testValidServiceInConfigurationReturnsPdoService() + public function testValidServiceInConfigurationReturnsPdoService(): void { - $mockPdo = $this->prophesize(PDO::class); + $mockPdo = $this->createMock(PDO::class); - $this->container->has('config')->willReturn(true); - $this->container->get('config')->willReturn([ + $this->container->set('config', [ 'authentication' => [ 'pdo' => 'My\Pdo\Service', ], ]); - $this->container->has('My\Pdo\Service')->willReturn(true); - $this->container->get('My\Pdo\Service')->willReturn($mockPdo->reveal()); + $this->container->set('My\Pdo\Service', $mockPdo); - $pdo = ($this->factory)($this->container->reveal()); + $pdo = ($this->factory)($this->container); - $this->assertInstanceOf(PDO::class, $pdo); + self::assertInstanceOf(PDO::class, $pdo); } - public function testRaisesExceptionIfPdoServiceIsInvalid() + public function testRaisesExceptionIfPdoServiceIsInvalid(): void { - $this->container->has('config')->willReturn(true); - $this->container->get('config')->willReturn([ + $this->container->set('config', [ 'authentication' => [ 'pdo' => 'My\Invalid\Service', ], ]); - $this->container->has('My\Invalid\Service')->willReturn(false); - $this->expectException(Exception\InvalidConfigException::class); - ($this->factory)($this->container->reveal()); + ($this->factory)($this->container); } } diff --git a/test/Repository/Pdo/RefreshTokenRepositoryFactoryTest.php b/test/Repository/Pdo/RefreshTokenRepositoryFactoryTest.php index 0bffae06..16259d11 100644 --- a/test/Repository/Pdo/RefreshTokenRepositoryFactoryTest.php +++ b/test/Repository/Pdo/RefreshTokenRepositoryFactoryTest.php @@ -8,29 +8,19 @@ use Mezzio\Authentication\OAuth2\Repository\Pdo\RefreshTokenRepository; use Mezzio\Authentication\OAuth2\Repository\Pdo\RefreshTokenRepositoryFactory; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Psr\Container\ContainerInterface; class RefreshTokenRepositoryFactoryTest extends TestCase { - use ProphecyTrait; - - private ObjectProphecy $container; - - protected function setUp(): void - { - $this->container = $this->prophesize(ContainerInterface::class); - $this->pdo = $this->prophesize(PdoService::class); - } - - public function testFactory() + public function testFactory(): void { - $this->container - ->get(PdoService::class) - ->willReturn($this->pdo->reveal()); - - $factory = (new RefreshTokenRepositoryFactory())($this->container->reveal()); - $this->assertInstanceOf(RefreshTokenRepository::class, $factory); + $container = $this->createMock(ContainerInterface::class); + $container->expects(self::once()) + ->method('get') + ->with(PdoService::class) + ->willReturn($this->createMock(PdoService::class)); + + $factory = (new RefreshTokenRepositoryFactory())($container); + self::assertInstanceOf(RefreshTokenRepository::class, $factory); } } diff --git a/test/Repository/Pdo/RefreshTokenRepositoryTest.php b/test/Repository/Pdo/RefreshTokenRepositoryTest.php index b2fc4d35..6893f8c6 100644 --- a/test/Repository/Pdo/RefreshTokenRepositoryTest.php +++ b/test/Repository/Pdo/RefreshTokenRepositoryTest.php @@ -12,100 +12,114 @@ use Mezzio\Authentication\OAuth2\Repository\Pdo\PdoService; use Mezzio\Authentication\OAuth2\Repository\Pdo\RefreshTokenRepository; use PDOStatement; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; use function date; use function time; class RefreshTokenRepositoryTest extends TestCase { - use ProphecyTrait; + /** @var PdoService&MockObject */ + private PdoService $pdo; + private RefreshTokenRepository $repo; protected function setUp(): void { - $this->pdo = $this->prophesize(PdoService::class); - $this->repo = new RefreshTokenRepository($this->pdo->reveal()); + $this->pdo = $this->createMock(PdoService::class); + $this->repo = new RefreshTokenRepository($this->pdo); } - public function testPersistNewRefreshTokenRaisesExceptionWhenStatementExecutionFails() + public function testPersistNewRefreshTokenRaisesExceptionWhenStatementExecutionFails(): void { - $accessToken = $this->prophesize(AccessTokenEntityInterface::class); - $accessToken->getIdentifier()->willReturn('access_token_id'); + $accessToken = $this->createMock(AccessTokenEntityInterface::class); + $accessToken->expects(self::once()) + ->method('getIdentifier') + ->willReturn('access_token_id'); $time = time(); - $date = $this->prophesize(DateTime::class); - $date->getTimestamp()->willReturn($time); - - $refreshToken = $this->prophesize(RefreshTokenEntityInterface::class); - $refreshToken->getIdentifier()->willReturn('id'); - $refreshToken->getAccessToken()->will([$accessToken, 'reveal']); - $refreshToken->getExpiryDateTime()->will([$date, 'reveal']); - - $statement = $this->prophesize(PDOStatement::class); - $statement->bindValue(':id', 'id')->shouldBeCalled(); - $statement->bindValue(':access_token_id', 'access_token_id')->shouldBeCalled(); - $statement->bindValue(':revoked', 0)->shouldBeCalled(); - $statement->bindValue(':expires_at', date('Y-m-d H:i:s', $time)) - ->shouldBeCalled(); - $statement->execute()->willReturn(false)->shouldBeCalled(); - - $this->pdo - ->prepare(Argument::containingString('INSERT INTO oauth_refresh_tokens')) - ->will([$statement, 'reveal']); + $date = DateTime::createFromFormat('U', (string) $time); + + $refreshToken = $this->createMock(RefreshTokenEntityInterface::class); + $refreshToken->expects(self::once()) + ->method('getIdentifier') + ->willReturn('id'); + $refreshToken->expects(self::once()) + ->method('getAccessToken') + ->willReturn($accessToken); + $refreshToken->expects(self::once()) + ->method('getExpiryDateTime') + ->willReturn($date); + + $statement = $this->createMock(PDOStatement::class); + $statement->expects(self::exactly(4)) + ->method('bindValue') + ->withConsecutive( + [':id', 'id'], + [':access_token_id', 'access_token_id'], + [':revoked', 0], + [':expires_at', date('Y-m-d H:i:s', $time)], + ); + + $statement->expects(self::once())->method('execute')->willReturn(false); + + $this->pdo->expects(self::once()) + ->method('prepare') + ->with(self::stringContains('INSERT INTO oauth_refresh_tokens')) + ->willReturn($statement); $this->expectException(UniqueTokenIdentifierConstraintViolationException::class); - $this->repo->persistNewRefreshToken($refreshToken->reveal()); + $this->repo->persistNewRefreshToken($refreshToken); } - public function testIsRefreshTokenRevokedReturnsFalseWhenStatementFailsExecution() + public function testIsRefreshTokenRevokedReturnsFalseWhenStatementFailsExecution(): void { - $statement = $this->prophesize(PDOStatement::class); - $statement->bindParam(':tokenId', 'token_id')->shouldBeCalled(); - $statement->execute()->willReturn(false)->shouldBeCalled(); - $statement->fetch()->shouldNotBeCalled(); + $statement = $this->createMock(PDOStatement::class); + $statement->expects(self::once())->method('bindParam')->with(':tokenId', 'token_id'); + $statement->expects(self::once())->method('execute')->willReturn(false); + $statement->expects(self::never())->method('fetch'); - $this->pdo - ->prepare(Argument::containingString('SELECT revoked FROM oauth_refresh_tokens')) - ->will([$statement, 'reveal']); + $this->pdo->expects(self::once()) + ->method('prepare') + ->with(self::stringContains('SELECT revoked FROM oauth_refresh_tokens')) + ->willReturn($statement); - $this->assertFalse($this->repo->isRefreshTokenRevoked('token_id')); + self::assertFalse($this->repo->isRefreshTokenRevoked('token_id')); } - public function testIsRefreshTokenRevokedReturnsTrue() + public function testIsRefreshTokenRevokedReturnsTrue(): void { - $statement = $this->prophesize(PDOStatement::class); - $statement->bindParam(':tokenId', 'token_id')->shouldBeCalled(); - $statement->execute()->willReturn(true)->shouldBeCalled(); - $statement->fetch()->willReturn(['revoked' => true]); + $statement = $this->createMock(PDOStatement::class); + $statement->expects(self::once())->method('bindParam')->with(':tokenId', 'token_id'); + $statement->expects(self::once())->method('execute')->willReturn(true); + $statement->expects(self::once())->method('fetch')->willReturn(['revoked' => true]); - $this->pdo - ->prepare(Argument::containingString('SELECT revoked FROM oauth_refresh_tokens')) - ->will([$statement, 'reveal']); + $this->pdo->expects(self::once()) + ->method('prepare') + ->with(self::stringContains('SELECT revoked FROM oauth_refresh_tokens')) + ->willReturn($statement); - $this->assertTrue($this->repo->isRefreshTokenRevoked('token_id')); + self::assertTrue($this->repo->isRefreshTokenRevoked('token_id')); } - public function testGetNewRefreshToken() + public function testGetNewRefreshToken(): void { $result = $this->repo->getNewRefreshToken(); - $this->assertInstanceOf(RefreshTokenEntity::class, $result); + self::assertInstanceOf(RefreshTokenEntity::class, $result); } - public function testRevokeRefreshToken() + public function testRevokeRefreshToken(): void { - $statement = $this->prophesize(PDOStatement::class); - $statement->bindParam(':tokenId', 'token_id')->shouldBeCalled(); - $statement->bindValue(':revoked', 1)->shouldBeCalled(); - $statement->execute()->willReturn(true)->shouldBeCalled(); - $statement->fetch()->shouldNotBeCalled(); - - $this->pdo - ->prepare(Argument::containingString( - 'UPDATE oauth_refresh_tokens SET revoked=:revoked WHERE id = :tokenId' - )) - ->will([$statement, 'reveal']); + $statement = $this->createMock(PDOStatement::class); + $statement->expects(self::once())->method('bindParam')->with(':tokenId', 'token_id'); + $statement->bindValue(':revoked', 1); + $statement->expects(self::once())->method('execute')->willReturn(true); + $statement->expects(self::never())->method('fetch'); + + $this->pdo->expects(self::once()) + ->method('prepare') + ->with(self::stringContains('UPDATE oauth_refresh_tokens SET revoked=:revoked WHERE id = :tokenId')) + ->willReturn($statement); $this->repo->revokeRefreshToken('token_id'); } diff --git a/test/Repository/Pdo/ScopeRepositoryFactoryTest.php b/test/Repository/Pdo/ScopeRepositoryFactoryTest.php index 1d15fbc5..5858d929 100644 --- a/test/Repository/Pdo/ScopeRepositoryFactoryTest.php +++ b/test/Repository/Pdo/ScopeRepositoryFactoryTest.php @@ -8,29 +8,19 @@ use Mezzio\Authentication\OAuth2\Repository\Pdo\ScopeRepository; use Mezzio\Authentication\OAuth2\Repository\Pdo\ScopeRepositoryFactory; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Psr\Container\ContainerInterface; class ScopeRepositoryFactoryTest extends TestCase { - use ProphecyTrait; - - private ObjectProphecy $container; - - protected function setUp(): void - { - $this->container = $this->prophesize(ContainerInterface::class); - $this->pdo = $this->prophesize(PdoService::class); - } - - public function testFactory() + public function testFactory(): void { - $this->container - ->get(PdoService::class) - ->willReturn($this->pdo->reveal()); - - $factory = (new ScopeRepositoryFactory())($this->container->reveal()); - $this->assertInstanceOf(ScopeRepository::class, $factory); + $container = $this->createMock(ContainerInterface::class); + $container->expects(self::once()) + ->method('get') + ->with(PdoService::class) + ->willReturn($this->createMock(PdoService::class)); + + $factory = (new ScopeRepositoryFactory())($container); + self::assertInstanceOf(ScopeRepository::class, $factory); } } diff --git a/test/Repository/Pdo/ScopeRepositoryTest.php b/test/Repository/Pdo/ScopeRepositoryTest.php index a74d7e1f..b46801e8 100644 --- a/test/Repository/Pdo/ScopeRepositoryTest.php +++ b/test/Repository/Pdo/ScopeRepositoryTest.php @@ -9,70 +9,74 @@ use Mezzio\Authentication\OAuth2\Repository\Pdo\PdoService; use Mezzio\Authentication\OAuth2\Repository\Pdo\ScopeRepository; use PDOStatement; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; class ScopeRepositoryTest extends TestCase { - use ProphecyTrait; + /** @var PdoService&MockObject **/ + private PdoService $pdo; + private ScopeRepository $repo; protected function setUp(): void { - $this->pdo = $this->prophesize(PdoService::class); - $this->repo = new ScopeRepository($this->pdo->reveal()); + $this->pdo = $this->createMock(PdoService::class); + $this->repo = new ScopeRepository($this->pdo); } - public function testGetScopeEntityByIdentifierReturnsNullWhenStatementExecutionFails() + public function testGetScopeEntityByIdentifierReturnsNullWhenStatementExecutionFails(): void { - $statement = $this->prophesize(PDOStatement::class); - $statement->bindParam(':identifier', 'id')->shouldBeCalled(); - $statement->execute()->willReturn(false)->shouldBeCalled(); - $statement->fetch()->shouldNotBeCalled(); + $statement = $this->createMock(PDOStatement::class); + $statement->expects(self::once())->method('bindParam')->with(':identifier', 'id'); + $statement->expects(self::once())->method('execute')->willReturn(false); + $statement->expects(self::never())->method('fetch'); - $this->pdo - ->prepare(Argument::containingString('SELECT id FROM oauth_scopes')) - ->will([$statement, 'reveal']); + $this->pdo->expects(self::once()) + ->method('prepare') + ->with(self::stringContains('SELECT id FROM oauth_scopes')) + ->willReturn($statement); - $this->assertNull($this->repo->getScopeEntityByIdentifier('id')); + self::assertNull($this->repo->getScopeEntityByIdentifier('id')); } - public function testGetScopeEntityByIdentifierReturnsNullWhenReturnedRowDoesNotHaveIdentifier() + public function testGetScopeEntityByIdentifierReturnsNullWhenReturnedRowDoesNotHaveIdentifier(): void { - $statement = $this->prophesize(PDOStatement::class); - $statement->bindParam(':identifier', 'id')->shouldBeCalled(); - $statement->execute()->willReturn(true)->shouldBeCalled(); - $statement->fetch()->willReturn([])->shouldBeCalled(); + $statement = $this->createMock(PDOStatement::class); + $statement->expects(self::once())->method('bindParam')->with(':identifier', 'id'); + $statement->expects(self::once())->method('execute')->willReturn(true); + $statement->expects(self::once())->method('fetch')->willReturn([]); - $this->pdo - ->prepare(Argument::containingString('SELECT id FROM oauth_scopes')) - ->will([$statement, 'reveal']); + $this->pdo->expects(self::once()) + ->method('prepare') + ->with(self::stringContains('SELECT id FROM oauth_scopes')) + ->willReturn($statement); - $this->assertNull($this->repo->getScopeEntityByIdentifier('id')); + self::assertNull($this->repo->getScopeEntityByIdentifier('id')); } - public function testGetScopeEntityByIndentifierReturnsScopes() + public function testGetScopeEntityByIndentifierReturnsScopes(): void { - $statement = $this->prophesize(PDOStatement::class); - $statement->bindParam(':identifier', 'id')->shouldBeCalled(); - $statement->execute()->willReturn(true)->shouldBeCalled(); - $statement->fetch()->willReturn([ + $statement = $this->createMock(PDOStatement::class); + $statement->expects(self::once())->method('bindParam')->with(':identifier', 'id'); + $statement->expects(self::once())->method('execute')->willReturn(true); + $statement->expects(self::once())->method('fetch')->willReturn([ 'id' => 'foo', - ])->shouldBeCalled(); + ]); - $this->pdo - ->prepare(Argument::containingString('SELECT id FROM oauth_scopes')) - ->will([$statement, 'reveal']); + $this->pdo->expects(self::once()) + ->method('prepare') + ->with(self::stringContains('SELECT id FROM oauth_scopes')) + ->willReturn($statement); $scope = $this->repo->getScopeEntityByIdentifier('id'); - $this->assertInstanceOf(ScopeEntity::class, $scope); - $this->assertEquals('foo', $scope->getIdentifier()); + self::assertInstanceOf(ScopeEntity::class, $scope); + self::assertEquals('foo', $scope->getIdentifier()); } - public function testFinalizeScopesWithEmptyScopes() + public function testFinalizeScopesWithEmptyScopes(): void { - $clientEntity = $this->prophesize(ClientEntityInterface::class); - $scopes = $this->repo->finalizeScopes([], 'foo', $clientEntity->reveal()); - $this->assertEquals([], $scopes); + $clientEntity = $this->createMock(ClientEntityInterface::class); + $scopes = $this->repo->finalizeScopes([], 'foo', $clientEntity); + self::assertEquals([], $scopes); } } diff --git a/test/Repository/Pdo/UserRepositoryTest.php b/test/Repository/Pdo/UserRepositoryTest.php index d071b529..eee0c5be 100644 --- a/test/Repository/Pdo/UserRepositoryTest.php +++ b/test/Repository/Pdo/UserRepositoryTest.php @@ -9,9 +9,8 @@ use Mezzio\Authentication\OAuth2\Repository\Pdo\PdoService; use Mezzio\Authentication\OAuth2\Repository\Pdo\UserRepository; use PDOStatement; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; use function password_hash; @@ -19,110 +18,112 @@ class UserRepositoryTest extends TestCase { - use ProphecyTrait; + /** @var PdoService&MockObject **/ + private PdoService $pdo; + private UserRepository $repo; protected function setUp(): void { - $this->pdo = $this->prophesize(PdoService::class); - $this->repo = new UserRepository($this->pdo->reveal()); + $this->pdo = $this->createMock(PdoService::class); + $this->repo = new UserRepository($this->pdo); } - public function testGetUserEntityByCredentialsReturnsNullIfStatementExecutionReturnsFalse() + public function testGetUserEntityByCredentialsReturnsNullIfStatementExecutionReturnsFalse(): void { - $statement = $this->prophesize(PDOStatement::class); - $statement->bindParam(':username', 'username')->shouldBeCalled(); - $statement->execute()->willReturn(false); + $statement = $this->createMock(PDOStatement::class); + $statement->expects(self::once())->method('bindParam')->with(':username', 'username'); + $statement->expects(self::once())->method('execute')->willReturn(false); - $this->pdo - ->prepare(Argument::containingString('SELECT password FROM oauth_users')) - ->will([$statement, 'reveal']); + $this->pdo->expects(self::once()) + ->method('prepare') + ->with(self::stringContains('SELECT password FROM oauth_users')) + ->willReturn($statement); - $client = $this->prophesize(ClientEntityInterface::class); + $client = $this->createMock(ClientEntityInterface::class); - $this->assertNull( + self::assertNull( $this->repo->getUserEntityByUserCredentials( 'username', 'password', 'auth', - $client->reveal() + $client ) ); } - public function testGetUserEntityByCredentialsReturnsNullIfPasswordVerificationFails() + public function testGetUserEntityByCredentialsReturnsNullIfPasswordVerificationFails(): void { - $statement = $this->prophesize(PDOStatement::class); - $statement->bindParam(':username', 'username')->shouldBeCalled(); - $statement->execute()->will(function () use ($statement): bool { - $statement->fetch()->willReturn([ - 'password' => 'not-the-same-password', - ]); - return true; - }); - - $this->pdo - ->prepare(Argument::containingString('SELECT password FROM oauth_users')) - ->will([$statement, 'reveal']); - - $client = $this->prophesize(ClientEntityInterface::class); - - $this->assertNull( + $statement = $this->createMock(PDOStatement::class); + $statement->expects(self::once())->method('bindParam')->with(':username', 'username'); + $statement->expects(self::once())->method('execute')->willReturn(true); + $statement->expects(self::once())->method('fetch')->willReturn([ + 'password' => 'not-the-same-password', + ]); + + $this->pdo->expects(self::once()) + ->method('prepare') + ->with(self::stringContains('SELECT password FROM oauth_users')) + ->willReturn($statement); + + $client = $this->createMock(ClientEntityInterface::class); + + self::assertNull( $this->repo->getUserEntityByUserCredentials( 'username', 'password', 'auth', - $client->reveal() + $client ) ); } - public function testGetUserEntityByCredentialsReturnsNullIfUserIsNotFound() + public function testGetUserEntityByCredentialsReturnsNullIfUserIsNotFound(): void { - $statement = $this->prophesize(PDOStatement::class); - $statement->bindParam(':username', 'username')->shouldBeCalled(); - $statement->execute()->will(function () use ($statement): bool { - $statement->fetch()->willReturn(null); - return true; - }); + $statement = $this->createMock(PDOStatement::class); + $statement->expects(self::once())->method('bindParam')->with(':username', 'username'); + $statement->expects(self::once())->method('execute')->willReturn(true); + $statement->expects(self::once())->method('fetch')->willReturn(null); - $this->pdo - ->prepare(Argument::containingString('SELECT password FROM oauth_users')) - ->will([$statement, 'reveal']); + $this->pdo->expects(self::once()) + ->method('prepare') + ->with(self::stringContains('SELECT password FROM oauth_users')) + ->willReturn($statement); - $client = $this->prophesize(ClientEntityInterface::class); + $client = $this->createMock(ClientEntityInterface::class); - $this->assertNull( + self::assertNull( $this->repo->getUserEntityByUserCredentials( 'username', 'password', 'auth', - $client->reveal() + $client ) ); } - public function testGetUserEntityByCredentialsReturnsEntity() + public function testGetUserEntityByCredentialsReturnsEntity(): void { - $statement = $this->prophesize(PDOStatement::class); - $statement->bindParam(':username', 'username')->shouldBeCalled(); - $statement->execute()->willReturn(true); - $statement->fetch()->willReturn([ + $statement = $this->createMock(PDOStatement::class); + $statement->expects(self::once())->method('bindParam')->with(':username', 'username'); + $statement->expects(self::once())->method('execute')->willReturn(true); + $statement->expects(self::once())->method('fetch')->willReturn([ 'password' => password_hash('password', PASSWORD_DEFAULT), ]); - $this->pdo - ->prepare(Argument::containingString('SELECT password FROM oauth_users WHERE username = :username')) - ->will([$statement, 'reveal']); + $this->pdo->expects(self::once()) + ->method('prepare') + ->with(self::stringContains('SELECT password FROM oauth_users WHERE username = :username')) + ->willReturn($statement); - $client = $this->prophesize(ClientEntityInterface::class); + $client = $this->createMock(ClientEntityInterface::class); $entity = $this->repo->getUserEntityByUserCredentials( 'username', 'password', 'auth', - $client->reveal() + $client ); - $this->assertInstanceOf(UserEntity::class, $entity); - $this->assertEquals('username', $entity->getIdentifier()); + self::assertInstanceOf(UserEntity::class, $entity); + self::assertEquals('username', $entity->getIdentifier()); } } diff --git a/test/RepositoryTraitTest.php b/test/RepositoryTraitTest.php index ba83f06e..5d6c0083 100644 --- a/test/RepositoryTraitTest.php +++ b/test/RepositoryTraitTest.php @@ -14,12 +14,12 @@ use Mezzio\Authentication\OAuth2\Exception; use Mezzio\Authentication\OAuth2\RepositoryTrait; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; use Psr\Container\ContainerInterface; class RepositoryTraitTest extends TestCase { - use ProphecyTrait; + private object $trait; + private InMemoryContainer $container; protected function setUp(): void { @@ -31,144 +31,100 @@ public function proxy(string $name, ContainerInterface $container): RepositoryIn return $this->$name($container); } }; - $this->container = $this->prophesize(ContainerInterface::class); + $this->container = new InMemoryContainer(); } - public function testGetUserRepositoryWithoutService() + public function testGetUserRepositoryWithoutService(): void { - $this->container - ->has(UserRepositoryInterface::class) - ->willReturn(false); - $this->expectException(Exception\InvalidConfigException::class); - $this->trait->proxy('getUserRepository', $this->container->reveal()); + $this->trait->proxy('getUserRepository', $this->container); } - public function testGetUserRepository() + public function testGetUserRepository(): void { - $this->container - ->has(UserRepositoryInterface::class) - ->willReturn(true); - $this->container - ->get(UserRepositoryInterface::class) - ->willReturn($this->prophesize(UserRepositoryInterface::class)->reveal()); - - $result = $this->trait->proxy('getUserRepository', $this->container->reveal()); - $this->assertInstanceOf(UserRepositoryInterface::class, $result); + $this->container->set(UserRepositoryInterface::class, $this->createMock(UserRepositoryInterface::class)); + $result = $this->trait->proxy('getUserRepository', $this->container); + self::assertInstanceOf(UserRepositoryInterface::class, $result); } - public function testGetScopeRepositoryWithoutService() + public function testGetScopeRepositoryWithoutService(): void { - $this->container - ->has(ScopeRepositoryInterface::class) - ->willReturn(false); - $this->expectException(Exception\InvalidConfigException::class); - $this->trait->proxy('getScopeRepository', $this->container->reveal()); + $this->trait->proxy('getScopeRepository', $this->container); } - public function testGetScopeRepository() + public function testGetScopeRepository(): void { - $this->container - ->has(ScopeRepositoryInterface::class) - ->willReturn(true); - $this->container - ->get(ScopeRepositoryInterface::class) - ->willReturn($this->prophesize(ScopeRepositoryInterface::class)->reveal()); - - $result = $this->trait->proxy('getScopeRepository', $this->container->reveal()); - $this->assertInstanceOf(ScopeRepositoryInterface::class, $result); + $this->container->set(ScopeRepositoryInterface::class, $this->createMock(ScopeRepositoryInterface::class)); + $result = $this->trait->proxy('getScopeRepository', $this->container); + self::assertInstanceOf(ScopeRepositoryInterface::class, $result); } - public function testGetAccessTokenRepositoryWithoutService() + public function testGetAccessTokenRepositoryWithoutService(): void { - $this->container - ->has(AccessTokenRepositoryInterface::class) - ->willReturn(false); - $this->expectException(Exception\InvalidConfigException::class); - $this->trait->proxy('getAccessTokenRepository', $this->container->reveal()); + $this->trait->proxy('getAccessTokenRepository', $this->container); } - public function testGetAccessTokenRepository() + public function testGetAccessTokenRepository(): void { - $this->container - ->has(AccessTokenRepositoryInterface::class) - ->willReturn(true); - $this->container - ->get(AccessTokenRepositoryInterface::class) - ->willReturn($this->prophesize(AccessTokenRepositoryInterface::class)->reveal()); - - $result = $this->trait->proxy('getAccessTokenRepository', $this->container->reveal()); - $this->assertInstanceOf(AccessTokenRepositoryInterface::class, $result); + $this->container->set( + AccessTokenRepositoryInterface::class, + $this->createMock(AccessTokenRepositoryInterface::class) + ); + + $result = $this->trait->proxy('getAccessTokenRepository', $this->container); + self::assertInstanceOf(AccessTokenRepositoryInterface::class, $result); } - public function testGetClientRepositoryWithoutService() + public function testGetClientRepositoryWithoutService(): void { - $this->container - ->has(ClientRepositoryInterface::class) - ->willReturn(false); - $this->expectException(Exception\InvalidConfigException::class); - $this->trait->proxy('getClientRepository', $this->container->reveal()); + $this->trait->proxy('getClientRepository', $this->container); } - public function testGetClientRepository() + public function testGetClientRepository(): void { - $this->container - ->has(ClientRepositoryInterface::class) - ->willReturn(true); - $this->container - ->get(ClientRepositoryInterface::class) - ->willReturn($this->prophesize(ClientRepositoryInterface::class)->reveal()); - - $result = $this->trait->proxy('getClientRepository', $this->container->reveal()); - $this->assertInstanceOf(ClientRepositoryInterface::class, $result); + $this->container->set( + ClientRepositoryInterface::class, + $this->createMock(ClientRepositoryInterface::class) + ); + + $result = $this->trait->proxy('getClientRepository', $this->container); + self::assertInstanceOf(ClientRepositoryInterface::class, $result); } - public function testGetRefreshTokenRepositoryWithoutService() + public function testGetRefreshTokenRepositoryWithoutService(): void { - $this->container - ->has(RefreshTokenRepositoryInterface::class) - ->willReturn(false); - $this->expectException(Exception\InvalidConfigException::class); - $this->trait->proxy('getRefreshTokenRepository', $this->container->reveal()); + $this->trait->proxy('getRefreshTokenRepository', $this->container); } - public function testGetRefreshTokenRepository() + public function testGetRefreshTokenRepository(): void { - $this->container - ->has(RefreshTokenRepositoryInterface::class) - ->willReturn(true); - $this->container - ->get(RefreshTokenRepositoryInterface::class) - ->willReturn($this->prophesize(RefreshTokenRepositoryInterface::class)->reveal()); - - $result = $this->trait->proxy('getRefreshTokenRepository', $this->container->reveal()); - $this->assertInstanceOf(RefreshTokenRepositoryInterface::class, $result); + $this->container->set( + RefreshTokenRepositoryInterface::class, + $this->createMock(RefreshTokenRepositoryInterface::class), + ); + + $result = $this->trait->proxy('getRefreshTokenRepository', $this->container); + self::assertInstanceOf(RefreshTokenRepositoryInterface::class, $result); } - public function testGetAuthCodeRepositoryWithoutService() + public function testGetAuthCodeRepositoryWithoutService(): void { - $this->container - ->has(AuthCodeRepositoryInterface::class) - ->willReturn(false); - $this->expectException(Exception\InvalidConfigException::class); - $this->trait->proxy('getAuthCodeRepository', $this->container->reveal()); + $this->trait->proxy('getAuthCodeRepository', $this->container); } - public function testGetAuthCodeRepository() + public function testGetAuthCodeRepository(): void { - $this->container - ->has(AuthCodeRepositoryInterface::class) - ->willReturn(true); - $this->container - ->get(AuthCodeRepositoryInterface::class) - ->willReturn($this->prophesize(AuthCodeRepositoryInterface::class)->reveal()); - - $result = $this->trait->proxy('getAuthCodeRepository', $this->container->reveal()); - $this->assertInstanceOf(AuthCodeRepositoryInterface::class, $result); + $this->container->set( + AuthCodeRepositoryInterface::class, + $this->createMock(AuthCodeRepositoryInterface::class), + ); + + $result = $this->trait->proxy('getAuthCodeRepository', $this->container); + self::assertInstanceOf(AuthCodeRepositoryInterface::class, $result); } } diff --git a/test/ResourceServerFactoryTest.php b/test/ResourceServerFactoryTest.php index 2464edfc..6adafd1d 100644 --- a/test/ResourceServerFactoryTest.php +++ b/test/ResourceServerFactoryTest.php @@ -10,13 +10,9 @@ use Mezzio\Authentication\OAuth2\Exception; use Mezzio\Authentication\OAuth2\ResourceServerFactory; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; -use Psr\Container\ContainerInterface; class ResourceServerFactoryTest extends TestCase { - use ProphecyTrait; - private const PUBLIC_KEY = __DIR__ . '/TestAsset/public.key'; private const PUBLIC_KEY_EXTENDED = [ @@ -25,67 +21,60 @@ class ResourceServerFactoryTest extends TestCase 'key_permissions_check' => false, ]; + private InMemoryContainer $container; + protected function setUp(): void { - $this->container = $this->prophesize(ContainerInterface::class); + $this->container = new InMemoryContainer(); } - public function testConstructor() + public function testConstructor(): void { $factory = new ResourceServerFactory(); - $this->assertInstanceOf(ResourceServerFactory::class, $factory); + self::assertInstanceOf(ResourceServerFactory::class, $factory); } - public function testInvokeWithEmptyConfig() + public function testInvokeWithEmptyConfig(): void { - $this->container->has('config')->willReturn(true); - $this->container->get('config')->willReturn([]); + $this->container->set('config', []); $factory = new ResourceServerFactory(); $this->expectException(Exception\InvalidConfigException::class); - $factory($this->container->reveal()); + $factory($this->container); } - public function testInvokeWithConfigWithoutRepository() + public function testInvokeWithConfigWithoutRepository(): void { - $this->container->has('config')->willReturn(true); - $this->container->get('config')->willReturn([ + $this->container->set('config', [ 'authentication' => [ 'public_key' => self::PUBLIC_KEY, ], ]); - $this->container - ->has(AccessTokenRepositoryInterface::class) - ->willReturn(false); $factory = new ResourceServerFactory(); $this->expectException(Exception\InvalidConfigException::class); - $factory($this->container->reveal()); + $factory($this->container); } - public function testInvokeWithConfigAndRepository() + public function testInvokeWithConfigAndRepository(): void { - $this->container->has('config')->willReturn(true); - $this->container->get('config')->willReturn([ + $this->container->set('config', [ 'authentication' => [ 'public_key' => self::PUBLIC_KEY, ], ]); - $this->container - ->has(AccessTokenRepositoryInterface::class) - ->willReturn(true); - $this->container - ->get(AccessTokenRepositoryInterface::class) - ->willReturn( - $this->prophesize(AccessTokenRepositoryInterface::class)->reveal() - ); + $this->container->set( + AccessTokenRepositoryInterface::class, + $this->createMock(AccessTokenRepositoryInterface::class) + ); $factory = new ResourceServerFactory(); - $resourceServer = $factory($this->container->reveal()); - $this->assertInstanceOf(ResourceServer::class, $resourceServer); + $resourceServer = $factory($this->container); + self::assertInstanceOf(ResourceServer::class, $resourceServer); } + /** @return Generator */ public function getExtendedKeyConfigs(): Generator { $extendedConfig = self::PUBLIC_KEY_EXTENDED; @@ -102,28 +91,24 @@ public function getExtendedKeyConfigs(): Generator /** * @dataProvider getExtendedKeyConfigs */ - public function testInvokeWithValidExtendedKey(array $keyConfig) + public function testInvokeWithValidExtendedKey(array $keyConfig): void { - $this->container->has('config')->willReturn(true); - $this->container->get('config')->willReturn([ + $this->container->set('config', [ 'authentication' => [ 'public_key' => $keyConfig, ], ]); - $this->container - ->has(AccessTokenRepositoryInterface::class) - ->willReturn(true); - $this->container - ->get(AccessTokenRepositoryInterface::class) - ->willReturn( - $this->prophesize(AccessTokenRepositoryInterface::class)->reveal() - ); + $this->container->set( + AccessTokenRepositoryInterface::class, + $this->createMock(AccessTokenRepositoryInterface::class) + ); $factory = new ResourceServerFactory(); - $resourceServer = $factory($this->container->reveal()); - $this->assertInstanceOf(ResourceServer::class, $resourceServer); + $resourceServer = $factory($this->container); + self::assertInstanceOf(ResourceServer::class, $resourceServer); } + /** @return Generator */ public function getInvalidExtendedKeyConfigs(): Generator { $extendedConfig = self::PUBLIC_KEY_EXTENDED; @@ -135,26 +120,21 @@ public function getInvalidExtendedKeyConfigs(): Generator /** * @dataProvider getInvalidExtendedKeyConfigs */ - public function testInvokeWithInvalidExtendedKey(array $keyConfig) + public function testInvokeWithInvalidExtendedKey(array $keyConfig): void { - $this->container->has('config')->willReturn(true); - $this->container->get('config')->willReturn([ + $this->container->set('config', [ 'authentication' => [ 'public_key' => $keyConfig, ], ]); - $this->container - ->has(AccessTokenRepositoryInterface::class) - ->willReturn(true); - $this->container - ->get(AccessTokenRepositoryInterface::class) - ->willReturn( - $this->prophesize(AccessTokenRepositoryInterface::class)->reveal() - ); + $this->container->set( + AccessTokenRepositoryInterface::class, + $this->createMock(AccessTokenRepositoryInterface::class) + ); $factory = new ResourceServerFactory(); $this->expectException(Exception\InvalidConfigException::class); - $factory($this->container->reveal()); + $factory($this->container); } } diff --git a/test/TokenEndpointHandlerFactoryTest.php b/test/TokenEndpointHandlerFactoryTest.php index 871055bd..a3e1ef49 100644 --- a/test/TokenEndpointHandlerFactoryTest.php +++ b/test/TokenEndpointHandlerFactoryTest.php @@ -5,11 +5,10 @@ namespace MezzioTest\Authentication\OAuth2; use League\OAuth2\Server\AuthorizationServer; +use Mezzio\Authentication\OAuth2\TokenEndpointHandler; use Mezzio\Authentication\OAuth2\TokenEndpointHandlerFactory; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; -use Psr\Container\ContainerInterface; -use Psr\Http\Message\ResponseFactoryInterface; +use Psr\Container\NotFoundExceptionInterface; use Psr\Http\Message\ResponseInterface; use TypeError; @@ -18,8 +17,6 @@ */ class TokenEndpointHandlerFactoryTest extends TestCase { - use ProphecyTrait; - private TokenEndpointHandlerFactory $subject; protected function setUp(): void @@ -28,53 +25,28 @@ protected function setUp(): void parent::setUp(); } - public function testEmptyContainerThrowsTypeError() + public function testEmptyContainerThrowsServiceNotFound(): void { - $container = $this->prophesize(ContainerInterface::class); - - $this->expectException(TypeError::class); - ($this->subject)($container); + $this->expectException(NotFoundExceptionInterface::class); + ($this->subject)(new InMemoryContainer()); } - public function testCreatesTokenEndpointHandler() + public function testCreatesTokenEndpointHandler(): void { - $server = $this->prophesize(AuthorizationServer::class); - $responseFactory = static function (): void { - }; - $container = $this->prophesize(ContainerInterface::class); + $container = new InMemoryContainer(); + $container->set(AuthorizationServer::class, $this->createMock(AuthorizationServer::class)); + $container->set(ResponseInterface::class, static fn () => null); - $container - ->has(ResponseFactoryInterface::class) - ->willReturn(false) - ->shouldBeCalledOnce(); - $container - ->get(AuthorizationServer::class) - ->willReturn($server->reveal()) - ->shouldBeCalledOnce(); - $container - ->get(ResponseInterface::class) - ->willReturn($responseFactory) - ->shouldBeCalledOnce(); - - ($this->subject)($container->reveal()); + self::assertInstanceOf(TokenEndpointHandler::class, ($this->subject)($container)); } - public function testDirectResponseInstanceFromContainerThrowsTypeError() + public function testDirectResponseInstanceFromContainerThrowsTypeError(): void { - $server = $this->prophesize(AuthorizationServer::class); - $container = $this->prophesize(ContainerInterface::class); - - $container - ->has(ResponseFactoryInterface::class) - ->willReturn(false); - $container - ->get(AuthorizationServer::class) - ->willReturn($server->reveal()); - $container - ->get(ResponseInterface::class) - ->willReturn($this->prophesize(ResponseInterface::class)->reveal()); + $container = new InMemoryContainer(); + $container->set(AuthorizationServer::class, $this->createMock(AuthorizationServer::class)); + $container->set(ResponseInterface::class, $this->createMock(ResponseInterface::class)); $this->expectException(TypeError::class); - ($this->subject)($container->reveal()); + ($this->subject)($container); } } diff --git a/test/TokenEndpointHandlerTest.php b/test/TokenEndpointHandlerTest.php index add1b9a7..1604f0aa 100644 --- a/test/TokenEndpointHandlerTest.php +++ b/test/TokenEndpointHandlerTest.php @@ -9,8 +9,6 @@ use Mezzio\Authentication\OAuth2\Exception\RuntimeException; use Mezzio\Authentication\OAuth2\TokenEndpointHandler; use PHPUnit\Framework\TestCase; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; @@ -19,8 +17,7 @@ */ class TokenEndpointHandlerTest extends TestCase { - use ProphecyTrait; - + /** @return callable(): ResponseInterface */ private function createResponseFactory(?ResponseInterface $response = null): callable { return function () use ($response): ResponseInterface { @@ -33,58 +30,62 @@ private function createResponseFactory(?ResponseInterface $response = null): cal }; } - public function testHandleUsesAuthorizationServer() + public function testHandleUsesAuthorizationServer(): void { - $server = $this->prophesize(AuthorizationServer::class); - $request = $this->prophesize(ServerRequestInterface::class); + $server = $this->createMock(AuthorizationServer::class); + $request = $this->createMock(ServerRequestInterface::class); $response = $this->createMock(ResponseInterface::class); $response ->method('withStatus') ->willReturnSelf(); $expectedResponse = $response; - $server->respondToAccessTokenRequest($request->reveal(), $expectedResponse) - ->shouldBeCalled() + $server->expects(self::once()) + ->method('respondToAccessTokenRequest') + ->with($request, $expectedResponse) ->willReturn($expectedResponse); - $subject = new TokenEndpointHandler($server->reveal(), $this->createResponseFactory($expectedResponse)); - self::assertSame($expectedResponse, $subject->handle($request->reveal())); + $subject = new TokenEndpointHandler($server, $this->createResponseFactory($expectedResponse)); + self::assertSame($expectedResponse, $subject->handle($request)); } - public function testOAuthExceptionProducesResult() + public function testOAuthExceptionProducesResult(): void { - $server = $this->prophesize(AuthorizationServer::class); - $request = $this->prophesize(ServerRequestInterface::class); + $server = $this->createMock(AuthorizationServer::class); + $request = $this->createMock(ServerRequestInterface::class); $response = $this->createMock(ResponseInterface::class); $response ->method('withStatus') ->willReturnSelf(); - $exception = $this->prophesize(OAuthServerException::class); + $exception = $this->createMock(OAuthServerException::class); $expectedResponse = $response; - $server->respondToAccessTokenRequest(Argument::cetera()) - ->willThrow($exception->reveal()); + $server->expects(self::once()) + ->method('respondToAccessTokenRequest') + ->willThrowException($exception); - $exception->generateHttpResponse($expectedResponse, Argument::cetera()) - ->shouldBeCalled() + $exception->expects(self::once()) + ->method('generateHttpResponse') + ->with($expectedResponse) ->willReturn($expectedResponse); - $subject = new TokenEndpointHandler($server->reveal(), $this->createResponseFactory($expectedResponse)); - self::assertSame($expectedResponse, $subject->handle($request->reveal())); + $subject = new TokenEndpointHandler($server, $this->createResponseFactory($expectedResponse)); + self::assertSame($expectedResponse, $subject->handle($request)); } - public function testGenericExceptionsFallsThrough() + public function testGenericExceptionsFallsThrough(): void { - $server = $this->prophesize(AuthorizationServer::class); - $request = $this->prophesize(ServerRequestInterface::class); + $server = $this->createMock(AuthorizationServer::class); + $request = $this->createMock(ServerRequestInterface::class); $exception = new RuntimeException(); - $server->respondToAccessTokenRequest(Argument::cetera()) - ->willThrow($exception); + $server->expects(self::once()) + ->method('respondToAccessTokenRequest') + ->willThrowException($exception); - $subject = new TokenEndpointHandler($server->reveal(), $this->createResponseFactory()); + $subject = new TokenEndpointHandler($server, $this->createResponseFactory()); $this->expectException(RuntimeException::class); - $subject->handle($request->reveal()); + $subject->handle($request); } }