Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ A Codeception module for Mezzio framework.

## Requirements

* `PHP 7.3` or higher.
* `PHP 7.4` or higher.

## Installation

Expand Down
67 changes: 10 additions & 57 deletions src/Codeception/Lib/Connector/Mezzio.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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);

Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down
12 changes: 5 additions & 7 deletions src/Codeception/Lib/Connector/Mezzio/ResponseCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,25 @@

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;
}

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;
}

Expand Down
12 changes: 6 additions & 6 deletions src/Codeception/Module/Mezzio.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
{
Expand Down