本文整理汇总了PHP中PHPUnit_Util_Test::getExpectedException方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Util_Test::getExpectedException方法的具体用法?PHP PHPUnit_Util_Test::getExpectedException怎么用?PHP PHPUnit_Util_Test::getExpectedException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPUnit_Util_Test
的用法示例。
在下文中一共展示了PHPUnit_Util_Test::getExpectedException方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetExpectedException
public function testGetExpectedException()
{
$this->assertEquals(array('class' => 'FooBarBaz', 'code' => 0, 'message' => ''), PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testOne'));
$this->assertEquals(array('class' => 'Foo_Bar_Baz', 'code' => 0, 'message' => ''), PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testTwo'));
$this->assertEquals(array('class' => 'Foo\\Bar\\Baz', 'code' => 0, 'message' => ''), PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testThree'));
$this->assertEquals(array('class' => 'ほげ', 'code' => 0, 'message' => ''), PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testFour'));
$this->assertEquals(array('class' => 'Class', 'code' => 1234, 'message' => 'Message'), PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testFive'));
$this->assertEquals(array('class' => 'Class', 'code' => 1234, 'message' => 'Message'), PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testSix'));
}
示例2: testGetExpectedException
public function testGetExpectedException()
{
$this->assertSame(array('class' => 'FooBarBaz', 'code' => NULL, 'message' => ''), PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testOne'));
$this->assertSame(array('class' => 'Foo_Bar_Baz', 'code' => NULL, 'message' => ''), PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testTwo'));
$this->assertSame(array('class' => 'Foo\\Bar\\Baz', 'code' => NULL, 'message' => ''), PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testThree'));
$this->assertSame(array('class' => 'ほげ', 'code' => NULL, 'message' => ''), PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testFour'));
$this->assertSame(array('class' => 'Class', 'code' => 1234, 'message' => 'Message'), PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testFive'));
$this->assertSame(array('class' => 'Class', 'code' => 1234, 'message' => 'Message'), PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testSix'));
$this->assertSame(array('class' => 'Class', 'code' => 'ExceptionCode', 'message' => 'Message'), PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testSeven'));
$this->assertSame(array('class' => 'Class', 'code' => 0, 'message' => 'Message'), PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testEight'));
$this->assertSame(array('class' => 'Class', 'code' => ExceptionTest::ERROR_CODE, 'message' => ExceptionTest::ERROR_MESSAGE), PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testNine'));
$this->assertSame(array('class' => 'Class', 'code' => My\Space\ExceptionNamespaceTest::ERROR_CODE, 'message' => My\Space\ExceptionNamespaceTest::ERROR_MESSAGE), PHPUnit_Util_Test::getExpectedException('My\\Space\\ExceptionNamespaceTest', 'testConstants'));
// Ensure the Class::CONST expression is only evaluated when the constant really exists
$this->assertSame(array('class' => 'Class', 'code' => 'ExceptionTest::UNKNOWN_CODE_CONSTANT', 'message' => 'ExceptionTest::UNKNOWN_MESSAGE_CONSTANT'), PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testUnknownConstants'));
$this->assertSame(array('class' => 'Class', 'code' => 'My\\Space\\ExceptionNamespaceTest::UNKNOWN_CODE_CONSTANT', 'message' => 'My\\Space\\ExceptionNamespaceTest::UNKNOWN_MESSAGE_CONSTANT'), PHPUnit_Util_Test::getExpectedException('My\\Space\\ExceptionNamespaceTest', 'testUnknownConstants'));
}
示例3: setExpectedExceptionFromAnnotation
/**
* @since Method available since Release 3.4.0
*/
protected function setExpectedExceptionFromAnnotation()
{
try {
$expectedException = PHPUnit_Util_Test::getExpectedException(get_class($this), $this->name);
if ($expectedException !== false) {
$this->setExpectedException($expectedException['class'], $expectedException['message'], $expectedException['code']);
if (!empty($expectedException['message_regex'])) {
$this->setExpectedExceptionRegExp($expectedException['class'], $expectedException['message_regex'], $expectedException['code']);
}
}
} catch (ReflectionException $e) {
}
}
示例4: setExpectedExceptionFromAnnotation
/**
* @since Method available since Release 3.4.0
*/
protected function setExpectedExceptionFromAnnotation()
{
try {
$method = new ReflectionMethod(get_class($this), $this->name);
$methodDocComment = $method->getDocComment();
$expectedException = PHPUnit_Util_Test::getExpectedException($methodDocComment);
if ($expectedException !== FALSE) {
$this->setExpectedException($expectedException['class'], $expectedException['message'], $expectedException['code']);
}
} catch (ReflectionException $e) {
}
}
示例5: testGetExpectedException
public function testGetExpectedException()
{
$this->assertEquals(array('class' => 'FooBarBaz', 'code' => 0, 'message' => ''), PHPUnit_Util_Test::getExpectedException('@expectedException FooBarBaz'));
$this->assertEquals(array('class' => 'Foo_Bar_Baz', 'code' => 0, 'message' => ''), PHPUnit_Util_Test::getExpectedException('@expectedException Foo_Bar_Baz'));
$this->assertEquals(array('class' => 'Foo\\Bar\\Baz', 'code' => 0, 'message' => ''), PHPUnit_Util_Test::getExpectedException('@expectedException Foo\\Bar\\Baz'));
}
示例6: testGetExpectedRegExp
/**
* @covers PHPUnit_Util_Test::getExpectedException
*/
public function testGetExpectedRegExp()
{
$this->assertArraySubset(array('message_regex' => '#regex#'), PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testWithRegexMessage'));
$this->assertArraySubset(array('message_regex' => '#regex#'), PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testWithRegexMessageFromClassConstant'));
$this->assertArraySubset(array('message_regex' => 'ExceptionTest::UNKNOWN_MESSAGE_REGEX_CONSTANT'), PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testWithUnknowRegexMessageFromClassConstant'));
}
示例7: createTest
/**
* @param ReflectionClass $theClass
* @param string $name
* @param array $classGroups
* @return PHPUnit_Framework_Test
*/
public static function createTest(ReflectionClass $theClass, $name, array $classGroups = array())
{
$className = $theClass->getName();
$method = new ReflectionMethod($className, $name);
$methodDocComment = $method->getDocComment();
if (!$theClass->isInstantiable()) {
return self::warning(sprintf('Cannot instantiate class "%s".', $className));
}
$constructor = $theClass->getConstructor();
$expectedException = PHPUnit_Util_Test::getExpectedException($methodDocComment);
if ($constructor !== NULL) {
$parameters = $constructor->getParameters();
// TestCase() or TestCase($name)
if (count($parameters) < 2) {
$test = new $className();
} else {
$data = PHPUnit_Util_Test::getProvidedData($className, $name, $methodDocComment);
$groups = PHPUnit_Util_Test::getGroups($methodDocComment, $classGroups);
if (is_array($data) || $data instanceof Iterator) {
$test = new PHPUnit_Framework_TestSuite($className . '::' . $name);
foreach ($data as $_dataName => $_data) {
$_test = new $className($name, $_data, $_dataName);
if ($_test instanceof PHPUnit_Framework_TestCase && isset($expectedException)) {
$_test->setExpectedException($expectedException['class'], $expectedException['message'], $expectedException['code']);
}
$test->addTest($_test, $groups);
}
} else {
$test = new $className();
}
}
}
if ($test instanceof PHPUnit_Framework_TestCase) {
$test->setName($name);
if (isset($expectedException)) {
$test->setExpectedException($expectedException['class'], $expectedException['message'], $expectedException['code']);
}
}
return $test;
}
示例8: getExpectedExceptionFromAnnotation
/**
* @since Method available since Release 3.4.0
* @param $class
* @param $methodName
* @return \Exception | null
*/
protected static function getExpectedExceptionFromAnnotation($class, $methodName)
{
try {
return \PHPUnit_Util_Test::getExpectedException(get_class($class), $methodName);
} catch (\ReflectionException $e) {
}
return null;
}
示例9: setExpectedExceptionFromAnnotation
/**
* @since Method available since Release 3.4.0
*/
protected function setExpectedExceptionFromAnnotation()
{
try {
$expectedException = PHPUnit_Util_Test::getExpectedException(get_class($this), $this->name);
if ($expectedException !== false) {
$this->expectException($expectedException['class']);
if ($expectedException['code'] !== null) {
$this->expectExceptionCode($expectedException['code']);
}
if ($expectedException['message'] !== '') {
$this->expectExceptionMessage($expectedException['message']);
} elseif ($expectedException['message_regex'] !== '') {
$this->expectExceptionMessageRegExp($expectedException['message_regex']);
}
}
} catch (ReflectionException $e) {
}
}