diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b7ff38ce..3531691a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: - php: [7.3, 7.4, 8.0] + php: [7.4, 8.0, 8.1] steps: - name: Checkout code @@ -27,17 +27,13 @@ jobs: path: framework-tests submodules: recursive - - name: Downgrade to composer v1 - if: matrix.php < 7.4 - run: composer self-update --1 - - name: Install Mezzio Sample on PHP 7 if: matrix.php < 8 run: composer update --no-dev --prefer-dist --no-interaction working-directory: framework-tests - name: Install Mezzio Sample on PHP 8 - if: matrix.php == 8.0 + if: matrix.php >= 8.0 run: composer update --no-dev --prefer-dist --no-interaction --ignore-platform-req=php working-directory: framework-tests @@ -49,10 +45,8 @@ jobs: run: composer install --prefer-dist --no-progress --no-interaction --no-suggest - name: Install dependencies on PHP 8 - if: matrix.php == 8.0 + if: matrix.php >= 8 run: composer install --prefer-dist --no-progress --no-interaction --ignore-platform-req=php - name: Run test suite - run: | - php vendor/bin/codecept build -c framework-tests - php vendor/bin/codecept run functional -c framework-tests + run: php vendor/bin/codecept run functional -c framework-tests diff --git a/composer.json b/composer.json index 13f1f503..4b008eeb 100644 --- a/composer.json +++ b/composer.json @@ -12,13 +12,15 @@ ], "minimum-stability": "RC", "require": { - "php": "^7.3 || ^8.0", + "php": "^7.4 || ^8.0", "codeception/lib-innerbrowser": "^1.0", - "codeception/codeception": "^4.0" + "codeception/codeception": "^4.0", + "container-interop/container-interop": "^1.2", + "laminas/laminas-diactoros": "^1.8.7", + "mezzio/mezzio": "^3.0" }, "require-dev": { - "codeception/module-rest": "^1.0", - "mezzio/mezzio": "^3.0" + "codeception/module-rest": "^1.0" }, "autoload": { "classmap": [ diff --git a/readme.md b/readme.md index 6c47d2b0..7636bde7 100644 --- a/readme.md +++ b/readme.md @@ -9,7 +9,7 @@ A Codeception module for Mezzio framework. ## Requirements -* `PHP 7.3` or higher. +* `PHP 7.4` or higher. ## Installation diff --git a/src/Codeception/Lib/Connector/Mezzio.php b/src/Codeception/Lib/Connector/Mezzio.php index 36411d68..7207cf30 100644 --- a/src/Codeception/Lib/Connector/Mezzio.php +++ b/src/Codeception/Lib/Connector/Mezzio.php @@ -5,37 +5,22 @@ namespace Codeception\Lib\Connector; use Codeception\Configuration; -use Codeception\Lib\Connector\Mezzio\ResponseCollector; use Exception; use Interop\Container\ContainerInterface; -use Symfony\Component\BrowserKit\AbstractBrowser as Client; -use Symfony\Component\BrowserKit\Response; -use Symfony\Component\BrowserKit\Request as BrowserKitRequest; use Laminas\Diactoros\ServerRequest; -use Mezzio\Application; use Laminas\Diactoros\UploadedFile; +use Mezzio\Application; +use Symfony\Component\BrowserKit\AbstractBrowser as Client; +use Symfony\Component\BrowserKit\Request as BrowserKitRequest; +use Symfony\Component\BrowserKit\Response; class Mezzio extends Client { + private Application $application; - /** - * @var Application - */ - private $application; - /** - * @var ResponseCollector - */ - private $responseCollector; - - /** - * @var ContainerInterface - */ - private $container; + private ContainerInterface $container; - /** - * @var array Configuration of the module - */ - private $config; + private array $config; /** * @param BrowserKitRequest $request @@ -65,15 +50,13 @@ public function doRequest($request) //required by WhoopsErrorHandler $serverParams['SCRIPT_NAME'] = 'Codeception'; } - + $cookies = $request->getCookies(); $headers = $this->extractHeaders($request); //set cookie header because dflydev/fig-cookies reads cookies from header if (!empty($cookies)) { - $headers['cookie'] = implode(';', array_map(function ($key, $value) { - return "$key=$value"; - }, array_keys($cookies), $cookies)); + $headers['cookie'] = implode(';', array_map(fn($key, $value) => "$key=$value", array_keys($cookies), $cookies)); } $mezzioRequest = new ServerRequest( @@ -99,15 +82,7 @@ public function doRequest($request) $application = $this->application; } - if (method_exists($application, 'handle')) { - // Mezzio v3 - $response = $application->handle($mezzioRequest); - } else { - //Older versions - $application->run($mezzioRequest); - $response = $this->responseCollector->getResponse(); - $this->responseCollector->clearResponse(); - } + $response = $application->handle($mezzioRequest); chdir($cwd); @@ -189,30 +164,9 @@ public function initApplication(): Application $this->application = $app; - $this->initResponseCollector(); - return $app; } - private function initResponseCollector(): void - { - if (!method_exists($this->application, 'getEmitter')) { - //Does not exist in Mezzio v3 - return; - } - - /** - * @var Mezzio\Emitter\EmitterStack - */ - $emitterStack = $this->application->getEmitter(); - while (!$emitterStack->isEmpty()) { - $emitterStack->pop(); - } - - $this->responseCollector = new ResponseCollector; - $emitterStack->unshift($this->responseCollector); - } - public function getContainer(): ContainerInterface { return $this->container; @@ -221,7 +175,6 @@ public function getContainer(): ContainerInterface public function setApplication(Application $application): void { $this->application = $application; - $this->initResponseCollector(); } public function setConfig(array $config): void diff --git a/src/Codeception/Lib/Connector/Mezzio/ResponseCollector.php b/src/Codeception/Lib/Connector/Mezzio/ResponseCollector.php index fd0dc373..82f6b5a5 100644 --- a/src/Codeception/Lib/Connector/Mezzio/ResponseCollector.php +++ b/src/Codeception/Lib/Connector/Mezzio/ResponseCollector.php @@ -4,18 +4,15 @@ namespace Codeception\Lib\Connector\Mezzio; +use Laminas\Diactoros\Response\EmitterInterface; use LogicException; use Psr\Http\Message\ResponseInterface; -use Laminas\Diactoros\Response\EmitterInterface; class ResponseCollector implements EmitterInterface { - /** - * @var ResponseInterface - */ - private $response; + private ?ResponseInterface $response = null; - public function emit(ResponseInterface $response) + public function emit(ResponseInterface $response): void { $this->response = $response; } @@ -23,8 +20,9 @@ public function emit(ResponseInterface $response) public function getResponse(): ResponseInterface { if ($this->response === null) { - throw new LogicException('Response wasn\'t emitted yet'); + throw new LogicException("Response wasn't emitted yet"); } + return $this->response; } diff --git a/src/Codeception/Module/Mezzio.php b/src/Codeception/Module/Mezzio.php index bd00489a..aa4c5b9c 100644 --- a/src/Codeception/Module/Mezzio.php +++ b/src/Codeception/Module/Mezzio.php @@ -4,10 +4,12 @@ namespace Codeception\Module; -use Codeception\Lib\Framework; -use Codeception\TestInterface; use Codeception\Lib\Connector\Mezzio as MezzioConnector; +use Codeception\Lib\Framework; use Codeception\Lib\Interfaces\DoctrineProvider; +use Codeception\TestInterface; +use Interop\Container\ContainerInterface; +use Mezzio\Application; /** * This module allows you to run tests inside Mezzio. @@ -49,16 +51,14 @@ class Mezzio extends Framework implements DoctrineProvider public $client; /** - * @var \Interop\Container\ContainerInterface * @deprecated Doesn't work as expected if Application is recreated between requests */ - public $container; + public ContainerInterface $container; /** - * @var \Mezzio\Application * @deprecated Doesn't work as expected if Application is recreated between requests */ - public $application; + public Application $application; public function _initialize() {