Laravel 実践開発(https://www.shuwasystem.co.jp/book/9784798059075.html)で勉強しています。
コンテンツ内の文字列を確認するテストなのですが、testPowerMyService()で"1番のりんごですね!"でテストが通るのは正常です。
testPowerMyServiceByMock()で'あああああああ'でもテストが通ってしまいます。なぜでしょうか?教えていただけると嬉しいです。
public function testPowerMyService() { $msg = '1番のりんごですね!'; $response = $this->get('/hello'); $content = $response->getContent(); echo $content; $response->assertSeeText( $msg, $content ); } public function testPowerMyServiceByMock() { $msg = 'あああああああ'; $mock = Mockery::mock(PowerMyService::class); $mock->shouldReceive('setId') ->withArgs([1]) ->once() ->andReturn(null); $mock->shouldReceive('say') ->once() ->andReturn($msg); $this->instance(PowerMyService::class, $mock); $response = $this->get('/hello'); $content = $response->getContent(); $response->assertSeeText($msg, $content); }
あなたの回答
tips
プレビュー