Skip to content

Commit

Permalink
Assert that failures are not success codes
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto-aguilar committed Nov 1, 2021
1 parent b9bac55 commit 67a89f5
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/Illuminate/Testing/PendingCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ class PendingCommand
*/
protected $expectedExitCode;

/**
* The not expected exit code.
*
* @var int
*/
protected $notExpectedExitCode;

/**
* Determine if the command has executed.
*
Expand Down Expand Up @@ -193,6 +200,19 @@ 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->notExpectedExitCode = $exitCode;

return $this;
}

/**
* Assert that the command has the success exit code.
*
Expand All @@ -210,7 +230,7 @@ public function assertSuccessful()
*/
public function assertFailed()
{
return $this->assertExitCode(Command::FAILURE);
return $this->assertNotExitCode(Command::SUCCESS);
}

/**
Expand Down Expand Up @@ -251,6 +271,11 @@ public function run()
$this->expectedExitCode, $exitCode,
"Expected status code {$this->expectedExitCode} but received {$exitCode}."
);
} else if ($this->notExpectedExitCode !== null) {
$this->test->assertNotEquals(
$this->notExpectedExitCode, $exitCode,
"Not expected status code {$this->notExpectedExitCode} was received."
);
}

$this->verifyExpectations();
Expand Down

0 comments on commit 67a89f5

Please sign in to comment.