According to the PHPUnit Documentation on @expectedExceptionMessage
, the string must only be a substring of the actual Exception
thrown.
In
If your test class extends PHPUnit_Framework_TestCase
, you should be able to use setExpectedException
method:
/**
* @param mixed $exceptionName
* @param string $exceptionMessage
* @param int $exceptionCode
*
* @since Method available since Release 3.2.0
*/
public function setExpectedException($exceptionName, $exceptionMessage = '', $exceptionCode = null)
{
$this->expectedException = $exceptionName;
$this->expectedExceptionMessage = $exceptionMessage;
$this->expectedExceptionCode = $exceptionCode;
}
It allows you to assert an exception class alone, exception message and even exception code.