Skip to content
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

Application class config #48

Merged
merged 2 commits into from
May 24, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/Codeception/Lib/Connector/Yii2.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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