I start with TDD and Laravel. In particular, I start with routes. I defined some, and I defined it poorly, so I was delighted with the "new" concept of TDD, I wanted to write some test for them.
The idea was to check routes, and only routes, in isolation, since everything I read about TDD recommendations. I know what I can do $this->call->('METHOD','something'), and the test answer is normal or something else, but I would like to know that the right method of the right controller is being called.
So, I thought I could mock the controller. This was my first attempt:
public function test_this_route_work_as_expected_mocking_the_controller()
{
$drawController = \Mockery::mock('App\Http\Controllers\DrawController');
$drawController->shouldReceive('show')->once();
App::instance('App\Http\Controllers\DrawController', $drawController);
$response = $this->call('GET','/draw/1');
print($response);
}
Route::resource('draw', 'DrawController');, , . . : " Mockery_0_App_Http_Controllers_DrawController:: getAfterFilters() ". :
$drawController->getAfterFilters()->willReturn(array());
:
BadMethodCallException: Method Mockery_0_App_Http_Controllers_DrawController::getAfterFilters() does not exist on this mock object
:
public function test_this_route_work_as_expected_mocking_the_controller_workaround()
{
$drawController = \Mockery::mock('App\Http\Controllers\DrawController');
$drawController->shouldReceive('getAfterFilters')->atMost(1000)->andReturn(array());
$drawController->shouldReceive('getBeforeFilters')->atMost(1000)->andReturn(array());
$drawController->shouldReceive('getMiddleware')->atMost(1000)->andReturn(array());
$drawController->shouldReceive('callAction')->once()->with('show',Mockery::any());
App::instance('App\Http\Controllers\DrawController', $drawController);
$response = $this->call('GET','/draw/1');
}
shouldReceives willReturns: atMost(1000) . :
1) Laravel 5? , , , ,
2) "MockStub" ? ?
.