【发布时间】:2017-01-08 01:51:10
【问题描述】:
我想模拟CommentModel 的getReviews 方法,以便测试它是否在ApiReviewCommentsController 方法中被调用。
这是我的方法:
class ApiReviewCommentsController extends ApiController
{
private $commentsModel;
public function __construct(CommentsModel $commentsModel)
{
$this->commentsModel = $commentsModel;
$this->commentsModel->getReviewComment();
}
}
这是我的测试:
public function testThatItShouldAddGetAllCommentsForReviewId(){
$reviewId = 1;
$commentsModel = $this->getMockBuilder(CommentsModel::class)->getMock();
$controller = new ApiReviewCommentsController($commentsModel);
$commentsModel->expects($this->once())
->method('getReviewComments')
->willReturn(false);
}
这是我的错误:
方法名称的期望失败等于 当被调用 1 次时。
方法预期调用1次,实际调用0次。
请问为什么没有调用该方法?
【问题讨论】:
标签: php unit-testing laravel-4 mocking phpunit