本文整理汇总了PHP中PHPUnit_Framework_TestCase::throwException方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Framework_TestCase::throwException方法的具体用法?PHP PHPUnit_Framework_TestCase::throwException怎么用?PHP PHPUnit_Framework_TestCase::throwException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPUnit_Framework_TestCase
的用法示例。
在下文中一共展示了PHPUnit_Framework_TestCase::throwException方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getValidIpAddress
/**
* @test
*/
public function getValidIpAddress()
{
$ip = '127.0.0.1';
$exception = parent::throwException(new CouldNotResolveIpAddressException());
$ipProvider = $this->getIpProviderMock($exception, 'foobar', $ip);
$currentIpAddress = $ipProvider->getCurrentIpAddress();
parent::assertEquals($ip, $currentIpAddress);
}
示例2: createUndeclaredMethods
private function createUndeclaredMethods()
{
foreach (array_keys($this->originClassMethods) as $originalMethodName) {
if (false == array_key_exists($originalMethodName, $this->mockMethods)) {
$method = $this->mock->expects($this->testCase->any());
$method->method($originalMethodName);
$method->will($this->testCase->throwException(new UndeclaredMethodInvocationException($originalMethodName)));
}
}
}
示例3: parseMockMethodArgs
/** @return array */
protected function parseMockMethodArgs($method, array $args)
{
$expects = TestCase::any();
$with = null;
$will = TestCase::returnValue(null);
if (count($args) == 1) {
if ($args[0] instanceof InvokedRecorder || $args[0] instanceof InvokedAtIndex) {
$expects = $args[0];
} else {
$will = $args[0];
}
} elseif (count($args) == 2) {
if ($args[1] instanceof InvokedRecorder || $args[1] instanceof InvokedAtIndex) {
if (is_array($args[0])) {
list($with, $expects) = $args;
} else {
list($will, $expects) = $args;
}
} elseif (is_array($args[0])) {
list($with, $will) = $args;
} else {
throw new \InvalidArgumentException();
}
} elseif (count($args) == 3) {
if (is_array($args[0]) && ($args[2] instanceof InvokedRecorder || $args[2] instanceof InvokedAtIndex)) {
list($with, $will, $expects) = $args;
} else {
throw new \InvalidArgumentException();
}
}
if ($will instanceof \Exception) {
$will = PhpUnitTestCase::throwException($will);
} elseif (!$will instanceof Stub && !$will instanceof \Closure && !is_null($will)) {
$will = PhpUnitTestCase::returnValue($will);
}
return array('method' => $method, 'expects' => $expects, 'with' => $with, 'will' => $will);
}
示例4: throwException
/**
*
*
* @param Exception $exception
* @return PHPUnit_Framework_MockObject_Stub_Exception
* @since Method available since Release 3.1.0
*/
function throwException(Exception $exception)
{
return PHPUnit_Framework_TestCase::throwException($exception);
}