Skip to content

Commit a07d447

Browse files
committed
Added watch for tests and renamed "clear" to "force" for composer:install
1 parent e46ca04 commit a07d447

File tree

3 files changed

+51
-28
lines changed

3 files changed

+51
-28
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "rregeer/gulp-php-dev-toolbox",
33
"description": "Php development toolbox using the gulp taskrunner",
4-
"version": "0.4.1",
4+
"version": "0.4.2",
55
"keywords": [
66
"Testing", "PHP", "phpunit", "Unittest", "Codestyle", "CI",
77
"Code complexity", "phpcs", "phpcbf", "phplint", "Gulp", "phpmd",

tasks/composer.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,28 @@ var del = require('del');
55
var gutil = require('gulp-util');
66

77
var knownOptions = {
8-
boolean: ['clean']
8+
boolean: ['force']
99
};
1010

1111
var commandLineOptions = minimist(process.argv.slice(2), knownOptions);
1212

1313
gulp.task('composer:install', 'Install all the required dependencies.', function () {
14-
if (commandLineOptions.clean) {
15-
del(['vendor/']);
16-
gutil.log(gutil.colors.blue('Clean install triggerd, the composer vendor directory will be removed.'));
14+
if (commandLineOptions.force) {
15+
del(['vendor/', 'composer.lock']);
16+
gutil.log(gutil.colors.blue('Forced install triggerd, removing the vendor diretory and composer lock file.'));
1717
}
1818

1919
return composer();
2020
},{
2121
options: {
22-
'clean': 'Clears the vendor folder before install the packages. For example gulp composer:install --clear'
22+
'force': 'Clears the vendor folder and composer lockfile before install the packages. For example gulp composer:install --force'
2323
}
2424
});
2525

2626
gulp.task('composer:update-lockfile', 'Only update the composer lock file.', function () {
2727
return composer('update', {lock: true});
2828
});
2929

30-
gulp.task('clear:vendor', 'Clear the composer vendor folder.', function() {
31-
return del(['vendor/']);
32-
});
33-
3430
gulp.task('composer', ['composer:install']);
3531

3632
gulp.task('default', ['composer:install']);

tasks/tests.js

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ var del = require('del');
55
var gulpif = require('gulp-if');
66
var fileExists = require('file-exists');
77
var gutil = require('gulp-util');
8+
var shell = require('gulp-shell');
9+
var _ = require('lodash');
810

911
var knownOptions = {
10-
string: ['testsuite', 'test'],
11-
boolean: ['coverage'],
12-
alias: ['s', 'c', 't']
12+
string: ['testsuite', 'test', 'source'],
13+
boolean: ['coverage']
1314
};
1415

1516
var commandLineOptions = minimist(process.argv.slice(2), knownOptions);
@@ -18,40 +19,39 @@ gulp.task('tests', 'Run the selected unit tests with phpunit. Requires a phpunit
1819
var options;
1920
var projectRoot = gulp.task.configuration.projectRoot;
2021

21-
options = {};
22+
options = {
23+
notify: false
24+
};
2225

2326
gutil.log(gutil.colors.blue('Running task \'tests\' in directoy: ' + projectRoot));
2427

25-
if (commandLineOptions.testsuite || commandLineOptions.s) {
26-
options.testSuite = commandLineOptions.testsuite || commandLineOptions.s;
28+
if (commandLineOptions.testsuite) {
29+
options.testSuite = commandLineOptions.testsuite;
30+
gutil.log(gutil.colors.blue('Run tests in test suite ' + commandLineOptions.testsuite));
2731
}
2832

29-
if(commandLineOptions.coverage || commandLineOptions.c) {
33+
if(commandLineOptions.coverage) {
3034
options.coverageHtml = 'coverage/';
3135
}
3236

33-
if(commandLineOptions.test || commandLineOptions.t) {
34-
options.filter = commandLineOptions.test || commandLineOptions.t;
37+
if(commandLineOptions.test) {
38+
options.testClass = commandLineOptions.test;
39+
gutil.log(gutil.colors.blue('Run test file ' + commandLineOptions.test));
3540
}
3641

3742
if(!fileExists(projectRoot + '/phpunit.xml.dist')) {
3843
gutil.log(gutil.colors.red('Mandatory file \'phpunit.xml.dist\' does not exists.'));
3944
return;
4045
}
4146

42-
return gulp.src('', {read: false})
43-
.pipe(shell(['cd ' +
44-
['vendor/bin/phpmd ' + source + ' text codesize,unusedcode,naming,design,cleancode,controversial']
45-
]));
46-
47-
return gulp.src(projectRoot + '/phpunit.xml.dist', {cwd: projectRoot})
47+
return gulp.src(projectRoot + '/phpunit.xml.dist')
4848
.pipe(gulpif(options.coverageHtml, gulp.dest('coverage/')))
4949
.pipe(phpunit(projectRoot + '/vendor/bin/phpunit', options));
5050
},{
5151
options: {
52-
'test | t': 'Run a single test. Example gulp tests --test [testname]',
53-
'testsuite | s': 'The test suite to run. Example gulp tests --testsuite [suiteName]',
54-
'coverage | c ': 'Run the tests with coverage enabled. Coverage will be stored in a HTML report in coverage/coverage-html. Example gulp tests --coverage'
52+
'test': 'Run a single test. Example gulp tests --test [testname]',
53+
'testsuite': 'The test suite to run. Example gulp tests --testsuite [suiteName]',
54+
'coverage': 'Run the tests with coverage enabled. Coverage will be stored in a HTML report in coverage/coverage-html. Example gulp tests --coverage'
5555
}
5656
});
5757

@@ -61,4 +61,31 @@ gulp.task('clear:coverage', 'Clear the coverage reports files.', function() {
6161
return del([projectRoot +'/coverage/**'], {force: true});
6262
});
6363

64+
gulp.task('watch:tests', 'Watch for file changes and execute the tests task. Default the tests directory will be watched.', function() {
65+
var projectRoot = gulp.task.configuration.projectRoot;
66+
var source = projectRoot + '/tests/';
67+
68+
if (!(commandLineOptions.test || commandLineOptions.testsuite)) {
69+
gutil.log(gutil.colors.red('No arguments supplied. Supply --test or --testsuite.'));
70+
return;
71+
}
72+
73+
if (commandLineOptions.source) {
74+
source = commandLineOptions.source;
75+
}
76+
else if(_.has(gulp.task.configuration, "tasks.watch:tests.source")) {
77+
source = gulp.task.configuration.tasks['watch:tests'].source;
78+
gutil.log(gutil.colors.blue("Read source from the configuration file: " + source));
79+
}
80+
81+
gutil.log(gutil.colors.blue('Watch directory ' + source +' for changes and run the tests on'));
82+
gulp.watch(source, ['tests']);
83+
},{
84+
options: {
85+
'test': 'The test to run when a file is changed. Example gulp watch:tests --test [path/test.php]',
86+
'testsuite': 'The test suite to run when a file is changed. Example gulp watch:tests --testsuite [suiteName]',
87+
'source': 'The directory to watch for file changes. Default the tests directory will be watched. Example gulp watch:tests --source=UnitTests/**/*.php'
88+
}
89+
});
90+
6491
gulp.task('default', ['tests']);

0 commit comments

Comments
 (0)