|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Sqlite\Tests; |
|
6
|
|
|
|
|
7
|
|
|
use Yiisoft\Db\Constraints\Constraint; |
|
8
|
|
|
use Yiisoft\Db\Tests\AnyValue; |
|
9
|
|
|
use Yiisoft\Db\Tests\SchemaTest as AbstractSchemaTest; |
|
10
|
|
|
|
|
11
|
|
|
class SchemaTest extends AbstractSchemaTest |
|
12
|
|
|
{ |
|
13
|
|
|
protected ?string $driverName = 'sqlite'; |
|
14
|
|
|
|
|
15
|
|
|
public function testGetSchemaNames() |
|
16
|
|
|
{ |
|
17
|
|
|
$this->markTestSkipped('Schemas are not supported in SQLite.'); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function getExpectedColumns() |
|
21
|
|
|
{ |
|
22
|
|
|
$columns = parent::getExpectedColumns(); |
|
23
|
|
|
|
|
24
|
|
|
unset( |
|
25
|
|
|
$columns['enum_col'], |
|
26
|
|
|
$columns['bit_col'], |
|
27
|
|
|
$columns['json_col'] |
|
28
|
|
|
); |
|
29
|
|
|
|
|
30
|
|
|
$columns['int_col']['dbType'] = 'integer'; |
|
31
|
|
|
$columns['int_col']['size'] = null; |
|
32
|
|
|
$columns['int_col']['precision'] = null; |
|
33
|
|
|
$columns['int_col2']['dbType'] = 'integer'; |
|
34
|
|
|
$columns['int_col2']['size'] = null; |
|
35
|
|
|
$columns['int_col2']['precision'] = null; |
|
36
|
|
|
$columns['bool_col']['type'] = 'boolean'; |
|
37
|
|
|
$columns['bool_col']['phpType'] = 'boolean'; |
|
38
|
|
|
$columns['bool_col2']['type'] = 'boolean'; |
|
39
|
|
|
$columns['bool_col2']['phpType'] = 'boolean'; |
|
40
|
|
|
$columns['bool_col2']['defaultValue'] = true; |
|
41
|
|
|
|
|
42
|
|
|
return $columns; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testCompositeFk() |
|
46
|
|
|
{ |
|
47
|
|
|
$db = $this->getConnection(); |
|
48
|
|
|
|
|
49
|
|
|
$schema = $db->getSchema(); |
|
50
|
|
|
|
|
51
|
|
|
$table = $schema->getTableSchema('composite_fk'); |
|
52
|
|
|
|
|
53
|
|
|
$this->assertCount(1, $table->foreignKeys); |
|
54
|
|
|
$this->assertTrue(isset($table->foreignKeys[0])); |
|
55
|
|
|
$this->assertEquals('order_item', $table->foreignKeys[0][0]); |
|
56
|
|
|
$this->assertEquals('order_id', $table->foreignKeys[0]['order_id']); |
|
57
|
|
|
$this->assertEquals('item_id', $table->foreignKeys[0]['item_id']); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function constraintsProvider() |
|
61
|
|
|
{ |
|
62
|
|
|
$result = parent::constraintsProvider(); |
|
63
|
|
|
|
|
64
|
|
|
$result['1: primary key'][2]->setName(null); |
|
65
|
|
|
$result['1: check'][2][0]->setColumnNames(null); |
|
66
|
|
|
$result['1: check'][2][0]->setExpression('"C_check" <> \'\''); |
|
67
|
|
|
$result['1: unique'][2][0]->setName(AnyValue::getInstance()); |
|
68
|
|
|
$result['1: index'][2][1]->setName(AnyValue::getInstance()); |
|
69
|
|
|
|
|
70
|
|
|
$result['2: primary key'][2]->setName(null); |
|
71
|
|
|
$result['2: unique'][2][0]->setName(AnyValue::getInstance()); |
|
72
|
|
|
$result['2: index'][2][2]->setName(AnyValue::getInstance()); |
|
73
|
|
|
|
|
74
|
|
|
$result['3: foreign key'][2][0]->setName(null); |
|
75
|
|
|
$result['3: index'][2] = []; |
|
76
|
|
|
|
|
77
|
|
|
$result['4: primary key'][2]->setName(null); |
|
78
|
|
|
$result['4: unique'][2][0]->setName(AnyValue::getInstance()); |
|
79
|
|
|
|
|
80
|
|
|
return $result; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @dataProvider quoteTableNameDataProvider |
|
85
|
|
|
* @param $name |
|
86
|
|
|
* @param $expectedName |
|
87
|
|
|
* @throws \yii\base\NotSupportedException |
|
88
|
|
|
*/ |
|
89
|
|
|
public function testQuoteTableName($name, $expectedName) |
|
90
|
|
|
{ |
|
91
|
|
|
$schema = $this->getConnection()->getSchema(); |
|
92
|
|
|
$quotedName = $schema->quoteTableName($name); |
|
93
|
|
|
$this->assertEquals($expectedName, $quotedName); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function quoteTableNameDataProvider() |
|
97
|
|
|
{ |
|
98
|
|
|
return [ |
|
99
|
|
|
['test', '`test`'], |
|
100
|
|
|
['test.test', '`test`.`test`'], |
|
101
|
|
|
['test.test.test', '`test`.`test`.`test`'], |
|
102
|
|
|
['`test`', '`test`'], |
|
103
|
|
|
['`test`.`test`', '`test`.`test`'], |
|
104
|
|
|
['test.`test`.test', '`test`.`test`.`test`'], |
|
105
|
|
|
]; |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|