パーシャルモックが何であるかを理解することに問題があります。以下の非常に単純な例:モックリー - パーシャルモック
UserEventTest.php
class UserEventTest extends PHPUnit_Framework_TestCase {
public function tearDown()
{
Mockery::close();
}
/**
* @test
*/
public function user_register()
{
$mailer = Mockery::mock('\App\Mailer');
$mailer->shouldReceive('setEmail')
->shouldReceive('sendActivationMessage')
->andReturn(true);
$user = Mockery::mock(\App\User::class);
$user->shouldReceive('getEmail')
->andReturn('[email protected]');
$userEventHandler = new \App\UserEventHandler($mailer, $user);
$this->assertEquals(true, $userEventHandler->onUserRegister());
}
}
このテストパスと(結構ですので)実際に電子メールを送信しません。このモックを部分模倣に変更すると、次のようになります。
$mailer = Mockery::mock('\App\Mailer')->makePartial();
それでも問題はないと思いますが、違いは何ですか?
例えば、にそれを変更:
$mailer = Mockery::mock('\App\Mailer[setEmail]');
すると、実際に電子メールを送信します。
私はこれらの相違点(特に部分模擬と通常の標準模擬とを比較すると)と特定の種類のモックをいつ使用するのかを教えてもらえますか?
Bobさんは、可能なすべてのテストダブルの違いを説明してくれました。https://8thlight.com/blog/uncle-bob/2014/05/14/TheLittleMocker.html – mingos