BaseTestCase   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 50
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getConnection() 0 4 1
A getDataSet() 0 4 1
A setUp() 0 9 2
A setUpBeforeClass() 0 12 2
1
<?php
2
/**
3
 * @link https://github.com/paulzi/yii2-auto-tree
4
 * @copyright Copyright (c) 2015 PaulZi <[email protected]>
5
 * @license MIT (https://github.com/paulzi/yii2-auto-tree/blob/master/LICENSE)
6
 */
7
8
namespace paulzi\autotree\tests;
9
10
use paulzi\autotree\tests\migrations\TestMigration;
11
use Yii;
12
use yii\db\Connection;
13
14
/**
15
 * @author PaulZi <[email protected]>
16
 */
17
class BaseTestCase extends \PHPUnit_Extensions_Database_TestCase
18
{
19
    protected static $driverName = 'sqlite';
20
21
22
    /**
23
     * @inheritdoc
24
     */
25
    public function getConnection()
26
    {
27
        return $this->createDefaultDBConnection(Yii::$app->getDb()->pdo);
28
    }
29
30
    /**
31
     * @inheritdoc
32
     */
33
    public function getDataSet()
34
    {
35
        return new \PHPUnit_Extensions_Database_DataSet_ArrayDataSet(require(__DIR__ . '/data/data.php'));
36
    }
37
38
    /**
39
     * @inheritdoc
40
     */
41
    protected function setUp()
42
    {
43
        if (Yii::$app->get('db', false) === null) {
44
            $this->markTestSkipped();
45
        } else {
46
            (new TestMigration())->up();
47
            parent::setUp();
48
        }
49
    }
50
51
    /**
52
     * @inheritdoc
53
     */
54
    public static function setUpBeforeClass()
55
    {
56
        $config = require(__DIR__ . '/data/config.php');
57
        $config = $config[static::$driverName];
58
        $config['class'] = Connection::className();
59
        try {
60
            Yii::$app->set('db', $config);
61
            Yii::$app->getDb()->open();
62
        } catch (\Exception $e) {
63
            Yii::$app->clear('db');
64
        }
65
    }
66
}