G
G
guyasyou2018-01-27 18:33:43
PHP
guyasyou, 2018-01-27 18:33:43

PHPUnit: Why doesn't PHP get ENV variable from phpunit.xml?

I fasten testing for PHP code.
I check in PhpStorm IDE. The tests are working.
But I can't pass a variable from phpunit.xml to php.
Here is the content of phpunit.xml:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" bootstrap="vendor/autoload.php">
    <testsuites>
        <testsuite name="Tests">
            <directory>./tests/</directory>
        </testsuite>
    </testsuites>
    <php>
        <env name="UNIT_TEST" value="true" />
    </php>
</phpunit>

Here is the bootstrap code: (loaded by autoloader)
<?php
define('APP_DIR', __DIR__);
define('BASE_DIR', dirname(APP_DIR));
define('CONFIGS_DIR', APP_DIR . '/configs');
define('VENDOR_DIR', BASE_DIR . '/vendor');
define('CACHE_DIR', BASE_DIR . '/cache');

var_dump(getenv('UNIT_TEST')); //return FALSE
var_dump($_ENV['UNIT_TEST']); //return NULL

Nifiga is not dumped by UNIT_TEST.
What's wrong?
UPD: Tests use parameters from phpunit.xml. Variables are simply ignored.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question