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

dropAll() return immediately if no tables found #193

Merged
merged 9 commits into from
Mar 5, 2024
5 changes: 5 additions & 0 deletions src/Schema/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ public function dropAllTables()
/** @var Connection $connection */
$connection = $this->connection;
$tables = $this->getTables();

if(count($tables) === 0) {
return;
}

$sortedTables = [];

// add parents counter
Expand Down
18 changes: 18 additions & 0 deletions tests/Schema/BuilderTestLast.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,22 @@ public function test_dropAllTables(): void
$tables = $sb->getTables();
$this->assertEmpty($tables);
}

public function test_dropAllTables_when_no_tables_exist(): void
{
$conn = $this->getDefaultConnection();
$sb = $conn->getSchemaBuilder();

// All tables must be dropped before hand to ensure that this test will cover the "early return" case
// for when there are no tables.
$sb->dropAllTables();
taka-oyama marked this conversation as resolved.
Show resolved Hide resolved

$tables = $sb->getTables();
$this->assertEmpty($tables);

$sb->dropAllTables();

$tables = $sb->getTables();
$this->assertEmpty($tables);
}
}
Loading