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..bd710a4 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`. @@ -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. @@ -178,6 +183,7 @@ class Yii2 extends Framework implements ActiveRecord, MultiSession, PartedModule 'recreateComponents' => [], 'recreateApplication' => false, 'closeSessionOnRecreateApplication' => true, + 'applicationClass' => null, ]; protected $requiredFields = ['configFile'];