|
10 | 10 | use Mockery;
|
11 | 11 | use Mockery\Exception\NoMatchingExpectationException;
|
12 | 12 | use PHPUnit\Framework\TestCase as PHPUnitTestCase;
|
| 13 | +use Symfony\Component\Console\Command\Command; |
13 | 14 | use Symfony\Component\Console\Helper\Table;
|
14 | 15 | use Symfony\Component\Console\Input\ArrayInput;
|
15 | 16 | use Symfony\Component\Console\Output\BufferedOutput;
|
@@ -51,6 +52,13 @@ class PendingCommand
|
51 | 52 | */
|
52 | 53 | protected $expectedExitCode;
|
53 | 54 |
|
| 55 | + /** |
| 56 | + * The unexpected exit code. |
| 57 | + * |
| 58 | + * @var int |
| 59 | + */ |
| 60 | + protected $unexpectedExitCode; |
| 61 | + |
54 | 62 | /**
|
55 | 63 | * Determine if the command has executed.
|
56 | 64 | *
|
@@ -192,6 +200,39 @@ public function assertExitCode($exitCode)
|
192 | 200 | return $this;
|
193 | 201 | }
|
194 | 202 |
|
| 203 | + /** |
| 204 | + * Assert that the command does not have the given exit code. |
| 205 | + * |
| 206 | + * @param int $exitCode |
| 207 | + * @return $this |
| 208 | + */ |
| 209 | + public function assertNotExitCode($exitCode) |
| 210 | + { |
| 211 | + $this->unexpectedExitCode = $exitCode; |
| 212 | + |
| 213 | + return $this; |
| 214 | + } |
| 215 | + |
| 216 | + /** |
| 217 | + * Assert that the command has the success exit code. |
| 218 | + * |
| 219 | + * @return $this |
| 220 | + */ |
| 221 | + public function assertSuccessful() |
| 222 | + { |
| 223 | + return $this->assertExitCode(Command::SUCCESS); |
| 224 | + } |
| 225 | + |
| 226 | + /** |
| 227 | + * Assert that the command does not have the success exit code. |
| 228 | + * |
| 229 | + * @return $this |
| 230 | + */ |
| 231 | + public function assertFailed() |
| 232 | + { |
| 233 | + return $this->assertNotExitCode(Command::SUCCESS); |
| 234 | + } |
| 235 | + |
195 | 236 | /**
|
196 | 237 | * Execute the command.
|
197 | 238 | *
|
@@ -230,6 +271,11 @@ public function run()
|
230 | 271 | $this->expectedExitCode, $exitCode,
|
231 | 272 | "Expected status code {$this->expectedExitCode} but received {$exitCode}."
|
232 | 273 | );
|
| 274 | + } elseif (! is_null($this->unexpectedExitCode)) { |
| 275 | + $this->test->assertNotEquals( |
| 276 | + $this->unexpectedExitCode, $exitCode, |
| 277 | + "Unexpected status code {$this->unexpectedExitCode} was received." |
| 278 | + ); |
233 | 279 | }
|
234 | 280 |
|
235 | 281 | $this->verifyExpectations();
|
|
0 commit comments