Passed
Pull Request — master (#420)
by Wilmer
02:59
created

AbstractTableSchemaTest::testCompositeFk()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 8
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Tests;
6
7
use PHPUnit\Framework\TestCase;
8
use Yiisoft\Db\Exception\NotSupportedException;
9
use Yiisoft\Db\Schema\ColumnSchema;
10
use Yiisoft\Db\Tests\Support\Stub\TableSchema;
11
use Yiisoft\Db\Tests\Support\TestTrait;
12
13
abstract class AbstractTableSchemaTest extends TestCase
14
{
15
    use TestTrait;
16
17
    public function testCompositeFk(): void
18
    {
19
        $tableSchema = new TableSchema();
20
21
        $this->expectException(NotSupportedException::class);
22
        $this->expectExceptionMessage('Yiisoft\Db\Tests\Support\Stub\TableSchema does not support composite FK.');
23
24
        $tableSchema->compositeFk(1, 'from', 'to');
25
    }
26
27
    public function testGetColumn(): void
28
    {
29
        // Defined column schema.
30
        $columnSchema = new ColumnSchema();
31
        $columnSchema->name('id');
32
33
        // Create table schema.
34
        $tableSchema = new TableSchema();
35
36
        $this->assertNull($tableSchema->getColumn('id'));
37
38
        $tableSchema->columns('id', $columnSchema);
39
40
        $this->assertSame($columnSchema, $tableSchema->getColumn('id'));
41
    }
42
43
    public function testGetColumns(): void
44
    {
45
        // Defined column schema.
46
        $columnSchema = new ColumnSchema();
47
        $columnSchema->name('id');
48
49
        // Create table schema.
50
        $tableSchema = new TableSchema();
51
52
        $this->assertSame([], $tableSchema->getColumns());
53
54
        $tableSchema->columns('id', $columnSchema);
55
56
        $this->assertSame(['id' => $columnSchema], $tableSchema->getColumns());
57
    }
58
59
    public function testGetColumnName(): void
60
    {
61
        // Defined column schema.
62
        $columnSchema = new ColumnSchema();
63
        $columnSchema->name('id');
64
65
        // Create table schema.
66
        $tableSchema = new TableSchema();
67
68
        $this->assertNull($tableSchema->getColumn('id'));
69
70
        $tableSchema->columns('id', $columnSchema);
71
72
        $this->assertSame(['id'], $tableSchema->getColumnNames());
73
    }
74
75
    public function testGetCreateSql(): void
76
    {
77
        $tableSchema = new TableSchema();
78
79
        $this->assertNull($tableSchema->getCreateSql());
80
81
        $tableSchema->createSql(
82
            <<<SQL
83
            CREATE TABLE `test` (`id` int(11) NOT NULL)
84
            SQL,
85
        );
86
87
        $this->assertSame(
88
            <<<SQL
89
            CREATE TABLE `test` (`id` int(11) NOT NULL)
90
            SQL,
91
            $tableSchema->getCreateSql(),
92
        );
93
    }
94
95
    public function testGetFullName(): void
96
    {
97
        $tableSchema = new TableSchema();
98
99
        $this->assertEmpty($tableSchema->getFullName());
100
101
        $tableSchema->fullName('test');
102
103
        $this->assertSame('test', $tableSchema->getFullName());
104
    }
105
106
    public function testGetName(): void
107
    {
108
        $tableSchema = new TableSchema();
109
110
        $this->assertEmpty($tableSchema->getName());
111
112
        $tableSchema->name('test');
113
114
        $this->assertSame('test', $tableSchema->getName());
115
    }
116
117
    public function testGetPrimaryKey(): void
118
    {
119
        $tableSchema = new TableSchema();
120
121
        $this->assertSame([], $tableSchema->getPrimaryKey());
122
123
        $tableSchema->primaryKey('id');
124
125
        $this->assertSame(['id'], $tableSchema->getPrimaryKey());
126
    }
127
128
    public function testGetSequencName(): void
129
    {
130
        $tableSchema = new TableSchema();
131
132
        $this->assertEmpty($tableSchema->getSequenceName());
133
134
        $tableSchema->sequenceName('test');
135
136
        $this->assertSame('test', $tableSchema->getSequenceName());
137
    }
138
139
    public function testGetServerName(): void
140
    {
141
        $tableSchema = new TableSchema();
142
143
        $this->assertEmpty($tableSchema->getServerName());
144
145
        $tableSchema->serverName('test');
146
147
        $this->assertSame('test', $tableSchema->getServerName());
148
    }
149
150
    public function testGetSchemaName(): void
151
    {
152
        $tableSchema = new TableSchema();
153
154
        $this->assertNull($tableSchema->getSchemaName());
155
156
        $tableSchema->schemaName('test');
157
158
        $this->assertSame('test', $tableSchema->getSchemaName());
159
    }
160
}
161