我在一个解析一些 xml 的类中有一个方法。如果找到标签<status >failure</status>,则返回异常。
我想构建一个单元测试来检查此方法在 status=failure 时是否返回异常。
目前,我无法使用phpunit和MOCKING完成它?
例子:
<?php
$mock = $this->getMock('Service_Order_Http', array('getResponse'));
$mock->expects($this->any())
->method('getResponse')
->will($this->throwException(new Exception()));
$e = null;
try {
$mock->getResponse();
} catch (Exception $e) {
}
$this->assertTrue($e instanceof Exception, "Method getResponse should have thrown an exception");
//phpunit sends back: PHPUnit_Framework_ExpectationFailedException : Failed asserting that exception of type "Exception" is thrown.
?>
谢谢你的帮助