jmccartie
jmccartie

Reputation: 4976

PHPUnit + Kohana: Undefined index: HTTP_HOST

Trying to run PHPUnit on my Kohana 2.3.4 install:

phpunit --colors --bootstrap=index.php ../../modules/phpunit/libraries/Tests.php

Getting an error at one of my modules:

<p><tt>modules/core/helpers/MY_url.php <strong>[118]:</strong></tt></p>
<p><code class="block">Undefined index: HTTP_HOST</code></p>

I realize this is happening since I'm going via command line so HTTP_HOST won't be set. Is there any way around this without rewriting HTTP_HOST in that module? I know I could rewrite it to be exec(hostname), but am trying to avoid rewriting every instance of HTTP_HOST in my code.

Any workaround you can think of?

Upvotes: 3

Views: 2664

Answers (3)

Shaun Hare
Shaun Hare

Reputation: 3871

Is this $_SERVER['HTTP_HOST']?

If so, have a look at adding an xml config file and setting it in there:

https://phpunit.de/manual/current/en/appendixes.configuration.html

Upvotes: 4

jmccartie
jmccartie

Reputation: 4976

We actually decided to use a different bootstrap, load in variables there, then require the Kohana index file.

Works like a charm. Thanks, Matt, for getting me started down that path.

Upvotes: 0

Matt
Matt

Reputation: 893

Quick and dirty way to fix it would be to set the value in the bootstrap if you're in cli mode.

The "better" way would be to set it in the test's setUp method

Upvotes: 5

Related Questions