Created
April 18, 2014 15:24
-
-
Save arnaudbreton/11049773 to your computer and use it in GitHub Desktop.
PHP Unit with Grunt
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
terminal = require('color-terminal') | |
log = (error, stdout, stderr, cb) -> | |
if error | |
terminal.color('red').write stdout | |
else | |
terminal.color('green').write stdout | |
cb() | |
module.exports = (grunt) -> | |
grunt.loadNpmTasks 'grunt-contrib-watch' | |
grunt.loadNpmTasks 'grunt-shell' | |
grunt.initConfig | |
testFilepath: null | |
watch: | |
php: | |
options: | |
event: 'changed' | |
spawn: false | |
files: [ | |
'foo/bar/**/*.php' | |
'foo/bar/**/*Test.php' | |
] | |
tasks: 'shell:phpunit' | |
shell: | |
phpunit: | |
options: | |
callback: log | |
command: 'echo <%= testFilepath %> && phpunit -c app <%= testFilepath %>' | |
grunt.event.on 'watch', (action, filepath, ext) -> | |
regex = new RegExp("foo/bar/([a-z0-9]+)/([a-z0-9/]+)", "i") | |
if filepath.match regex | |
if filepath.indexOf('Test') is -1 | |
testFilepath = filepath.replace regex, "foo/bar/$1/Tests/$2Test" | |
else | |
testFilepath = filepath | |
grunt.config 'testFilepath', testFilepath |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment