From 247717406904e3a80551c2aa0e388ef055db6168 Mon Sep 17 00:00:00 2001 From: TavoNiievez Date: Thu, 21 Oct 2021 22:23:44 -0500 Subject: [PATCH 1/2] Update codebase to PHP 7.4 --- .github/workflows/main.yml | 14 ++++--------- composer.json | 6 ++++-- readme.md | 2 +- src/Codeception/Lib/Connector/Mezzio.php | 20 ++++--------------- .../Connector/Mezzio/ResponseCollector.php | 10 ++++------ src/Codeception/Module/Mezzio.php | 8 ++++---- 6 files changed, 21 insertions(+), 39 deletions(-) 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..1c29660f 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" }, "require-dev": { "codeception/module-rest": "^1.0", - "mezzio/mezzio": "^3.0" + "mezzio/mezzio": "^3.0", + "laminas/laminas-diactoros": "^1.8.7", + "container-interop/container-interop": "^1.2" }, "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..273d749e 100644 --- a/src/Codeception/Lib/Connector/Mezzio.php +++ b/src/Codeception/Lib/Connector/Mezzio.php @@ -17,25 +17,13 @@ class Mezzio extends Client { + private Application $application; - /** - * @var Application - */ - private $application; - /** - * @var ResponseCollector - */ - private $responseCollector; + private ResponseCollector $responseCollector; - /** - * @var ContainerInterface - */ - private $container; + private ContainerInterface $container; - /** - * @var array Configuration of the module - */ - private $config; + private array $config; /** * @param BrowserKitRequest $request diff --git a/src/Codeception/Lib/Connector/Mezzio/ResponseCollector.php b/src/Codeception/Lib/Connector/Mezzio/ResponseCollector.php index fd0dc373..88afda63 100644 --- a/src/Codeception/Lib/Connector/Mezzio/ResponseCollector.php +++ b/src/Codeception/Lib/Connector/Mezzio/ResponseCollector.php @@ -10,12 +10,9 @@ 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..21b29a04 100644 --- a/src/Codeception/Module/Mezzio.php +++ b/src/Codeception/Module/Mezzio.php @@ -8,6 +8,8 @@ use Codeception\TestInterface; use Codeception\Lib\Connector\Mezzio as MezzioConnector; use Codeception\Lib\Interfaces\DoctrineProvider; +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() { From f05f81301775ca261dea2730113e45a545a7c639 Mon Sep 17 00:00:00 2001 From: TavoNiievez Date: Tue, 30 Nov 2021 19:12:00 -0500 Subject: [PATCH 2/2] Update code standards --- composer.json | 10 ++-- src/Codeception/Lib/Connector/Mezzio.php | 49 +++---------------- .../Connector/Mezzio/ResponseCollector.php | 2 +- src/Codeception/Module/Mezzio.php | 4 +- 4 files changed, 15 insertions(+), 50 deletions(-) diff --git a/composer.json b/composer.json index 1c29660f..4b008eeb 100644 --- a/composer.json +++ b/composer.json @@ -14,13 +14,13 @@ "require": { "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", - "laminas/laminas-diactoros": "^1.8.7", - "container-interop/container-interop": "^1.2" + "codeception/module-rest": "^1.0" }, "autoload": { "classmap": [ diff --git a/src/Codeception/Lib/Connector/Mezzio.php b/src/Codeception/Lib/Connector/Mezzio.php index 273d749e..7207cf30 100644 --- a/src/Codeception/Lib/Connector/Mezzio.php +++ b/src/Codeception/Lib/Connector/Mezzio.php @@ -5,22 +5,19 @@ 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; - private ResponseCollector $responseCollector; - private ContainerInterface $container; private array $config; @@ -53,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( @@ -87,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); @@ -177,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; @@ -209,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 88afda63..82f6b5a5 100644 --- a/src/Codeception/Lib/Connector/Mezzio/ResponseCollector.php +++ b/src/Codeception/Lib/Connector/Mezzio/ResponseCollector.php @@ -4,9 +4,9 @@ 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 { diff --git a/src/Codeception/Module/Mezzio.php b/src/Codeception/Module/Mezzio.php index 21b29a04..aa4c5b9c 100644 --- a/src/Codeception/Module/Mezzio.php +++ b/src/Codeception/Module/Mezzio.php @@ -4,10 +4,10 @@ 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;