Skip to content

Instantly share code, notes, and snippets.

@grohiro
Created June 23, 2017 06:02
Show Gist options
  • Select an option

  • Save grohiro/29be6a8e3b2be7bb92a000606a376fb4 to your computer and use it in GitHub Desktop.

Select an option

Save grohiro/29be6a8e3b2be7bb92a000606a376fb4 to your computer and use it in GitHub Desktop.
An autoload.php for PHPUnit with Laravel 5+.
<?php
// Put me into tests/autoload.php
require_once __DIR__.'/../vendor/autoload.php';
try {
$env = env('APP_ENV');
$filename = sprintf(".env.%s", $env);
(new Dotenv\Dotenv(dirname(__DIR__), $filename))->load();
} catch (Dotenv\Exception\InvalidPathException $e) {
echo ".env for test is missing.";
exit(1);
}
require_once 'bootstrap/app.php';
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="tests/autoload.php" // here!
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Application Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
</php>
</phpunit>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment