Returns the expected exception for a test.
@since Method available since Release 3.3.6
string $className:
string $methodName:
array
public static function getExpectedException($className, $methodName) {
$reflector = new ReflectionMethod($className, $methodName);
$docComment = $reflector
->getDocComment();
$docComment = substr($docComment, 3, -2);
if (preg_match(self::REGEX_EXPECTED_EXCEPTION, $docComment, $matches)) {
$annotations = self::parseTestMethodAnnotations($className, $methodName);
$class = $matches[1];
$code = NULL;
$message = '';
if (isset($matches[2])) {
$message = trim($matches[2]);
}
else {
if (isset($annotations['method']['expectedExceptionMessage'])) {
$message = self::_parseAnnotationContent($annotations['method']['expectedExceptionMessage'][0]);
}
}
if (isset($matches[3])) {
$code = $matches[3];
}
else {
if (isset($annotations['method']['expectedExceptionCode'])) {
$code = self::_parseAnnotationContent($annotations['method']['expectedExceptionCode'][0]);
}
}
if (is_numeric($code)) {
$code = (int) $code;
}
else {
if (is_string($code) && defined($code)) {
$code = (int) constant($code);
}
}
return array(
'class' => $class,
'code' => $code,
'message' => $message,
);
}
return FALSE;
}