I went a completely different route and found success...
My TestCase.php is as follows:
<?php
use Illuminate\Support\Facades\Artisan as Artisan;
class TestCase extends Laravel\Lumen\Testing\TestCase
{
public function createApplication()
{
return require __DIR__ . '/../bootstrap/app.php';
}
public function setUp()
{
parent::setUp();
// Replace the testing.sqlite with stub.sqlite
// stub.sqlite is kept updated by way of `gulp watch`
// or `gulp stubdb`
exec('rm '. __DIR__ . '/../storage/testing.sqlite');
exec(
'cp '. __DIR__ . '/../storage/stub.sqlite '
. __DIR__ . '/../storage/testing.sqlite'
);
}
public function tearDown()
{
// Leaves the databse as-is in case we want to see
// what happened during the last run
parent::tearDown();
}
}
I then created a gulpfile.js with the following:
// Thanks to https://gist.github.com/duellsy/9125911
var gulp = require('gulp'),
watch = require('gulp-watch'),
exec = require('child_process').exec,
phpunit = require('gulp-phpunit'),
notify = require('gulp-notify'),
gutil = require('gulp-util'),
sys = require('sys');
gulp.task('phpunit', function(){
exec('./vendor/phpunit/phpunit/phpunit tests', function(error, stdout, stderr) {
console.log(stdout);
console.log(stderr);
if (error !== null) {
notify('Unit test failed: ' + error);
gutil.beep();
}
});
});
// Re-create the stub db when a migration or seed file changes
gulp.task('stubdb', function() {
// Backup the current .env file
exec('rm -f .env.backup');
exec('cp .env .env.backup');
// Replace .env with .env.stub (temporarily)
exec('rm -f .env');
exec('cp .env.stub .env');
// Execute migrate command
exec('php artisan migrate:refresh --seed', function(error, stdout) {
sys.puts(stdout);
if (error !== null) {
sys.puts(error);
}
gulp.run('phpunit');
// Replace .env with .env.backup
exec('rm -f .env');
exec('cp .env.backup .env');
});
});
gulp.task('watch', function() {
gulp.watch('database/**/*.php', ['stubdb']);
gulp.watch('app/**/*.php', ['phpunit']);
gulp.watch('app/*.php', ['phpunit']);
// gulp.watch('tests/**/*.php', ['phpunit']);
// gulp.watch('tests/*.php', ['phpunit']);
});
gulp.task('default', ['watch']);
And my .env.stub file looks like this:
APP_ENV=local
APP_DEBUG=true
APP_KEY=somethingcrazy
APP_LOCALE=en
APP_FALLBACK_LOCALE=en
DB_CONNECTION=sqlite
DB_DATABASE=storage/stub.sqlite
So, now you'll see that now I just run gulp and keep it going, so that it watches my migrations and seeds. If it sees anything changing, it recreates the different .env files, runs the migrate command, and then puts the .env files back (leaving some backups just in case something goes wrong).
Then, in the phpunit.xml file, I changed the environment to use "testing" like this:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="bootstrap/app.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/unit/</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
<env name="DB_DATABASE" value="storage/testing.sqlite"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
</php>
</phpunit>
That way, it uses the testing.sqlite file each time, and if I ever change migrations or seeds, that file is automatically created for me based on the stub when the TestCase.php:setup() method is run.
Voila. All works like a charm and runs super duper speedy-like.