diff --git a/src/Illuminate/Testing/PendingCommand.php b/src/Illuminate/Testing/PendingCommand.php index 7b90444bddd2..870108644336 100644 --- a/src/Illuminate/Testing/PendingCommand.php +++ b/src/Illuminate/Testing/PendingCommand.php @@ -10,6 +10,7 @@ use Mockery; use Mockery\Exception\NoMatchingExpectationException; use PHPUnit\Framework\TestCase as PHPUnitTestCase; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\BufferedOutput; @@ -51,6 +52,13 @@ class PendingCommand */ protected $expectedExitCode; + /** + * The unexpected exit code. + * + * @var int + */ + protected $unexpectedExitCode; + /** * Determine if the command has executed. * @@ -192,6 +200,39 @@ public function assertExitCode($exitCode) return $this; } + /** + * Assert that the command does not have the given exit code. + * + * @param int $exitCode + * @return $this + */ + public function assertNotExitCode($exitCode) + { + $this->unexpectedExitCode = $exitCode; + + return $this; + } + + /** + * Assert that the command has the success exit code. + * + * @return $this + */ + public function assertSuccessful() + { + return $this->assertExitCode(Command::SUCCESS); + } + + /** + * Assert that the command does not have the success exit code. + * + * @return $this + */ + public function assertFailed() + { + return $this->assertNotExitCode(Command::SUCCESS); + } + /** * Execute the command. * @@ -230,6 +271,11 @@ public function run() $this->expectedExitCode, $exitCode, "Expected status code {$this->expectedExitCode} but received {$exitCode}." ); + } elseif (! is_null($this->unexpectedExitCode)) { + $this->test->assertNotEquals( + $this->unexpectedExitCode, $exitCode, + "Unexpected status code {$this->unexpectedExitCode} was received." + ); } $this->verifyExpectations();