Skip to content

Commit

Permalink
Fix and improve tests (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov authored Nov 7, 2023
1 parent 2ef6724 commit 5ae8c9d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
4 changes: 0 additions & 4 deletions tests/Common/AbstractMigratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ public function testMaxSqlOutputLength(): void
'Execute SQL: CREATE TABLE person [... hidden] ... Done',
$informer->getOutput(),
);

$migrator->down(new M231015155500ExecuteSql());
}

public function testZeroMaxSqlOutputLength(): void
Expand All @@ -120,7 +118,5 @@ public function testZeroMaxSqlOutputLength(): void
'Execute SQL: [... hidden] ... Done',
$informer->getOutput(),
);

$migrator->down(new M231015155500ExecuteSql());
}
}
11 changes: 8 additions & 3 deletions tests/Support/Factory/MssqlFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Yiisoft\Db\Migration\Tests\Support\Helper\ContainerConfig;
use Yiisoft\Db\Migration\Tests\Support\Helper\ContainerHelper;

use function array_intersect;
use function dirname;

final class MssqlFactory
Expand Down Expand Up @@ -73,12 +74,16 @@ public static function clearDatabase(ContainerInterface $container): void
'test_table',
'target_table',
'new_table',
'person',
'book',
'chapter',
];

$tables = array_intersect($tables, $db->getSchema()->getTableNames());
$command = $db->createCommand();

foreach ($tables as $table) {
if ($db->getTableSchema($table)) {
$db->createCommand()->dropTable($table)->execute();
}
$command->dropTable($table)->execute();
}

$db->close();
Expand Down
11 changes: 8 additions & 3 deletions tests/Support/Factory/MysqlFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Yiisoft\Db\Migration\Tests\Support\Helper\ContainerConfig;
use Yiisoft\Db\Migration\Tests\Support\Helper\ContainerHelper;

use function array_intersect;
use function dirname;

final class MysqlFactory
Expand Down Expand Up @@ -73,12 +74,16 @@ public static function clearDatabase(ContainerInterface $container): void
'test_table',
'target_table',
'new_table',
'person',
'book',
'chapter',
];

$tables = array_intersect($tables, $db->getSchema()->getTableNames());
$command = $db->createCommand();

foreach ($tables as $table) {
if ($db->getTableSchema($table)) {
$db->createCommand('DROP TABLE IF EXISTS ' . $table . ' CASCADE;')->execute();
}
$command->setSql('DROP TABLE IF EXISTS ' . $table . ' CASCADE')->execute();
}

$db->close();
Expand Down
11 changes: 8 additions & 3 deletions tests/Support/Factory/OracleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Yiisoft\Db\Migration\Tests\Support\Helper\ContainerConfig;
use Yiisoft\Db\Migration\Tests\Support\Helper\ContainerHelper;

use function array_intersect;
use function dirname;

final class OracleFactory
Expand Down Expand Up @@ -73,12 +74,16 @@ public static function clearDatabase(ContainerInterface $container): void
'test_table',
'target_table',
'new_table',
'PERSON',
'book',
'chapter',
];

$tables = array_intersect($tables, $db->getSchema()->getTableNames());
$command = $db->createCommand();

foreach ($tables as $table) {
if ($db->getTableSchema($table) !== null) {
$db->createCommand()->dropTable($table)->execute();
}
$command->dropTable($table)->execute();
}

$db->close();
Expand Down
3 changes: 2 additions & 1 deletion tests/Support/Factory/SqLiteFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ static function (string $id) use (&$container, $config): object {
public static function clearDatabase(ContainerInterface $container): void
{
$db = $container->get(SqLiteConnection::class);
$command = $db->createCommand();

foreach ($db->getSchema()->getTableNames() as $tableName) {
$db->createCommand()->dropTable($tableName)->execute();
$command->dropTable($tableName)->execute();
}

$db->close();
Expand Down

0 comments on commit 5ae8c9d

Please sign in to comment.