Skip to content

Commit 20d3888

Browse files
committed
Clean code in tests, refactor for PHPUNIT v.10.
1 parent 137b0a7 commit 20d3888

20 files changed

+132
-401
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Yii Core version 2 Change Log
5151
- Enh #109: Clean tests for `PHPUnit` v.10 (@terabytesoftw)
5252
- Enh #110: Update database versions in build workflows `MariaDb 10.6`, `MySQL 8.0`, `Oracle 12c`, `PostgreSQL 12` (@terabytesoftw)
5353
- Enh #111: Refactor `ColumnSchema::class` in `MSSQL`, `MySQL`, `Oracle`, `PostgreSQL` (@terabytesoftw)
54+
- Enh #112: Clean code in tests, refactor for `PHPUNIT` v.10 (@terabytesoftw)
5455

5556
Yii Framework 2 Change Log
5657
==========================

tests/framework/db/CommandTest.php

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -800,14 +800,10 @@ public function testAddDropUnique()
800800
$this->assertEquals(['int1', 'int2'], $schema->getTableUniques($tableName, true)[0]->columnNames);
801801
}
802802

803-
public function testAddDropCheck()
803+
public function testAddDropCheck(): void
804804
{
805805
$db = $this->getConnection(false);
806806

807-
if (version_compare($db->getServerVersion(), '8.0.16', '<')) {
808-
$this->markTestSkipped('MySQL < 8.0.16 does not support CHECK constraints.');
809-
}
810-
811807
$tableName = 'test_ck';
812808
$name = 'test_ck_constraint';
813809
$schema = $db->getSchema();
@@ -1129,22 +1125,18 @@ public function testBindValuesSupportsDeprecatedPDOCastingFormat()
11291125
$this->assertTrue(true);
11301126
}
11311127

1132-
public function testBindValuesSupportsEnums()
1128+
public function testBindValuesSupportsEnums(): void
11331129
{
1134-
if (version_compare(PHP_VERSION, '8.1.0') >= 0) {
1135-
$db = $this->getConnection();
1136-
$command = $db->createCommand();
1130+
$db = $this->getConnection();
1131+
$command = $db->createCommand();
11371132

1138-
$command->setSql('SELECT :p1')->bindValues([':p1' => enums\Status::ACTIVE]);
1139-
$this->assertSame('ACTIVE', $command->params[':p1']);
1133+
$command->setSql('SELECT :p1')->bindValues([':p1' => enums\Status::ACTIVE]);
1134+
$this->assertSame('ACTIVE', $command->params[':p1']);
11401135

1141-
$command->setSql('SELECT :p1')->bindValues([':p1' => enums\StatusTypeString::ACTIVE]);
1142-
$this->assertSame('active', $command->params[':p1']);
1136+
$command->setSql('SELECT :p1')->bindValues([':p1' => enums\StatusTypeString::ACTIVE]);
1137+
$this->assertSame('active', $command->params[':p1']);
11431138

1144-
$command->setSql('SELECT :p1')->bindValues([':p1' => enums\StatusTypeInt::ACTIVE]);
1145-
$this->assertSame(1, $command->params[':p1']);
1146-
} else {
1147-
$this->markTestSkipped('Enums are not supported in PHP < 8.1');
1148-
}
1139+
$command->setSql('SELECT :p1')->bindValues([':p1' => enums\StatusTypeInt::ACTIVE]);
1140+
$this->assertSame(1, $command->params[':p1']);
11491141
}
11501142
}

tests/framework/db/SchemaTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,7 @@ public function testGetSchemaNames()
4343

4444
$schemas = $schema->getSchemaNames();
4545

46-
if ($db->driverName === 'oci' && version_compare($db->serverVersion, '12.1', '<')) {
47-
$this->assertEmpty($schemas);
48-
} else {
49-
$this->assertNotEmpty($schemas);
50-
}
46+
$this->assertNotEmpty($schemas);
5147

5248
foreach ($this->expectedSchemas as $schema) {
5349
$this->assertContains($schema, $schemas);

tests/framework/db/mysql/ActiveRecordTest.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,8 @@ public function testCastValues()
4747
//$this->assertSame(false, $model->bool_col2);
4848
}
4949

50-
public function testJsonColumn()
50+
public function testJsonColumn(): void
5151
{
52-
if (version_compare($this->getConnection()->getSchema()->getServerVersion(), '5.7', '<')) {
53-
$this->markTestSkipped('JSON columns are not supported in MySQL < 5.7');
54-
}
55-
if (version_compare(PHP_VERSION, '5.6', '<')) {
56-
$this->markTestSkipped('JSON columns are not supported in PDO for PHP < 5.6');
57-
}
58-
5952
$data = [
6053
'obj' => ['a' => ['b' => ['c' => 2.7418]]],
6154
'array' => [1,2,null,3],

tests/framework/db/mysql/BaseActiveRecordTest.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,8 @@ class BaseActiveRecordTest extends \yiiunit\framework\db\BaseActiveRecordTest
1717
*
1818
* @dataProvider provideArrayValueWithChange
1919
*/
20-
public function testJsonDirtyAttributesWithDataChange($actual, $modified)
20+
public function testJsonDirtyAttributesWithDataChange($actual, $modified): void
2121
{
22-
if (version_compare($this->getConnection()->getSchema()->getServerVersion(), '5.7', '<')) {
23-
$this->markTestSkipped('JSON columns are not supported in MySQL < 5.7');
24-
}
25-
if (version_compare(PHP_VERSION, '5.6', '<')) {
26-
$this->markTestSkipped('JSON columns are not supported in PDO for PHP < 5.6');
27-
}
28-
2922
$createdStorage = new Storage(['data' => $actual]);
3023

3124
$createdStorage->save();

tests/framework/db/mysql/CommandTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,10 @@ class CommandTest extends \yiiunit\framework\db\CommandTest
1515
{
1616
public $driverName = 'mysql';
1717

18-
public function testAddDropCheckSeveral()
18+
public function testAddDropCheckSeveral(): void
1919
{
2020
$db = $this->getConnection(false);
2121

22-
if (version_compare($db->getServerVersion(), '8.0.16', '<')) {
23-
$this->markTestSkipped('MySQL < 8.0.16 does not support CHECK constraints.');
24-
}
25-
2622
$tableName = 'test_ck_several';
2723
$schema = $db->getSchema();
2824

tests/framework/db/mysql/QueryBuilderTest.php

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,7 @@ public function columnTypes()
7070
],
7171
];
7272

73-
/*
74-
* TODO Remove in Yii 2.1
75-
*
76-
* Disabled due bug in MySQL extension
77-
* @link https://bugs.php.net/bug.php?id=70384
78-
*/
79-
if (version_compare(PHP_VERSION, '5.6', '>=')) {
80-
$columns[] = [
81-
Schema::TYPE_JSON,
82-
$this->json(),
83-
"json",
84-
];
85-
}
73+
$columns[] = [Schema::TYPE_JSON, $this->json(), "json"];
8674

8775
return array_merge(parent::columnTypes(), $this->columnTimeTypes(), $columns);
8876
}
@@ -125,28 +113,25 @@ public function columnTimeTypes()
125113
/**
126114
* @link https://github.com/yiisoft/yii2/issues/14367
127115
*/
128-
$mysqlVersion = $this->getDb()->getSlavePdo(true)->getAttribute(\PDO::ATTR_SERVER_VERSION);
129-
$supportsFractionalSeconds = version_compare($mysqlVersion,'5.6.4', '>=');
130-
if ($supportsFractionalSeconds) {
131-
$expectedValues = [
132-
'datetime(0) NOT NULL',
133-
'datetime(0)',
134-
'time(0) NOT NULL',
135-
'time(0)',
136-
'timestamp(0) NOT NULL',
137-
'timestamp(0) NULL DEFAULT NULL',
138-
];
116+
$expectedValues = [
117+
'datetime(0) NOT NULL',
118+
'datetime(0)',
119+
'time(0) NOT NULL',
120+
'time(0)',
121+
'timestamp(0) NOT NULL',
122+
'timestamp(0) NULL DEFAULT NULL',
123+
];
139124

140-
foreach ($expectedValues as $index => $expected) {
141-
$columns[$index][2] = $expected;
142-
}
125+
foreach ($expectedValues as $index => $expected) {
126+
$columns[$index][2] = $expected;
143127
}
144128

145129
/**
146130
* @link https://github.com/yiisoft/yii2/issues/14834
147131
*/
148132
$sqlModes = $this->getConnection(false)->createCommand('SELECT @@sql_mode')->queryScalar();
149133
$sqlModes = explode(',', $sqlModes);
134+
150135
if (in_array('NO_ZERO_DATE', $sqlModes, true)) {
151136
$this->markTestIncomplete(
152137
"MySQL doesn't allow the 'TIMESTAMP' column definition when the NO_ZERO_DATE mode enabled. " .
@@ -156,7 +141,7 @@ public function columnTimeTypes()
156141
$columns[] = [
157142
Schema::TYPE_TIMESTAMP,
158143
$this->timestamp(),
159-
$supportsFractionalSeconds ? 'timestamp(0)' : 'timestamp',
144+
'timestamp(0)',
160145
];
161146
}
162147

0 commit comments

Comments
 (0)