Skip to content
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

ENV variables within SF4 #114

Closed
tarlepp opened this issue Dec 5, 2017 · 5 comments
Closed

ENV variables within SF4 #114

tarlepp opened this issue Dec 5, 2017 · 5 comments

Comments

@tarlepp
Copy link
Contributor

tarlepp commented Dec 5, 2017

Hmm seems like env variables are not working within symfony 4, for some reason eg. ENV_TEST_CHANNEL_READABLE is not set as it was on 3.x branch.

@DonCallisto
Copy link
Collaborator

Could you reproduce the case with test in a brand new repo?

@tarlepp
Copy link
Contributor Author

tarlepp commented Dec 6, 2017

Hmm, it seems that the problem is within EnvCommandCreator::execute method.

Currently it contains following:

return $_ENV + [
                self::ENV_TEST_CHANNEL.'='.(int) $i,
                self::ENV_TEST_CHANNEL_READABLE.'=test_'.(int) $i,
                self::ENV_TEST_CHANNELS_NUMBER.'='.(int) $maxProcesses,
                self::ENV_TEST_ARGUMENT.'='.$suite,
                self::ENV_TEST_INCREMENTAL_NUMBER.'='.(int) $currentProcessCounter,
                self::ENV_TEST_IS_FIRST_ON_CHANNEL.'='.(int) $isFirstOnItsThread,
                'PATH='.getenv('PATH'),
            ];

And with that those aren't added to env variables as expected, but if modify that part like above all works as expected:

return array_merge($_ENV, [
            self::ENV_TEST_CHANNEL => (int) $i,
            self::ENV_TEST_CHANNEL_READABLE => 'test_' . (int) $i,
            self::ENV_TEST_CHANNELS_NUMBER => (int) $maxProcesses,
            self::ENV_TEST_ARGUMENT => $suite,
            self::ENV_TEST_INCREMENTAL_NUMBER => (int) $currentProcessCounter,
            self::ENV_TEST_IS_FIRST_ON_CHANNEL => (int) $isFirstOnItsThread,
            'PATH' => \getenv('PATH'),
        ]);

And how did I test this, just simple throw new \Exception(getenv('ENV_TEST_CHANNEL_READABLE')); on my test bootstrap file.

Result with original:

Fatal error: Uncaught Error: Wrong parameters for Exception([string $message [, long $code [, Throwable $previous = NULL]]]) in /home/wunder/PhpstormProjects/symfony-flex-backend/bootstrap.php on line 18

Error: Wrong parameters for Exception([string $message [, long $code [, Throwable $previous = NULL]]]) in /home/wunder/PhpstormProjects/symfony-flex-backend/bootstrap.php on line 18

Call Stack:
    0.0001     366120   1. {main}() /home/wunder/PhpstormProjects/symfony-flex-backend/vendor/phpunit/phpunit/phpunit:0
    0.0215    1230152   2. PHPUnit\TextUI\Command::main() /home/wunder/PhpstormProjects/symfony-flex-backend/vendor/phpunit/phpunit/phpunit:53
    0.0215    1230264   3. PHPUnit\TextUI\Command->run() /home/wunder/PhpstormProjects/symfony-flex-backend/vendor/phpunit/phpunit/src/TextUI/Command.php:148
    0.0215    1230264   4. PHPUnit\TextUI\Command->handleArguments() /home/wunder/PhpstormProjects/symfony-flex-backend/vendor/phpunit/phpunit/src/TextUI/Command.php:159
    0.0246    1605096   5. PHPUnit\TextUI\Command->handleBootstrap() /home/wunder/PhpstormProjects/symfony-flex-backend/vendor/phpunit/phpunit/src/TextUI/Command.php:788
    0.0247    1611256   6. PHPUnit\Util\Fileloader::checkAndLoad() /home/wunder/PhpstormProjects/symfony-flex-backend/vendor/phpunit/phpunit/src/TextUI/Command.php:991
    0.0247    1611560   7. PHPUnit\Util\Fileloader::load() /home/wunder/PhpstormProjects/symfony-flex-backend/vendor/phpunit/phpunit/src/Util/Fileloader.php:48
    0.0248    1613160   8. include_once('/home/wunder/PhpstormProjects/symfony-flex-backend/tests/bootstrap_fastest.php') /home/wunder/PhpstormProjects/symfony-flex-backend/vendor/phpunit/phpunit/src/Util/Fileloader.php:64
    0.0248    1619144   9. require('/home/wunder/PhpstormProjects/symfony-flex-backend/bootstrap.php') /home/wunder/PhpstormProjects/symfony-flex-backend/tests/bootstrap_fastest.php:14
    0.0248    1625232  10. Exception->__construct() /home/wunder/PhpstormProjects/symfony-flex-backend/bootstrap.php:18

PHP Fatal error:  Uncaught Error: Wrong parameters for Exception([string $message [, long $code [, Throwable $previous = NULL]]]) in /home/wunder/PhpstormProjects/symfony-flex-backend/bootstrap.php:18
Stack trace:
#0 /home/wunder/PhpstormProjects/symfony-flex-backend/bootstrap.php(18): Exception->__construct(false)
#1 /home/wunder/PhpstormProjects/symfony-flex-backend/tests/bootstrap_fastest.php(14): require('/home/wunder/Ph...')
#2 /home/wunder/PhpstormProjects/symfony-flex-backend/vendor/phpunit/phpunit/src/Util/Fileloader.php(64): include_once('/home/wunder/Ph...')
#3 /home/wunder/PhpstormProjects/symfony-flex-backend/vendor/phpunit/phpunit/src/Util/Fileloader.php(48): PHPUnit\Util\Fileloader::load('/home/wunder/Ph...')
#4 /home/wunder/PhpstormProjects/symfony-flex-backend/vendor/phpunit/phpunit/src/TextUI/Command.php(991): PHPUnit\Util\Fileloader::checkAndLoad('/home/wunder/Ph...')
#5 /home/wunder/PhpstormProjects/symfony-flex-backend/vendor/phpunit/phpunit/src/TextUI/Command.php(788): PHPUnit\TextUI\Command->handleBootstr in /home/wunder/PhpstormProjects/symfony-flex-backend/bootstrap.php on line 18

So the env variable doesn't exists at all, and after that small change:

Fatal error: Uncaught Exception: test_1 in /home/wunder/PhpstormProjects/symfony-flex-backend/bootstrap.php on line 18

Exception: test_1 in /home/wunder/PhpstormProjects/symfony-flex-backend/bootstrap.php on line 18

Call Stack:
    0.0001     366728   1. {main}() /home/wunder/PhpstormProjects/symfony-flex-backend/vendor/phpunit/phpunit/phpunit:0
    0.0092    1230760   2. PHPUnit\TextUI\Command::main() /home/wunder/PhpstormProjects/symfony-flex-backend/vendor/phpunit/phpunit/phpunit:53
    0.0092    1230872   3. PHPUnit\TextUI\Command->run() /home/wunder/PhpstormProjects/symfony-flex-backend/vendor/phpunit/phpunit/src/TextUI/Command.php:148
    0.0092    1230872   4. PHPUnit\TextUI\Command->handleArguments() /home/wunder/PhpstormProjects/symfony-flex-backend/vendor/phpunit/phpunit/src/TextUI/Command.php:159
    0.0119    1605776   5. PHPUnit\TextUI\Command->handleBootstrap() /home/wunder/PhpstormProjects/symfony-flex-backend/vendor/phpunit/phpunit/src/TextUI/Command.php:788
    0.0120    1611936   6. PHPUnit\Util\Fileloader::checkAndLoad() /home/wunder/PhpstormProjects/symfony-flex-backend/vendor/phpunit/phpunit/src/TextUI/Command.php:991
    0.0120    1612240   7. PHPUnit\Util\Fileloader::load() /home/wunder/PhpstormProjects/symfony-flex-backend/vendor/phpunit/phpunit/src/Util/Fileloader.php:48
    0.0121    1613840   8. include_once('/home/wunder/PhpstormProjects/symfony-flex-backend/tests/bootstrap_fastest.php') /home/wunder/PhpstormProjects/symfony-flex-backend/vendor/phpunit/phpunit/src/Util/Fileloader.php:64
    0.0122    1619824   9. require('/home/wunder/PhpstormProjects/symfony-flex-backend/bootstrap.php') /home/wunder/PhpstormProjects/symfony-flex-backend/tests/bootstrap_fastest.php:14

PHP Fatal error:  Uncaught Exception: test_1 in /home/wunder/PhpstormProjects/symfony-flex-backend/bootstrap.php:18
Stack trace:
#0 /home/wunder/PhpstormProjects/symfony-flex-backend/tests/bootstrap_fastest.php(14): require()
#1 /home/wunder/PhpstormProjects/symfony-flex-backend/vendor/phpunit/phpunit/src/Util/Fileloader.php(64): include_once('/home/wunder/Ph...')
#2 /home/wunder/PhpstormProjects/symfony-flex-backend/vendor/phpunit/phpunit/src/Util/Fileloader.php(48): PHPUnit\Util\Fileloader::load('/home/wunder/Ph...')
#3 /home/wunder/PhpstormProjects/symfony-flex-backend/vendor/phpunit/phpunit/src/TextUI/Command.php(991): PHPUnit\Util\Fileloader::checkAndLoad('/home/wunder/Ph...')
#4 /home/wunder/PhpstormProjects/symfony-flex-backend/vendor/phpunit/phpunit/src/TextUI/Command.php(788): PHPUnit\TextUI\Command->handleBootstrap('/home/wunder/Ph...')
#5 /home/wunder/PhpstormProjects/symfony-flex-backend/vendor/phpunit/phpunit/src/TextUI/Command.php(159): PHPUnit\TextUI\Command->handleArguments(Array)
#6 /home/wunder/PhpstormProjec in /home/wunder/PhpstormProjects/symfony-flex-backend/bootstrap.php on line 18

And this is what I expected to get.

@tarlepp
Copy link
Contributor Author

tarlepp commented Dec 6, 2017

And you could easily test this with my project https://github.com/tarlepp/symfony-flex-backend just clone it run composer install and after that find tests/ -name "*Test.php" | php ./vendor/bin/fastest -v -p 8 -b "php ./tests/bootstrap.php" "php ./vendor/bin/phpunit {} -c phpunit.fastest.xml --coverage-php build/fastest/{n}.cov;"

@francoispluchino
Copy link
Collaborator

For Fastest to work properly with Symfony 4 Flex, the PR #117, #118, #119 are required.

@francoispluchino
Copy link
Collaborator

This issue can be closed normally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants