Skip to content

Commit 1d26aae

Browse files
[9.x] Make Command components Factory extensible (#43439)
* Make Command components Factory extensible * Fix issue for default bind * Fix mocking in tests
1 parent f4179b2 commit 1d26aae

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/Illuminate/Console/Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function run(InputInterface $input, OutputInterface $output): int
118118
OutputStyle::class, ['input' => $input, 'output' => $output]
119119
);
120120

121-
$this->components = new Factory($this->output);
121+
$this->components = $this->laravel->make(Factory::class, ['output' => $this->output]);
122122

123123
return parent::run(
124124
$this->input = $input, $this->output

tests/Console/CommandTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Console\Application;
66
use Illuminate\Console\Command;
77
use Illuminate\Console\OutputStyle;
8+
use Illuminate\Console\View\Components\Factory;
89
use Mockery as m;
910
use PHPUnit\Framework\TestCase;
1011
use Symfony\Component\Console\Input\ArrayInput;
@@ -35,7 +36,9 @@ public function handle()
3536

3637
$input = new ArrayInput([]);
3738
$output = new NullOutput;
38-
$application->shouldReceive('make')->with(OutputStyle::class, ['input' => $input, 'output' => $output])->andReturn(m::mock(OutputStyle::class));
39+
$outputStyle = m::mock(OutputStyle::class);
40+
$application->shouldReceive('make')->with(OutputStyle::class, ['input' => $input, 'output' => $output])->andReturn($outputStyle);
41+
$application->shouldReceive('make')->with(Factory::class, ['output' => $outputStyle])->andReturn(m::mock(Factory::class));
3942

4043
$application->shouldReceive('call')->with([$command, 'handle'])->andReturnUsing(function () use ($command, $application) {
4144
$commandCalled = m::mock(Command::class);

tests/Database/SeedCommandTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Illuminate\Tests\Database;
44

55
use Illuminate\Console\OutputStyle;
6+
use Illuminate\Console\View\Components\Factory;
67
use Illuminate\Container\Container;
78
use Illuminate\Contracts\Events\Dispatcher;
89
use Illuminate\Database\ConnectionResolverInterface;
@@ -23,6 +24,7 @@ public function testHandle()
2324
{
2425
$input = new ArrayInput(['--force' => true, '--database' => 'sqlite']);
2526
$output = new NullOutput;
27+
$outputStyle = new OutputStyle($input, $output);
2628

2729
$seeder = m::mock(Seeder::class);
2830
$seeder->shouldReceive('setContainer')->once()->andReturnSelf();
@@ -38,7 +40,10 @@ public function testHandle()
3840
$container->shouldReceive('environment')->once()->andReturn('testing');
3941
$container->shouldReceive('make')->with('DatabaseSeeder')->andReturn($seeder);
4042
$container->shouldReceive('make')->with(OutputStyle::class, m::any())->andReturn(
41-
new OutputStyle($input, $output)
43+
$outputStyle
44+
);
45+
$container->shouldReceive('make')->with(Factory::class, m::any())->andReturn(
46+
new Factory($outputStyle)
4247
);
4348

4449
$command = new SeedCommand($resolver);
@@ -59,6 +64,7 @@ public function testWithoutModelEvents()
5964
'--class' => UserWithoutModelEventsSeeder::class,
6065
]);
6166
$output = new NullOutput;
67+
$outputStyle = new OutputStyle($input, $output);
6268

6369
$instance = new UserWithoutModelEventsSeeder();
6470

@@ -75,7 +81,10 @@ public function testWithoutModelEvents()
7581
$container->shouldReceive('environment')->once()->andReturn('testing');
7682
$container->shouldReceive('make')->with(UserWithoutModelEventsSeeder::class)->andReturn($seeder);
7783
$container->shouldReceive('make')->with(OutputStyle::class, m::any())->andReturn(
78-
new OutputStyle($input, $output)
84+
$outputStyle
85+
);
86+
$container->shouldReceive('make')->with(Factory::class, m::any())->andReturn(
87+
new Factory($outputStyle)
7988
);
8089

8190
$command = new SeedCommand($resolver);

0 commit comments

Comments
 (0)