Skip to content

Instantly share code, notes, and snippets.

@duellsy
Created February 20, 2014 23:52
Show Gist options
  • Save duellsy/9125911 to your computer and use it in GitHub Desktop.
Save duellsy/9125911 to your computer and use it in GitHub Desktop.
Laravel auto testing gulp
var gulp = require('gulp');
var sass = require('gulp-sass');
var minifycss = require('gulp-minify-css');
var autoprefixer = require('gulp-autoprefixer');
var phpunit = require('gulp-phpunit');
var notify = require('gulp-notify');
var gutil = require('gulp-util');
var exec = require('child_process').exec;
var sys = require('sys');
var livereload = require('gulp-livereload');
var lr = require('tiny-lr');
var path = require('path');
var fs = require('fs');
var server = lr();
gulp.task('sass', function(){
return gulp.src('assets/sass/*.scss')
.pipe(sass())
.pipe(autoprefixer('last 2 version'))
.pipe(minifycss())
.pipe(gulp.dest('public/css'))
.pipe(notify({message: 'CSS minified'}))
.pipe(livereload(server));
});
gulp.task('phpunit', function(){
exec('vendor/bin/phpunit', function(error, stdout) {
console.log(stdout);
if (error !== null) {
gulp.src('app/views/layouts/default.blade.php')
.pipe(notify('Unit test failed: ' + error));
gutil.beep();
}
});
});
gulp.task('blade', function() {
return gulp.src('app/views/layouts/default.blade.php')
.pipe(livereload(server));
});
gulp.task('testdbsetup', function(){
exec('php artisan migrate:refresh --seed --database="setup" --env="testing"', function(error, stdout) {
sys.puts(stdout);
gulp.run('phpunit');
});
});
gulp.task('watch', function(){
gulp.watch('app/database/**/*.php', ['testdbsetup']);
server.listen(35729, function(err) {
if(err) {console.log(err);}//assuming this works? Haven't had a err yet so don't know
gulp.watch('assets/sass/**/*.scss', ['sass']);
gulp.watch('app/views/**/*.blade.php', ['blade']);
});
gulp.watch('app/**/*.php', ['phpunit']);
});
gulp.task('default', ['sass', 'watch', 'phpunit']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment