2

I have following server variable inphpunit.xml:

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

Sometimes while developing, I want haveAPP_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] totrue, but leaves value from XML.

Is there any way to overwrite it from CLI?

Abdulla Nilam's user avatar
Abdulla Nilam
39.7k18 gold badges85 silver badges115 bronze badges
askedOct 21 at 11:28
Justinas's user avatar

1 Answer1

3

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

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


Inphpunit.xml

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

InPHP

$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
answeredOct 21 at 11:48
Abdulla Nilam's user avatar
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy 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.