diff --git a/.editorconfig b/.editorconfig index f650ee2..b885d53 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,7 +12,7 @@ charset = utf-8 [*.php] indent_size = 4 -[{*.yml,$.yaml}] +[{*.yml,*.yaml}] indent_size = 4 [docs/**openapi.yml] diff --git a/composer.json b/composer.json index 1804c4c..2d33570 100644 --- a/composer.json +++ b/composer.json @@ -24,9 +24,11 @@ "behat/symfony2-extension": "^2.1", "friendsofphp/php-cs-fixer": "^2.16", "nelmio/cors-bundle": "^2.1", + "nyholm/psr7": "^1.3", "phpspec/prophecy-phpunit": "^2.0", "phpunit/phpunit": "^9.4", "symfony/phpunit-bridge": "^5.1", + "symfony/psr-http-message-bridge": "^2.0", "symfony/web-profiler-bundle": "4.4.*", "wiremock-php/wiremock-php": "^2.27" }, diff --git a/composer.lock b/composer.lock index 1d1f029..677ff62 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a68e0bb44d3b8d743a52061d73c9e53c", + "content-hash": "45f262c7ff707204cedc9ca5b9e604d0", "packages": [ { "name": "doctrine/annotations", - "version": "1.10.4", + "version": "1.11.0", "source": { "type": "git", "url": "https://github.com/doctrine/annotations.git", - "reference": "bfe91e31984e2ba76df1c1339681770401ec262f" + "reference": "88fb6fb1dae011de24dd6b632811c1ff5c2928f5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/annotations/zipball/bfe91e31984e2ba76df1c1339681770401ec262f", - "reference": "bfe91e31984e2ba76df1c1339681770401ec262f", + "url": "https://api.github.com/repos/doctrine/annotations/zipball/88fb6fb1dae011de24dd6b632811c1ff5c2928f5", + "reference": "88fb6fb1dae011de24dd6b632811c1ff5c2928f5", "shasum": "" }, "require": { @@ -27,13 +27,14 @@ }, "require-dev": { "doctrine/cache": "1.*", + "doctrine/coding-standard": "^6.0 || ^8.1", "phpstan/phpstan": "^0.12.20", "phpunit/phpunit": "^7.5 || ^9.1.5" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.9.x-dev" + "dev-master": "1.11.x-dev" } }, "autoload": { @@ -68,13 +69,13 @@ } ], "description": "Docblock Annotations Parser", - "homepage": "http://www.doctrine-project.org", + "homepage": "https://www.doctrine-project.org/projects/annotations.html", "keywords": [ "annotations", "docblock", "parser" ], - "time": "2020-08-10T19:35:50+00:00" + "time": "2020-10-17T22:05:33+00:00" }, { "name": "doctrine/cache", @@ -239,33 +240,32 @@ }, { "name": "doctrine/dbal", - "version": "2.11.1", + "version": "2.12.0", "source": { "type": "git", "url": "https://github.com/doctrine/dbal.git", - "reference": "6e6903cd5e3a5be60a79439e3ee8fe126f78fe86" + "reference": "c6d37b4c42aaa3c3ee175f05eca68056f4185646" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/dbal/zipball/6e6903cd5e3a5be60a79439e3ee8fe126f78fe86", - "reference": "6e6903cd5e3a5be60a79439e3ee8fe126f78fe86", + "url": "https://api.github.com/repos/doctrine/dbal/zipball/c6d37b4c42aaa3c3ee175f05eca68056f4185646", + "reference": "c6d37b4c42aaa3c3ee175f05eca68056f4185646", "shasum": "" }, "require": { "doctrine/cache": "^1.0", "doctrine/event-manager": "^1.0", "ext-pdo": "*", - "php": "^7.3" + "php": "^7.3 || ^8" }, "require-dev": { "doctrine/coding-standard": "^8.1", "jetbrains/phpstorm-stubs": "^2019.1", - "nikic/php-parser": "^4.4", "phpstan/phpstan": "^0.12.40", - "phpunit/phpunit": "^9.3", + "phpunit/phpunit": "^9.4", "psalm/plugin-phpunit": "^0.10.0", "symfony/console": "^2.0.5|^3.0|^4.0|^5.0", - "vimeo/psalm": "^3.14.2" + "vimeo/psalm": "^3.17.2" }, "suggest": { "symfony/console": "For helpful console commands such as SQL execution and import of files." @@ -343,7 +343,7 @@ "type": "tidelift" } ], - "time": "2020-09-27T04:09:41+00:00" + "time": "2020-10-22T17:26:24+00:00" }, { "name": "doctrine/doctrine-bundle", @@ -2919,16 +2919,16 @@ }, { "name": "symfony/polyfill-intl-idn", - "version": "v1.18.1", + "version": "v1.19.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-idn.git", - "reference": "5dcab1bc7146cf8c1beaa4502a3d9be344334251" + "reference": "4ad5115c0f5d5172a9fe8147675ec6de266d8826" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/5dcab1bc7146cf8c1beaa4502a3d9be344334251", - "reference": "5dcab1bc7146cf8c1beaa4502a3d9be344334251", + "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/4ad5115c0f5d5172a9fe8147675ec6de266d8826", + "reference": "4ad5115c0f5d5172a9fe8147675ec6de266d8826", "shasum": "" }, "require": { @@ -2943,7 +2943,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.18-dev" + "dev-main": "1.19-dev" }, "thanks": { "name": "symfony/polyfill", @@ -3000,20 +3000,20 @@ "type": "tidelift" } ], - "time": "2020-08-04T06:02:08+00:00" + "time": "2020-10-21T09:57:48+00:00" }, { "name": "symfony/polyfill-intl-normalizer", - "version": "v1.18.1", + "version": "v1.19.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-normalizer.git", - "reference": "37078a8dd4a2a1e9ab0231af7c6cb671b2ed5a7e" + "reference": "8db0ae7936b42feb370840cf24de1a144fb0ef27" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/37078a8dd4a2a1e9ab0231af7c6cb671b2ed5a7e", - "reference": "37078a8dd4a2a1e9ab0231af7c6cb671b2ed5a7e", + "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/8db0ae7936b42feb370840cf24de1a144fb0ef27", + "reference": "8db0ae7936b42feb370840cf24de1a144fb0ef27", "shasum": "" }, "require": { @@ -3025,7 +3025,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.18-dev" + "dev-main": "1.19-dev" }, "thanks": { "name": "symfony/polyfill", @@ -3081,20 +3081,20 @@ "type": "tidelift" } ], - "time": "2020-07-14T12:35:20+00:00" + "time": "2020-10-23T09:01:57+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.18.1", + "version": "v1.19.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "a6977d63bf9a0ad4c65cd352709e230876f9904a" + "reference": "b5f7b932ee6fa802fc792eabd77c4c88084517ce" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/a6977d63bf9a0ad4c65cd352709e230876f9904a", - "reference": "a6977d63bf9a0ad4c65cd352709e230876f9904a", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/b5f7b932ee6fa802fc792eabd77c4c88084517ce", + "reference": "b5f7b932ee6fa802fc792eabd77c4c88084517ce", "shasum": "" }, "require": { @@ -3106,7 +3106,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.18-dev" + "dev-main": "1.19-dev" }, "thanks": { "name": "symfony/polyfill", @@ -3158,20 +3158,20 @@ "type": "tidelift" } ], - "time": "2020-07-14T12:35:20+00:00" + "time": "2020-10-23T09:01:57+00:00" }, { "name": "symfony/polyfill-php72", - "version": "v1.18.1", + "version": "v1.19.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php72.git", - "reference": "639447d008615574653fb3bc60d1986d7172eaae" + "reference": "beecef6b463b06954638f02378f52496cb84bacc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/639447d008615574653fb3bc60d1986d7172eaae", - "reference": "639447d008615574653fb3bc60d1986d7172eaae", + "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/beecef6b463b06954638f02378f52496cb84bacc", + "reference": "beecef6b463b06954638f02378f52496cb84bacc", "shasum": "" }, "require": { @@ -3180,7 +3180,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.18-dev" + "dev-main": "1.19-dev" }, "thanks": { "name": "symfony/polyfill", @@ -3231,20 +3231,20 @@ "type": "tidelift" } ], - "time": "2020-07-14T12:35:20+00:00" + "time": "2020-10-23T09:01:57+00:00" }, { "name": "symfony/polyfill-php73", - "version": "v1.18.1", + "version": "v1.19.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php73.git", - "reference": "fffa1a52a023e782cdcc221d781fe1ec8f87fcca" + "reference": "9d920e3218205554171b2503bb3e4a1366824a16" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/fffa1a52a023e782cdcc221d781fe1ec8f87fcca", - "reference": "fffa1a52a023e782cdcc221d781fe1ec8f87fcca", + "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/9d920e3218205554171b2503bb3e4a1366824a16", + "reference": "9d920e3218205554171b2503bb3e4a1366824a16", "shasum": "" }, "require": { @@ -3253,7 +3253,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.18-dev" + "dev-main": "1.19-dev" }, "thanks": { "name": "symfony/polyfill", @@ -3307,20 +3307,20 @@ "type": "tidelift" } ], - "time": "2020-07-14T12:35:20+00:00" + "time": "2020-10-23T09:01:57+00:00" }, { "name": "symfony/polyfill-php80", - "version": "v1.18.1", + "version": "v1.19.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "d87d5766cbf48d72388a9f6b85f280c8ad51f981" + "reference": "f54ef00f4678f348f133097fa8c3701d197ff44d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/d87d5766cbf48d72388a9f6b85f280c8ad51f981", - "reference": "d87d5766cbf48d72388a9f6b85f280c8ad51f981", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/f54ef00f4678f348f133097fa8c3701d197ff44d", + "reference": "f54ef00f4678f348f133097fa8c3701d197ff44d", "shasum": "" }, "require": { @@ -3329,7 +3329,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.18-dev" + "dev-main": "1.19-dev" }, "thanks": { "name": "symfony/polyfill", @@ -3387,7 +3387,7 @@ "type": "tidelift" } ], - "time": "2020-07-14T12:35:20+00:00" + "time": "2020-10-23T09:01:57+00:00" }, { "name": "symfony/routing", @@ -4262,16 +4262,16 @@ }, { "name": "composer/xdebug-handler", - "version": "1.4.3", + "version": "1.4.4", "source": { "type": "git", "url": "https://github.com/composer/xdebug-handler.git", - "reference": "ebd27a9866ae8254e873866f795491f02418c5a5" + "reference": "6e076a124f7ee146f2487554a94b6a19a74887ba" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/ebd27a9866ae8254e873866f795491f02418c5a5", - "reference": "ebd27a9866ae8254e873866f795491f02418c5a5", + "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/6e076a124f7ee146f2487554a94b6a19a74887ba", + "reference": "6e076a124f7ee146f2487554a94b6a19a74887ba", "shasum": "" }, "require": { @@ -4316,7 +4316,7 @@ "type": "tidelift" } ], - "time": "2020-08-19T10:27:58+00:00" + "time": "2020-10-24T12:39:10+00:00" }, { "name": "doctrine/instantiator", @@ -4648,6 +4648,79 @@ ], "time": "2020-09-26T10:30:38+00:00" }, + { + "name": "nyholm/psr7", + "version": "1.3.1", + "source": { + "type": "git", + "url": "https://github.com/Nyholm/psr7.git", + "reference": "21b71a31eab5c0c2caf967b9c0fd97020254ed75" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Nyholm/psr7/zipball/21b71a31eab5c0c2caf967b9c0fd97020254ed75", + "reference": "21b71a31eab5c0c2caf967b9c0fd97020254ed75", + "shasum": "" + }, + "require": { + "php": ">=7.1", + "php-http/message-factory": "^1.0", + "psr/http-factory": "^1.0", + "psr/http-message": "^1.0" + }, + "provide": { + "psr/http-factory-implementation": "1.0", + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "http-interop/http-factory-tests": "dev-master", + "php-http/psr7-integration-tests": "^1.0", + "phpunit/phpunit": "^7.5", + "symfony/error-handler": "^4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "Nyholm\\Psr7\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com" + }, + { + "name": "Martijn van der Ven", + "email": "martijn@vanderven.se" + } + ], + "description": "A fast PHP7 implementation of PSR-7", + "homepage": "http://tnyholm.se", + "keywords": [ + "psr-17", + "psr-7" + ], + "funding": [ + { + "url": "https://github.com/Zegnat", + "type": "github" + }, + { + "url": "https://github.com/nyholm", + "type": "github" + } + ], + "time": "2020-06-13T15:59:10+00:00" + }, { "name": "phar-io/manifest", "version": "2.0.1", @@ -4802,6 +4875,56 @@ ], "time": "2020-10-14T08:39:05+00:00" }, + { + "name": "php-http/message-factory", + "version": "v1.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-http/message-factory.git", + "reference": "a478cb11f66a6ac48d8954216cfed9aa06a501a1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-http/message-factory/zipball/a478cb11f66a6ac48d8954216cfed9aa06a501a1", + "reference": "a478cb11f66a6ac48d8954216cfed9aa06a501a1", + "shasum": "" + }, + "require": { + "php": ">=5.4", + "psr/http-message": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com" + } + ], + "description": "Factory interfaces for PSR-7 HTTP Message", + "homepage": "http://php-http.org", + "keywords": [ + "factory", + "http", + "message", + "stream", + "uri" + ], + "time": "2015-12-19T14:08:53+00:00" + }, { "name": "phpdocumentor/reflection-common", "version": "2.2.0", @@ -5359,16 +5482,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.4.1", + "version": "9.4.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "1f09a12726593737e8a228ebb1c8647305d07c41" + "reference": "3866b2eeeed21b1b099c4bc0b7a1690ac6fd5baa" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1f09a12726593737e8a228ebb1c8647305d07c41", - "reference": "1f09a12726593737e8a228ebb1c8647305d07c41", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3866b2eeeed21b1b099c4bc0b7a1690ac6fd5baa", + "reference": "3866b2eeeed21b1b099c4bc0b7a1690ac6fd5baa", "shasum": "" }, "require": { @@ -5454,7 +5577,59 @@ "type": "github" } ], - "time": "2020-10-11T07:41:19+00:00" + "time": "2020-10-19T09:23:29+00:00" + }, + { + "name": "psr/http-factory", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-factory.git", + "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-factory/zipball/12ac7fcd07e5b077433f5f2bee95b3a771bf61be", + "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be", + "shasum": "" + }, + "require": { + "php": ">=7.0.0", + "psr/http-message": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interfaces for PSR-7 HTTP message factories", + "keywords": [ + "factory", + "http", + "message", + "psr", + "psr-17", + "psr-7", + "request", + "response" + ], + "time": "2019-04-30T12:38:16+00:00" }, { "name": "sebastian/cli-parser", @@ -6569,6 +6744,84 @@ ], "time": "2020-09-02T16:08:58+00:00" }, + { + "name": "symfony/psr-http-message-bridge", + "version": "v2.0.2", + "source": { + "type": "git", + "url": "https://github.com/symfony/psr-http-message-bridge.git", + "reference": "51a21cb3ba3927d4b4bf8f25cc55763351af5f2e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/psr-http-message-bridge/zipball/51a21cb3ba3927d4b4bf8f25cc55763351af5f2e", + "reference": "51a21cb3ba3927d4b4bf8f25cc55763351af5f2e", + "shasum": "" + }, + "require": { + "php": ">=7.1", + "psr/http-message": "^1.0", + "symfony/http-foundation": "^4.4 || ^5.0" + }, + "require-dev": { + "nyholm/psr7": "^1.1", + "symfony/phpunit-bridge": "^4.4 || ^5.0" + }, + "suggest": { + "nyholm/psr7": "For a super lightweight PSR-7/17 implementation" + }, + "type": "symfony-bridge", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Bridge\\PsrHttpMessage\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "PSR HTTP message bridge", + "homepage": "http://symfony.com", + "keywords": [ + "http", + "http-message", + "psr-17", + "psr-7" + ], + "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": "2020-09-29T08:17:46+00:00" + }, { "name": "symfony/stopwatch", "version": "v4.4.15", @@ -7132,16 +7385,16 @@ }, { "name": "twig/twig", - "version": "v3.0.5", + "version": "v3.1.0", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "9b76b1535483cdf4edf01bb787b0217b62bd68a5" + "reference": "9a29e1fa7b5431969f96878b8662e3fcb18601b7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/9b76b1535483cdf4edf01bb787b0217b62bd68a5", - "reference": "9b76b1535483cdf4edf01bb787b0217b62bd68a5", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/9a29e1fa7b5431969f96878b8662e3fcb18601b7", + "reference": "9a29e1fa7b5431969f96878b8662e3fcb18601b7", "shasum": "" }, "require": { @@ -7156,7 +7409,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-master": "3.1-dev" } }, "autoload": { @@ -7200,7 +7453,7 @@ "type": "tidelift" } ], - "time": "2020-08-05T15:13:19+00:00" + "time": "2020-10-21T12:45:34+00:00" }, { "name": "wiremock-php/wiremock-php", diff --git a/config/packages/test/psr_http_message_bridge.yaml b/config/packages/test/psr_http_message_bridge.yaml new file mode 100644 index 0000000..6db2d42 --- /dev/null +++ b/config/packages/test/psr_http_message_bridge.yaml @@ -0,0 +1,15 @@ +services: + + Nyholm\Psr7\Factory\Psr17Factory: + # Allows getting it in tests + public: true + + Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface: + class: 'Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory' + Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface: + class: 'Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory' + arguments: + - '@Nyholm\Psr7\Factory\Psr17Factory' + - '@Nyholm\Psr7\Factory\Psr17Factory' + - '@Nyholm\Psr7\Factory\Psr17Factory' + - '@Nyholm\Psr7\Factory\Psr17Factory' diff --git a/config/packages/test/services.yaml b/config/packages/test/services.yaml index 7301ee3..7116159 100644 --- a/config/packages/test/services.yaml +++ b/config/packages/test/services.yaml @@ -8,6 +8,9 @@ services: # See docker-compose.yml arguments: ['wiremock', '8080'] + App\Psr7Kernel\Psr7KernelAdapter: + autowire: true + # Mark Secondary Ports (Hexagonal Architecture meaning) public to allow mocking them in behat tests # To be done in config/services.yml if concrete class, or in config/packages/test/services.yml if Interface App\Domain\WeatherProvider: ~ diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index 1a016bf..ed07ec1 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -4,19 +4,19 @@ use App\Domain\RunningSessionRepository; use App\Domain\WeatherProvider; use App\Infrastructure\Symfony\Serializer\RegisterRunningSessionDeserializerTest; +use App\Psr7Kernel\Psr7KernelTestTrait; use Behat\Behat\Context\Context; use PHPUnit\Framework\Assert; use Prophecy\Prophecy\ObjectProphecy; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; +use Psr\Http\Message\ResponseInterface; use Symfony\Component\HttpKernel\KernelInterface; class FeatureContext implements Context { use BehatProphecyTrait; + use Psr7KernelTestTrait; - private KernelInterface $kernel; - private ?Response $response; + private ?ResponseInterface $response; /** @var ObjectProphecy|WeatherProvider */ private $weatherProvider; /** @var ObjectProphecy|RunningSessionRepository */ @@ -24,7 +24,7 @@ class FeatureContext implements Context public function __construct(KernelInterface $kernel) { - $this->kernel = $kernel; + $this->initPsr7Kernel($kernel->getContainer()); $this->weatherProvider = $this->prophesize(WeatherProvider::class); $kernel->getContainer()->set(WeatherProvider::class, $this->weatherProvider->reveal()); @@ -49,9 +49,12 @@ public function currentTemperatureIs($temperature) public function iRegisterARunningSessionWith($id, $distance, $shoes) { $body = RegisterRunningSessionDeserializerTest::createBody($id, $distance, $shoes); - $request = Request::create('/runningsessions/'.$id, 'PUT', [], [], [], [], $body); + $request = $this->psr17Factory + ->createServerRequest('PUT', '/runningsessions/'.$id) + ->withHeader('Content-Type', 'application/json') + ->withBody($this->psr17Factory->createStream($body)); - $this->response = $this->kernel->handle($request); + $this->response = $this->psr7Kernel->handleOrThrow($request); } /** diff --git a/symfony.lock b/symfony.lock index d6c772a..c9d52d5 100644 --- a/symfony.lock +++ b/symfony.lock @@ -122,6 +122,18 @@ "nikic/php-parser": { "version": "v4.10.2" }, + "nyholm/psr7": { + "version": "1.0", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "master", + "version": "1.0", + "ref": "7c0a9352a57376f04f5444e74565102c3a23d0c7" + }, + "files": [ + "config/packages/nyholm_psr7.yaml" + ] + }, "phar-io/manifest": { "version": "2.0.1" }, @@ -134,6 +146,9 @@ "php-cs-fixer/diff": { "version": "v1.3.1" }, + "php-http/message-factory": { + "version": "v1.0.2" + }, "phpdocumentor/reflection-common": { "version": "2.2.0" }, @@ -187,6 +202,9 @@ "psr/http-client": { "version": "1.0.1" }, + "psr/http-factory": { + "version": "1.0.1" + }, "psr/http-message": { "version": "1.0.1" }, @@ -377,6 +395,9 @@ "symfony/process": { "version": "v4.4.15" }, + "symfony/psr-http-message-bridge": { + "version": "v2.0.2" + }, "symfony/routing": { "version": "4.2", "recipe": { diff --git a/tests/Infrastructure/Symfony/Controller/RunningSessionControllerTest.php b/tests/Infrastructure/Symfony/Controller/RunningSessionControllerTest.php index 44e556e..f0eaaa9 100644 --- a/tests/Infrastructure/Symfony/Controller/RunningSessionControllerTest.php +++ b/tests/Infrastructure/Symfony/Controller/RunningSessionControllerTest.php @@ -8,17 +8,18 @@ use App\Application\Command\RegisterRunningSessionHandler; use App\Domain\RunningSessionFactory; use App\Infrastructure\Symfony\Serializer\RegisterRunningSessionDeserializerTest; +use App\Psr7Kernel\Psr7KernelTestTrait; use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\HttpKernelInterface; class RunningSessionControllerTest extends KernelTestCase { use ProphecyTrait; + use Psr7KernelTestTrait; /** @var ObjectProphecy|RegisterRunningSessionHandler */ private $registerRunningSessionHandler; @@ -26,6 +27,7 @@ class RunningSessionControllerTest extends KernelTestCase protected function setUp(): void { self::bootKernel(); + $this->initPsr7Kernel(self::$kernel->getContainer()); $this->registerRunningSessionHandler = $this->prophesize(RegisterRunningSessionHandler::class); self::$container->set(RegisterRunningSessionHandler::class, $this->registerRunningSessionHandler->reveal()); @@ -38,7 +40,11 @@ public function testPutRouteSendsCommandToHandlerAndDisplayItsResult() //When (Act) $body = RegisterRunningSessionDeserializerTest::createBody(42); - $response = $this->whenISendThisRequest(Request::create('/runningsessions/42', 'PUT', [], [], [], [], $body)); + $response = $this->whenISendThisRequest($this->psr17Factory + ->createServerRequest('PUT', '/runningsessions/42') + ->withHeader('Content-Type', 'application/json') + ->withBody($this->psr17Factory->createStream($body)) + ); //Then (Assert) //less strict assertion (type only): see RegisterRunningSessionDeserializer for conversion from json to command object @@ -46,7 +52,7 @@ public function testPutRouteSendsCommandToHandlerAndDisplayItsResult() //less strict assertion: See RunningSessionSerializerTest for json response creation self::assertSame(201, $response->getStatusCode()); - self::assertSame('application/json', $response->headers->get('Content-Type')); + self::assertSame('application/json', $response->getHeaderLine('Content-Type')); } private function givenHandlerResponseIsARunningSession() @@ -56,10 +62,9 @@ private function givenHandlerResponseIsARunningSession() ->willReturn(RunningSessionFactory::create()); } - private function whenISendThisRequest(Request $request): Response + private function whenISendThisRequest(ServerRequestInterface $psr7ServerRequest): ResponseInterface { - //$catch=false: prevents Symfony from catching exceptions - return self::$kernel->handle($request, HttpKernelInterface::MASTER_REQUEST, false); + return $this->psr7Kernel->handleOrThrow($psr7ServerRequest); } private function thenARegisterRunningSessionCommandHasBeenSentToHandler() diff --git a/tests/Psr7Kernel/Psr7KernelAdapter.php b/tests/Psr7Kernel/Psr7KernelAdapter.php new file mode 100644 index 0000000..610adc8 --- /dev/null +++ b/tests/Psr7Kernel/Psr7KernelAdapter.php @@ -0,0 +1,48 @@ +symfonyKernel = $symfonyKernel; + $this->symfonyRequestFactory = $symfonyRequestFactory; + $this->psr7ResponseFactory = $psr7ResponseFactory; + } + + /** + * @throws \Exception To let tests fail or expect specific exceptions + */ + public function handleOrThrow(ServerRequestInterface $psr7ServerRequest): ResponseInterface + { + // See https://symfony.com/doc/4.4/components/psr7.html#converting-objects-implementing-psr-7-interfaces-to-httpfoundation + $symfonyRequest = $this->symfonyRequestFactory->createRequest($psr7ServerRequest); + + $catchExceptions = false; + $symfonyResponse = $this->symfonyKernel + ->handle($symfonyRequest, HttpKernelInterface::MASTER_REQUEST, $catchExceptions); + + // See https://symfony.com/doc/4.4/components/psr7.html#converting-from-httpfoundation-objects-to-psr-7 + return $this->psr7ResponseFactory->createResponse($symfonyResponse); + } +} diff --git a/tests/Psr7Kernel/Psr7KernelTestTrait.php b/tests/Psr7Kernel/Psr7KernelTestTrait.php new file mode 100644 index 0000000..19e8161 --- /dev/null +++ b/tests/Psr7Kernel/Psr7KernelTestTrait.php @@ -0,0 +1,27 @@ +psr17Factory = $container->get(Psr17Factory::class); + $this->psr7Kernel = $container->get(Psr7KernelAdapter::class); + } +}