Passed
Branch dev (f56f10)
by Wilmer
04:41 queued 01:34
created

TestColumnSchemaBuilderTrait::checkBuildString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 4
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\TestSupport;
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
    public function getColumnSchemaBuilder(string $type, ?int $length = null): ColumnSchemaBuilder
23
    {
24
        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
    public function checkBuildString(string $expected, string $type, ?int $length, $calls): void
34
    {
35
        $builder = $this->getColumnSchemaBuilder($type, $length);
36
37
        foreach ($calls as $call) {
38
            $method = array_shift($call);
39
            call_user_func_array([$builder, $method], $call);
40
        }
41
42
        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