Closed clwehunt closed 1 year ago
Had the same problem, cost me a day of my life, the paratest worker has every ENV-parameter as $_SERVER parameter (I don't know why) and the ServerConstAdapter we use as default adapter by creating Dotenv with Dotenv::createImmutable(__DIR__)
will return that every ENV-parameter is externally defined (see ImmutableWriter->isExternallyDefined($parameterName)
) and so it will not be loaded from .env and you have no $_ENV parameters in a worker.
You can bypass this problem by not loading the adapter ServerConstAdapter:
$repository = RepositoryBuilder::createWithNoAdapters()
->addAdapter(EnvConstAdapter::class)
->immutable()
->make();
$dotenv = Dotenv::create($repository, __DIR__);
$dotenv->load();
@steltner Would you be able to write a brief paragraph about this issue and propose a PR with it?
@steltner Would you be able to write a brief paragraph about this issue and propose a PR with it?
@steltner @Slamdunk Just following up on this issue if you have time. Thanks
Had the same problem, cost me a day of my life, the paratest worker has every ENV-parameter as $_SERVER parameter (I don't know why) and the ServerConstAdapter we use as default adapter by creating Dotenv with
Dotenv::createImmutable(__DIR__)
will return that every ENV-parameter is externally defined (seeImmutableWriter->isExternallyDefined($parameterName)
) and so it will not be loaded from .env and you have no $_ENV parameters in a worker.You can bypass this problem by not loading the adapter ServerConstAdapter:
$repository = RepositoryBuilder::createWithNoAdapters() ->addAdapter(EnvConstAdapter::class) ->immutable() ->make(); $dotenv = Dotenv::create($repository, __DIR__); $dotenv->load();
@steltner Thanks so much, In the meantime I have this workaround and it seems to be working ok.
Any update on this? Due to the recent upgrade on Laravel and using Pest this behavior breaks our CI.
I would lovely send a PR with the fix, but unfortunately I really don't know even where to start here.
but unfortunately I really don't know even where to start here
Without being able to reproduce the big, me neither
At least the use case I can provide.
As it works from the common run and not in parallel, we assumed that might be a problem here, but can also be a problem on Pest or phpunit itself.
@leonardoldr23 can you create a dedicated repository with the minimal code needed for the bug to raise, and instructions on how to expose it?
@Slamdunk of course, here it is: https://github.com/leonardoldr23/envparatestshowcase
To run, clone/download then:
Afterwards, to reproduce the problem simply run this commands and you will see the issue:
I will send in attachment an image on the problem happening too:
As you can see, when using parallel the output keeps the ansii characters which are very bad on Jenkins (yeah, Jenkins should support them too :D)
How are CLI flags associated with ENV variables?
They are passed as $_SERVER variables just as like environments after the reading.
Then that sounds unrelated to ParaTest, which never touches $_SERVER
variable
I don't remember why I came to relate with this issue exactly, but I showed the issue running at all, if you need I can open a new issue
You showed the issue, but you didn't prove it's ParaTest fault and not, lets say, Pest or Laravel
Ok, I really don't know how can I do it in any other way than showing that without paratest it works, and with paratests it not works. Just leave it be then, we will find another way or tool to parallelize the tests. Thanks for your time.
showing that without paratest it works, and with paratests it not works
Pest overwrites many classes of ParaTest, so when you activate the --parallel
flag it's not just ParaTest alone involved in the output. I suggest you to raise this issue in Pest.
This issue has gone two months without activity. In another two weeks, I will close it.
But! If you comment or otherwise update it, I will reset the clock, and if you label it Backlog
or In Progress
, I will leave it alone ... forever!
Summary
I am testing out a very simple phpUnit test.
Current behavior
Running phpunit the results are: Environment: test 02/02/2023 11:25:02 pm
Running paratest via the following command:
vendor/bin/paratest --runner WrapperRunner
You can see from the output above that paratest loads the same bootstrap file and can access it as the environment is printed correctly.
How to reproduce: command, code and error stack trace
Composer.json require:
Have an .env file with APP_ENV="test"
Have a bootstrap file referenced in phpunit.xml that loads the .env file:
Have a test defined as:
Run vendor/bin/paratest --runner WrapperRunner
Expected behavior
I would expect the output to be the same as phpUnit, the environment variable to be available, and the assertion to be true: ParaTest v6.8.1 upon PHPUnit 9.5.28 by Sebastian Bergmann and contributors.
Environment: test 02/02/2023 11:28:15 pm