diff --git a/tests/Common/AbstractMigratorTest.php b/tests/Common/AbstractMigratorTest.php index 2b1551fd..195e8197 100644 --- a/tests/Common/AbstractMigratorTest.php +++ b/tests/Common/AbstractMigratorTest.php @@ -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 @@ -120,7 +118,5 @@ public function testZeroMaxSqlOutputLength(): void 'Execute SQL: [... hidden] ... Done', $informer->getOutput(), ); - - $migrator->down(new M231015155500ExecuteSql()); } } diff --git a/tests/Support/Factory/MssqlFactory.php b/tests/Support/Factory/MssqlFactory.php index 5aa5c23c..1b66d06c 100644 --- a/tests/Support/Factory/MssqlFactory.php +++ b/tests/Support/Factory/MssqlFactory.php @@ -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 @@ -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(); diff --git a/tests/Support/Factory/MysqlFactory.php b/tests/Support/Factory/MysqlFactory.php index 90153163..4d52dd64 100644 --- a/tests/Support/Factory/MysqlFactory.php +++ b/tests/Support/Factory/MysqlFactory.php @@ -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 @@ -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(); diff --git a/tests/Support/Factory/OracleFactory.php b/tests/Support/Factory/OracleFactory.php index 1781b6dd..44e25483 100644 --- a/tests/Support/Factory/OracleFactory.php +++ b/tests/Support/Factory/OracleFactory.php @@ -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 @@ -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(); diff --git a/tests/Support/Factory/SqLiteFactory.php b/tests/Support/Factory/SqLiteFactory.php index 34b4f6fe..7dee09a7 100644 --- a/tests/Support/Factory/SqLiteFactory.php +++ b/tests/Support/Factory/SqLiteFactory.php @@ -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();