diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fd04358..24f09315 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Changed Fixed - `Schema\Grammar::compileAdd()` `Schema\Grammar::compileChange()` `Schema\Grammar::compileChange()` now create separate statements (#159) +- `Connection::runDdlBatch()` with empty statement now return an empty array instead of throwing an error (#169) # v6.1.2 (2024-01-16) diff --git a/src/Concerns/ManagesDataDefinitions.php b/src/Concerns/ManagesDataDefinitions.php index 9dcca986..333f1859 100644 --- a/src/Concerns/ManagesDataDefinitions.php +++ b/src/Concerns/ManagesDataDefinitions.php @@ -58,6 +58,10 @@ public function runDdls(array $ddls): LongRunningOperation */ public function runDdlBatch(array $statements): mixed { + if (count($statements) === 0) { + return []; + } + $start = microtime(true); $result = $this->waitForOperation( diff --git a/tests/Concerns/ManagesDataDefinitionsTest.php b/tests/Concerns/ManagesDataDefinitionsTest.php index 1327c30d..0a512fb3 100644 --- a/tests/Concerns/ManagesDataDefinitionsTest.php +++ b/tests/Concerns/ManagesDataDefinitionsTest.php @@ -42,6 +42,19 @@ public function test_runDdlBatch(): void Event::assertDispatchedTimes(QueryExecuted::class, 1); } + public function test_runDdlBatch_with_empty_statement(): void + { + $events = Event::fake([QueryExecuted::class]); + $conn = $this->getDefaultConnection(); + $conn->setEventDispatcher($events); + $conn->enableQueryLog(); + $result = $conn->runDdlBatch([]); + + $this->assertSame([], $result); + $this->assertCount(0, $conn->getQueryLog()); + Event::assertNotDispatched(QueryExecuted::class); + } + public function test_createDatabase_with_statements(): void { $events = Event::fake([QueryExecuted::class]);