forked from phpro/grumphp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSymfonyConsoleTest.php
194 lines (175 loc) · 5.2 KB
/
SymfonyConsoleTest.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<?php
declare(strict_types=1);
namespace GrumPHPTest\Unit\Task;
use GrumPHP\Runner\TaskResultInterface;
use GrumPHP\Task\Context\ContextInterface;
use GrumPHP\Task\Context\GitPreCommitContext;
use GrumPHP\Task\Context\RunContext;
use GrumPHP\Task\SymfonyConsole;
use GrumPHP\Task\TaskInterface;
use GrumPHP\Test\Task\AbstractExternalTaskTestCase;
final class SymfonyConsoleTest extends AbstractExternalTaskTestCase
{
protected function provideTask(): TaskInterface
{
return new SymfonyConsole(
$this->processBuilder->reveal(),
$this->formatter->reveal()
);
}
public function provideConfigurableOptions(): iterable
{
yield 'default' => [
[],
[
'bin' => './bin/console',
'command' => [],
]
];
yield 'single-command' => [
[
'command' => ['task:run'],
],
[
'bin' => './bin/console',
'command' => [
'task:run'
],
]
];
yield 'array-command' => [
[
'command' => ['task:run', '--env', 'dev', '-vvv'],
],
[
'bin' => './bin/console',
'command' => [
'task:run',
'--env',
'dev',
'-vvv'
],
]
];
}
public function provideRunContexts(): iterable
{
yield 'run-context' => [
true,
$this->mockContext(RunContext::class)
];
yield 'pre-commit-context' => [
true,
$this->mockContext(GitPreCommitContext::class)
];
yield 'other' => [
false,
$this->mockContext()
];
}
public function provideFailsOnStuff(): iterable
{
yield 'exitCode1' => [
[
'command' => ['--version']
],
$this->mockContext(RunContext::class, ['hello.php', 'hello2.php']),
function() {
$process = $this->mockProcess(1);
$this->mockProcessBuilder('./bin/console', $process);
$this->formatter->format($process)->willReturn('nope');
},
'nope'
];
}
public function providePassesOnStuff(): iterable
{
yield 'exitCode0' => [
[
'command' => ['--version']
],
$this->mockContext(RunContext::class, ['hello.php', 'hello2.php']),
function() {
$this->mockProcessBuilder('./bin/console', $this->mockProcess());
}
];
}
public function provideSkipsOnStuff(): iterable
{
yield 'no-files' => [
[],
$this->mockContext(RunContext::class),
function() {
}
];
}
public function provideExternalTaskRuns(): iterable
{
yield 'single-command' => [
[
'command' => ['lint:container']
],
$this->mockContext(RunContext::class, ['hello.php', 'hello2.php']),
'./bin/console',
[
'lint:container',
]
];
yield 'array-command' => [
[
'command' => [
'task:run',
'--env',
'dev',
'-vvv'
]
],
$this->mockContext(RunContext::class, ['hello.php', 'hello2.php']),
'./bin/console',
[
'task:run',
'--env',
'dev',
'-vvv'
]
];
}
/**
* @test
* @dataProvider provideFailsNonBlockingOnStuff
*/
public function it_fails_non_blocking_on_stuff(
array $config,
ContextInterface $context,
callable $configurator,
string $expectedErrorMessage,
): void {
$task = $this->configureTask($config);
\Closure::bind($configurator, $this)($task->getConfig()->getOptions(), $context);
$result = $task->run($context);
self::assertInstanceOf(TaskResultInterface::class, $result);
self::assertSame(TaskResultInterface::NONBLOCKING_FAILED, $result->getResultCode());
self::assertSame($task, $result->getTask());
self::assertSame($context, $result->getContext());
self::assertSame($expectedErrorMessage, $result->getMessage());
}
public function provideFailsNonBlockingOnStuff(): iterable
{
yield 'no-command' => [
[
// missing command
],
$this->mockContext(RunContext::class, ['hello.php', 'hello2.php']),
function() {},
'Missing "command" configuration for task "symfony_console".'
];
yield 'missing-command-data' => [
[
'command' => [], // missing command config
],
$this->mockContext(RunContext::class, ['hello.php', 'hello2.php']),
function() {},
'Missing "command" configuration for task "symfony_console".'
];
}
}