Passed
Push — master ( f4eeb8...0d22ee )
by Sergei
11:47 queued 01:39
created

TestColumnSchemaBuilderTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 57.14%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 48
ccs 8
cts 14
cp 0.5714
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A typesProviderTrait() 0 17 1
A checkBuildString() 0 10 2
A getColumnSchemaBuilder() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\TestUtility;
6
7
use Yiisoft\Db\Expression\Expression;
8
use Yiisoft\Db\Schema\ColumnSchemaBuilder;
9
use Yiisoft\Db\Schema\Schema;
10
11
use function array_shift;
12
use function call_user_func_array;
13
14
trait TestColumnSchemaBuilderTrait
15
{
16
    /**
17
     * @param string $type
18
     * @param int|null $length
19
     *
20
     * @return ColumnSchemaBuilder
21
     */
22 15
    public function getColumnSchemaBuilder(string $type, ?int $length = null): ColumnSchemaBuilder
23
    {
24 15
        return new ColumnSchemaBuilder($type, $length);
25
    }
26
27
    /**
28
     * @param string $expected
29
     * @param string $type
30
     * @param int|null $length
31
     * @param array $calls
32
     */
33 22
    public function checkBuildString(string $expected, string $type, ?int $length, $calls): void
34
    {
35 22
        $builder = $this->getColumnSchemaBuilder($type, $length);
36
37 22
        foreach ($calls as $call) {
38 22
            $method = array_shift($call);
39 22
            call_user_func_array([$builder, $method], $call);
40
        }
41
42 22
        self::assertEquals($expected, $builder->__toString());
43
    }
44
45
    public function typesProviderTrait(): array
46
    {
47
        return [
48
            ['integer NULL DEFAULT NULL', Schema::TYPE_INTEGER, null, [
49
                ['unsigned'], ['null'],
50
            ]],
51
            ['integer(10)', Schema::TYPE_INTEGER, 10, [
52
                ['unsigned'],
53
            ]],
54
            ['timestamp() WITH TIME ZONE NOT NULL', 'timestamp() WITH TIME ZONE', null, [
55
                ['notNull'],
56
            ]],
57
            ['timestamp() WITH TIME ZONE DEFAULT NOW()', 'timestamp() WITH TIME ZONE', null, [
58
                ['defaultValue', new Expression('NOW()')],
59
            ]],
60
            ['integer(10)', Schema::TYPE_INTEGER, 10, [
61
                ['comment', 'test'],
62
            ]],
63
        ];
64
    }
65
}
66