2

I have following server variable in phpunit.xml:

<php>
    <server name="APP_DEBUG" value="false"/>
</php>

Sometimes while developing, I want have APP_DEBUG enabled. What I usually do is add it into CLI command:

APP_DEBUG=true phpunit -c phpunit.xml

and in PHP:

$appDebug = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? null;

But this does not set $_SERVER['APP_DEBUG] to true, but leaves value from XML.

Is there any way to overwrite it from CLI?

1 Answer 1

3

don't use <server> for this. Use <env> and read it via getenv().

APP_DEBUG=true phpunit sets an environment variable, which is visible via getenv() / $_ENV, not $_SERVER.


In phpunit.xml

<php>
  <!-- default off -->
  <env name="APP_DEBUG" value="false" force="false"/>
</php>

In PHP

$appDebug = getenv('APP_DEBUG') ?? ($_ENV['APP_DEBUG'] ?? null);

// if you want a real boolean:
$debug = filter_var($appDebug, FILTER_VALIDATE_BOOLEAN);

Now in CLI

APP_DEBUG=true vendor/bin/phpunit -c phpunit.xml
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.