1
私は週からphpunitを学んでいます。テストされたクラスから一つのメソッドだけをどうやって模倣するのか分かりません。 (それは私が名前空間を書いていないので例です)。たぶん、あなたは私にPhpunit模擬テストクラスの1つのメソッド - Mockeryを使用
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());
}
}