According to the PHPUnit Documentation on @expectedExceptionMessage
, the string must only be a substring of the actual Exception
thrown.
In
Another possible solution, to make sure that error have happened:
$errorHappened = false;
try {
//call your code here
} catch (\Exception $e) {
$errorHappened = true;
$this->assertEquals($e->getMessage(), "Expected error text");
$this->assertEquals($e->getCode(), "Expected error code");
}
$this->assertTrue($errorHappened);