Skip to content

Commit

Permalink
Ability to specify application class in config (#48)
Browse files Browse the repository at this point in the history
Add config option `applicationClass` to module. It allows you to specify which type of an application you want in your test suite.
  • Loading branch information
DBX12 committed May 24, 2021
1 parent 77ef751 commit 09853fe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/Codeception/Lib/Connector/Yii2.php
Expand Up @@ -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 = [];

Expand Down Expand Up @@ -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']))
Expand All @@ -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());
}
Expand Down
8 changes: 7 additions & 1 deletion src/Codeception/Module/Yii2.php
Expand Up @@ -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`.
Expand Down Expand Up @@ -89,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.
Expand Down Expand Up @@ -178,6 +183,7 @@ class Yii2 extends Framework implements ActiveRecord, MultiSession, PartedModule
'recreateComponents' => [],
'recreateApplication' => false,
'closeSessionOnRecreateApplication' => true,
'applicationClass' => null,
];

protected $requiredFields = ['configFile'];
Expand Down

0 comments on commit 09853fe

Please sign in to comment.