Created
January 25, 2016 21:10
-
-
Save fvosberg/4d677a9190d42dd3bda6 to your computer and use it in GitHub Desktop.
Gulpfile for phpunit in composer project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'); | |
var exec = require('child_process').exec; | |
var path = require('path'); | |
var fs = require('fs'); | |
gulp.task('phpunit', function() { | |
var class_file_to_test_file = function(class_path) { | |
var test_file = class_path.replace(/\/Classes\//g, '/Tests/Unit/'); | |
return test_file.slice(0, -4) + 'Test.php'; | |
}; | |
var exec_phpunit_for_test_file = function(path) { | |
var test_command = 'vendor/bin/phpunit ' + path; | |
console.log(test_command); | |
exec(test_command, function(error, stdout) { | |
console.log(stdout); | |
}); | |
}; | |
gulp.watch('Classes/**/*.php', function(event) { | |
var test_file = class_file_to_test_file(event.path); | |
exec_phpunit_for_test_file(test_file); | |
}); | |
gulp.watch('Tests/Unit/**/*Test.php', function(event) { | |
var test_file = event.path; | |
exec_phpunit_for_test_file(test_file); | |
}); | |
exec_phpunit_for_test_file('Tests'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment