-
Notifications
You must be signed in to change notification settings - Fork 11.1k
/
InteractsWithConsole.php
103 lines (87 loc) · 2.08 KB
/
InteractsWithConsole.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
namespace Illuminate\Foundation\Testing\Concerns;
use Illuminate\Console\OutputStyle;
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Testing\PendingCommand;
trait InteractsWithConsole
{
/**
* Indicates if the console output should be mocked.
*
* @var bool
*/
public $mockConsoleOutput = true;
/**
* Indicates if the command is expected to output anything.
*
* @var bool|null
*/
public $expectsOutput;
/**
* All of the expected output lines.
*
* @var array
*/
public $expectedOutput = [];
/**
* All of the expected text to be present in the output.
*
* @var array
*/
public $expectedOutputSubstrings = [];
/**
* All of the output lines that aren't expected to be displayed.
*
* @var array
*/
public $unexpectedOutput = [];
/**
* All of the text that is not expected to be present in the output.
*
* @var array
*/
public $unexpectedOutputSubstrings = [];
/**
* All of the expected output tables.
*
* @var array
*/
public $expectedTables = [];
/**
* All of the expected questions.
*
* @var array
*/
public $expectedQuestions = [];
/**
* All of the expected choice questions.
*
* @var array
*/
public $expectedChoices = [];
/**
* Call artisan command and return code.
*
* @param string $command
* @param array $parameters
* @return \Illuminate\Testing\PendingCommand|int
*/
public function artisan($command, $parameters = [])
{
if (! $this->mockConsoleOutput) {
return $this->app[Kernel::class]->call($command, $parameters);
}
return new PendingCommand($this, $this->app, $command, $parameters);
}
/**
* Disable mocking the console output.
*
* @return $this
*/
protected function withoutMockingConsoleOutput()
{
$this->mockConsoleOutput = false;
$this->app->offsetUnset(OutputStyle::class);
return $this;
}
}