Skip to content

Commit 09853fe

Browse files
authored
Ability to specify application class in config (#48)
Add config option `applicationClass` to module. It allows you to specify which type of an application you want in your test suite.
1 parent 77ef751 commit 09853fe

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/Codeception/Lib/Connector/Yii2.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ class Yii2 extends Client
8383
*/
8484
public $closeSessionOnRecreateApplication = true;
8585

86+
/**
87+
* @var string The FQN of the application class to use. In a default Yii setup, should be either `yii\web\Application`
88+
* or `yii\console\Application`
89+
*/
90+
public $applicationClass = null;
91+
8692

8793
private $emails = [];
8894

@@ -266,7 +272,11 @@ public function startApp()
266272
codecept_debug('Starting application');
267273
$config = require($this->configFile);
268274
if (!isset($config['class'])) {
269-
$config['class'] = 'yii\web\Application';
275+
if (null !== $this->applicationClass) {
276+
$config['class'] = $this->applicationClass;
277+
} else {
278+
$config['class'] = 'yii\web\Application';
279+
}
270280
}
271281

272282
if (isset($config['container']))
@@ -276,7 +286,7 @@ public function startApp()
276286
}
277287

278288
$config = $this->mockMailer($config);
279-
/** @var \yii\web\Application $app */
289+
/** @var \yii\base\Application $app */
280290
Yii::$app = Yii::createObject($config);
281291
Yii::setLogger(new Logger());
282292
}

src/Codeception/Module/Yii2.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646
* * `configFile` *required* - path to the application config file. The file
4747
* should be configured for the test environment and return a configuration
4848
* array.
49+
* * `applicationClass` - Fully qualified class name for the application. There are
50+
* several ways to define the application class. Either via a `class` key in the Yii
51+
* config, via specifying this codeception module configuration value or let codeception
52+
* use its default value `yii\web\Application`. In a standard Yii application, this
53+
* value should be either `yii\console\Application`, `yii\web\Application` or unset.
4954
* * `entryUrl` - initial application url (default: http://localhost/index-test.php).
5055
* * `entryScript` - front script title (like: index-test.php). If not set it's
5156
* taken from `entryUrl`.
@@ -89,7 +94,7 @@
8994
*
9095
* By default all available methods are loaded, but you can also use the `part`
9196
* option to select only the needed actions and to avoid conflicts. The
92-
* avilable parts are:
97+
* available parts are:
9398
*
9499
* * `init` - use the module only for initialization (for acceptance tests).
95100
* * `orm` - include only `haveRecord/grabRecord/seeRecord/dontSeeRecord` actions.
@@ -178,6 +183,7 @@ class Yii2 extends Framework implements ActiveRecord, MultiSession, PartedModule
178183
'recreateComponents' => [],
179184
'recreateApplication' => false,
180185
'closeSessionOnRecreateApplication' => true,
186+
'applicationClass' => null,
181187
];
182188

183189
protected $requiredFields = ['configFile'];

0 commit comments

Comments
 (0)