According to the PHPUnit Documentation on @expectedExceptionMessage
, the string must only be a substring of the actual Exception
thrown.
In
When this question was posted, PHPUnit v3.7 didn't have a solution to this problem. Newer versions have a new @expectedExceptionMessageRegExp option that you can use to add a regular expression to match the exception message against.
Your case, using ^ and $ to force the string to be exactly what is expected, could look like this:
/**
* @expectedException \Exception
* @expectedExceptionMessageRegExp /^a < b\.$/
*/
public function testValues_ALessBOnly()
{
$myClass = new MyClass()
$myClass->validate(1, 2, 4, 3);
}