You are here

public static function PHPUnit_Util_Test::getExpectedException in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpunit/phpunit/src/Util/Test.php \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

3 calls to PHPUnit_Util_Test::getExpectedException()
PHPUnit_Framework_TestCase::setExpectedExceptionFromAnnotation in vendor/phpunit/phpunit/src/Framework/TestCase.php
@since Method available since Release 3.4.0
Util_TestTest::testGetExpectedException in vendor/phpunit/phpunit/tests/Util/TestTest.php
@covers PHPUnit_Util_Test::getExpectedException @todo Split up in separate tests
Util_TestTest::testGetExpectedRegExp in vendor/phpunit/phpunit/tests/Util/TestTest.php
@covers PHPUnit_Util_Test::getExpectedException

File

vendor/phpunit/phpunit/src/Util/Test.php, line 266

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 = '';
    $messageRegExp = '';
    if (isset($matches[2])) {
      $message = trim($matches[2]);
    }
    elseif (isset($annotations['method']['expectedExceptionMessage'])) {
      $message = self::parseAnnotationContent($annotations['method']['expectedExceptionMessage'][0]);
    }
    if (isset($annotations['method']['expectedExceptionMessageRegExp'])) {
      $messageRegExp = self::parseAnnotationContent($annotations['method']['expectedExceptionMessageRegExp'][0]);
    }
    if (isset($matches[3])) {
      $code = $matches[3];
    }
    elseif (isset($annotations['method']['expectedExceptionCode'])) {
      $code = self::parseAnnotationContent($annotations['method']['expectedExceptionCode'][0]);
    }
    if (is_numeric($code)) {
      $code = (int) $code;
    }
    elseif (is_string($code) && defined($code)) {
      $code = (int) constant($code);
    }
    return array(
      'class' => $class,
      'code' => $code,
      'message' => $message,
      'message_regex' => $messageRegExp,
    );
  }
  return false;
}