Passed
Pull Request — master (#368)
by Sergei
02:51
created

TestCase::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 1 Features 0
Metric Value
eloc 2
c 4
b 1
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\ActiveRecord\Tests;
6
7
use Yiisoft\ActiveRecord\ConnectionProvider;
8
use Yiisoft\ActiveRecord\Tests\Support\DbHelper;
9
use Yiisoft\Db\Connection\ConnectionInterface;
10
11
abstract class TestCase extends \PHPUnit\Framework\TestCase
12
{
13
    abstract protected function createConnection(): ConnectionInterface;
14
15
    protected function checkFixture(ConnectionInterface $db, string $tablename, bool $reset = false): void
16
    {
17
        $schema = $db->getSchema();
18
        $tableSchema = $schema->getTableSchema($tablename, true);
19
20
        if ($tableSchema === null || $reset) {
21
            DbHelper::loadFixture($db);
22
23
            $schema->refresh();
24
        }
25
    }
26
27
    protected function db(): ConnectionInterface
28
    {
29
        return ConnectionProvider::get();
30
    }
31
32
    protected function setUp(): void
33
    {
34
        parent::setUp();
35
36
        ConnectionProvider::set($this->createConnection());
37
    }
38
39
    protected function tearDown(): void
40
    {
41
        parent::tearDown();
42
43
        $this->db()->close();
44
    }
45
}
46