Summer Sale! All accounts are 50% off this week.

hbjydev's avatar

Unable to run unit tests against the right DB

Hi all,

I'm running into issues trying to use PHPUnit and I'm not entirely sure why. I have two problems, essentially;

  1. PHPUnit won't seem to actually override the settings that Laravel should pick up (by way of the <php> block in the phpunit.xml file or the .env.testing file, neither work)
  2. It doesn't seem to be able to use XDebug to run code coverage reports. I use Pest over the top of PHPUnit and it keeps reporting that it couldn't find/use XDebug for Coverage, despite it being enabled and set to develop,coverage,debug,profile mode in my xdebug.ini file in /etc/php.d/ on a Remi-based PHP install (Rocky Linux 8.5 Docker image).

Find the relevant docker-compose.yml, .env.testing and phpunit.xml at rpa.st/XOLA

Thanks!

- Hayden

0 likes
5 replies
Sinnbeck's avatar

First make sure that you dont have your config cached. If you do, it will completely ignore the phpunit.xml file

php artisan config:clear`
hbjydev's avatar

@Sinnbeck I already have, no dice I'm afraid. It still doesn't seem to use the right database.

Sinnbeck's avatar

@hbjydev Ok. So show your phpunit.xml file. Let us focus one issue at a time, as the two questions are very different

hbjydev's avatar

@Sinnbeck If you look in the post body, you'll see the rpa.st link -- rpa.st/XOLA

It includes my phpunit.xml, docker-compose.yml and .env.testing files.

hbjydev's avatar

@Sinnbeck Not sure if it's relevant, but when I run this and explicitly specify APP_ENV on the command-line while running the tests, it gets the right app.env config var.

[root@f21cf9d4680a html]# vendor/bin/phpunit tests/Feature/Http/Controllers
PHPUnit 9.5.14 by Sebastian Bergmann and contributors.

"production"
[root@f21cf9d4680a html]# APP_ENV=testing vendor/bin/phpunit tests/Feature/Http/Controllers
PHPUnit 9.5.14 by Sebastian Bergmann and contributors.

"testing"

Please or to participate in this conversation.