guard-phpunit 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +37 -0
- data/LICENSE +19 -19
- data/README.md +106 -106
- data/lib/guard/phpunit.rb +112 -112
- data/lib/guard/phpunit/formatter.rb +64 -64
- data/lib/guard/phpunit/formatters/PHPUnit-Progress/PHPUnit/Extensions/Progress/ResultPrinter.php +498 -498
- data/lib/guard/phpunit/formatters/PHPUnit-Progress/README.markdown +44 -0
- data/lib/guard/phpunit/formatters/PHPUnit-Progress/Tests/_files/Number.php +78 -0
- data/lib/guard/phpunit/formatters/PHPUnit-Progress/Tests/_files/NumberTest.php +99 -0
- data/lib/guard/phpunit/formatters/PHPUnit-Progress/Tests/_files/emptyTest.php +6 -0
- data/lib/guard/phpunit/formatters/PHPUnit-Progress/Tests/printer_basic.phpt +22 -0
- data/lib/guard/phpunit/formatters/PHPUnit-Progress/Tests/printer_errors.phpt +27 -0
- data/lib/guard/phpunit/formatters/PHPUnit-Progress/Tests/printer_errors_variation.phpt +28 -0
- data/lib/guard/phpunit/formatters/PHPUnit-Progress/Tests/printer_failing.phpt +31 -0
- data/lib/guard/phpunit/formatters/PHPUnit-Progress/Tests/printer_failing_variation.phpt +32 -0
- data/lib/guard/phpunit/formatters/PHPUnit-Progress/Tests/printer_incomplete.phpt +19 -0
- data/lib/guard/phpunit/formatters/PHPUnit-Progress/Tests/printer_incomplete_variation.phpt +20 -0
- data/lib/guard/phpunit/formatters/PHPUnit-Progress/Tests/printer_passing.phpt +19 -0
- data/lib/guard/phpunit/formatters/PHPUnit-Progress/Tests/printer_passing_variation.phpt +20 -0
- data/lib/guard/phpunit/formatters/PHPUnit-Progress/Tests/printer_skipped.phpt +19 -0
- data/lib/guard/phpunit/formatters/PHPUnit-Progress/Tests/printer_skipped_variation.phpt +20 -0
- data/lib/guard/phpunit/formatters/PHPUnit-Progress/phpunit.xml +4 -0
- data/lib/guard/phpunit/formatters/PHPUnit-Progress/screenshot.png +0 -0
- data/lib/guard/phpunit/inspector.rb +54 -54
- data/lib/guard/phpunit/notifier.rb +68 -68
- data/lib/guard/phpunit/runner.rb +197 -194
- data/lib/guard/phpunit/templates/Guardfile +3 -3
- data/lib/guard/phpunit/version.rb +6 -6
- metadata +37 -3
@@ -0,0 +1,19 @@
|
|
1
|
+
--TEST--
|
2
|
+
phpunit Number - Only skipped tests
|
3
|
+
--FILE--
|
4
|
+
<?php
|
5
|
+
$group = 'skipped';
|
6
|
+
$testClass = 'NumberTest';
|
7
|
+
|
8
|
+
$_SERVER['argv'][1] = '--group';
|
9
|
+
$_SERVER['argv'][2] = $group;
|
10
|
+
$_SERVER['argv'][3] = dirname(__FILE__) . "/_files/${testClass}.php";
|
11
|
+
|
12
|
+
require_once 'PHPUnit/Autoload.php';
|
13
|
+
PHPUnit_TextUI_Command::main();
|
14
|
+
?>
|
15
|
+
--EXPECTF--
|
16
|
+
%rS+%r
|
17
|
+
|
18
|
+
Finished in %i second%S
|
19
|
+
%i tests, 0 assertions, %i skipped
|
@@ -0,0 +1,20 @@
|
|
1
|
+
--TEST--
|
2
|
+
phpunit Number - Only skipped tests and colors enabled
|
3
|
+
--FILE--
|
4
|
+
<?php
|
5
|
+
$group = 'skipped';
|
6
|
+
$testClass = 'NumberTest';
|
7
|
+
|
8
|
+
$_SERVER['argv'][1] = '--group';
|
9
|
+
$_SERVER['argv'][2] = $group;
|
10
|
+
$_SERVER['argv'][3] = '--colors';
|
11
|
+
$_SERVER['argv'][4] = dirname(__FILE__) . "/_files/${testClass}.php";
|
12
|
+
|
13
|
+
require_once 'PHPUnit/Autoload.php';
|
14
|
+
PHPUnit_TextUI_Command::main();
|
15
|
+
?>
|
16
|
+
--EXPECTF--
|
17
|
+
[33mS[0m[33mS[0m
|
18
|
+
|
19
|
+
Finished in %i second%S
|
20
|
+
[33m2 tests, 0 assertions, 2 skipped[0m
|
Binary file
|
@@ -1,54 +1,54 @@
|
|
1
|
-
module Guard
|
2
|
-
class PHPUnit
|
3
|
-
|
4
|
-
# The Guard::PHPUnit inspector verfies that the changed paths
|
5
|
-
# are valid for Guard::PHPUnit.
|
6
|
-
#
|
7
|
-
module Inspector
|
8
|
-
class << self
|
9
|
-
|
10
|
-
attr_accessor :tests_path
|
11
|
-
|
12
|
-
# Clean the changed paths and return only valid
|
13
|
-
# PHPUnit tests files.
|
14
|
-
#
|
15
|
-
# @param [Array<String>] paths the changed paths
|
16
|
-
# @return [Array<String>] the valid tests files
|
17
|
-
#
|
18
|
-
def clean(paths)
|
19
|
-
paths.uniq!
|
20
|
-
paths.compact!
|
21
|
-
paths = paths.select { |p| test_file?(p) }
|
22
|
-
clear_tests_files_list
|
23
|
-
paths
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
# Checks if the paths is a valid test file.
|
29
|
-
#
|
30
|
-
# @param [String] path the test path
|
31
|
-
# @return [Boolean] whether the path a valid test or not
|
32
|
-
#
|
33
|
-
def test_file?(path)
|
34
|
-
tests_files.include?(path)
|
35
|
-
end
|
36
|
-
|
37
|
-
# Scans the tests path and keeps a list of all
|
38
|
-
# tests paths.
|
39
|
-
#
|
40
|
-
def tests_files
|
41
|
-
@tests_files ||= Dir.glob( File.join(tests_path, '**', '*Test.php') )
|
42
|
-
end
|
43
|
-
|
44
|
-
# Clears the list of PHPUnit tests.
|
45
|
-
#
|
46
|
-
# @see #clean
|
47
|
-
#
|
48
|
-
def clear_tests_files_list
|
49
|
-
@tests_files = nil
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
1
|
+
module Guard
|
2
|
+
class PHPUnit
|
3
|
+
|
4
|
+
# The Guard::PHPUnit inspector verfies that the changed paths
|
5
|
+
# are valid for Guard::PHPUnit.
|
6
|
+
#
|
7
|
+
module Inspector
|
8
|
+
class << self
|
9
|
+
|
10
|
+
attr_accessor :tests_path
|
11
|
+
|
12
|
+
# Clean the changed paths and return only valid
|
13
|
+
# PHPUnit tests files.
|
14
|
+
#
|
15
|
+
# @param [Array<String>] paths the changed paths
|
16
|
+
# @return [Array<String>] the valid tests files
|
17
|
+
#
|
18
|
+
def clean(paths)
|
19
|
+
paths.uniq!
|
20
|
+
paths.compact!
|
21
|
+
paths = paths.select { |p| test_file?(p) }
|
22
|
+
clear_tests_files_list
|
23
|
+
paths
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
# Checks if the paths is a valid test file.
|
29
|
+
#
|
30
|
+
# @param [String] path the test path
|
31
|
+
# @return [Boolean] whether the path a valid test or not
|
32
|
+
#
|
33
|
+
def test_file?(path)
|
34
|
+
tests_files.include?(path)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Scans the tests path and keeps a list of all
|
38
|
+
# tests paths.
|
39
|
+
#
|
40
|
+
def tests_files
|
41
|
+
@tests_files ||= Dir.glob( File.join(tests_path, '**', '*Test.php') )
|
42
|
+
end
|
43
|
+
|
44
|
+
# Clears the list of PHPUnit tests.
|
45
|
+
#
|
46
|
+
# @see #clean
|
47
|
+
#
|
48
|
+
def clear_tests_files_list
|
49
|
+
@tests_files = nil
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -1,68 +1,68 @@
|
|
1
|
-
module Guard
|
2
|
-
class PHPUnit
|
3
|
-
|
4
|
-
# The Guard::PHPUnit notifier displays a notification pop-up
|
5
|
-
# with the tests results.
|
6
|
-
#
|
7
|
-
module Notifier
|
8
|
-
class << self
|
9
|
-
|
10
|
-
# Displays a system notification.
|
11
|
-
#
|
12
|
-
# @param [String] message the message to show
|
13
|
-
# @param [Hash] options the notifier options
|
14
|
-
#
|
15
|
-
def notify(message, options)
|
16
|
-
::Guard::Notifier.notify(message, options)
|
17
|
-
end
|
18
|
-
|
19
|
-
# Displays a notification about the tests results.
|
20
|
-
#
|
21
|
-
# @param [Hash] test_results the parsed tests results
|
22
|
-
# @option test_results [Integer] :tests tests count
|
23
|
-
# @option test_results [Integer] :failures failures count
|
24
|
-
# @option test_results [Integer] :errors count count
|
25
|
-
# @option test_results [Integer] :pending pending tests count
|
26
|
-
# @option test_results [Integer] :duration tests duration
|
27
|
-
#
|
28
|
-
def notify_results(test_results)
|
29
|
-
notify(message(test_results), {
|
30
|
-
:title => 'PHPUnit results',
|
31
|
-
:image => image(test_results)
|
32
|
-
})
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
# Formats the message for the tests results notifier.
|
38
|
-
#
|
39
|
-
# @param (see .notify)
|
40
|
-
# @return [String] the message
|
41
|
-
#
|
42
|
-
def message(results)
|
43
|
-
message = "#{results[:tests]} tests, #{results[:failures]} failures"
|
44
|
-
message << "\n#{results[:errors]} errors" if results[:errors] > 0
|
45
|
-
message << " (#{results[:pending]} pending)" if results[:pending] > 0
|
46
|
-
message << "\nin #{results[:duration]} seconds"
|
47
|
-
message
|
48
|
-
end
|
49
|
-
|
50
|
-
# Returns the appropriate image for the tests results.
|
51
|
-
#
|
52
|
-
# @param (see .notify)
|
53
|
-
# @return [Symbol] the image symbol
|
54
|
-
#
|
55
|
-
def image(results)
|
56
|
-
case
|
57
|
-
when results[:failures] + results[:errors] > 0
|
58
|
-
:failed
|
59
|
-
when results[:pending] > 0
|
60
|
-
:pending
|
61
|
-
else
|
62
|
-
:success
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
1
|
+
module Guard
|
2
|
+
class PHPUnit
|
3
|
+
|
4
|
+
# The Guard::PHPUnit notifier displays a notification pop-up
|
5
|
+
# with the tests results.
|
6
|
+
#
|
7
|
+
module Notifier
|
8
|
+
class << self
|
9
|
+
|
10
|
+
# Displays a system notification.
|
11
|
+
#
|
12
|
+
# @param [String] message the message to show
|
13
|
+
# @param [Hash] options the notifier options
|
14
|
+
#
|
15
|
+
def notify(message, options)
|
16
|
+
::Guard::Notifier.notify(message, options)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Displays a notification about the tests results.
|
20
|
+
#
|
21
|
+
# @param [Hash] test_results the parsed tests results
|
22
|
+
# @option test_results [Integer] :tests tests count
|
23
|
+
# @option test_results [Integer] :failures failures count
|
24
|
+
# @option test_results [Integer] :errors count count
|
25
|
+
# @option test_results [Integer] :pending pending tests count
|
26
|
+
# @option test_results [Integer] :duration tests duration
|
27
|
+
#
|
28
|
+
def notify_results(test_results)
|
29
|
+
notify(message(test_results), {
|
30
|
+
:title => 'PHPUnit results',
|
31
|
+
:image => image(test_results)
|
32
|
+
})
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
# Formats the message for the tests results notifier.
|
38
|
+
#
|
39
|
+
# @param (see .notify)
|
40
|
+
# @return [String] the message
|
41
|
+
#
|
42
|
+
def message(results)
|
43
|
+
message = "#{results[:tests]} tests, #{results[:failures]} failures"
|
44
|
+
message << "\n#{results[:errors]} errors" if results[:errors] > 0
|
45
|
+
message << " (#{results[:pending]} pending)" if results[:pending] > 0
|
46
|
+
message << "\nin #{results[:duration]} seconds"
|
47
|
+
message
|
48
|
+
end
|
49
|
+
|
50
|
+
# Returns the appropriate image for the tests results.
|
51
|
+
#
|
52
|
+
# @param (see .notify)
|
53
|
+
# @return [Symbol] the image symbol
|
54
|
+
#
|
55
|
+
def image(results)
|
56
|
+
case
|
57
|
+
when results[:failures] + results[:errors] > 0
|
58
|
+
:failed
|
59
|
+
when results[:pending] > 0
|
60
|
+
:pending
|
61
|
+
else
|
62
|
+
:success
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/guard/phpunit/runner.rb
CHANGED
@@ -1,194 +1,197 @@
|
|
1
|
-
require 'tmpdir'
|
2
|
-
require 'fileutils'
|
3
|
-
|
4
|
-
module Guard
|
5
|
-
class PHPUnit
|
6
|
-
|
7
|
-
# The Guard::PHPUnit runner handles running the tests, displaying
|
8
|
-
# their output and notifying the user about the results.
|
9
|
-
#
|
10
|
-
module Runner
|
11
|
-
class << self
|
12
|
-
|
13
|
-
# The exittcode phpunit returns when the tests contain failures
|
14
|
-
#
|
15
|
-
PHPUNIT_FAILURES_EXITCODE = 1
|
16
|
-
|
17
|
-
# The exittcode phpunit returns when the tests contain errors
|
18
|
-
#
|
19
|
-
PHPUNIT_ERRORS_EXITCODE = 2
|
20
|
-
|
21
|
-
# Runs the PHPUnit tests and displays notifications
|
22
|
-
# about the results.
|
23
|
-
#
|
24
|
-
# @param [Array<Strings>] path to the tests files.
|
25
|
-
# @param (see PHPUnit#initialize)
|
26
|
-
# @return [Boolean] whether the tests were run successfully
|
27
|
-
#
|
28
|
-
def run(paths, options = {})
|
29
|
-
paths = Array(paths)
|
30
|
-
|
31
|
-
return false if paths.empty?
|
32
|
-
|
33
|
-
unless phpunit_exists?
|
34
|
-
UI.error('phpunit is not installed on your machine.', :reset => true)
|
35
|
-
return false
|
36
|
-
end
|
37
|
-
|
38
|
-
run_tests(paths, options)
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
# Checks that phpunit is installed on the user's
|
44
|
-
# machine.
|
45
|
-
#
|
46
|
-
# @return [Boolean] The status of phpunit
|
47
|
-
#
|
48
|
-
def phpunit_exists?
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
#
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
#
|
90
|
-
#
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
#
|
100
|
-
#
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
#
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
#
|
120
|
-
#
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
#
|
129
|
-
#
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
#
|
138
|
-
#
|
139
|
-
#
|
140
|
-
#
|
141
|
-
#
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
#
|
153
|
-
#
|
154
|
-
#
|
155
|
-
# @
|
156
|
-
#
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
#
|
168
|
-
#
|
169
|
-
#
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
cmd_parts
|
177
|
-
cmd_parts <<
|
178
|
-
cmd_parts << path
|
179
|
-
|
180
|
-
cmd_parts
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
#
|
187
|
-
#
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
end
|
1
|
+
require 'tmpdir'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module Guard
|
5
|
+
class PHPUnit
|
6
|
+
|
7
|
+
# The Guard::PHPUnit runner handles running the tests, displaying
|
8
|
+
# their output and notifying the user about the results.
|
9
|
+
#
|
10
|
+
module Runner
|
11
|
+
class << self
|
12
|
+
|
13
|
+
# The exittcode phpunit returns when the tests contain failures
|
14
|
+
#
|
15
|
+
PHPUNIT_FAILURES_EXITCODE = 1
|
16
|
+
|
17
|
+
# The exittcode phpunit returns when the tests contain errors
|
18
|
+
#
|
19
|
+
PHPUNIT_ERRORS_EXITCODE = 2
|
20
|
+
|
21
|
+
# Runs the PHPUnit tests and displays notifications
|
22
|
+
# about the results.
|
23
|
+
#
|
24
|
+
# @param [Array<Strings>] path to the tests files.
|
25
|
+
# @param (see PHPUnit#initialize)
|
26
|
+
# @return [Boolean] whether the tests were run successfully
|
27
|
+
#
|
28
|
+
def run(paths, options = {})
|
29
|
+
paths = Array(paths)
|
30
|
+
|
31
|
+
return false if paths.empty?
|
32
|
+
|
33
|
+
unless phpunit_exists?
|
34
|
+
UI.error('phpunit is not installed on your machine.', :reset => true)
|
35
|
+
return false
|
36
|
+
end
|
37
|
+
|
38
|
+
run_tests(paths, options)
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
# Checks that phpunit is installed on the user's
|
44
|
+
# machine.
|
45
|
+
#
|
46
|
+
# @return [Boolean] The status of phpunit
|
47
|
+
#
|
48
|
+
def phpunit_exists?
|
49
|
+
`phpunit --version`
|
50
|
+
true
|
51
|
+
rescue Errno::ENOENT
|
52
|
+
false
|
53
|
+
end
|
54
|
+
|
55
|
+
# Executes the testing command on the tests
|
56
|
+
# and returns the status of this process.
|
57
|
+
#
|
58
|
+
# @param (see #run)
|
59
|
+
# @param (see #run)
|
60
|
+
#
|
61
|
+
def run_tests(paths, options)
|
62
|
+
|
63
|
+
notify_start(paths, options)
|
64
|
+
|
65
|
+
if paths.length == 1
|
66
|
+
tests_path = paths.first
|
67
|
+
output = execute_command phpunit_command(tests_path, options)
|
68
|
+
else
|
69
|
+
create_tests_folder_for(paths) do |tests_folder|
|
70
|
+
output = execute_command phpunit_command(tests_folder, options)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# print the output to the terminal
|
75
|
+
UI.info output
|
76
|
+
|
77
|
+
# return false in case the system call fails with no status!
|
78
|
+
return false if $?.nil?
|
79
|
+
|
80
|
+
if $?.success? or tests_contain_failures? or tests_contain_errors?
|
81
|
+
notify_results(output, options)
|
82
|
+
else
|
83
|
+
notify_failure(options)
|
84
|
+
end
|
85
|
+
|
86
|
+
$?.success?
|
87
|
+
end
|
88
|
+
|
89
|
+
# Displays the start testing notification.
|
90
|
+
#
|
91
|
+
# @param (see #run)
|
92
|
+
# @param (see #run)
|
93
|
+
#
|
94
|
+
def notify_start(paths, options)
|
95
|
+
message = options[:message] || "Running: #{paths.join(' ')}"
|
96
|
+
UI.info(message, :reset => true)
|
97
|
+
end
|
98
|
+
|
99
|
+
# Displays a notification about the tests results.
|
100
|
+
#
|
101
|
+
# @param [String] output the tests output
|
102
|
+
# @param (see #run)
|
103
|
+
#
|
104
|
+
def notify_results(output, options)
|
105
|
+
return if options[:notification] == false
|
106
|
+
results = Formatter.parse_output(output)
|
107
|
+
Notifier.notify_results(results)
|
108
|
+
end
|
109
|
+
|
110
|
+
# Displays a notification about failing to run the tests
|
111
|
+
#
|
112
|
+
# @param (see #run)
|
113
|
+
#
|
114
|
+
def notify_failure(options)
|
115
|
+
return if options[:notification] == false
|
116
|
+
Notifier.notify('Failed! Check the console', :title => 'PHPUnit results', :image => :failed)
|
117
|
+
end
|
118
|
+
|
119
|
+
# Checks the exitstatus of the phpunit command
|
120
|
+
# for a sign of failures in the tests.
|
121
|
+
#
|
122
|
+
# @return [Boolean] whether the tests contain failures or not
|
123
|
+
#
|
124
|
+
def tests_contain_failures?
|
125
|
+
$?.exitstatus == PHPUNIT_FAILURES_EXITCODE
|
126
|
+
end
|
127
|
+
|
128
|
+
# Checks the exitstatus of the phpunit command
|
129
|
+
# for a sign of errors in the tests.
|
130
|
+
#
|
131
|
+
# @return [Boolean] whether the tests contain errors or not
|
132
|
+
#
|
133
|
+
def tests_contain_errors?
|
134
|
+
$?.exitstatus == PHPUNIT_ERRORS_EXITCODE
|
135
|
+
end
|
136
|
+
|
137
|
+
# Creates a temporary folder which has links to
|
138
|
+
# the tests paths. This method is used because PHPUnit
|
139
|
+
# can't run multiple tests files at the same time and generate
|
140
|
+
# one result for them.
|
141
|
+
#
|
142
|
+
# @param (see #run)
|
143
|
+
# @yield [String] d the temporary dir for the tests
|
144
|
+
#
|
145
|
+
def create_tests_folder_for(paths)
|
146
|
+
Dir.mktmpdir('guard_phpunit') do |d|
|
147
|
+
symlink_paths_to_tests_folder(paths, d)
|
148
|
+
yield d
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
# Creates symbolic links inside the folder pointing
|
153
|
+
# back to the paths.
|
154
|
+
#
|
155
|
+
# @see #create_tests_folder_for
|
156
|
+
#
|
157
|
+
# @param (see #run)
|
158
|
+
# @param [String] the folder in which the links must be made
|
159
|
+
#
|
160
|
+
def symlink_paths_to_tests_folder(paths, folder)
|
161
|
+
paths.each do |p|
|
162
|
+
FileUtils.mkdir_p( File.join(folder, File.dirname(p) ) ) unless File.dirname(p) == '.'
|
163
|
+
FileUtils.ln_s(Pathname.new(p).realpath, File.join(folder, p))
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
# Generates the phpunit command for the tests paths.
|
168
|
+
#
|
169
|
+
# @param (see #run)
|
170
|
+
# @param (see #run)
|
171
|
+
# @see #run_tests
|
172
|
+
#
|
173
|
+
def phpunit_command(path, options)
|
174
|
+
formatter_path = File.join( File.dirname(__FILE__), 'formatters', 'PHPUnit-Progress')
|
175
|
+
|
176
|
+
cmd_parts = []
|
177
|
+
cmd_parts << "phpunit"
|
178
|
+
cmd_parts << "--include-path #{formatter_path}"
|
179
|
+
cmd_parts << "--printer PHPUnit_Extensions_Progress_ResultPrinter"
|
180
|
+
cmd_parts << options[:cli] if options[:cli]
|
181
|
+
cmd_parts << path
|
182
|
+
|
183
|
+
cmd_parts.join(' ')
|
184
|
+
end
|
185
|
+
|
186
|
+
# Executes a system command and returns the output.
|
187
|
+
#
|
188
|
+
# @param [String] command the command to be run
|
189
|
+
# @return [String] the output of the executed command
|
190
|
+
#
|
191
|
+
def execute_command(command)
|
192
|
+
%x{#{command}}
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|