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

[9.x] Fixes usage of Migrator without output #43326

Merged
merged 1 commit into from
Jul 20, 2022
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
7 changes: 4 additions & 3 deletions src/Illuminate/Database/Migrations/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use ReflectionClass;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;

class Migrator
Expand Down Expand Up @@ -726,9 +727,9 @@ public function setOutput(OutputInterface $output)
*/
protected function write($component, ...$arguments)
{
if ($this->output) {
with(new $component($this->output))->render(...$arguments);
}
with(new $component(
$this->output ?: new NullOutput()
))->render(...$arguments);
}

/**
Expand Down
12 changes: 12 additions & 0 deletions tests/Integration/Migration/MigratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ public function testMigrate()
$this->assertTrue(DB::getSchemaBuilder()->hasColumn('people', 'last_name'));
}

public function testMigrateWithoutOutput()
{
$this->app->forgetInstance('migrator');
$this->subject = $this->app->make('migrator');

$this->subject->run([__DIR__.'/fixtures']);

$this->assertTrue(DB::getSchemaBuilder()->hasTable('people'));
$this->assertTrue(DB::getSchemaBuilder()->hasColumn('people', 'first_name'));
$this->assertTrue(DB::getSchemaBuilder()->hasColumn('people', 'last_name'));
}

public function testRollback()
{
$this->getConnection()->statement('CREATE TABLE people(id INT, first_name VARCHAR, last_name VARCHAR);');
Expand Down