Commit b90f8865 by Klimov Paul

Unit test for MongoDB migration controller added

parent 5fb654f9
......@@ -136,14 +136,14 @@ class MigrateController extends BaseMigrateController
return $history;
}
private $baseMigrationEnsured = false;
/**
* Ensures migration history contains at least base migration entry.
*/
protected function ensureBaseMigrationHistory()
{
static $ensured = false;
if (!$ensured) {
if (!$this->baseMigrationEnsured) {
$query = new Query;
$row = $query->select(['version'])
->from($this->migrationCollection)
......@@ -153,7 +153,7 @@ class MigrateController extends BaseMigrateController
if (empty($row)) {
$this->addMigrationHistory(self::BASE_MIGRATION);
}
$ensured = true;
$this->baseMigrationEnsured = true;
}
}
......
<?php
namespace yiiunit\extensions\mongodb\console\controllers;
use yii\mongodb\Exception;
use yii\mongodb\Migration;
use yii\mongodb\Query;
use Yii;
use yiiunit\extensions\mongodb\MongoDbTestCase;
use yiiunit\framework\console\controllers\MigrateControllerTestTrait;
use yii\mongodb\console\controllers\MigrateController;
/**
* Unit test for [[\yii\mongodb\console\controllers\MigrateController]].
* @see MigrateController
*
* @group mongodb
* @group console
*/
class MigrateControllerTest extends MongoDbTestCase
{
use MigrateControllerTestTrait;
public function setUp()
{
$this->migrateControllerClass = MigrateController::className();
$this->migrationBaseClass = Migration::className();
parent::setUp();
$this->setUpMigrationPath();
Yii::$app->setComponents(['mongodb' => $this->getConnection()]);
}
public function tearDown()
{
parent::tearDown();
try {
$this->getConnection()->getCollection('migration')->drop();
} catch (Exception $e) {
// shutdown exception
}
$this->tearDownMigrationPath();
}
/**
* @return array applied migration entries
*/
protected function getMigrationHistory()
{
$query = new Query();
return $query->from('migration')->all();
}
}
\ No newline at end of file
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