Closed carltondickson closed 1 year ago
Hi @carltondickson. I don't get many issues and didn't notice. I do apologise for not getting back to you sooner!
Thanks for the detailed description of the problem. This is an interesting issue, and I have an idea about what might be causing it.
Adapt performs some checks before building the database. When it throws the "The .env.testing file could not be loaded" exception, it failed when checking to see that .env.testing
exists, and is a file.
I'm not sure at the moment about the intermittency you get, but I can trigger the same error when I run phpunit with a command line like yours.
When running phpunit whilst in the project root-directory, my tests run fine. e.g.
cd /var/www/html/ && ./vendor/bin/phpunit
But when running it from outside the project root-dir, I get the exception. e.g.
cd / && php /var/www/html/vendor/bin/phpunit --configuration /var/www/html/phpunit.xml
For you, the equivalent of running it from the project root-dir would be:
cd /opt/project/ && php vendor/phpunit/phpunit/phpunit --configuration phpunit.xml --filter "/(OurProject\\Tests\\Integration\\TestClass::testFunction)( .*)?$/" --test-suffix TestClass.php tests/integration --teamcity
I'll look into this further and get back to you. Ultimately Adapt should use the project root-dir when looking for the .env.testing
file.
Here are some other notes I wrote before working out a way to trigger the error:
Yes, Laravel's Dusk testing process does do some file copying, but it doesn't touch .env.testing
. So I don't think that's playing a role here.
When running php artisan dusk
, Laravel backs up your .env
file to .env.backup
and copies .env.dusk
over .env
(it swaps it back afterwards). It does this so that when Laravel answers the browser's request, it runs using your intended dusk settings.
Adapt doesn't do any file copying like this. As an aside, Adapt approaches this problem differently which makes this copying unnecessary. When using Adapt, I'd recommend adding your Dusk tests as a test-suite in phpunit.xml
so it runs alongside your other tests.
Hi @carltondickson. I've released a new version to address this.
It should now handle the situation when you run the tests from a directory other than the base project directory.
In this situation, you will still need to specify the --configuration
path (so Laravel picks up the phpunit.xml settings), but you were doing this anyway.
php /opt/project/vendor/phpunit/phpunit/phpunit --configuration /opt/project/phpunit.xml --filter "/(OurProject\\Tests\\Integration\\TestClass::testFunction)( .*)?$/" --test-suffix TestClass.php /opt/project/tests/integration --teamcity
I was able to reproduce the problem, however I'm a bit unsure about the intermittency you were seeing - where it would sometimes work and sometimes not. That makes me thing something else is going on as well.
If you're able to, would you mind updating to the latest version, and seeing how it goes?
Thanks, will give it a try and if I notice it again I'll raise an issue with specific steps
Description:
It's hard to recreate reliably but it happens a lot. It feels like the first time I run a test CLASS when I haven't run one for a few minutes in PHPSTORM it fails with this error, subsequent runs are fine if I run them back to back. Same can happen with test methods, run a test class, switch to another class and run a specific test and it can fail in the same way...running it immediately afterwards will always pass.
Logs:
The failing case
Running a second time is fine
Other Relevant Details:
[docker://kind.local/php-dev-baked:create/]:php /opt/project/vendor/phpunit/phpunit/phpunit --configuration /opt/project/phpunit.xml --filter "/(OurProject\\Tests\\Integration\\TestClass::testFunction)( .*)?$/" --test-suffix TestClass.php /opt/project/tests/integration --teamcity
.env.testing
file always exists