diff --git a/src/Generator/PrintChanges.php b/src/Generator/PrintChanges.php index d0f55ac..3c1227e 100644 --- a/src/Generator/PrintChanges.php +++ b/src/Generator/PrintChanges.php @@ -60,11 +60,6 @@ public function hasChanges(): bool private function describeChanges(AbstractTable $table): void { - if (!$table->exists()) { - $this->output->writeln(' - create table'); - return; - } - if ($table->getStatus() === AbstractTable::STATUS_DECLARED_DROPPED) { $this->output->writeln(' - drop table'); return; @@ -83,6 +78,10 @@ private function describeChanges(AbstractTable $table): void $this->output->write("\n"); + if (!$table->exists()) { + $this->output->writeln(' - create table'); + } + $cmp = $table->getComparator(); $this->describeColumns($cmp); diff --git a/tests/Schema/Generator/PrintChangesTest.php b/tests/Schema/Generator/PrintChangesTest.php index 831196f..50cab90 100644 --- a/tests/Schema/Generator/PrintChangesTest.php +++ b/tests/Schema/Generator/PrintChangesTest.php @@ -50,11 +50,32 @@ public function testRunWithoutChanges(): void public function testRunCreateTable(): void { + $this->compiler->compile($this->registry, [new RenderTables()]); + $this->generator->run($this->registry); + + $content = $this->output->fetch(); + $this->assertStringContainsString('Schema changes:', $content); + $this->assertStringContainsString('default.users: 5 change(s) detected', $content); + } + + public function testRunCreateTableVerbose(): void + { + $this->compiler->compile($this->registry, [new RenderTables()]); + + $this->output->setVerbosity(BufferedOutput::VERBOSITY_VERBOSE); $this->generator->run($this->registry); $content = $this->output->fetch(); $this->assertStringContainsString('Schema changes:', $content); - $this->assertStringContainsString('default.users - create table', $content); + $this->assertStringContainsString('default.users', $content); + $this->assertStringContainsString('- create table', $content); + $this->assertStringContainsString('- add column [id]', $content); + $this->assertStringContainsString('- add column [user_name]', $content); + $this->assertStringContainsString('- add column [active]', $content); + $this->assertStringContainsString('- add column [balance]', $content); + $this->assertStringContainsString('- add column [created_at]', $content); + + $this->assertStringNotContainsString('default.users: 5 change(s) detected', $content); } public function testRunDropTable(): void