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

Asked

Viewed 106 times

2

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

I even published something related to the configuration of the environment local here in : How to define routes in Laravel that work only in development environment?

I like very much to use the above configuration to define the data of the local database, and already leave the production configuration ready, for when it is time to upload the file, not have to touch 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 those of the production.

I know you have a folder called app/config/testing, where I can also add the database.php, but would not like to be "copying and pasting" the database settings local to put in the testing, but only use the same configuration.

What’s the best way to do it in Laravel 4?

1 answer

1

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

You can create a file called app/config/testing/database.php and, when "copy and paste" the app/config/local/database.php, you can simply use the function include.

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

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

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

So if your code has anything like this:

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

Do so:

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

  if ($env === 'testing') $env = 'local';

Browser other questions tagged

You are not signed in. Login or sign up in order to post.