I am trying to run laravel feature tests in parallel mode as it is in document. My phpunit.xml is configed as below :
<php>
<env name="APP_ENV" value="testing"/>
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="MAIL_DRIVER" value="array"/>
<env name="DB_CONNECTION" value="mysql"/>
</php>
and I am running the tests with this command :
php artisan test --parallel
The result is all tests fail with this error message :
PDOException: SQLSTATE[HY000] [1049] Unknown database 'mydbname_test_11'
should I create this database before starting test or laravel creates that automatically ?
Yes, the database must exist before you run your test. another thing to note is that parallel unlike PHP artisan test, will not migrate your database for you. So what I found works best is to migrate my database before running the test in parallel.
You do not need to manually create databases to run tests in parallel. Laravel will create these databases for you automatically and tear them down when your tests have finished.
This is true also when running in Bitbucket Pipelines, for the commenter that asked.
From the documentation on parallel testing in Laravel (9.x):
As long as you have configured a primary database connection, Laravel automatically handles creating and migrating a test database for each parallel process that is running your tests. The test databases will be suffixed with a process token which is unique per process. For example, if you have two parallel test processes, Laravel will create and use your_db_test_1 and your_db_test_2 test databases.
Your issue is likely to be a composer dependency that is preventing Laravel from creating these databases. In my case, it was the grimzby/laravel-mysql-spatial package. Link to the relevant issue here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With