diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3926b69..2ab7200 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,7 +24,7 @@ jobs: strategy: matrix: - php: [7.4, 8.0] + php: [8.0] steps: - name: Checkout code @@ -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 diff --git a/composer.json b/composer.json index 011c93d..e923a96 100644 --- a/composer.json +++ b/composer.json @@ -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": [ diff --git a/src/Codeception/Lib/Connector/Laminas.php b/src/Codeception/Lib/Connector/Laminas.php index 1ccd07b..f759ab8 100644 --- a/src/Codeception/Lib/Connector/Laminas.php +++ b/src/Codeception/Lib/Connector/Laminas.php @@ -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; @@ -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()); @@ -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); @@ -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(); @@ -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); @@ -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; diff --git a/src/Codeception/Module/Laminas.php b/src/Codeception/Module/Laminas.php index 93c40f9..f183b51 100644 --- a/src/Codeception/Module/Laminas.php +++ b/src/Codeception/Module/Laminas.php @@ -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; @@ -72,8 +73,8 @@ class Laminas extends Framework implements DoctrineProvider, PartedModule /** @var LaminasConnector */ public ?AbstractBrowser $client = null; - /** @var string[] */ - protected $config = [ + /** @var array */ + protected array $config = [ 'config' => 'tests/application.config.php', 'em_service' => 'Doctrine\ORM\EntityManager', ]; @@ -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)) { @@ -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 = []; @@ -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');