Passed
Pull Request — master (#20362)
by Wilmer
05:37
created

DbFixture::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @link https://www.yiiframework.com/
4
 * @copyright Copyright (c) 2008 Yii Software LLC
5
 * @license https://www.yiiframework.com/license/
6
 */
7
8
namespace yii\test;
9
10
use yii\base\BaseObject;
11
use yii\db\Connection;
12
use yii\di\Instance;
13
14
/**
15
 * DbFixture is the base class for DB-related fixtures.
16
 *
17
 * DbFixture provides the [[db]] connection to be used by DB fixtures.
18
 *
19
 * For more details and usage information on DbFixture, see the [guide article on fixtures](guide:test-fixtures).
20
 *
21
 * @author Qiang Xue <[email protected]>
22
 * @since 2.0
23
 */
24
abstract class DbFixture extends Fixture
25
{
26
    /**
27
     * @var Connection|array|string the DB connection object or the application component ID of the DB connection.
28
     * After the DbFixture object is created, if you want to change this property, you should only assign it
29
     * with a DB connection object.
30
     * Starting from version 2.0.2, this can also be a configuration array for creating the object.
31
     */
32
    public $db = 'db';
33
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function init()
39
    {
40
        parent::init();
41
        $this->db = Instance::ensure($this->db, BaseObject::class);
42
    }
43
}
44