gulp-phpunit

PHPUnit plugin for Gulp

gulp-phpunit

PHPUnit plugin for gulp 3

First, install gulp-phpunit as a development dependency:

npm install --save-dev gulp-phpunit

Then, add it to your gulpfile.js:

var phpunit = require('gulp-phpunit');
 
// option 1: default format 
gulp.task('phpunit', function() {
    gulp.src('phpunit.xml').pipe(phpunit());
});
 
// option 2: with defined bin and options 
gulp.task('phpunit', function() {
    var options = {debug: false};
    gulp.src('phpunit.xml').pipe(phpunit('./vendor/bin/phpunit',options));
});
 
 
// Note: Windows OS may require double backslashes if using other than default location (option 1) 
gulp.task('phpunit', function() {
  gulp.src('phpunit.xml').pipe(phpunit('.\\path\\to\\phpunit'));
});
 
// option 3: supply callback to integrate something like notification (using gulp-notify) 
 
var gulp = require('gulp'),
 notify  = require('gulp-notify'),
 phpunit = require('gulp-phpunit'),
 _       = require('lodash');
 
  gulp.task('phpunit', function() {
    gulp.src('phpunit.xml')
      .pipe(phpunit('', {notify: true}))
      .on('error', notify.onError(testNotification('fail', 'phpunit')))
      .pipe(notify(testNotification('pass', 'phpunit')));
  });
 
function testNotification(statuspluginNameoverride) {
    var options = {
        title:   ( status == 'pass' ) ? 'Tests Passed' : 'Tests Failed',
        message: ( status == 'pass' ) ? '\n\nAll tests have passed!\n\n' : '\n\nOne or more tests failed...\n\n',
        icon:    __dirname + '/node_modules/gulp-' + pluginName +'/assets/test-' + status + '.png'
    };
    options = _.merge(options, override);
  return options;
}
 
 

Type: String

The path to the desired PHPUnit binary

  • If not supplied, the defeault path will be ./vendor/bin/phpunit

Type: Boolean

Debug mode enabled (enables --debug switch as well)

Type: Boolean

Clear console before executing command

Type: Boolean

Executes dry run (doesn't actually execute tests, just echo command that would be executed)

Type: String

Define a specific class for testing (supply full path to test class)

Type: String

Define a specific test suite for testing (supply full path to test suite)

Type: String

Define a path to an xml configuration file (supply full path and filename)

Type: Boolean

Call user supplied callback to handle notification

Type: String

Generate code coverage report in Clover XML format.

Type: String

Generate code coverage report in Crap4J XML format.

Type: String

Generate code coverage report in HTML format.

Type: String

Export PHP_CodeCoverage object to file.

Type: String

Generate code coverage report in text format. -- Default: Standard output.

Type: String

Generate code coverage report in PHPUnit XML format.

Type: String

Log test execution in JUnit XML format to file.

Type: String

Log test execution in TAP format to file.

Type: String

Log test execution in JSON format.

Type: String

Write agile documentation in HTML format to file.

Type: String

Write agile documentation in Text format to file.

Type: String

Filter which tests to run.

Type: String

Filter which testsuite to run.

Type: String

Only runs tests from the specified group(s).

Type: String

Exclude tests from the specified group(s).

Type: String

List available test groups.

Type: String

Only search for test in files with specified suffix(es). Default: Test.php,.phpt

Type: String

Be strict about tests that do not test anything.

Type: Boolean

Be strict about unintentionally covered code.

Type: Boolean

Be strict about output during tests.

Type: Boolean

Enforce time limit based on test size.

Type: Boolean

Disallow @todo-annotated tests.

Type: Boolean

Run tests in strict mode (enables all of the above).

Type: Boolean

Run each test in a separate PHP process.

Type: Boolean

Do not backup and restore $GLOBALS for each test.

Type: Boolean

Backup and restore static attributes for each test.

Type: Boolean

Use colors in output.

Type: Boolean

Write to STDERR instead of STDOUT.

Type: Boolean

Stop execution upon first error.

Type: Boolean

Stop execution upon first error or failure.

Type: Boolean

Stop execution upon first risky test.

Type: Boolean

Stop execution upon first incomplete test.

Type: Boolean

Stop execution upon first skipped test.

Type: String

TestSuiteLoader implementation to use.

Type: Integer | String

Runs the test(s) repeatedly.

Type: Boolean

Report test execution progress in TAP format.

Type: Boolean

Report test execution progress in TestDox format.

Type: String

TestSuiteListener implementation to use.

Type: String

A "bootstrap" PHP file that is run before the tests.

Type: String

Read configuration from XML file.

Type: Boolean

Ignore default configuration file (phpunit.xml).

Type: Boolean

Prepend PHP's include_path with given path(s).

gulp-phpunit written by Mike Erickson

E-Mail: codedungeon@gmail.com

Twitter: @codedungeon

Website: codedungeon.org