【发布时间】:2018-05-26 01:39:53
【问题描述】:
我从一周开始就在学习 phpunit。我不知道如何只模拟测试类中的一种方法。 (这只是一个例子,所以我没有写命名空间)。也许你可以帮助我
class SomeService
{
public function firstMethod()
{
return 'smth';
}
public function secondMethd()
{
return $this->firstMethod() . ' plus some text example';
}
}
和测试:
class SomeServiceUnitTest extends TestCase
{
private $someService;
public function setUp()
{
parent::setUp();
$this->someService = new SomeService();
}
public function tearDown()
{
$this->someService = null;
parent::tearDown();
}
public function test_secondMethod()
{
$mock = Mockery::mock('App\Services\SomeService');
$mock->shouldReceive('firstMethod')->andReturn('rerg');
exit($this->walletService->secondMethd());
}
}
【问题讨论】:
标签: php unit-testing phpunit mockery