Skip to content

Commit b433970

Browse files
committed
dont mock console output by default
1 parent 6a8ab13 commit b433970

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/Illuminate/Foundation/Testing/Concerns/InteractsWithConsole.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
namespace Illuminate\Foundation\Testing\Concerns;
44

5+
use Illuminate\Contracts\Console\Kernel;
56
use Illuminate\Foundation\Testing\PendingCommand;
67

78
trait InteractsWithConsole
89
{
10+
protected $mockConsoleOutput = false;
11+
912
/**
1013
* All of the expected output lines.
1114
*
@@ -29,6 +32,10 @@ trait InteractsWithConsole
2932
*/
3033
public function artisan($command, $parameters = [])
3134
{
35+
if (! $this->mockConsoleOutput) {
36+
return $this->app[Kernel::class]->call($command, $parameters);
37+
}
38+
3239
$this->beforeApplicationDestroyed(function () {
3340
if (count($this->expectedQuestions)) {
3441
$this->fail('Question "'.array_first($this->expectedQuestions)[0].'" was not asked.');
@@ -41,4 +48,11 @@ public function artisan($command, $parameters = [])
4148

4249
return new PendingCommand($this, $this->app, $command, $parameters);
4350
}
51+
52+
protected function withMockedConsoleOutput()
53+
{
54+
$this->mockConsoleOutput = true;
55+
56+
return $this;
57+
}
4458
}

tests/Integration/Console/ConsoleApplicationTest.php

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

55
use Illuminate\Console\Command;
6+
use Illuminate\Foundation\Testing\PendingCommand;
67
use Orchestra\Testbench\TestCase;
78
use Illuminate\Contracts\Console\Kernel;
89

@@ -19,14 +20,27 @@ public function test_artisan_call_using_command_name()
1920
{
2021
$exitCode = $this->artisan('foo:bar', [
2122
'id' => 1,
22-
])->assertExitCode(0);
23+
]);
24+
25+
$this->assertSame(0, $exitCode);
2326
}
2427

2528
public function test_artisan_call_using_command_class()
2629
{
2730
$exitCode = $this->artisan(FooCommandStub::class, [
2831
'id' => 1,
29-
])->assertExitCode(0);
32+
]);
33+
34+
$this->assertSame(0, $exitCode);
35+
}
36+
37+
public function test_artisan_call_using_command_class_with_mocked_output()
38+
{
39+
$pendingCommand = $this->withMockedConsoleOutput()->artisan(FooCommandStub::class, ['id' => 1]);
40+
41+
$this->assertInstanceOf(PendingCommand::class, $pendingCommand);
42+
43+
$pendingCommand->assertExitCode(0);
3044
}
3145
}
3246

0 commit comments

Comments
 (0)