我想要的功能測試,這是被其他服務中嘲笑服務:如何嘲笑服務,以注入其正確
$client = static::createClient();
$stub = $this->createMock(MailService::class);
$stub->method('sendMailToUser')->willReturn(9);
$client->getContainer()->set('belka.auth_bundle.mail_service', $stub);
// the *real* test should start here
,如果我試圖把一個die
命令內原來的sendMailToUser
,我得到的是代碼停止運行,儘管我試圖通過返回9來嘲笑它。它有什麼問題?我測試該服務具有以下聲明,然後我猜注入的服務是在一個上面寫道:
belka.auth_bundle.user_handler:
class: Belka\AuthBundle\Handler\UserHandler
arguments:
- '@belka.auth_bundle.user_repository'
- '@belka.auth_bundle.mail_service'
calls:
- [setRequest, ["@request_stack"]]
- [setSettings, ["@belka.auth_bundle.setting_handler"]]
- [setBodyJsonHandler, ["@belka.container_support_bundle.body_json_handler"]]
- [setQuantityHandler, ["@belka.container_support_bundle.quantityhandler"]]