Commit f11d6089 by Alexander Makarov

Re-init application if it was destroyed during RBAC test

parent 3af22ece
<?php <?php
namespace yiiunit\framework\rbac; namespace yiiunit\framework\rbac;
use Yii;
use yii\console\Application; use yii\console\Application;
use yii\console\controllers\MigrateController; use yii\console\controllers\MigrateController;
use yii\db\Connection; use yii\db\Connection;
...@@ -19,6 +20,21 @@ abstract class DbManagerTestCase extends ManagerTestCase ...@@ -19,6 +20,21 @@ abstract class DbManagerTestCase extends ManagerTestCase
*/ */
protected static $db; protected static $db;
public static function getApplication()
{
if (Yii::$app === null) {
new Application([
'id' => 'Migrator',
'basePath' => '@yiiunit',
'components' => [
'db' => static::getConnection(),
'authManager' => '\yii\rbac\DbManager',
],
]);
}
return Yii::$app;
}
public static function setUpBeforeClass() public static function setUpBeforeClass()
{ {
parent::setUpBeforeClass(); parent::setUpBeforeClass();
...@@ -30,25 +46,16 @@ abstract class DbManagerTestCase extends ManagerTestCase ...@@ -30,25 +46,16 @@ abstract class DbManagerTestCase extends ManagerTestCase
static::markTestSkipped('pdo and ' . $pdo_database . ' extension are required.'); static::markTestSkipped('pdo and ' . $pdo_database . ' extension are required.');
} }
new Application([ static::getApplication()->runAction('migrate/up', ['migrationPath' => '@yii/rbac/migrations/', 'interactive' => false]);
'id' => 'Migrator',
'basePath' => '@yiiunit',
'components' => [
'db' => static::getConnection(),
'authManager' => '\yii\rbac\DbManager',
],
]);
\Yii::$app->runAction('migrate/up', ['migrationPath' => '@yii/rbac/migrations/', 'interactive' => false]);
} }
public static function tearDownAfterClass() public static function tearDownAfterClass()
{ {
\Yii::$app->runAction('migrate/down', ['migrationPath' => '@yii/rbac/migrations/', 'interactive' => false]); static::getApplication()->runAction('migrate/down', ['migrationPath' => '@yii/rbac/migrations/', 'interactive' => false]);
if (static::$db) { if (static::$db) {
static::$db->close(); static::$db->close();
} }
\Yii::$app = null; Yii::$app = null;
parent::tearDownAfterClass(); parent::tearDownAfterClass();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment