8

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. How do I proceed? I can't mock the query builder since I need to assert on it's results.

1 Answer 1

7

I've figured out the problem, I've been using config caching in my local environment and it's been preventing Laravel from using the phpunit config. the config:clear artisan command's helped. I've also changed the file cache driver to the array one for my local env.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.