Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and improve tests #229

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading