class Guard::PHPUnit2
The PHPUnit guard gets notified about system events.
Constants
- DEFAULT_OPTIONS
Public Class Methods
Initialize Guard::PHPUnit.
@param [Array<Guard::Watcher>] watchers the watchers in the Guard
block @param [Hash] options the options for the Guard
@option options [Boolean] :all_on_start run all tests on start @option options [Boolean] :all_after_pass run all tests after failed tests pass @option options [Boolean] :keep_failed remember failed tests or not @option options [String] :cli The CLI arguments passed to phpunit @option options [String] :tests_path the path where all tests exist
# File lib/guard/phpunit2.rb, line 38 def initialize(options = {}) defaults = DEFAULT_OPTIONS.clone @options = defaults.merge(options) super(@options) @failed_paths = [] @previous_failed = false Inspector.tests_path = @options[:tests_path] end
Public Instance Methods
Gets called when all tests should be run.
@raise (see start
)
# File lib/guard/phpunit2.rb, line 61 def run_all success = runner.run(options[:tests_path], options.merge( :message => 'Running all tests' )) @previous_failed = !success throw :task_has_failed unless success end
Gets called when the watched tests have changes.
@param [Array<String>] paths to the changed tests @raise (see start
)
# File lib/guard/phpunit2.rb, line 75 def run_on_changes(paths) paths = Inspector.clean(paths + @failed_paths) success = runner.run(paths, options) update_failed_paths(success, paths) run_all_after_pass(success) throw :task_has_failed unless success end
Gets called once when Guard
starts.
@raise [:task_has_failed] when stop has failed
# File lib/guard/phpunit2.rb, line 53 def start run_all if options[:all_on_start] end
Private Instance Methods
Runs all tests after the failed tests pass.
@param (see .update_failed_paths)
# File lib/guard/phpunit2.rb, line 110 def run_all_after_pass(tests_passed) return unless @options[:all_after_pass] if tests_passed run_all if @previous_failed else @previous_failed = true end end
# File lib/guard/phpunit2.rb, line 86 def runner options[:realtime] ? RealtimeRunner : Runner end
Adds or removes path to the failed_paths bassed on the tests result.
@param [Boolean] tests_passed whether the tests passed or not @param [Array<String>] paths the tests paths
# File lib/guard/phpunit2.rb, line 96 def update_failed_paths(tests_passed, paths) return unless @options[:keep_failed] if tests_passed @failed_paths -= paths else @failed_paths += paths end end