1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Tests\Schema; |
6
|
|
|
|
7
|
|
|
use Yiisoft\Db\Exception\NotSupportedException; |
8
|
|
|
use Yiisoft\Db\Tests\AbstractSchemaTest; |
9
|
|
|
use Yiisoft\Db\Tests\Support\Assert; |
10
|
|
|
use Yiisoft\Db\Tests\Support\TestTrait; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @group db |
14
|
|
|
* |
15
|
|
|
* @psalm-suppress PropertyNotSetInConstructor |
16
|
|
|
*/ |
17
|
|
|
final class SchemaTest extends AbstractSchemaTest |
18
|
|
|
{ |
19
|
|
|
use TestTrait; |
20
|
|
|
|
21
|
|
|
public function testFindViewNames(): void |
22
|
|
|
{ |
23
|
|
|
$db = $this->getConnection(); |
24
|
|
|
|
25
|
|
|
$schema = $db->getSchema(); |
26
|
|
|
|
27
|
|
|
$this->assertSame([], Assert::invokeMethod($schema, 'findViewNames', ['dbo'])); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testGetSchemaChecks(): void |
31
|
|
|
{ |
32
|
|
|
$db = $this->getConnection(); |
33
|
|
|
|
34
|
|
|
$schema = $db->getSchema(); |
35
|
|
|
|
36
|
|
|
$this->expectException(NotSupportedException::class); |
37
|
|
|
$this->expectExceptionMessage( |
38
|
|
|
'Yiisoft\Db\Tests\Support\Stub\Schema does not support fetching all table names.' |
39
|
|
|
); |
40
|
|
|
|
41
|
|
|
$schema->getSchemaChecks(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testGetSchemaDefaultValues(): void |
45
|
|
|
{ |
46
|
|
|
$db = $this->getConnection(); |
47
|
|
|
|
48
|
|
|
$schema = $db->getSchema(); |
49
|
|
|
|
50
|
|
|
$this->expectException(NotSupportedException::class); |
51
|
|
|
$this->expectExceptionMessage( |
52
|
|
|
'Yiisoft\Db\Tests\Support\Stub\Schema does not support fetching all table names.' |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
$schema->getSchemaDefaultValues(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testGetSchemaForeignKeys(): void |
59
|
|
|
{ |
60
|
|
|
$db = $this->getConnection(); |
61
|
|
|
|
62
|
|
|
$schema = $db->getSchema(); |
63
|
|
|
|
64
|
|
|
$this->expectException(NotSupportedException::class); |
65
|
|
|
$this->expectExceptionMessage( |
66
|
|
|
'Yiisoft\Db\Tests\Support\Stub\Schema does not support fetching all table names.' |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
$schema->getSchemaForeignKeys(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function testGetSchemaIndexes(): void |
73
|
|
|
{ |
74
|
|
|
$db = $this->getConnection(); |
75
|
|
|
|
76
|
|
|
$schema = $db->getSchema(); |
77
|
|
|
|
78
|
|
|
$this->expectException(NotSupportedException::class); |
79
|
|
|
$this->expectExceptionMessage( |
80
|
|
|
'Yiisoft\Db\Tests\Support\Stub\Schema does not support fetching all table names.' |
81
|
|
|
); |
82
|
|
|
|
83
|
|
|
$schema->getSchemaIndexes(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function testGetSchemaNames(): void |
87
|
|
|
{ |
88
|
|
|
$db = $this->getConnection(); |
89
|
|
|
|
90
|
|
|
$schema = $db->getSchema(); |
91
|
|
|
|
92
|
|
|
$this->expectException(NotSupportedException::class); |
93
|
|
|
$this->expectExceptionMessage( |
94
|
|
|
'Yiisoft\Db\Tests\Support\Stub\Schema does not support fetching all schema names.' |
95
|
|
|
); |
96
|
|
|
|
97
|
|
|
$schema->getSchemaNames(); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function testGetSchemaPrimaryKeys(): void |
101
|
|
|
{ |
102
|
|
|
$db = $this->getConnection(); |
103
|
|
|
|
104
|
|
|
$schema = $db->getSchema(); |
105
|
|
|
|
106
|
|
|
$this->expectException(NotSupportedException::class); |
107
|
|
|
$this->expectExceptionMessage( |
108
|
|
|
'Yiisoft\Db\Tests\Support\Stub\Schema does not support fetching all table names.' |
109
|
|
|
); |
110
|
|
|
|
111
|
|
|
$schema->getSchemaPrimaryKeys(); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function testGetSchemaUniques(): void |
115
|
|
|
{ |
116
|
|
|
$db = $this->getConnection(); |
117
|
|
|
|
118
|
|
|
$schema = $db->getSchema(); |
119
|
|
|
|
120
|
|
|
$this->expectException(NotSupportedException::class); |
121
|
|
|
$this->expectExceptionMessage( |
122
|
|
|
'Yiisoft\Db\Tests\Support\Stub\Schema does not support fetching all table names.' |
123
|
|
|
); |
124
|
|
|
|
125
|
|
|
$schema->getSchemaUniques(); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function testGetTableChecks(): void |
129
|
|
|
{ |
130
|
|
|
$db = $this->getConnection(); |
131
|
|
|
|
132
|
|
|
$schema = $db->getSchema(); |
133
|
|
|
|
134
|
|
|
$this->expectException(NotSupportedException::class); |
135
|
|
|
$this->expectExceptionMessage( |
136
|
|
|
'Yiisoft\Db\Tests\Support\Stub\Schema::loadTableChecks is not supported by this DBMS.' |
137
|
|
|
); |
138
|
|
|
|
139
|
|
|
$schema->getTableChecks('customer'); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function testGetTableDefaultValues(): void |
143
|
|
|
{ |
144
|
|
|
$db = $this->getConnection(); |
145
|
|
|
|
146
|
|
|
$schema = $db->getSchema(); |
147
|
|
|
|
148
|
|
|
$this->expectException(NotSupportedException::class); |
149
|
|
|
$this->expectExceptionMessage( |
150
|
|
|
'Yiisoft\Db\Tests\Support\Stub\Schema::loadTableDefaultValues is not supported by this DBMS.' |
151
|
|
|
); |
152
|
|
|
|
153
|
|
|
$schema->getTableDefaultValues('customer'); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
public function testGetTableForeignKeys(): void |
157
|
|
|
{ |
158
|
|
|
$db = $this->getConnection(); |
159
|
|
|
|
160
|
|
|
$schema = $db->getSchema(); |
161
|
|
|
|
162
|
|
|
$this->expectException(NotSupportedException::class); |
163
|
|
|
$this->expectExceptionMessage( |
164
|
|
|
'Yiisoft\Db\Tests\Support\Stub\Schema::loadTableForeignKeys is not supported by this DBMS.' |
165
|
|
|
); |
166
|
|
|
|
167
|
|
|
$schema->getTableForeignKeys('customer'); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
public function testResolveTableName(): void |
171
|
|
|
{ |
172
|
|
|
$db = $this->getConnection(); |
173
|
|
|
|
174
|
|
|
$schema = $db->getSchema(); |
175
|
|
|
|
176
|
|
|
$this->expectException(NotSupportedException::class); |
177
|
|
|
$this->expectExceptionMessage('Yiisoft\Db\Tests\Support\Stub\Schema does not support resolving table names.'); |
178
|
|
|
|
179
|
|
|
Assert::invokeMethod($schema, 'resolveTableName', ['customer']); |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
|