【发布时间】:2011-08-01 21:52:01
【问题描述】:
我注意到,当我使用模拟对象时,PHPUnit 会正确报告执行的测试数量,但会错误地报告我所做的断言数量。事实上,每次我嘲笑它都算作另一个断言。一个包含 6 个测试、7 个断言语句的测试文件,每个测试模拟一次报告 6 个测试、13 个断言。
这是一个测试文件,除一个测试外,其他所有测试都被删除(此处用于说明),另外我介绍了另一个不存根的测试来追踪此问题。 PHPUnit 报告 2 个测试,3 个断言。我删除了虚拟对象:1 个测试,2 个断言。
require_once '..\src\AntProxy.php';
class AntProxyTest extends PHPUnit_Framework_TestCase {
const sample_client_id = '495d179b94879240799f69e9fc868234';
const timezone = 'Australia/Sydney';
const stubbed_ant = "stubbed ant";
const date_format = "Y";
public function testBlankCategoryIfNoCacheExists() {
$cat = '';
$cache_filename = $cat.'.xml';
if (file_exists($cache_filename))
unlink($cache_filename);
$stub = $this->stub_Freshant($cat);
$expected_output = self::stubbed_ant;
$actual_output = $stub->getant();
$this->assertEquals($expected_output, $actual_output);
}
public function testDummyWithoutStubbing() {
$nostub = new AntProxy(self::sample_client_id, '', self::timezone, self::date_format);
$this->assertTrue(true);
}
private function stub_FreshAnt($cat) {
$stub = $this->getMockBuilder('AntProxy')
->setMethods(array('getFreshAnt'))
->setConstructorArgs(array(self::sample_client_id, $cat, self::timezone, self::date_format))
->getMock();
$stub->expects($this->any())
->method('getFreshAnt')
->will($this->returnValue(self::stubbed_ant));
return $stub;
}
}
就像在框架的一个模拟方法中留下了一个断言。有没有办法显示每个(通过)断言?
【问题讨论】:
标签: phpunit