From 40d7c32c377a25414058be5e07d2093a7f27f928 Mon Sep 17 00:00:00 2001 From: DBX12 Date: Tue, 11 May 2021 07:56:54 +0200 Subject: [PATCH 1/2] Add config option applicationClass to module The config option applicationClass allows you to specify which type of application you want in your test suite. --- src/Codeception/Lib/Connector/Yii2.php | 14 ++++++++++++-- src/Codeception/Module/Yii2.php | 6 ++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Codeception/Lib/Connector/Yii2.php b/src/Codeception/Lib/Connector/Yii2.php index 22b5e9d..cb248f6 100644 --- a/src/Codeception/Lib/Connector/Yii2.php +++ b/src/Codeception/Lib/Connector/Yii2.php @@ -83,6 +83,12 @@ class Yii2 extends Client */ public $closeSessionOnRecreateApplication = true; + /** + * @var string The FQN of the application class to use. In a default Yii setup, should be either `yii\web\Application` + * or `yii\console\Application` + */ + public $applicationClass = null; + private $emails = []; @@ -266,7 +272,11 @@ public function startApp() codecept_debug('Starting application'); $config = require($this->configFile); if (!isset($config['class'])) { - $config['class'] = 'yii\web\Application'; + if (null !== $this->applicationClass) { + $config['class'] = $this->applicationClass; + } else { + $config['class'] = 'yii\web\Application'; + } } if (isset($config['container'])) @@ -276,7 +286,7 @@ public function startApp() } $config = $this->mockMailer($config); - /** @var \yii\web\Application $app */ + /** @var \yii\base\Application $app */ Yii::$app = Yii::createObject($config); Yii::setLogger(new Logger()); } diff --git a/src/Codeception/Module/Yii2.php b/src/Codeception/Module/Yii2.php index 5ffe49a..867fcd9 100644 --- a/src/Codeception/Module/Yii2.php +++ b/src/Codeception/Module/Yii2.php @@ -46,6 +46,11 @@ * * `configFile` *required* - path to the application config file. The file * should be configured for the test environment and return a configuration * array. + * * `applicationClass` - Fully qualified class name for the application. There are + * several ways to define the application class. Either via a `class` key in the Yii + * config, via specifying this codeception module configuration value or let codeception + * use its default value `yii\web\Application`. In a standard Yii application, this + * value should be either `yii\console\Application`, `yii\web\Application` or unset. * * `entryUrl` - initial application url (default: http://localhost/index-test.php). * * `entryScript` - front script title (like: index-test.php). If not set it's * taken from `entryUrl`. @@ -178,6 +183,7 @@ class Yii2 extends Framework implements ActiveRecord, MultiSession, PartedModule 'recreateComponents' => [], 'recreateApplication' => false, 'closeSessionOnRecreateApplication' => true, + 'applicationClass' => null, ]; protected $requiredFields = ['configFile']; From 77ae8aae443063a250ee69aa80cf47397cf56735 Mon Sep 17 00:00:00 2001 From: DBX12 Date: Tue, 11 May 2021 08:09:20 +0200 Subject: [PATCH 2/2] Fix typo Not mine but if you see it, you own it. --- src/Codeception/Module/Yii2.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Codeception/Module/Yii2.php b/src/Codeception/Module/Yii2.php index 867fcd9..bd710a4 100644 --- a/src/Codeception/Module/Yii2.php +++ b/src/Codeception/Module/Yii2.php @@ -94,7 +94,7 @@ * * By default all available methods are loaded, but you can also use the `part` * option to select only the needed actions and to avoid conflicts. The - * avilable parts are: + * available parts are: * * * `init` - use the module only for initialization (for acceptance tests). * * `orm` - include only `haveRecord/grabRecord/seeRecord/dontSeeRecord` actions.