0

I had developed a Laravel repo in WSL (Windows), and everything was fine.

Later, I bought a laptop with Ubuntu on it and wanted that to be my main development machine. So I downloaded my repo, copied over my various .env files, and set up the MySQL database with the appropriate schemas and users.

But my PHPUnit tests still wouldn't work.

And I was struggling to figure out from the Laravel docs what steps I'd missed.

Ryan
  • 22,332
  • 31
  • 176
  • 357

1 Answers1

0

These were the commands that I needed to run:

php artisan migrate --env=testing
php artisan db:seed --env=testing

Then ./vendor/phpunit/phpunit/phpunit tests/Feature/ worked fine.

P.S. php artisan migrate:refresh --seed --env=testing is also useful to know about.

Ryan
  • 22,332
  • 31
  • 176
  • 357
  • 1
    Sounds like you could benefit from the `RefreshDatabase` testing trait, which would run the migrations for you if needed. Also, should tests really rely on externally run seeders? – Brian Thompson Aug 25 '21 at 14:42
  • @BrianThompson Thanks for those good points! I will look into those improvements. – Ryan Aug 25 '21 at 14:47
  • @Ryan I am pretty sure you are a good developer, so remember always to read the documentation before attempting anything, as you are making use of 2 things: `--env` (this is not explained in the documentation, but run `php artisan`, you should see `--env` exists) in your commands and you lack the use of [`use RefreshDatabase`](https://laravel.com/docs/8.x/database-testing#resetting-the-database-after-each-test) trait. – matiaslauriti Aug 27 '21 at 04:58