Skip to content

Commit

Permalink
Merge pull request #22 from Codeception/codecept5
Browse files Browse the repository at this point in the history
Support Codeception 5
  • Loading branch information
Naktibalda authored Feb 20, 2022
2 parents 3c8ae13 + 10c3171 commit f825e91
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 42 deletions.
21 changes: 5 additions & 16 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
strategy:
matrix:
php: [7.4, 8.0]
php: [8.0]

steps:
- name: Checkout code
Expand All @@ -43,32 +43,21 @@ jobs:
- name: Validate composer.json and composer.lock
run: composer validate

- name: Install dependencies on PHP7
if: matrix.php < 8
run: composer install --prefer-dist --no-progress --no-interaction --no-suggest

- name: Install dependencies on PHP8
if: matrix.php == 8.0
run: composer install --prefer-dist --no-progress --no-interaction --ignore-platform-reqs
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-interaction

- name: Checkout Laminas tests
uses: actions/checkout@v2
with:
repository: Naktibalda/codeception-laminas-tests
path: framework-tests
ref: 'master'
ref: '5.0'
submodules: recursive

- name: Install dependencies of Laminas tests on PHP 7
if: matrix.php < 8
- name: Install dependencies of Laminas tests
run: composer update --no-dev --prefer-dist --no-interaction
working-directory: framework-tests

- name: Install dependencies of Laminas tests on PHP 8
if: matrix.php == 8.0
run: composer update --no-dev --prefer-dist --no-interaction --ignore-platform-reqs
working-directory: framework-tests

- name: Create database schema
run: php vendor/bin/doctrine-module orm:schema-tool:create
working-directory: framework-tests
Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
"name": "Michael Bodnarchuk"
}
],
"minimum-stability": "RC",
"minimum-stability": "dev",
"require": {
"php": "^7.4 | ^8.0",
"codeception/lib-innerbrowser": "^2.0",
"codeception/codeception": "^4.1",
"php": "^8.0",
"codeception/lib-innerbrowser": "^3.0",
"codeception/codeception": "^5.0.0-alpha2",
"laminas/laminas-db": "^2.11.3",
"laminas/laminas-mvc": "^3.1.1"
},
"require-dev": {
"codeception/module-asserts": "^2.0",
"codeception/module-doctrine2": "^2.0",
"codeception/module-rest": "^2.0"
"codeception/module-asserts": "^3.0",
"codeception/module-doctrine2": "^3.0",
"codeception/module-rest": "^3.0"
},
"autoload": {
"classmap": [
Expand Down
18 changes: 8 additions & 10 deletions src/Codeception/Lib/Connector/Laminas.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
use function explode;
use function html_entity_decode;
use function implode;
use function is_null;
use function parse_str;
use function str_replace;
use function strpos;
use function strtolower;
use function strtoupper;
use function substr;
Expand Down Expand Up @@ -57,6 +55,9 @@ public function doRequest($request): Response
$this->createApplication();

$laminasRequest = $this->application->getRequest();
if (!$laminasRequest instanceof LaminasRequest) {
throw new \InvalidArgumentException('Expected to get instance of ' . LaminasRequest::class);
}
$uri = new HttpUri($request->getUri());
$queryString = $uri->getQuery();
$method = strtoupper($request->getMethod());
Expand All @@ -72,12 +73,12 @@ public function doRequest($request): Response
$post = $request->getParameters();
}

$laminasRequest->setCookies(new Parameters($request->getCookies()));
$laminasRequest->setCookies($request->getCookies());
$laminasRequest->setServer(new Parameters($request->getServer()));
$laminasRequest->setQuery(new Parameters($query));
$laminasRequest->setPost(new Parameters($post));
$laminasRequest->setFiles(new Parameters($request->getFiles()));
$laminasRequest->setContent(is_null($content) ? '' : $content);
$laminasRequest->setContent($content ?? '');
$laminasRequest->setMethod($method);
$laminasRequest->setUri($uri);

Expand Down Expand Up @@ -116,7 +117,7 @@ public function getLaminasRequest(): LaminasRequest
return $this->laminasRequest;
}

public function grabServiceFromContainer(string $service)
public function grabServiceFromContainer(string $service): object
{
$serviceManager = $this->application->getServiceManager();

Expand All @@ -133,10 +134,7 @@ public function persistService(string $name): void
$this->persistentServices[$name] = $service;
}

/**
* @param array|object $service
*/
public function addServiceToContainer(string $name, $service): void
public function addServiceToContainer(string $name, array|object $service): void
{
$this->application->getServiceManager()->setAllowOverride(true);
$this->application->getServiceManager()->setService($name, $service);
Expand Down Expand Up @@ -175,7 +173,7 @@ private function extractHeaders(BrowserKitRequest $browserKitRequest): Headers
ENT_NOQUOTES
);

if (strpos($header, 'Http-') === 0) {
if (str_starts_with($header, 'Http-')) {
$headers[substr($header, 5)] = $val;
} elseif (isset($contentHeaders[$header])) {
$headers[$header] = $val;
Expand Down
22 changes: 13 additions & 9 deletions src/Codeception/Module/Laminas.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Codeception\Lib\Interfaces\PartedModule;
use Codeception\TestInterface;
use Codeception\Util\ReflectionHelper;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use Laminas\Console\Console;
use Laminas\Db\Adapter\AdapterInterface;
Expand Down Expand Up @@ -72,8 +73,8 @@ class Laminas extends Framework implements DoctrineProvider, PartedModule
/** @var LaminasConnector */
public ?AbstractBrowser $client = null;

/** @var string[] */
protected $config = [
/** @var array<string, mixed> */
protected array $config = [
'config' => 'tests/application.config.php',
'em_service' => 'Doctrine\ORM\EntityManager',
];
Expand All @@ -85,11 +86,11 @@ class Laminas extends Framework implements DoctrineProvider, PartedModule
protected int $time = 0;

/**
* Used to collect domains while recursively traversing route tree
* @var string[] Used to collect domains while recursively traversing route tree
*/
private array $domainCollector = [];

public function _initialize()
public function _initialize(): void
{
$initAutoloaderFile = Configuration::projectDir() . 'init_autoloader.php';
if (file_exists($initAutoloaderFile)) {
Expand All @@ -110,14 +111,14 @@ public function _initialize()
$this->client->setApplicationConfig($this->applicationConfig);
}

public function _before(TestInterface $test)
public function _before(TestInterface $test): void
{
$this->client = new LaminasConnector();
$this->client->setApplicationConfig($this->applicationConfig);
$_SERVER['REQUEST_URI'] = '';
}

public function _after(TestInterface $test)
public function _after(TestInterface $test): void
{
$_SESSION = [];
$_GET = [];
Expand All @@ -130,17 +131,20 @@ public function _after(TestInterface $test)
parent::_after($test);
}

public function _parts()
/**
* @return string[]
*/
public function _parts(): array
{
return ['services'];
}

public function _afterSuite()
public function _afterSuite(): void
{
unset($this->client);
}

public function _getEntityManager()
public function _getEntityManager(): EntityManagerInterface
{
if (!$this->client) {
$this->fail('Laminas module is not loaded');
Expand Down

0 comments on commit f825e91

Please sign in to comment.