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

TestColumnSchemaBuilderTrait::checkBuildString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 4
dl 0
loc 10
ccs 6
cts 6
cp 1
crap 2
rs 10
c 0
b 0
f 0
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