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] Improve output for some Artisan commands #43547

Merged
merged 3 commits into from Aug 4, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/Illuminate/Database/Console/Migrations/FreshCommand.php
Expand Up @@ -90,8 +90,6 @@ protected function needsSeeding()
*/
protected function runSeeder($database)
{
$this->newLine();

$this->call('db:seed', array_filter([
'--database' => $database,
'--class' => $this->option('seeder') ?: 'Database\\Seeders\\DatabaseSeeder',
Expand Down
4 changes: 0 additions & 4 deletions src/Illuminate/Database/Console/Migrations/MigrateCommand.php
Expand Up @@ -91,10 +91,6 @@ public function handle()
// seed task to re-populate the database, which is convenient when adding
// a migration and a seed at the same time, as it is only this command.
if ($this->option('seed') && ! $this->option('pretend')) {
if (! empty($migrations)) {
$this->newLine();
}

$this->call('db:seed', [
'--class' => $this->option('seeder') ?: 'Database\\Seeders\\DatabaseSeeder',
'--force' => true,
Expand Down
2 changes: 0 additions & 2 deletions src/Illuminate/Database/Console/Migrations/RefreshCommand.php
Expand Up @@ -132,8 +132,6 @@ protected function needsSeeding()
*/
protected function runSeeder($database)
{
$this->newLine();

$this->call('db:seed', array_filter([
'--database' => $database,
'--class' => $this->option('seeder') ?: 'Database\\Seeders\\DatabaseSeeder',
Expand Down
10 changes: 9 additions & 1 deletion src/Illuminate/Database/Migrations/Migrator.php
Expand Up @@ -180,6 +180,10 @@ public function runPending(array $migrations, array $options = [])
}

$this->fireMigrationEvent(new MigrationsEnded('up'));

if ($this->output) {
$this->output->writeln('');
}
}

/**
Expand Down Expand Up @@ -233,7 +237,11 @@ public function rollback($paths = [], array $options = [])
return [];
}

return $this->rollbackMigrations($migrations, $paths, $options);
return tap($this->rollbackMigrations($migrations, $paths, $options), function () {
if ($this->output) {
$this->output->writeln('');
}
});
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/Illuminate/Database/Seeder.php
Expand Up @@ -61,6 +61,10 @@ public function call($class, $silent = false, array $parameters = [])
static::$called[] = $class;
}

if (! $silent && $this->command->getOutput()) {
$this->command->getOutput()->writeln('');
}

return $this;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Database/DatabaseSeederTest.php
Expand Up @@ -38,9 +38,9 @@ public function testCallResolveTheClassAndCallsRun()
$seeder = new TestSeeder;
$seeder->setContainer($container = m::mock(Container::class));
$output = m::mock(OutputInterface::class);
$output->shouldReceive('writeln')->once();
$output->shouldReceive('writeln')->twice();
$command = m::mock(Command::class);
$command->shouldReceive('getOutput')->once()->andReturn($output);
$command->shouldReceive('getOutput')->times(3)->andReturn($output);
$seeder->setCommand($command);
$container->shouldReceive('make')->once()->with('ClassName')->andReturn($child = m::mock(Seeder::class));
$child->shouldReceive('setContainer')->once()->with($container)->andReturn($child);
Expand Down
6 changes: 6 additions & 0 deletions tests/Integration/Migration/MigratorTest.php
Expand Up @@ -32,6 +32,8 @@ public function testMigrate()
$this->expectTask('2015_10_04_000000_modify_people_table', 'DONE');
$this->expectTask('2016_10_04_000000_modify_people_table', 'DONE');

$this->output->shouldReceive('writeln')->once();

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

$this->assertTrue(DB::getSchemaBuilder()->hasTable('people'));
Expand Down Expand Up @@ -64,6 +66,8 @@ public function testRollback()
$this->expectTask('2015_10_04_000000_modify_people_table', 'DONE');
$this->expectTask('2014_10_12_000000_create_people_table', 'DONE');

$this->output->shouldReceive('writeln')->once();

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

$this->assertFalse(DB::getSchemaBuilder()->hasTable('people'));
Expand All @@ -85,6 +89,8 @@ public function testPretendMigrate()
$this->expectTwoColumnDetail('2016_10_04_000000_modify_people_table');
$this->expectBulletList(['alter table "people" add column "last_name" varchar']);

$this->output->shouldReceive('writeln')->once();

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

$this->assertFalse(DB::getSchemaBuilder()->hasTable('people'));
Expand Down