How do I use the same app / config / local / database.php configuration when I'm running in "testing" environment?

2

In Laravel 4 , we have three types of environments that can be defined: local , production and testing .

I've even posted something about configuring the local environment here: #

I like to use the above configuration to set the local database data, and to leave the production configuration ready, so when it is time to upload the file, do not have to mess with any configuration.

However, when I run the tests of phpunit (which would invoke the environment of testing of Laravel 4 ), the database settings used have been production .

I know I have a folder named app/config/testing , where I can also add database.php , but I would not like to "copy and paste" the local settings to testing , but only use the same configuration.

What is the best way to do this in Laravel 4 ?

    
asked by anonymous 01.03.2016 / 13:20

1 answer

1

At first, there is a game that can be done.

You can create a file named app/config/testing/database.php , and by copying and pasting the app/config/local/database.php setting, you can simply use the include function.

return include_once __DIR__  . '/../local/database.php';

Another way is to make the application recognize that you are in local environment, when running testing .

In the bootstrap/start.php file, there is an excerpt where the value of the current environment is defined in the $env variable.

So if your code looks something like this:

$env = $app->detectEnvironment(array(/** **/));

Do this:

  $env = $app->detectEnvironment(array(/** **/));

  if ($env === 'testing') $env = 'local';
    
02.03.2016 / 12:31