Skip to content
This repository was archived by the owner on Mar 31, 2020. It is now read-only.

Commit cc5cab9

Browse files
committed
Remove some duplication
1 parent f0491ba commit cc5cab9

File tree

3 files changed

+25
-50
lines changed

3 files changed

+25
-50
lines changed

tasks/phpspec.js

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ var gulp = require('gulp');
22
var Elixir = require('laravel-elixir');
33

44
var config = Elixir.config;
5-
var notify = new Elixir.Notification();
5+
var runTests = require('./shared/Tests.js');
6+
67

78
/*
89
|----------------------------------------------------------------
9-
| PHPUnit Testing
10+
| PHPSpec Testing
1011
|----------------------------------------------------------------
1112
|
1213
| This task will trigger your entire PHPUnit test suite and it
@@ -16,24 +17,10 @@ var notify = new Elixir.Notification();
1617
*/
1718

1819
Elixir.extend('phpSpec', function(src, command) {
19-
src = src || (config.testing.phpSpec.path + '/**/*Spec.php'),
20-
command = command || 'vendor/bin/phpspec run';
21-
22-
new Elixir.Task('phpSpec', function(error) {
23-
Elixir.Log.heading('Triggering PHPSpec: ' + command);
24-
25-
return (
26-
gulp
27-
.src('')
28-
.pipe(Elixir.Plugins.shell(command))
29-
.on('error', function(e) {
30-
notify.forFailedTests(e, 'PHPSpec');
31-
32-
this.emit('end');
33-
})
34-
.pipe(notify.forPassedTests('PHPSpec'))
35-
);
36-
})
37-
.watch(src);
20+
runTests(
21+
'PHPSpec',
22+
src || (config.testing.phpSpec.path + '/**/*Spec.php'),
23+
command || 'vendor/bin/phpspec run'
24+
);
3825
});
3926

tasks/phpunit.js

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ var gulp = require('gulp');
22
var Elixir = require('laravel-elixir');
33

44
var config = Elixir.config;
5-
var notify = new Elixir.Notification();
5+
var runTests = require('./shared/Tests.js');
6+
67

78
/*
89
|----------------------------------------------------------------
@@ -16,24 +17,10 @@ var notify = new Elixir.Notification();
1617
*/
1718

1819
Elixir.extend('phpUnit', function(src, command) {
19-
src = src || (config.testing.phpUnit.path + '/**/*Test.php');
20-
command = command || 'vendor/bin/phpunit --verbose';
21-
22-
new Elixir.Task('phpUnit', function(error) {
23-
Elixir.Log.heading('Triggering PHPUnit: ' + command);
24-
25-
return (
26-
gulp
27-
.src('')
28-
.pipe(Elixir.Plugins.shell(command))
29-
.on('error', function(e) {
30-
notify.forFailedTests(e, 'PHPUnit');
31-
32-
this.emit('end');
33-
})
34-
.pipe(notify.forPassedTests('PHPUnit'))
35-
);
36-
})
37-
.watch(src);
20+
runTests(
21+
'PHPUnit',
22+
src || (config.testing.phpUnit.path + '/**/*Test.php'),
23+
command || 'vendor/bin/phpunit --verbose'
24+
);
3825
});
3926

tasks/shared/Tests.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,24 @@ var Elixir = require('../../index');
33

44
var notify = new Elixir.Notification();
55

6-
module.exports = function(options) {
7-
new Elixir.Task(options.name, function() {
8-
this.log(options.src);
6+
module.exports = function(name, src, command) {
7+
new Elixir.Task(name, function(error) {
8+
Elixir.Log.heading('Triggering ' + name + ': ' + command);
99

1010
return (
1111
gulp
12-
.src(options.src)
13-
.pipe(options.plugin('', options.pluginOptions))
12+
.src('')
13+
.pipe(Elixir.Plugins.shell(command))
1414
.on('error', function(e) {
15-
notify.forFailedTests(e, options.name);
15+
notify.forFailedTests(e, name);
1616

1717
this.emit('end');
1818
})
19-
.pipe(notify.forPassedTests(options.name))
19+
.pipe(notify.forPassedTests(name))
2020
);
2121
})
22-
.watch(options.src, 'tdd')
22+
.watch(src)
2323
.watch(Elixir.config.appPath + '/**/*.php', 'tdd')
24-
.watch(Elixir.config.viewPath +'/**/*.php', 'tdd')
24+
.watch(Elixir.config.viewPath +'/**/*.php', 'tdd');
2525
};
26+

0 commit comments

Comments
 (0)