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

TestCase   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 26
Bugs 3 Features 1
Metric Value
wmc 6
eloc 11
c 26
b 3
f 1
dl 0
loc 33
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 0 5 1
A setUp() 0 5 1
A checkFixture() 0 9 3
A db() 0 3 1
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