title: Laravel 5 how to run tests in a different database the right way?
body: <p>I'm on 5.1 and not able to find a definite answer what's the best practice regarding an eco- and test-system to use a separate database for tests.</p>
  
  <p>I've:</p>
  
  <ul>
  <li>a development machine for dev and running local tests</li>
  <li>an external service running by CI (only runs phpunit)</li>
  </ul>
  
  <p>When I run tests locally, I don't want them to interfere with my dev database, thus I've created dedicated database for tests.</p>
  
  <p>To overcome the limitation that I've only one <code>.env</code> file, I've modified the <code>phpunit.xml.dist</code> file to have different database credentials defined via <code>&lt;env name="..." value=".."/&gt;</code>.</p>
  
  <p>When I want to run the tests on a remote CI service, I again need different values for user/pass and database names. In that case I've a "template phpunit.xml" file in my repo which, during the initialization phase on the remote CI, I generate with their respective environment variables (which are different than the ones I use).</p>
  
  <p>For all non-production related environments I need to keep three files in sync otherwise things will start to break:</p>
  
  <ul>
  <li><code>.env</code></li>
  <li><code>phpunit.xml.dist</code></li>
  <li><code>phpunit.xml</code> template file generated on demand on remote CI system</li>
  </ul>
  
  <p>I understand the benefits of the non-versioned <code>.env</code>, but it gets a huge pain to always keep those things in sync.</p>
  
  <p>Are there better ways to manage this?</p>