diff --git a/src/Illuminate/Database/Seeder.php b/src/Illuminate/Database/Seeder.php index f060f4b6cafa..7a502a34ac89 100755 --- a/src/Illuminate/Database/Seeder.php +++ b/src/Illuminate/Database/Seeder.php @@ -3,7 +3,7 @@ namespace Illuminate\Database; use Illuminate\Console\Command; -use Illuminate\Console\View\Components\Task; +use Illuminate\Console\View\Components\TwoColumnDetail; use Illuminate\Container\Container; use Illuminate\Database\Console\Seeds\WithoutModelEvents; use Illuminate\Support\Arr; @@ -49,20 +49,29 @@ public function call($class, $silent = false, array $parameters = []) $name = get_class($seeder); - if ($silent || ! isset($this->command)) { - $seeder->__invoke($parameters); - } else { - with(new Task($this->command->getOutput()))->render( + if ($silent === false && isset($this->command)) { + with(new TwoColumnDetail($this->command->getOutput()))->render( $name, - fn () => $seeder->__invoke($parameters), + 'RUNNING' ); } - static::$called[] = $class; - } + $startTime = microtime(true); + + $seeder->__invoke($parameters); + + if ($silent === false && isset($this->command)) { + $runTime = number_format((microtime(true) - $startTime) * 1000, 2); + + with(new TwoColumnDetail($this->command->getOutput()))->render( + $name, + "$runTime ms DONE" + ); - if (! $silent && $this->command->getOutput()) { - $this->command->getOutput()->writeln(''); + $this->command->getOutput()->writeln(''); + } + + static::$called[] = $class; } return $this; diff --git a/tests/Database/DatabaseSeederTest.php b/tests/Database/DatabaseSeederTest.php index beeec27b90f2..aa80f2c5f453 100755 --- a/tests/Database/DatabaseSeederTest.php +++ b/tests/Database/DatabaseSeederTest.php @@ -38,7 +38,7 @@ public function testCallResolveTheClassAndCallsRun() $seeder = new TestSeeder; $seeder->setContainer($container = m::mock(Container::class)); $output = m::mock(OutputInterface::class); - $output->shouldReceive('writeln')->twice(); + $output->shouldReceive('writeln')->times(3); $command = m::mock(Command::class); $command->shouldReceive('getOutput')->times(3)->andReturn($output); $seeder->setCommand($command); @@ -46,7 +46,6 @@ public function testCallResolveTheClassAndCallsRun() $child->shouldReceive('setContainer')->once()->with($container)->andReturn($child); $child->shouldReceive('setCommand')->once()->with($command)->andReturn($child); $child->shouldReceive('__invoke')->once(); - $output->shouldReceive('write')->times(3); $seeder->call('ClassName'); }