-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve class command via application resolution (#29869)
- Loading branch information
1 parent
aa2e7b6
commit 8d4a301
Showing
2 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Console; | ||
|
||
use Mockery as m; | ||
use Illuminate\Console\Command; | ||
use PHPUnit\Framework\TestCase; | ||
use Illuminate\Console\Application; | ||
use Illuminate\Console\OutputStyle; | ||
use Symfony\Component\Console\Input\ArrayInput; | ||
use Symfony\Component\Console\Output\NullOutput; | ||
|
||
class CommandTest extends TestCase | ||
{ | ||
protected function tearDown(): void | ||
{ | ||
m::close(); | ||
} | ||
|
||
public function testCallingClassCommandResolveCommandViaApplicationResolution() | ||
{ | ||
$command = new Command(); | ||
|
||
$application = m::mock(Application::class); | ||
$command->setLaravel($application); | ||
|
||
$input = new ArrayInput([]); | ||
$output = new NullOutput(); | ||
$application->shouldReceive('make')->with(OutputStyle::class, ['input' => $input, 'output' => $output])->andReturn(m::mock(OutputStyle::class)); | ||
|
||
$application->shouldReceive('call')->with([$command, 'handle'])->andReturnUsing(function () use ($command, $application) { | ||
$commandCalled = m::mock(Command::class); | ||
|
||
$application->shouldReceive('make')->once()->with(Command::class)->andReturn($commandCalled); | ||
|
||
$commandCalled->shouldReceive('setApplication')->once()->with(null); | ||
$commandCalled->shouldReceive('setLaravel')->once()->with($application); | ||
$commandCalled->shouldReceive('run')->once(); | ||
|
||
$command->call(Command::class); | ||
}); | ||
|
||
$command->run($input, $output); | ||
} | ||
} |