Ben94's avatar
Level 1

Test Database with multiple Databases

I have created an .env.testing with the following data:

DB_CONNECTION=sqlite
DB_DATABASE=database/test.sqlite

So everytime I ran phpunit it put the data in the test.sqlite file. However, I now need to use two development databases, so I added these lines to my Models.

class ExampleModelOne {
    protected $connection = 'mysql';
    ...
}
class ExampleModelTwo {
    protected $connection = 'sqlsrv';
    ...
}

The problem is that I now receive the following error:

Access denied for user ''@'localhost' to database 'database/test.sqlite'

Is there any way to solve this? I'm trying to prevent manually editing the files each time.

Regards

PS for reference, this is my .env file

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=***
DB_USERNAME=root
DB_PASSWORD=

DB_SRV_CONNECTION=sqlsrv
DB_SRV_HOST=***
DB_SRV_PORT=1433
DB_SRV_DATABASE=***
DB_SRV_USERNAME=***
DB_SRV_PASSWORD=***
0 likes
1 reply
shez1983's avatar

i think you just need to add

DB_SRV_CONNECTION=sqlsrv
DB_SRV_DATABASE=***

to your testing env like u have the first one

Please or to participate in this conversation.