Okipa's avatar

Laravel 5.2 Codeception functional test issue with PUT / PATCH requests

Hi there,

I have a problem on the update treatment processed into my functional tests on Codeception : I systematically have a 404 error. Here are the details.

Everything is going well for every other simulated http requests but when codeception tries to execute the update method on a put HTTP request (POST request with a "_method" param having the value "PUT") is never executed by my controller, which lead codeception on the update url without the redirection that should happen after the treatment in this update method. I tried to redirect to my home page on top of my update method to test that fact and the redirection never happens.

For information, I use the Laravel5 module. Here is my functional.suite.yml file content :

class_name: FunctionalTester
    modules:
        enabled:
            - Asserts
            - \Helper\Functional
            - MailCatcher
            - Laravel5:
                environment_file: .env.testing
    config:
        MailCatcher:
            url: 'http://192.168.10.10'
            port: '1080'

I tried to replace the "PUT" value of the "_method" param by "PATCH" to see if any change could be seen but the problem persists and the behaviour is still the same.

Codeception includes the Laravel5 app to test it. The only clue I have is that the testing environment has a problem to interpret the PUT or PATCH request. There is no problem for a simple POST request (creation doesn't cause any problem).

I precise that the HTML form is correct, the update happens correctly in my local environment and the http request contains correct params. Here is what I have when I execute it the with the --debug option :

[Uri] http://project/en/permissions/update
[Method] POST
[Parameters] {"_token":"RUx7DjU3b6GEjodnpwXvJJYJIcmQJGbabj23q0yK","_method":"PATCH","_id":"1","name_en":"Administrator","name_fr":"Administrateur","slug":"admin"}
[Page] http://project/en/permissions/update
[Response] 200
[Request Cookies] {"XSRF-TOKEN":"eyJpdiI6InZQV2NVcTRoZHVONXYzZzNLTnBWU1E9PSIsInZhbHVlIjoiWWhWa0kyUGxJNkJRTXIyaEhVcDdHR0tRcklHZStpVWdlTjlDdmRKVmEyVDFPWkxBVmhLc1lra05zeWh1ZWtKMENCc29lWFZTN2lSd3dIbjZyNEo5eWc9PSIsIm1hYyI6ImEzMDNmOWM5OGQzNzE4ZWI5MDg0MTI0ZmQwMTI1ZTk0OTM1OTY4NjA5ZTZjMGFhYTI0MTdlMzMzM2QyMWQ4MzUifQ==","laravel_session":"eyJpdiI6ImF4cVFYYVNUU3J0WUd2VzNRZlhSc3c9PSIsInZhbHVlIjoibDdPd3ZEZVZOdDJwRlBjMVZtc2dNM0I3WUw0REEzK25NVFVWT1FIRjEzR05tRGZLXC9SYUZkRmhEdXlyQVdybURHTWVQVUtucnBkZEwwaTN4NWF6XC9YQT09IiwibWFjIjoiMzliODY4ZWUwYmZjODI1OTVkMTBiYjA4ODY2OWNiODc3ZTI1NzAzZmJhMjg4OTY4Y2MzM2VkMjYyYTkwOTQ2MyJ9"}
[Response Headers] {"cache-control":["no-cache"],"Set-Cookie":[{},{}]}

As you can see, the process end on a 200 response and that is all.. I tested it with a few pages and the problem is the same everywhere.

Here is my routes file. As you can see, I use LaravelLocalization, this is a multilingual app. I only show you the permissions routes but they are all managed this way.

Route::group([
    'prefix'     => LaravelLocalization::setLocale(),
    'middleware' => [
        'auth',
        'localize',
        'localeSessionRedirect',
        'localizationRedirect',
    ]], function () {
        // permissions
        Route::get(LaravelLocalization::transRoute('routes.permissions.index'), ['as' => 'permissions.index', 'uses' => 'User\PermissionsController@index']);
        Route::get(LaravelLocalization::transRoute('routes.permissions.create'), ['as' => 'permissions.create', 'uses' => 'User\PermissionsController@create']);
        Route::post(LaravelLocalization::transRoute('routes.permissions.store'), ['as' => 'permissions.store', 'uses' => 'User\PermissionsController@store']);
        Route::get(LaravelLocalization::transRoute('routes.permissions.edit'), ['as' => 'permissions.edit', 'uses' => 'User\PermissionsController@edit']);
        Route::put(LaravelLocalization::transRoute('routes.permissions.update'), ['as' => 'permissions.update', 'uses' => 'User\PermissionsController@update']);
        Route::delete(LaravelLocalization::transRoute('routes.permissions.destroy'), ['as' => 'permissions.destroy', 'uses' => 'User\PermissionsController@destroy']); 
    ]);

Following the solution explained [here][1], I tried to place the following code into the file tests/_bootstrap.php :

Request::enableHttpMethodParameterOverride();

It had no effect, I still have a 200 response and the update method from my controller is never reached.
I checked if the $httpMethodParameterOverride param was passed to true just after the method execution and could verify that is has been successful set to true.

I need help on this issue, I'm am blocked and I have no clue.. [1]: http://stackoverflow.com/questions/34922592/laravel-and-codeception-test-fails-on-put-forms

0 likes
2 replies
Okipa's avatar

I have a clue on an investigation way : I succeeded to execute an update on a entity named 'District' and this is the only one on my project to have the same route in english and in french. As I specified earlier, I use the LaravelLocalization plugin and the routes translation may be the cause of the bad interpretation of the _method param with the PUTvalue that should redirect toward the update method of my controller.

If anybody has a clue on this problem, I'm taking it !

Please or to participate in this conversation.