@@ -20,19 +20,17 @@ class SchemaTest extends \yiiunit\framework\db\SchemaTest
2020{
2121 public $ driverName = 'mysql ' ;
2222
23- public function testLoadDefaultDatetimeColumn ()
23+ public function testLoadDefaultDatetimeColumn (): void
2424 {
25- if (!version_compare ($ this ->getConnection ()->pdo ->getAttribute (\PDO ::ATTR_SERVER_VERSION ), '5.6 ' , '>= ' )) {
26- $ this ->markTestSkipped ('Default datetime columns are supported since MySQL 5.6. ' );
27- }
25+
2826 $ sql = <<<SQL
29- CREATE TABLE IF NOT EXISTS `datetime_test` (
30- `id` int(11) NOT NULL AUTO_INCREMENT,
31- `dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
32- `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
33- PRIMARY KEY (`id`)
34- ) ENGINE=InnoDB DEFAULT CHARSET=utf8
35- SQL ;
27+ CREATE TABLE IF NOT EXISTS `datetime_test` (
28+ `id` int(11) NOT NULL AUTO_INCREMENT,
29+ `dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
30+ `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
31+ PRIMARY KEY (`id`)
32+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8
33+ SQL ;
3634
3735 $ this ->getConnection ()->createCommand ($ sql )->execute ();
3836
@@ -44,17 +42,14 @@ public function testLoadDefaultDatetimeColumn()
4442 $ this ->assertEquals ('CURRENT_TIMESTAMP ' , (string )$ dt ->defaultValue );
4543 }
4644
47- public function testDefaultDatetimeColumnWithMicrosecs ()
45+ public function testDefaultDatetimeColumnWithMicrosecs (): void
4846 {
49- if (!version_compare ($ this ->getConnection ()->pdo ->getAttribute (\PDO ::ATTR_SERVER_VERSION ), '5.6.4 ' , '>= ' )) {
50- $ this ->markTestSkipped ('CURRENT_TIMESTAMP with microseconds as default column value is supported since MySQL 5.6.4. ' );
51- }
5247 $ sql = <<<SQL
53- CREATE TABLE IF NOT EXISTS `current_timestamp_test` (
54- `dt` datetime(2) NOT NULL DEFAULT CURRENT_TIMESTAMP(2),
55- `ts` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3)
56- ) ENGINE=InnoDB DEFAULT CHARSET=utf8
57- SQL ;
48+ CREATE TABLE IF NOT EXISTS `current_timestamp_test` (
49+ `dt` datetime(2) NOT NULL DEFAULT CURRENT_TIMESTAMP(2),
50+ `ts` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3)
51+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8
52+ SQL ;
5853
5954 $ this ->getConnection ()->createCommand ($ sql )->execute ();
6055
@@ -94,23 +89,15 @@ public function constraintsProvider()
9489 * @param string $type
9590 * @param mixed $expected
9691 */
97- public function testTableSchemaConstraints ($ tableName , $ type , $ expected )
92+ public function testTableSchemaConstraints ($ tableName , $ type , $ expected ): void
9893 {
99- $ version = $ this ->getConnection (false )->getServerVersion ();
100-
10194 if ($ expected === false ) {
10295 $ this ->expectException ('yii\base\NotSupportedException ' );
10396 }
10497
98+ $ version = $ this ->getConnection (false )->getServerVersion ();
99+
105100 if (
106- $ this ->driverName === 'mysql ' &&
107- \stripos ($ version , 'MariaDb ' ) === false &&
108- version_compare ($ version , '8.0.16 ' , '< ' ) &&
109- $ type === 'checks '
110- ) {
111- $ this ->expectException ('yii\base\NotSupportedException ' );
112- } elseif (
113- $ this ->driverName === 'mysql ' &&
114101 \stripos ($ version , 'MariaDb ' ) === false &&
115102 version_compare ($ version , '8.0.16 ' , '>= ' ) &&
116103 $ tableName === 'T_constraints_1 ' &&
@@ -129,23 +116,15 @@ public function testTableSchemaConstraints($tableName, $type, $expected)
129116 * @param string $type
130117 * @param mixed $expected
131118 */
132- public function testTableSchemaConstraintsWithPdoUppercase ($ tableName , $ type , $ expected )
119+ public function testTableSchemaConstraintsWithPdoUppercase ($ tableName , $ type , $ expected ): void
133120 {
134- $ version = $ this ->getConnection (false )->getServerVersion ();
135-
136121 if ($ expected === false ) {
137122 $ this ->expectException ('yii\base\NotSupportedException ' );
138123 }
139124
125+ $ version = $ this ->getConnection (false )->getServerVersion ();
126+
140127 if (
141- $ this ->driverName === 'mysql ' &&
142- \stripos ($ version , 'MariaDb ' ) === false &&
143- version_compare ($ version , '8.0.16 ' , '< ' ) &&
144- $ type === 'checks '
145- ) {
146- $ this ->expectException ('yii\base\NotSupportedException ' );
147- } elseif (
148- $ this ->driverName === 'mysql ' &&
149128 \stripos ($ version , 'MariaDb ' ) === false &&
150129 version_compare ($ version , '8.0.16 ' , '>= ' ) &&
151130 $ tableName === 'T_constraints_1 ' &&
@@ -166,23 +145,15 @@ public function testTableSchemaConstraintsWithPdoUppercase($tableName, $type, $e
166145 * @param string $type
167146 * @param mixed $expected
168147 */
169- public function testTableSchemaConstraintsWithPdoLowercase ($ tableName , $ type , $ expected )
148+ public function testTableSchemaConstraintsWithPdoLowercase ($ tableName , $ type , $ expected ): void
170149 {
171- $ version = $ this ->getConnection (false )->getServerVersion ();
172-
173150 if ($ expected === false ) {
174151 $ this ->expectException ('yii\base\NotSupportedException ' );
175152 }
176153
154+ $ version = $ this ->getConnection (false )->getServerVersion ();
155+
177156 if (
178- $ this ->driverName === 'mysql ' &&
179- \stripos ($ version , 'MariaDb ' ) === false &&
180- version_compare ($ version , '8.0.16 ' , '< ' ) &&
181- $ type === 'checks '
182- ) {
183- $ this ->expectException ('yii\base\NotSupportedException ' );
184- } elseif (
185- $ this ->driverName === 'mysql ' &&
186157 \stripos ($ version , 'MariaDb ' ) === false &&
187158 version_compare ($ version , '8.0.16 ' , '>= ' ) &&
188159 $ tableName === 'T_constraints_1 ' &&
@@ -356,13 +327,6 @@ public function getExpectedColumns()
356327 $ columns ['bigint_col ' ]['precision ' ] = null ;
357328 }
358329
359- if (version_compare ($ version , '5.7 ' , '< ' ) && \stripos ($ version , 'MariaDb ' ) === false ) {
360- $ columns ['int_col3 ' ]['phpType ' ] = 'string ' ;
361- $ columns ['json_col ' ]['type ' ] = 'text ' ;
362- $ columns ['json_col ' ]['dbType ' ] = 'longtext ' ;
363- $ columns ['json_col ' ]['phpType ' ] = 'string ' ;
364- }
365-
366330 return $ columns ;
367331 }
368332}
0 commit comments