MigrateControllerTest.php 1.34 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
<?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;

/**
 * Unit test for [[\yii\mongodb\console\controllers\MigrateController]].
 * @see MigrateController
 *
 * @group mongodb
 * @group console
 */
class MigrateControllerTest extends MongoDbTestCase
{
    use MigrateControllerTestTrait;

    public function setUp()
    {
25
        $this->migrateControllerClass = EchoMigrateController::className();
26 27 28 29 30 31 32 33 34 35 36
        $this->migrationBaseClass = Migration::className();

        parent::setUp();

        $this->setUpMigrationPath();
        Yii::$app->setComponents(['mongodb' => $this->getConnection()]);
    }

    public function tearDown()
    {
        parent::tearDown();
Carsten Brandt committed
37 38 39 40 41 42
        if (extension_loaded('mongo')) {
            try {
                $this->getConnection()->getCollection('migration')->drop();
            } catch (Exception $e) {
                // shutdown exception
            }
43 44 45 46 47 48 49 50 51 52 53 54 55
        }
        $this->tearDownMigrationPath();
    }

    /**
     * @return array applied migration entries
     */
    protected function getMigrationHistory()
    {
        $query = new Query();
        return $query->from('migration')->all();
    }
}