PHPUnit and Grunt Together At Last
I've been playing around with a Gruntfile that was posted on reddit last week:
https://coderwall.com/p/chdf1w
It automatically runs PHPUnit when you modify a file in your application directory or in your test folder. The only real problems I've run into with it is that because it's using watch it has a tendency to eat up 100% of my VMs CPU and it will occasionally start running all the unit tests or get stuck running the same unit test (a restart of the grunt process always fixes the problem).
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-shell');
grunt.initConfig({
testFilepath: null,
watch: {
php: {
options: {
event: 'changed',
spawn: false
},
files: ['application/**/*.php', 'tests/**/*Test.php'],
tasks: 'shell:phpunit'
}
},
shell: {
phpunit: {
command: 'echo <%= testFilepath %> && vendor/bin/phpunit -c tests --stop-on-error --stop-on-failure <%= testFilepath %>'
}
}
});
grunt.registerTask('default', ['watch'])
return grunt.event.on('watch', function(action, filepath, ext) {
var regex, testFilepath;
regex = new RegExp("application/([a-z0-9/]+)\.php", "i");
if (filepath.match(regex)) {
if (filepath.indexOf('Test') === -1) {
testFilepath = filepath.replace(regex, "tests/$1Test.php");
} else {
testFilepath = filepath;
}
return grunt.config('testFilepath', testFilepath);
}
});
};
Scott Keck-Warren
Scott is the Director of Technology at WeCare Connect where he strives to provide solutions for his customers needs. He's the father of two and can be found most weekends working on projects around the house with his loving partner.
RSS
Top Posts
- Working With Soft Deletes in Laravel (By Example)
- Fixing CMake was unable to find a build program corresponding to "Unix Makefiles"
- Upgrading to Laravel 8.x
- Get The Count of the Number of Users in an AD Group
- Multiple Vagrant VMs in One Vagrantfile
- Fixing the "this is larger than GitHub's recommended maximum file size of 50.00 MB" error
- Changing the Directory Vagrant Stores the VMs In
- Accepting Android SDK Licenses From The OSX Command Line
- Fixing the 'Target class [config] does not exist' Error
- Using Rectangle to Manage MacOS Windows