I use Laravel 5.3.22 and want to unit-test my application using an in-memory sqlite database migrating/rolling back for every test as it's said here. This is the connections section my database.php config:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
...
],
'testing' => [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
],
This is the phpunit env config:
<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="testing"/>
</php>
The phpunit config implies that laravel shoud use the "testing" sqlite connection for testing, but it doesn't care and go on with the primary mysql connection. This is not an option, I have a big and complex schema and it can't be used for unit-testing with mysql. Who do I proceed? I'm just starting with testing and new here. It seems that unit testing of database-based applications makes no sense, it dramatically slows down the process. And I can't mock the query builder since I need to assert on it's results.
Aucun commentaire:
Enregistrer un commentaire