Skip to content
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
8 changes: 5 additions & 3 deletions src/Illuminate/Database/Console/Seeds/SeedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Console\Command;
use Illuminate\Console\ConfirmableTrait;
use Illuminate\Console\Prohibitable;
use Illuminate\Database\ConnectionResolverInterface as Resolver;
use Illuminate\Database\Eloquent\Model;
use Symfony\Component\Console\Attribute\AsCommand;
Expand All @@ -13,7 +14,7 @@
#[AsCommand(name: 'db:seed')]
class SeedCommand extends Command
{
use ConfirmableTrait;
use ConfirmableTrait, Prohibitable;

/**
* The console command name.
Expand Down Expand Up @@ -55,8 +56,9 @@ public function __construct(Resolver $resolver)
*/
public function handle()
{
if (! $this->confirmToProceed()) {
return 1;
if ($this->isProhibited() ||
! $this->confirmToProceed()) {
return Command::FAILURE;
}

$this->components->info('Seeding database.');
Expand Down
32 changes: 32 additions & 0 deletions tests/Database/SeedCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Tests\Database;

use Illuminate\Console\Command;
use Illuminate\Console\OutputStyle;
use Illuminate\Console\View\Components\Factory;
use Illuminate\Container\Container;
Expand Down Expand Up @@ -103,8 +104,39 @@ public function testWithoutModelEvents()
$container->shouldHaveReceived('call')->with([$command, 'handle']);
}

public function testProhibitable()
{
$input = new ArrayInput([]);
$output = new NullOutput;
$outputStyle = new OutputStyle($input, $output);

$resolver = m::mock(ConnectionResolverInterface::class);

$container = m::mock(Container::class);
$container->shouldReceive('call');
$container->shouldReceive('runningUnitTests')->andReturn('true');
$container->shouldReceive('make')->with(OutputStyle::class, m::any())->andReturn(
$outputStyle
);
$container->shouldReceive('make')->with(Factory::class, m::any())->andReturn(
new Factory($outputStyle)
);

$command = new SeedCommand($resolver);
$command->setLaravel($container);

// call run to set up IO, then fire manually.
$command->run($input, $output);

SeedCommand::prohibit();

Assert::assertSame(Command::FAILURE, $command->handle());
}

protected function tearDown(): void
{
SeedCommand::prohibit(false);

Model::unsetEventDispatcher();

m::close();
Expand Down
Loading