Module: Guard::PHPUnit::Runner
- Defined in:
- lib/guard/phpunit/runner.rb
Overview
The Guard::PHPUnit runner handles running the tests, displaying their output and notifying the user about the results.
Constant Summary
- PHPUNIT_FAILURES_EXITCODE =
The exittcode phpunit returns when the tests contain failures
1- PHPUNIT_ERRORS_EXITCODE =
The exittcode phpunit returns when the tests contain errors
2
Class Method Summary (collapse)
-
+ (Object) create_tests_folder_for(paths) {|String| ... }
private
Creates a temporary folder which has links to the tests paths.
-
+ (String) execute_command(command)
private
Executes a system command and returns the output.
-
+ (Object) notify_failure(options)
private
Displays a notification about failing to run the tests.
-
+ (Object) notify_results(output, options)
private
Displays a notification about the tests results.
-
+ (Object) notify_start(paths, options)
private
Displays the start testing notification.
-
+ (Object) phpunit_command(path, options)
private
Generates the phpunit command for the tests paths.
-
+ (Boolean) phpunit_exists?
private
Checks that phpunit is installed on the user's machine.
-
+ (Boolean) run(paths, options = {})
Runs the PHPUnit tests and displays notifications about the results.
-
+ (Object) run_tests(paths, options)
private
Executes the testing command on the tests and returns the status of this process.
-
+ (Object) symlink_paths_to_tests_folder(paths, folder)
private
Creates symbolic links inside the folder pointing back to the paths.
-
+ (Boolean) tests_contain_errors?
private
Checks the exitstatus of the phpunit command for a sign of errors in the tests.
-
+ (Boolean) tests_contain_failures?
private
Checks the exitstatus of the phpunit command for a sign of failures in the tests.
Class Method Details
+ (Object) create_tests_folder_for(paths) {|String| ... } (private)
Creates a temporary folder which has links to the tests paths. This method is used because PHPUnit can't run multiple tests files at the same time and generate one result for them.
142 143 144 145 146 147 |
# File 'lib/guard/phpunit/runner.rb', line 142 def create_tests_folder_for(paths) Dir.mktmpdir('guard_phpunit') do |d| symlink_paths_to_tests_folder(paths, d) yield d end end |
+ (String) execute_command(command) (private)
Executes a system command and returns the output.
188 189 190 |
# File 'lib/guard/phpunit/runner.rb', line 188 def execute_command(command) %x{#{command}} end |
+ (Object) notify_failure(options) (private)
Displays a notification about failing to run the tests
111 112 113 114 |
# File 'lib/guard/phpunit/runner.rb', line 111 def notify_failure() return if [:notification] == false Notifier.notify('Failed! Check the console', :title => 'PHPUnit results', :image => :failed) end |
+ (Object) notify_results(output, options) (private)
Displays a notification about the tests results.
101 102 103 104 105 |
# File 'lib/guard/phpunit/runner.rb', line 101 def notify_results(output, ) return if [:notification] == false results = Formatter.parse_output(output) Notifier.notify_results(results) end |
+ (Object) notify_start(paths, options) (private)
Displays the start testing notification.
91 92 93 94 |
# File 'lib/guard/phpunit/runner.rb', line 91 def notify_start(paths, ) = [:message] || "Running: #{paths.join(' ')}" UI.info(, :reset => true) end |
+ (Object) phpunit_command(path, options) (private)
Generates the phpunit command for the tests paths.
170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/guard/phpunit/runner.rb', line 170 def phpunit_command(path, ) formatter_path = File.join( File.dirname(__FILE__), 'formatters', 'PHPUnit-Progress') cmd_parts = [] cmd_parts << "phpunit" cmd_parts << "--include-path #{formatter_path}" cmd_parts << "--printer PHPUnit_Extensions_Progress_ResultPrinter" cmd_parts << [:cli] if [:cli] cmd_parts << path cmd_parts.join(' ') end |
+ (Boolean) phpunit_exists? (private)
Checks that phpunit is installed on the user's machine.
48 49 50 |
# File 'lib/guard/phpunit/runner.rb', line 48 def phpunit_exists? system('which phpunit > /dev/null 2>&1') end |
+ (Boolean) run(paths, options = {})
Runs the PHPUnit tests and displays notifications about the results.
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/guard/phpunit/runner.rb', line 28 def run(paths, = {}) paths = Array(paths) return false if paths.empty? unless phpunit_exists? UI.error('phpunit is not installed on your machine.', :reset => true) return false end run_tests(paths, ) end |
+ (Object) run_tests(paths, options) (private)
Executes the testing command on the tests and returns the status of this process.
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 |
# File 'lib/guard/phpunit/runner.rb', line 58 def run_tests(paths, ) notify_start(paths, ) if paths.length == 1 tests_path = paths.first output = execute_command phpunit_command(tests_path, ) else create_tests_folder_for(paths) do |tests_folder| output = execute_command phpunit_command(tests_folder, ) end end # print the output to the terminal UI.info output # return false in case the system call fails with no status! return false if $?.nil? if $?.success? or tests_contain_failures? or tests_contain_errors? notify_results(output, ) else notify_failure() end $?.success? end |
+ (Object) symlink_paths_to_tests_folder(paths, folder) (private)
Creates symbolic links inside the folder pointing back to the paths.
157 158 159 160 161 162 |
# File 'lib/guard/phpunit/runner.rb', line 157 def symlink_paths_to_tests_folder(paths, folder) paths.each do |p| FileUtils.mkdir_p( File.join(folder, File.dirname(p) ) ) unless File.dirname(p) == '.' FileUtils.ln_s(Pathname.new(p).realpath, File.join(folder, p)) end end |
+ (Boolean) tests_contain_errors? (private)
Checks the exitstatus of the phpunit command for a sign of errors in the tests.
130 131 132 |
# File 'lib/guard/phpunit/runner.rb', line 130 def tests_contain_errors? $?.exitstatus == PHPUNIT_ERRORS_EXITCODE end |
+ (Boolean) tests_contain_failures? (private)
Checks the exitstatus of the phpunit command for a sign of failures in the tests.
121 122 123 |
# File 'lib/guard/phpunit/runner.rb', line 121 def tests_contain_failures? $?.exitstatus == PHPUNIT_FAILURES_EXITCODE end |