Laravel Testing Configuration


Example

The phpunit.xml file is the default configuration file for tests and is already setup for testing with PHPUnit.

The default testing environment APP_ENV is defined as testing with array being the cache driver CACHE_DRIVER. With this setup, no data (session/cache) will be retained while testing.

To run tests against a specific environment like homestead the defaults can be changed to:

<env name="DB_HOST" value="192.168.10.10"/>
<env name="DB_DATABASE" value="homestead"/>
<env name="DB_USERNAME" value="homestead"/>
<env name="DB_PASSWORD" value="secret"/>

Or to use a temporary in memory database:

<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>

One last note to keep in mind from the Laravel documentation:

Make sure to clear your configuration cache using the config:clear Artisan command before running your tests!