1
주일부터 phpunit을 배우고 있습니다. 테스트 된 클래스에서 하나의 메소드 만 조롱하는 방법을 모르겠습니다. (예를 들어서 만 네임 스페이스를 쓰지 않았습니다). 어쩌면 당신은 나에게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());
}
}