Skip to content

Compatibility with Codeception 5 and PHP 8.1 #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Feb 25, 2022
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
2 changes: 1 addition & 1 deletion .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.4, 8.0, 8.1]
php: [8.0, 8.1]

steps:
- name: Checkout code
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/.idea/
/nbproject/
/vendor/
/composer.lock
tests/_support
Expand Down
18 changes: 11 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@
"name":"Michael Bodnarchuk"
}
],
"minimum-stability": "RC",
"minimum-stability": "dev",
"require": {
"php": ">=7.4.0 <=8.1 | ~8.1.0",
"codeception/lib-innerbrowser": "^1.0",
"codeception/codeception": "^4.0"
"php": "^8.0",
"codeception/codeception": "^5.0.0-alpha2",
"codeception/lib-innerbrowser": "^3.0"
},
"require-dev": {
"yiisoft/yii2": "dev-master",
"yiisoft/yii2-app-advanced": "dev-master",
"codeception/verify": "<2",
"phpunit/phpunit": "dev-master as 9.5.99",
"codeception/verify": "^2.2",
"codemix/yii2-localeurls": "^1.7",
"codeception/module-asserts": "^2.0",
"codeception/module-filesystem": "^2.0"
"codeception/module-asserts": "^3.0",
"codeception/module-filesystem": "^3.0"
},
"autoload":{
"classmap": ["src/"]
Expand All @@ -40,6 +41,9 @@
]
},
"config": {
"allow-plugins": {
"yiisoft/yii2-composer": true
},
"classmap-authoritative": true
},
"repositories": [
Expand Down
2 changes: 1 addition & 1 deletion src/Codeception/Lib/Connector/Yii2.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function resetApplication($closeSession = true)
}
Yii::$app = null;
\yii\web\UploadedFile::reset();
if (method_exists(\yii\base\Event::className(), 'offAll')) {
if (method_exists(\yii\base\Event::class, 'offAll')) {
\yii\base\Event::offAll();
}
Yii::setLogger(null);
Expand Down
2 changes: 1 addition & 1 deletion src/Codeception/Lib/Connector/Yii2/FixturesStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function fixtures()
public function globalFixtures()
{
return [
InitDbFixture::className()
InitDbFixture::class
];
}
}
65 changes: 35 additions & 30 deletions src/Codeception/Module/Yii2.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use yii\db\Connection;
use yii\db\QueryInterface;
use yii\db\Transaction;
use yii\helpers\Url;

/**
* This module provides integration with [Yii framework](http://www.yiiframework.com/) (2.0).
Expand Down Expand Up @@ -131,7 +132,7 @@
*
* ```php
* <?php
* $I->haveFixtures(['posts' => PostsFixture::className()]);
* $I->haveFixtures(['posts' => PostsFixture::class]);
* ```
*
* or, if you need to load fixtures before the test, you
Expand All @@ -142,7 +143,7 @@
* // inside Cest file or Codeception\TestCase\Unit
* public function _fixtures()
* {
* return ['posts' => PostsFixture::className()]
* return ['posts' => PostsFixture::class]
* }
* ```
*
Expand Down Expand Up @@ -171,7 +172,7 @@ class Yii2 extends Framework implements ActiveRecord, MultiSession, PartedModule
* Application config file must be set.
* @var array
*/
protected $config = [
protected array $config = [
'fixturesMethod' => '_fixtures',
'cleanup' => true,
'ignoreCollidingDSN' => false,
Expand All @@ -186,12 +187,12 @@ class Yii2 extends Framework implements ActiveRecord, MultiSession, PartedModule
'applicationClass' => null,
];

protected $requiredFields = ['configFile'];
protected array $requiredFields = ['configFile'];

/**
* @var Yii2Connector\FixturesStore[]
*/
public $loadedFixtures = [];
public array $loadedFixtures = [];

/**
* Helper to manage database connections
Expand Down Expand Up @@ -256,7 +257,7 @@ private function initServerGlobal()
]);
}

protected function validateConfig()
protected function validateConfig(): void
{
parent::validateConfig();

Expand Down Expand Up @@ -402,7 +403,7 @@ protected function rollbackTransactions()
}
}

public function _parts()
public function _parts(): array
{
return ['orm', 'init', 'fixtures', 'email'];
}
Expand Down Expand Up @@ -443,9 +444,9 @@ public function amLoggedInAs($user)
* ```php
* <?php
* $I->haveFixtures([
* 'posts' => PostsFixture::className(),
* 'posts' => PostsFixture::class,
* 'user' => [
* 'class' => UserFixture::className(),
* 'class' => UserFixture::class,
* 'dataFile' => '@tests/_data/models/user.php',
* ],
* ]);
Expand All @@ -461,7 +462,7 @@ public function amLoggedInAs($user)
* public function _fixtures(){
* return [
* 'user' => [
* 'class' => UserFixture::className(),
* 'class' => UserFixture::class,
* 'dataFile' => codecept_data_dir() . 'user.php'
* ]
* ];
Expand Down Expand Up @@ -511,7 +512,7 @@ function ($fixturesStore) {
*
* ```php
* <?php
* $I->haveFixtures(['users' => UserFixture::className()]);
* $I->haveFixtures(['users' => UserFixture::class]);
*
* $users = $I->grabFixture('users');
*
Expand Down Expand Up @@ -577,7 +578,7 @@ public function haveRecord($model, $attributes = [])
* @param array $attributes
* @part orm
*/
public function seeRecord($model, $attributes = [])
public function seeRecord(string $model, array $attributes = []): void
{
$record = $this->findRecord($model, $attributes);
if (!$record) {
Expand All @@ -597,7 +598,7 @@ public function seeRecord($model, $attributes = [])
* @param array $attributes
* @part orm
*/
public function dontSeeRecord($model, $attributes = [])
public function dontSeeRecord(string $model, array $attributes = []): void
{
$record = $this->findRecord($model, $attributes);
$this->debugSection($model, json_encode($record));
Expand All @@ -618,7 +619,7 @@ public function dontSeeRecord($model, $attributes = [])
* @return mixed
* @part orm
*/
public function grabRecord($model, $attributes = [])
public function grabRecord(string $model, array $attributes = []): mixed
{
return $this->findRecord($model, $attributes);
}
Expand All @@ -628,7 +629,7 @@ public function grabRecord($model, $attributes = [])
* @param array $attributes
* @return mixed
*/
protected function findRecord($model, $attributes = [])
protected function findRecord(string $model, array $attributes = []): mixed
{
if (!class_exists($model)) {
throw new \RuntimeException("Class $model does not exist");
Expand Down Expand Up @@ -660,10 +661,14 @@ protected function findRecord($model, $attributes = [])
* @param string $route A route
* @param array $params Additional route parameters
*/
public function amOnRoute($route, array $params = [])
public function amOnRoute(string $route, array $params = []): void
{
if (Yii::$app->controller === null) {
$route = "/{$route}";
}

array_unshift($params, $route);
$this->amOnPage($params);
$this->amOnPage(Url::to($params));
}

/**
Expand All @@ -679,7 +684,7 @@ public function amOnRoute($route, array $params = [])
*
* @param string|array $page the URI or route in array format
*/
public function amOnPage($page)
public function amOnPage(string $page): void
{
parent::amOnPage($page);
}
Expand Down Expand Up @@ -715,7 +720,7 @@ protected function clientRequest(string $method, string $uri, array $parameters
* @throws \Codeception\Exception\ModuleException
* @deprecated in your tests you can use \Yii::$app directly.
*/
public function grabComponent($component)
public function grabComponent(mixed $component)
{
try {
return $this->client->getComponent($component);
Expand All @@ -740,7 +745,7 @@ public function grabComponent($component)
* @throws \Codeception\Exception\ModuleException
* @part email
*/
public function seeEmailIsSent($num = null)
public function seeEmailIsSent(int $num = null): void
{
if ($num === null) {
$this->assertNotEmpty($this->grabSentEmails(), 'emails were sent');
Expand All @@ -754,7 +759,7 @@ public function seeEmailIsSent($num = null)
*
* @part email
*/
public function dontSeeEmailIsSent()
public function dontSeeEmailIsSent(): void
{
$this->seeEmailIsSent(0);
}
Expand All @@ -775,7 +780,7 @@ public function dontSeeEmailIsSent()
* @return array
* @throws \Codeception\Exception\ModuleException
*/
public function grabSentEmails()
public function grabSentEmails(): array
{
try {
return $this->client->getEmails();
Expand All @@ -795,7 +800,7 @@ public function grabSentEmails()
* ```
* @part email
*/
public function grabLastSentEmail()
public function grabLastSentEmail(): object
{
$this->seeEmailIsSent();
$messages = $this->grabSentEmails();
Expand All @@ -814,7 +819,7 @@ public function getInternalDomains(): array
return $this->client->getInternalDomains();
}

private function defineConstants()
private function defineConstants(): void
{
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'test');
Expand All @@ -837,15 +842,15 @@ public function setCookie($name, $val, $params = [])
* @param string $val The value of the CSRF token
* @return string[] Returns an array containing the name of the CSRF param and the masked CSRF token.
*/
public function createAndSetCsrfCookie($val)
public function createAndSetCsrfCookie(string $val): array
{
$masked = $this->client->maskToken($val);
$name = $this->client->getCsrfParamName();
$this->setCookie($name, $val);
return [$name, $masked];
}

public function _afterSuite()
public function _afterSuite(): void
{
parent::_afterSuite();
codecept_debug('Suite done, restoring $_SERVER to original');
Expand All @@ -856,7 +861,7 @@ public function _afterSuite()
/**
* Initialize an empty session. Implements MultiSession.
*/
public function _initializeSession()
public function _initializeSession(): void
{
$this->client->removeContext();
$this->headers = [];
Expand All @@ -868,7 +873,7 @@ public function _initializeSession()
* Return the session content for future restoring. Implements MultiSession.
* @return array backup data
*/
public function _backupSession()
public function _backupSession(): array
{
if (isset(Yii::$app) && Yii::$app->session->useCustomStorage) {
throw new ModuleException($this, "Yii2 MultiSession only supports the default session backend.");
Expand All @@ -885,7 +890,7 @@ public function _backupSession()
* Restore a session. Implements MultiSession.
* @param array output of _backupSession()
*/
public function _loadSession($session)
public function _loadSession($session): void
{
$this->client->setContext($session['clientContext']);
$this->headers = $session['headers'];
Expand All @@ -904,7 +909,7 @@ public function _loadSession($session)
/**
* Close and dump a session. Implements MultiSession.
*/
public function _closeSession($session = null)
public function _closeSession($session = null): void
{
if (!$session) {
$this->_initializeSession();
Expand Down
8 changes: 5 additions & 3 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
defined('YII_DEBUG') || define('YII_DEBUG', true);
defined('YII_ENV') || define('YII_ENV', 'test');

require dirname(__DIR__) . '/vendor/autoload.php';

Yii::$container = new \yii\di\Container();

$link = __DIR__ . '/../vendor/yiisoft/yii2-app-advanced/vendor';
if (!file_exists($link) && !symlink(__DIR__ . '/../vendor', $link)) {
$link = dirname(__DIR__) . '/vendor/yiisoft/yii2-app-advanced/vendor';
if (!file_exists($link) && !symlink(dirname(__DIR__) . '/vendor', $link)) {
die('failed to create symlink');
}
}
2 changes: 1 addition & 1 deletion tests/cases/closeConnections/codeception.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
paths:
tests: .
log: ../../_output
output: ../../_output
data: _data
support: ../../_support
namespace: tests\
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/closeConnectionsNoCleanup/codeception.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
paths:
tests: .
log: ../../_output
output: ../../_output
data: _data
support: ../../_support
namespace: tests\
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/events/codeception.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
paths:
tests: .
log: ../../_output
output: ../../_output
data: _data
support: ../../_support
namespace: tests\
Expand Down
Loading