Question

Is there a way to install PHPUnit automatically using just NPM/Grunt?

I know about the grunt-phpunit package, but this still requires that you install PHPUnit itself with Composer or something else. Is there an easy way to automate this?

I'm working on setting up some automated testing stuff that'll run locally and be shared, and I'd like to keep the instructions as just:

npm install -g grunt-cli
npm install
grunt
Was it helpful?

Solution

I figured out a solution for this. It does add one more step (grunt install), but it does the trick.

Basically use the grunt-wget package to download the composer file from the download page.

Then use this custom script to run the composer file and download it:

module.exports = function (grunt) {
    grunt.registerTask('install-composer', function() {
        var spawn = require('child_process').spawn;
        var done = this.async();

        var php = spawn('php', ['composer-install.php'], {cwd: 'test/download'});

        php.stdout.on('data', function (data) {
            grunt.log.debug(data);
        });

        php.stderr.on('data', function (data) {
            grunt.log.error(data);
            done(false);
        });

        php.on('close', function (code) {
            done(code === 0);
        });
    });
};

'test/download' is the location I store the composer.phar file and where I wget-ed the file from the server. If you want to change that, just change that destination.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top