New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel5 Undefined index: HTTP_HOST issue #3263

Closed
mohamed-atef opened this Issue Jun 22, 2016 · 15 comments

Comments

Projects
None yet
7 participants
@mohamed-atef

mohamed-atef commented Jun 22, 2016

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.

@Naktibalda

This comment has been minimized.

Show comment
Hide comment
@Naktibalda

Naktibalda Jun 22, 2016

Member

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

Member

Naktibalda commented Jun 22, 2016

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

@RomaGilyov

This comment has been minimized.

Show comment
Hide comment
@RomaGilyov

RomaGilyov Jun 23, 2016

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

RomaGilyov commented Jun 23, 2016

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

@janhenkgerritsen

This comment has been minimized.

Show comment
Hide comment
@janhenkgerritsen

janhenkgerritsen Jun 23, 2016

Contributor

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.

Contributor

janhenkgerritsen commented Jun 23, 2016

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.

@mohamed-atef

This comment has been minimized.

Show comment
Hide comment
@mohamed-atef

mohamed-atef Jun 23, 2016

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

mohamed-atef commented Jun 23, 2016

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

@janhenkgerritsen

This comment has been minimized.

Show comment
Hide comment
@janhenkgerritsen

janhenkgerritsen Jun 23, 2016

Contributor

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?

Contributor

janhenkgerritsen commented Jun 23, 2016

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?

@mohamed-atef

This comment has been minimized.

Show comment
Hide comment
@mohamed-atef

mohamed-atef Jun 23, 2016

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

mohamed-atef commented Jun 23, 2016

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

@janhenkgerritsen

This comment has been minimized.

Show comment
Hide comment
@janhenkgerritsen

janhenkgerritsen Jun 23, 2016

Contributor

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.

Contributor

janhenkgerritsen commented Jun 23, 2016

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.

@mohamed-atef

This comment has been minimized.

Show comment
Hide comment
@mohamed-atef

mohamed-atef Jun 23, 2016

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
...

mohamed-atef commented Jun 23, 2016

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
...

@janhenkgerritsen

This comment has been minimized.

Show comment
Hide comment
@janhenkgerritsen

janhenkgerritsen Jun 23, 2016

Contributor

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?

Contributor

janhenkgerritsen commented Jun 23, 2016

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?

@mohamed-atef

This comment has been minimized.

Show comment
Hide comment
@mohamed-atef

mohamed-atef Jun 23, 2016

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

mohamed-atef commented Jun 23, 2016

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

@janhenkgerritsen

This comment has been minimized.

Show comment
Hide comment
@janhenkgerritsen

janhenkgerritsen Jun 23, 2016

Contributor

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

Contributor

janhenkgerritsen commented Jun 23, 2016

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

@DavertMik DavertMik added the Laravel5 label Jun 27, 2016

@deleugpn

This comment has been minimized.

Show comment
Hide comment
@deleugpn

deleugpn Jul 20, 2016

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.

deleugpn commented Jul 20, 2016

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.

deleugpn added a commit to deleugpn/codeception-laravel5-sample that referenced this issue Jul 20, 2016

Update api.suite.yml
Switching the order of the module dependence in order to resolve the problem mentioned in Codeception/Codeception#3263
@janhenkgerritsen

This comment has been minimized.

Show comment
Hide comment
@janhenkgerritsen

janhenkgerritsen Jul 20, 2016

Contributor

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

Contributor

janhenkgerritsen commented Jul 20, 2016

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

@janhenkgerritsen

This comment has been minimized.

Show comment
Hide comment
@janhenkgerritsen

janhenkgerritsen Sep 23, 2016

Contributor

Issue fixed with #3539.

Contributor

janhenkgerritsen commented Sep 23, 2016

Issue fixed with #3539.

@fawel11

This comment has been minimized.

Show comment
Hide comment
@fawel11

fawel11 Jul 24, 2018

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.

fawel11 commented Jul 24, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment