【发布时间】:2014-11-28 05:40:15
【问题描述】:
我有一个实现内置 Countable 接口的 PHP 对象。然后我模拟这个对象进行单元测试:
$mapper = $this->getMockBuilder("Search_Model_Mapper_Search")
->disableOriginalConstructor()
->setMethods(array("find", "count"))
->getMock();
$mapper->expects($this->once())
->method("find")
->with(array("body" => "kajsgfkblkjasfgdjkb"))
->will($this->returnValue($mapper));
$mapper->expects($this->once())
->method("count")
->will($this->returnValue(0));
被测试的代码部分如下:
$results = $this->getMapper("fulltext")->find(array("body" => $requestParams['q']));
if (count($results) === 0) {
$this->view->messages[] = "Sorry, no results were found. Please check your search terms and try again";
return;
}
PHPUnit 4.0.17 无法识别 count() 的使用 - 我必须使用 $results->count() 才能满足断言。
PHPUnit 3.4 没有这个问题。
我在 PHPUnit 文档中找不到任何帮助解决此问题的内容 - 有什么我遗漏的吗?
【问题讨论】:
标签: php interface count mocking phpunit