publicfunctiontestShouldReturnTestMessageWithTomWhenCallSayHelloGivenNameTom() { $response = $this->get('/sayHello/tom'); $response->assertStatus(200)->assertSee('Hello tom, this a test message'); }
当对 SayHelloFormatter 中的 format 进行mock时:
1 2 3 4 5 6 7 8 9 10
publicfunctiontestShouldReturnMethodHasBeenMockedWhenCallSayHelloGivenNameTomAndUsingMockery() { $mock = Mockery::mock(Controller::class)->makePartial(); $mock->shouldReceive('format')->andReturn('This method has been mocked.'); $this->app->instance(Controller::class, $mock);
$response = $this->get('/sayHello/tom');
$response->assertStatus(200)->assertSee('This method has been mocked.'); }