class Guard::PHPUnit2

The PHPUnit guard gets notified about system events.

Constants

DEFAULT_OPTIONS

Public Class Methods

new(options = {}) click to toggle source

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

Calls superclass method
# 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

run_all() click to toggle source

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
run_on_changes(paths) click to toggle source

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
start() click to toggle source

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

run_all_after_pass(tests_passed) click to toggle source

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
runner() click to toggle source
# File lib/guard/phpunit2.rb, line 86
def runner
  options[:realtime] ? RealtimeRunner : Runner
end
update_failed_paths(tests_passed, paths) click to toggle source

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