I found this that might help: http://stackoverflow.com/questions/23625478/mocking-in-controller-tests-with-laravel-model-binding
Jun 1, 2015
3
Level 1
Route Model Binding problem with Unit testing
I have:
//route.php
Route::pattern('record', '[0-9]+');
post('record/{record}/edit', ['as' => 'record.update', 'uses' =>'Backend\User\RecordController@update']);
//RecordController.php
//..
RecordController::__construct(RecordRepositoryContract $model)
//...
RecordController::update(RecordRequest $request, Record $record)
{
$response = $this->model->update($record, $request->only('name', 'tags'));
//...
I am mocking $request, $model and i am calling 'record.update' in my tests like this:
$response = $this->route('POST', 'record.update', 1);
I have a record id = 1.
but I am getting redirect to '/' and I don't know why...
My RouteServiceProvider.php is like this:
$router->model('record', 'App\Eloquents\Record', function(){
throw new RecordNotFoundException();
});
it's not throwing exception just been redirect to '/'. I don't know why...
Level 1
Finally found my problem:
I typed this:
$this->app->instance('App\Contracts\RecordRepositoryContract', $request);
instead of this:
$this->app->instance('App\Http\Requests\RecordRequest', $request);
I guess it's because yesterday was already too late at night, hahaha.
1 like
Please or to participate in this conversation.