【发布时间】:2015-12-18 22:13:24
【问题描述】:
目标.php
<?php
class Target
{
public function validate()
{
$this->getData();
return true;
}
public function getData()
{
return array();
}
}
TargetTest.php
<?php
class TargetTest extends PHPUnit_Framework_TestCase
{
public function testValidate()
{
$mock = m::mock('Target');
$mock->shouldReceive('getData')
->once();
$expected = $this->exp->validate();
$this->assertTrue($expected);
}
}
结果
Mockery\Exception\InvalidCountException: Method getData() from Mockery_1_ExpWarning should be called
exactly 1 times but called 0 times.
我使用Mockery作为mock工具,示例总是关于如何用DI进行mock,我想知道我可以mock内部方法吗?
【问题讨论】:
-
您的 TargetTest 课程有点混乱。 ExpWarning 是 Target 类的真实类名吗?他的 $this->exp 对象是谁?为什么不 $mock?请解释清楚
标签: php unit-testing phpunit mockery