Skip to content

Instantly share code, notes, and snippets.

@arnaudbreton
Created April 18, 2014 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arnaudbreton/11049773 to your computer and use it in GitHub Desktop.
Save arnaudbreton/11049773 to your computer and use it in GitHub Desktop.
PHP Unit with Grunt
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