DbFixture.php 1.04 KB
Newer Older
Qiang Xue committed
1 2 3 4 5 6 7 8 9 10 11
<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace yii\test;

use Yii;
use yii\db\Connection;
12 13
use yii\di\Instance;
use yii\base\Object;
Qiang Xue committed
14 15

/**
Qiang Xue committed
16
 * DbFixture is the base class for DB-related fixtures.
Qiang Xue committed
17
 *
Qiang Xue committed
18
 * DbFixture provides the [[db]] connection to be used by DB fixtures.
Qiang Xue committed
19 20 21 22
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @since 2.0
 */
Qiang Xue committed
23
abstract class DbFixture extends Fixture
Qiang Xue committed
24
{
25
    /**
26
     * @var Connection|array|string the DB connection object or the application component ID of the DB connection.
27 28
     * After the DbFixture object is created, if you want to change this property, you should only assign it
     * with a DB connection object.
29
     * Starting from version 2.0.2, this can also be a configuration array for creating the object.
30 31
     */
    public $db = 'db';
Qiang Xue committed
32

33

34 35 36 37 38 39
    /**
     * @inheritdoc
     */
    public function init()
    {
        parent::init();
40
        $this->db = Instance::ensure($this->db, Object::className());
41
    }
Qiang Xue committed
42
}