@@ -5,11 +5,12 @@ var del = require('del');
5
5
var gulpif = require ( 'gulp-if' ) ;
6
6
var fileExists = require ( 'file-exists' ) ;
7
7
var gutil = require ( 'gulp-util' ) ;
8
+ var shell = require ( 'gulp-shell' ) ;
9
+ var _ = require ( 'lodash' ) ;
8
10
9
11
var knownOptions = {
10
- string : [ 'testsuite' , 'test' ] ,
11
- boolean : [ 'coverage' ] ,
12
- alias : [ 's' , 'c' , 't' ]
12
+ string : [ 'testsuite' , 'test' , 'source' ] ,
13
+ boolean : [ 'coverage' ]
13
14
} ;
14
15
15
16
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
18
19
var options ;
19
20
var projectRoot = gulp . task . configuration . projectRoot ;
20
21
21
- options = { } ;
22
+ options = {
23
+ notify : false
24
+ } ;
22
25
23
26
gutil . log ( gutil . colors . blue ( 'Running task \'tests\' in directoy: ' + projectRoot ) ) ;
24
27
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 ) ) ;
27
31
}
28
32
29
- if ( commandLineOptions . coverage || commandLineOptions . c ) {
33
+ if ( commandLineOptions . coverage ) {
30
34
options . coverageHtml = 'coverage/' ;
31
35
}
32
36
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 ) ) ;
35
40
}
36
41
37
42
if ( ! fileExists ( projectRoot + '/phpunit.xml.dist' ) ) {
38
43
gutil . log ( gutil . colors . red ( 'Mandatory file \'phpunit.xml.dist\' does not exists.' ) ) ;
39
44
return ;
40
45
}
41
46
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' )
48
48
. pipe ( gulpif ( options . coverageHtml , gulp . dest ( 'coverage/' ) ) )
49
49
. pipe ( phpunit ( projectRoot + '/vendor/bin/phpunit' , options ) ) ;
50
50
} , {
51
51
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'
55
55
}
56
56
} ) ;
57
57
@@ -61,4 +61,31 @@ gulp.task('clear:coverage', 'Clear the coverage reports files.', function() {
61
61
return del ( [ projectRoot + '/coverage/**' ] , { force : true } ) ;
62
62
} ) ;
63
63
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
+
64
91
gulp . task ( 'default' , [ 'tests' ] ) ;
0 commit comments