I have a standard app built on Laravel and have been creating unit tests as I go. Everything has been based on the default MySQL DB. I have introduced MongoDB as a secondary DB needed for other data.
Here's my PHP section in the phpunit.xml
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
<env name="MONGO_DATABASE" value="tap_testing"/>
</php>
My default DB for mongo is tap and I wanted to use a secondary DB tap_testing for unit tests. When I run the tests, they are writing to tap. So something is broken or I have missed a step in adding a new DB but all the online tutorials I have found said it's as simple as what I have listed above.
I have also ran into an issue last week that was tracked down to APP_ENV showing as local and not testing, so I feel like there's an underlying issue on why it's not respecting the phpunit.xml env vars.
In fact, I just ran it right now, and it's wiping my local DB instead of using an in memory DB.
I just run stuff like this in the project root:
$ phpunit
$ php laravel dusk
And this is my mongodb entry in config/database.php
'mongodb' => [
'driver' => env('MONGO_DRIVER','mongodb'),
'host' => env('MONGO_HOST', '127.0.0.1'),
'port' => env('MONGO_PORT', 27017),
'database' => env('MONGO_DATABASE'),
/*'username' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),*/
'options' => [
'database' => 'admin' // sets the authentication database required by mongo 3
]
],
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire