have a test DB in MySQL (backend_apis_laravel_testing) that gets used for all PhpUnit tests. I do not want to use Sqlite (because I don't know how to view the database and tables in sqlite)
clear any cache (if needed) before PHPUnit runs
migrate the DB (and seeds) before PHPUnit runs, and cleanup after
ignore all settings in phpunit.xml, and only use the .env.testing file (not sure what takes precedence - the .env.testing file, or the settings in phpunit.xml. I would like my .env.testing file to override the phpunit.xml - for reasons that will take too long to explain, I am not allowed to change the phpunit.xml file.
These are the .env.testing settings I would like to use:
And yet, running phpunit keeps using phpunit.xml's settings (and connecting to sqlite, which I don't want).
I also don't know how to do the DB migration setup / teardown (and cache clearing) in Laravel 7. Tips appreciated.
You can use the RefreshDatabase and then use a setUp method that runs before each test or just place the setup in the test
use RefreshDatabase;
public function guests_can_list_all_books()
{
$author1 = factory(Author::class)->create();
$author2 = factory(Author::class)->create();
Or you can have seeders that you seed with in your tests.