amite's avatar
Level 4

PHPUnit separate connection to mysql test database Laravel 5.2 not working

I am trying to connect my Testcase integration tests to a separate database connection but its not happening. The test suite keeps connecting to the default database connection instead.

In phpunit.xml I have set this variable: <env name="DB_CONNECTION" value="mysql_testing"/>

And in my database.php I have this:

'mysql_testing' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('TEST_DB', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix' => '',
            'strict' => false,
            'engine' => null,
        ],

In my .env I have also set TEST_DB=flyer_test.

so why does my test suite try and connect to my default database connection? What am I doing wrong?

0 likes
2 replies
amite's avatar
amite
OP
Best Answer
Level 4

Ok so the problem was I wasn't passing in the configuration file to PHPStorm. Once I did that through the 'edit configurations' dialog, I could see this in the console

vagrant:///Users/amiterandole/PhpstormProjects/flyer/usr/bin/php /home/vagrant/.phpstorm_helpers/phpunit.php --configuration /vagrant/phpunit.xml tests\integration\models\LikesTest /vagrant/tests/integration/models/LikesTest.php

and it worked!

Please or to participate in this conversation.