public static function PHPUnit_Util_Test::getExpectedException

Returns the expected exception for a test.

@since Method available since Release 3.3.6

Parameters

string $className:

string $methodName:

Return value

array

2 calls to PHPUnit_Util_Test::getExpectedException()
PHPUnit_Framework_TestCase::setExpectedExceptionFromAnnotation in drupal/core/vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php
@since Method available since Release 3.4.0
Util_TestTest::testGetExpectedException in drupal/core/vendor/phpunit/phpunit/Tests/Util/TestTest.php

File

drupal/core/vendor/phpunit/phpunit/PHPUnit/Util/Test.php, line 146

Class

PHPUnit_Util_Test
Test helpers.

Code

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;
}