Skip to content

Commit 513c7e9

Browse files
authored
Update codebase to PHP 7.4 (#12)
1 parent 7539f8d commit 513c7e9

6 files changed

Lines changed: 32 additions & 85 deletions

File tree

.github/workflows/main.yml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88

99
strategy:
1010
matrix:
11-
php: [7.3, 7.4, 8.0]
11+
php: [7.4, 8.0, 8.1]
1212

1313
steps:
1414
- name: Checkout code
@@ -27,17 +27,13 @@ jobs:
2727
path: framework-tests
2828
submodules: recursive
2929

30-
- name: Downgrade to composer v1
31-
if: matrix.php < 7.4
32-
run: composer self-update --1
33-
3430
- name: Install Mezzio Sample on PHP 7
3531
if: matrix.php < 8
3632
run: composer update --no-dev --prefer-dist --no-interaction
3733
working-directory: framework-tests
3834

3935
- name: Install Mezzio Sample on PHP 8
40-
if: matrix.php == 8.0
36+
if: matrix.php >= 8.0
4137
run: composer update --no-dev --prefer-dist --no-interaction --ignore-platform-req=php
4238
working-directory: framework-tests
4339

@@ -49,10 +45,8 @@ jobs:
4945
run: composer install --prefer-dist --no-progress --no-interaction --no-suggest
5046

5147
- name: Install dependencies on PHP 8
52-
if: matrix.php == 8.0
48+
if: matrix.php >= 8
5349
run: composer install --prefer-dist --no-progress --no-interaction --ignore-platform-req=php
5450

5551
- name: Run test suite
56-
run: |
57-
php vendor/bin/codecept build -c framework-tests
58-
php vendor/bin/codecept run functional -c framework-tests
52+
run: php vendor/bin/codecept run functional -c framework-tests

composer.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
],
1313
"minimum-stability": "RC",
1414
"require": {
15-
"php": "^7.3 || ^8.0",
15+
"php": "^7.4 || ^8.0",
1616
"codeception/lib-innerbrowser": "^1.0",
17-
"codeception/codeception": "^4.0"
17+
"codeception/codeception": "^4.0",
18+
"container-interop/container-interop": "^1.2",
19+
"laminas/laminas-diactoros": "^1.8.7",
20+
"mezzio/mezzio": "^3.0"
1821
},
1922
"require-dev": {
20-
"codeception/module-rest": "^1.0",
21-
"mezzio/mezzio": "^3.0"
23+
"codeception/module-rest": "^1.0"
2224
},
2325
"autoload": {
2426
"classmap": [

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ A Codeception module for Mezzio framework.
99

1010
## Requirements
1111

12-
* `PHP 7.3` or higher.
12+
* `PHP 7.4` or higher.
1313

1414
## Installation
1515

src/Codeception/Lib/Connector/Mezzio.php

Lines changed: 10 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,22 @@
55
namespace Codeception\Lib\Connector;
66

77
use Codeception\Configuration;
8-
use Codeception\Lib\Connector\Mezzio\ResponseCollector;
98
use Exception;
109
use Interop\Container\ContainerInterface;
11-
use Symfony\Component\BrowserKit\AbstractBrowser as Client;
12-
use Symfony\Component\BrowserKit\Response;
13-
use Symfony\Component\BrowserKit\Request as BrowserKitRequest;
1410
use Laminas\Diactoros\ServerRequest;
15-
use Mezzio\Application;
1611
use Laminas\Diactoros\UploadedFile;
12+
use Mezzio\Application;
13+
use Symfony\Component\BrowserKit\AbstractBrowser as Client;
14+
use Symfony\Component\BrowserKit\Request as BrowserKitRequest;
15+
use Symfony\Component\BrowserKit\Response;
1716

1817
class Mezzio extends Client
1918
{
19+
private Application $application;
2020

21-
/**
22-
* @var Application
23-
*/
24-
private $application;
25-
/**
26-
* @var ResponseCollector
27-
*/
28-
private $responseCollector;
29-
30-
/**
31-
* @var ContainerInterface
32-
*/
33-
private $container;
21+
private ContainerInterface $container;
3422

35-
/**
36-
* @var array Configuration of the module
37-
*/
38-
private $config;
23+
private array $config;
3924

4025
/**
4126
* @param BrowserKitRequest $request
@@ -65,15 +50,13 @@ public function doRequest($request)
6550
//required by WhoopsErrorHandler
6651
$serverParams['SCRIPT_NAME'] = 'Codeception';
6752
}
68-
53+
6954
$cookies = $request->getCookies();
7055
$headers = $this->extractHeaders($request);
7156

7257
//set cookie header because dflydev/fig-cookies reads cookies from header
7358
if (!empty($cookies)) {
74-
$headers['cookie'] = implode(';', array_map(function ($key, $value) {
75-
return "$key=$value";
76-
}, array_keys($cookies), $cookies));
59+
$headers['cookie'] = implode(';', array_map(fn($key, $value) => "$key=$value", array_keys($cookies), $cookies));
7760
}
7861

7962
$mezzioRequest = new ServerRequest(
@@ -99,15 +82,7 @@ public function doRequest($request)
9982
$application = $this->application;
10083
}
10184

102-
if (method_exists($application, 'handle')) {
103-
// Mezzio v3
104-
$response = $application->handle($mezzioRequest);
105-
} else {
106-
//Older versions
107-
$application->run($mezzioRequest);
108-
$response = $this->responseCollector->getResponse();
109-
$this->responseCollector->clearResponse();
110-
}
85+
$response = $application->handle($mezzioRequest);
11186

11287
chdir($cwd);
11388

@@ -189,30 +164,9 @@ public function initApplication(): Application
189164

190165
$this->application = $app;
191166

192-
$this->initResponseCollector();
193-
194167
return $app;
195168
}
196169

197-
private function initResponseCollector(): void
198-
{
199-
if (!method_exists($this->application, 'getEmitter')) {
200-
//Does not exist in Mezzio v3
201-
return;
202-
}
203-
204-
/**
205-
* @var Mezzio\Emitter\EmitterStack
206-
*/
207-
$emitterStack = $this->application->getEmitter();
208-
while (!$emitterStack->isEmpty()) {
209-
$emitterStack->pop();
210-
}
211-
212-
$this->responseCollector = new ResponseCollector;
213-
$emitterStack->unshift($this->responseCollector);
214-
}
215-
216170
public function getContainer(): ContainerInterface
217171
{
218172
return $this->container;
@@ -221,7 +175,6 @@ public function getContainer(): ContainerInterface
221175
public function setApplication(Application $application): void
222176
{
223177
$this->application = $application;
224-
$this->initResponseCollector();
225178
}
226179

227180
public function setConfig(array $config): void

src/Codeception/Lib/Connector/Mezzio/ResponseCollector.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,25 @@
44

55
namespace Codeception\Lib\Connector\Mezzio;
66

7+
use Laminas\Diactoros\Response\EmitterInterface;
78
use LogicException;
89
use Psr\Http\Message\ResponseInterface;
9-
use Laminas\Diactoros\Response\EmitterInterface;
1010

1111
class ResponseCollector implements EmitterInterface
1212
{
13-
/**
14-
* @var ResponseInterface
15-
*/
16-
private $response;
13+
private ?ResponseInterface $response = null;
1714

18-
public function emit(ResponseInterface $response)
15+
public function emit(ResponseInterface $response): void
1916
{
2017
$this->response = $response;
2118
}
2219

2320
public function getResponse(): ResponseInterface
2421
{
2522
if ($this->response === null) {
26-
throw new LogicException('Response wasn\'t emitted yet');
23+
throw new LogicException("Response wasn't emitted yet");
2724
}
25+
2826
return $this->response;
2927
}
3028

src/Codeception/Module/Mezzio.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
namespace Codeception\Module;
66

7-
use Codeception\Lib\Framework;
8-
use Codeception\TestInterface;
97
use Codeception\Lib\Connector\Mezzio as MezzioConnector;
8+
use Codeception\Lib\Framework;
109
use Codeception\Lib\Interfaces\DoctrineProvider;
10+
use Codeception\TestInterface;
11+
use Interop\Container\ContainerInterface;
12+
use Mezzio\Application;
1113

1214
/**
1315
* This module allows you to run tests inside Mezzio.
@@ -49,16 +51,14 @@ class Mezzio extends Framework implements DoctrineProvider
4951
public $client;
5052

5153
/**
52-
* @var \Interop\Container\ContainerInterface
5354
* @deprecated Doesn't work as expected if Application is recreated between requests
5455
*/
55-
public $container;
56+
public ContainerInterface $container;
5657

5758
/**
58-
* @var \Mezzio\Application
5959
* @deprecated Doesn't work as expected if Application is recreated between requests
6060
*/
61-
public $application;
61+
public Application $application;
6262

6363
public function _initialize()
6464
{

0 commit comments

Comments
 (0)