BaseTestCase::getDataSet()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * @link https://github.com/paulzi/yii2-nested-sets
4
 * @copyright Copyright (c) 2015 PaulZi <[email protected]>
5
 * @license MIT (https://github.com/paulzi/yii2-nested-sets/blob/master/LICENSE)
6
 */
7
8
namespace paulzi\nestedsets\tests;
9
10
use paulzi\nestedsets\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
            if (Yii::$app->db->driverName === 'pgsql') {
48
                Yii::$app->db->createCommand("SELECT setval(pg_get_serial_sequence('tree', 'id'), 25)")->execute();
49
                Yii::$app->db->createCommand("SELECT setval(pg_get_serial_sequence('multiple_tree', 'id'), 39)")->execute();
50
            }
51
            parent::setUp();
52
        }
53
    }
54
55
    /**
56
     * @inheritdoc
57
     */
58
    public static function setUpBeforeClass()
59
    {
60
        $config = require(__DIR__ . '/data/config.php');
61
        $config = $config[static::$driverName];
62
        $config['class'] = Connection::className();
0 ignored issues
show
Deprecated Code introduced by
The method yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
63
        try {
64
            Yii::$app->set('db', $config);
65
            Yii::$app->getDb()->open();
66
        } catch (\Exception $e) {
67
            Yii::$app->clear('db');
68
        }
69
    }
70
}