Closed schonhoff closed 2 years ago
Hi there,
Thanks for reporting but it looks like this is a question which can be asked on a support channel. Please only use this issue tracker for reporting bugs with the library itself. If you have a question on how to use functionality provided by this repo you can try one of the following channels:
However, this issue will not be locked and everyone is still free to discuss solutions to your problem!
Thanks.
Hello @driesvints ,
the tests did not create a test database automatically like it is mentioned in the docs. I would suggest this is a bug and not a discussion nor a question. I suggested possible solutions to the problem and updated my original post and the title to make it clear. I hope this show my bug report more clearly. Also I found other tickets like this https://github.com/laravel/framework/issues/40488 but as I mentioned I tested it in a newly created Laravel app and had the error.
Improtant: The error occurs only if the database engines between testing and local are different. .env:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
phpunit.xml:
<php>
<env name="APP_ENV" value="testing"/>
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="DB_CONNECTION" value="sqlite"/>
<!-- <env name="DB_DATABASE" value=":memory:"/> -->
<env name="MAIL_MAILER" value="array"/>
<env name="QUEUE_CONNECTION" value="sync"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="TELESCOPE_ENABLED" value="false"/>
</php>
No .env.testing needed for this.
So there isn't really a bug here but rather a config issue. You need to make sure your env files are properly pointing towards your test environment and as you say above by default in the skeleton it's not configured for sqlite. If you want to use a file base sqlite testing environment you need to define the proper database in your phpunit.xml.
And you also need to create that main database up front as it's needed for migrations. Only parallel databases during testing are created. I've sent in a PR to the docs to clarify this: https://github.com/laravel/docs/pull/8323
@driesvints Thanks for the clarification. My thought was that parallel testing will create its one databases and will migrate them. But that they need a "core" database wasn't clear for me. Hopefully the clarification in the docs helps out other people too! Thanks and have a good night/day :)
Description:
Hello everyone,
I tried to change my testing database to sqlite instead of sqlite in-memory because we have a lot of migrations and want to use the dumped version of it instead to execute all migrations. After changing my .env.testing file to use the sqlite database driver from the original config, I tried to run my tests. The following error occurred:
I did not create any sqlite files because in the documentation for testing in parallel it mentioned (https://laravel.com/docs/9.x/testing#parallel-testing-and-databases):
I thought the database will be created and the dump and/or migrations will be run.
Possible solutions
@timacdonald added a prompt for installing the sqlite databse if it is doesn't exists in the PR https://github.com/laravel/framework/pull/43867 Maybe something like this would be helpful? Or should the test databases be created in the storage/framework/testing directory without any prompt? I don't know the expected behavior because I can't execute it myself.
Not using parallel testing will throw this error:
Steps To Reproduce:
Here is a Laravel app test repo where only the Installation step of the bootcamp is done (https://bootcamp.laravel.com/blade/installation) and 2 other small changes: https://github.com/schonhoff/chirper
<env name="DB_CONNECTION" value="sqlite"/>
inphpunit.xml
RefreshDatabase
Trait toTestCase.php
Other things to know:
If there are any questions feel free to ask.