Codeception: Laravel5 Undefined index: HTTP_HOST issue

Created on 22 Jun 2016  路  15Comments  路  Source: Codeception/Codeception

I'm facing an exception of "[ErrorException] Undefined index: HTTP_HOST" while running API test with codeception 2.2 with Laravel module.
Everything was working just fine before but after upgrading to the new edition this exception has been thrown.
thanks,
Mohamed.

BUG Laravel5

Most helpful comment

Ok, thanks for letting me know. I will investigate this issue further, but at least you have a workaround for now :)

All 15 comments

Don't use $_SERVER in your code, retrieve headers from request object.
https://laravel.com/api/5.2/Illuminate/Http/Request.html#method_header

Have the same issue, didn't use $_SERVER in my code, getting all headers from the Request object only

Can you provide your Codeception and suite configuration files?

And what version of Laravel are you using?

Do you get this error for all tests or only in specific tests?

Please provide additional details to make it a bit easier for us to find out what the problem could be.

Hello,

  • I'm using Laravel Framework version 5.2.39.
  • Yes, I'm getting this error for all tests, not just specific one.

Api suite configuration:

class_name: ApiTester
modules:
    enabled:
        - \Helper\Api
        - Asserts
        - Filesystem
        - Laravel5:
            environment_file: .env.test
        - REST:
            url: http://test-api.dev
            depends: Laravel5

thanks

You should remove the url configuration option for the REST module from your api suite config file. If your tests do depend on an URL for the application you should set it through the url configuration option for the Laravel5 module.

I don't know why this does not give problems in earlier versions of Codeception and starts giving errors for Codeception 2.2 though. Any idea @Naktibalda or @DavertMik?

I have removed the "URL" configuration option and hardcoded the URL inside the test itself to avoid this conflict but unfortunately got the same error

I created a clean install of the latest versions of Laravel 5 and Codeception, you can view the code at https://github.com/janhenkgerritsen/codeception-issue-3263.

I added an API suite with a sample test CheckErrorCept. The API suite configuration looks like this:

class_name: ApiTester
modules:
    enabled:
        - \Helper\Api
        - Asserts
        - Filesystem
        - Laravel5:
            environment_file: .env.test
            url: http://test-api.dev
        - REST:
            depends: Laravel5

Like this, everything works as expected. But if you move the url configuration option from the Laravel5 section to the REST section you will get the error you mention. So to reproduce your error you should have the following in the API suite configuration file:

        - Laravel5:
            environment_file: .env.test
        - REST:
            depends: Laravel5
            url: http://test-api.dev

Please take a look at this code and see what is different from your own setup. Maybe that will give a clue to what is going wrong at your end.

thanks for the code,
I used the same code you sent in the sample test CheckErrorCept and it works fine but when I tried to change the URL at the same code to another page "http://test-api.dev/demo/users?page=2" that I know it works well in the browser it gives me the same error.
I ran it under debugging mode "-vvv" and there was an issue with
[ErrorException] Undefined index: HTTP_HOST
/vendor/codeception/codeception/src/Codeception/Module/Laravel5.php:1015
/vendor/codeception/codeception/src/Codeception/Module/Laravel5.php:998
...

Could you try to put the configuration of the Laravel module below the configuration of the REST module? So something like this:

        - REST:
            depends: Laravel5
            url: http://test-api.dev
        - Laravel5:
            environment_file: .env.test

I think I found an issue, but this should be a workaround for this issue. Can you let me know if this fixes your problem? Or maybe you get another error message?

Yes, it works fine after changing the order of the modules.
thanks

Ok, thanks for letting me know. I will investigate this issue further, but at least you have a workaround for now :)

Finally found this thread after hours of search. @janhenkgerritsen If it's not too much trouble, could you make sure that your sample (https://github.com/janhenkgerritsen/codeception-laravel5-sample/blob/codeception-2.2/tests/api.suite.yml) respects this issue?
I believe people usually mirror that sample of yours to try and achieve Codeception Testing with Laravel 5 and if that sample have the correct order there's a chance it will save some time.

I'm not experienced with Git and GitHub yet, but I will be trying to make a Pull Request with what I mean here, but in case I fail to do that, I'm posting this comment.

Thanks for the pull request, I hadn't thought of updating the sample application myself.

Issue fixed with #3539.

I got the same error while installing :composer require barryvdh/laravel-debugbar:~2.4
Removed this code from appServiceProvider: $_SERVER['HTTP_HOST']
Now it is working well.

Was this page helpful?
0 / 5 - 0 ratings