Passed
Pull Request — 4 (#9749)
by Sergey
08:46
created

MySQLSchemaManagerTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 197
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 121
dl 0
loc 197
rs 10
c 1
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testMYSQL_8_0_16() 0 30 1
A testMySQLForcedON() 0 30 1
A testMariaDBForcedOFF() 0 30 1
A testMYSQL_8_0_17() 0 30 1
A testMariaDB() 0 30 1
A testMySQLForcedOFF() 0 30 1
1
<?php
2
3
namespace SilverStripe\ORM\Tests;
4
5
use SilverStripe\Core\Config\Config;
6
use SilverStripe\ORM\Connect\MySQLSchemaManager;
7
use SilverStripe\Dev\SapphireTest;
8
use SilverStripe\ORM\Tests\MySQLSchemaManagerTest\MySQLDBDummy;
9
10
class MySQLSchemaManagerTest extends SapphireTest
11
{
12
    public function testMYSQL_8_0_16()
13
    {
14
        Config::forClass(MySQLSchemaManager::class)->set('schema_use_int_width', null);
15
16
        $mysqlDBdummy = new MySQLDBDummy('8.0.16-standard');
17
        $mgr = new MySQLSchemaManager();
18
        $mgr->setDatabase($mysqlDBdummy);
19
20
        $this->assertEquals(
21
            'tinyint(1) unsigned not null',
22
            $mgr->boolean([]),
23
            'mysql 8.0.16 boolean has width'
24
        );
25
26
        $this->assertEquals(
27
            'int(11) not null',
28
            $mgr->int([]),
29
            'mysql 8.0.16 int has width'
30
        );
31
32
        $this->assertEquals(
33
            'bigint(20) not null',
34
            $mgr->bigint([]),
35
            'mysql 8.0.16 bigint has width'
36
        );
37
38
        $this->assertEquals(
39
            'int(11) not null auto_increment',
40
            $mgr->IdColumn([]),
41
            'mysql 8.0.16 IdColumn has width'
42
        );
43
    }
44
45
    public function testMYSQL_8_0_17()
46
    {
47
        Config::forClass(MySQLSchemaManager::class)->set('schema_use_int_width', null);
48
49
        $mysqlDBdummy = new MySQLDBDummy('8.0.17');
50
        $mgr = new MySQLSchemaManager();
51
        $mgr->setDatabase($mysqlDBdummy);
52
53
        $this->assertEquals(
54
            'tinyint unsigned not null',
55
            $mgr->boolean([]),
56
            'mysql 8.0.17 boolean has no width'
57
        );
58
59
        $this->assertEquals(
60
            'int not null',
61
            $mgr->int([]),
62
            'mysql 8.0.17 int has no width'
63
        );
64
65
        $this->assertEquals(
66
            'bigint not null',
67
            $mgr->bigint([]),
68
            'mysql 8.0.17 bigint has no width'
69
        );
70
71
        $this->assertEquals(
72
            'int not null auto_increment',
73
            $mgr->IdColumn([]),
74
            'mysql 8.0.17 IdColumn has no width'
75
        );
76
    }
77
78
    public function testMariaDB()
79
    {
80
        Config::forClass(MySQLSchemaManager::class)->set('schema_use_int_width', null);
81
82
        $mariaDBdummy = new MySQLDBDummy('10.4.7-MariaDB');
83
        $mgr = new MySQLSchemaManager();
84
        $mgr->setDatabase($mariaDBdummy);
85
86
        $this->assertEquals(
87
            'tinyint(1) unsigned not null',
88
            $mgr->boolean([]),
89
            'mariadb boolean has width'
90
        );
91
92
        $this->assertEquals(
93
            'int(11) not null',
94
            $mgr->int([]),
95
            'mariadb int has width'
96
        );
97
98
        $this->assertEquals(
99
            'bigint(20) not null',
100
            $mgr->bigint([]),
101
            'mariadb bigint has width'
102
        );
103
104
        $this->assertEquals(
105
            'int(11) not null auto_increment',
106
            $mgr->IdColumn([]),
107
            'mariadb IdColumn has width'
108
        );
109
    }
110
111
    public function testMySQLForcedON()
112
    {
113
        Config::forClass(MySQLSchemaManager::class)->set('schema_use_int_width', true);
114
115
        $mysqlDBdummy = new MySQLDBDummy('8.0.17-standard');
116
        $mgr = new MySQLSchemaManager();
117
        $mgr->setDatabase($mysqlDBdummy);
118
119
        $this->assertEquals(
120
            'tinyint(1) unsigned not null',
121
            $mgr->boolean([]),
122
            'mysql 8.0.17 boolean forced on has width'
123
        );
124
125
        $this->assertEquals(
126
            'int(11) not null',
127
            $mgr->int([]),
128
            'mysql 8.0.17 int forced on has width'
129
        );
130
131
        $this->assertEquals(
132
            'bigint(20) not null',
133
            $mgr->bigint([]),
134
            'mysql 8.0.17 bigint forced on has width'
135
        );
136
137
        $this->assertEquals(
138
            'int(11) not null auto_increment',
139
            $mgr->IdColumn([]),
140
            'mysql 8.0.17 IdColumn forced on has width'
141
        );
142
    }
143
144
    public function testMySQLForcedOFF()
145
    {
146
        Config::forClass(MySQLSchemaManager::class)->set('schema_use_int_width', false);
147
148
        $mysqlDBdummy = new MySQLDBDummy('8.0.16-standard');
149
        $mgr = new MySQLSchemaManager();
150
        $mgr->setDatabase($mysqlDBdummy);
151
152
        $this->assertEquals(
153
            'tinyint unsigned not null',
154
            $mgr->boolean([]),
155
            'mysql 8.0.16 boolean forced off has no width'
156
        );
157
158
        $this->assertEquals(
159
            'int not null',
160
            $mgr->int([]),
161
            'mysql 8.0.16 int forced off has no width'
162
        );
163
164
        $this->assertEquals(
165
            'bigint not null',
166
            $mgr->bigint([]),
167
            'mysql 8.0.16 bigint forced off has no width'
168
        );
169
170
        $this->assertEquals(
171
            'int not null auto_increment',
172
            $mgr->IdColumn([]),
173
            'mysql 8.0.16 IdColumn forced off has no width'
174
        );
175
    }
176
177
    public function testMariaDBForcedOFF()
178
    {
179
        Config::forClass(MySQLSchemaManager::class)->set('schema_use_int_width', false);
180
181
        $mysqlDBdummy = new MySQLDBDummy('10.0.1-MariaDB');
182
        $mgr = new MySQLSchemaManager();
183
        $mgr->setDatabase($mysqlDBdummy);
184
185
        $this->assertEquals(
186
            'tinyint unsigned not null',
187
            $mgr->boolean([]),
188
            'mariadb boolean forced off has no width'
189
        );
190
191
        $this->assertEquals(
192
            'int not null',
193
            $mgr->int([]),
194
            'mariadb int forced off has no width'
195
        );
196
197
        $this->assertEquals(
198
            'bigint not null',
199
            $mgr->bigint([]),
200
            'mariadb bigint forced off has no width'
201
        );
202
203
        $this->assertEquals(
204
            'int not null auto_increment',
205
            $mgr->IdColumn([]),
206
            'mariadb IdColumn forced off has no width'
207
        );
208
    }
209
}
210