Passed
Pull Request — master (#20)
by Wilmer
13:35
created

SchemaTest::getExpectedColumns()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

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