Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,17 @@ protected function failureDescription($other): string
{
return 'the command '.$this->toString();
}

/**
* {@inheritdoc}
*/
protected function additionalFailureDescription($other): string
{
$mapping = [
Command::FAILURE => 'Command failed.',
Command::INVALID => 'Command was invalid.',
];

return $mapping[$other] ?? sprintf('Command returned exit status %d.', $other);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,31 @@ public function testConstraint()
$this->assertTrue($constraint->evaluate(Command::SUCCESS, '', true));
$this->assertFalse($constraint->evaluate(Command::FAILURE, '', true));
$this->assertFalse($constraint->evaluate(Command::INVALID, '', true));
}

/**
* @dataProvider providesUnsuccessful
*/
public function testUnsuccessfulCommand(string $expectedException, int $exitCode)
{
$constraint = new CommandIsSuccessful();

try {
$constraint->evaluate(Command::FAILURE);
$constraint->evaluate($exitCode);
} catch (ExpectationFailedException $e) {
$this->assertStringContainsString('Failed asserting that the command is successful.', TestFailure::exceptionToString($e));
$this->assertStringContainsString($expectedException, TestFailure::exceptionToString($e));

return;
}

$this->fail();
}

public function providesUnsuccessful(): iterable
{
yield 'Failed' => ['Command failed.', Command::FAILURE];
yield 'Invalid' => ['Command was invalid.', Command::INVALID];
yield 'Exit code 3' => ['Command returned exit status 3.', 3];
}
}