Class: Guard::PHPUnit

Inherits:
Guard
  • Object
show all
Defined in:
lib/guard/phpunit.rb,
lib/guard/phpunit/runner.rb,
lib/guard/phpunit/notifier.rb,
lib/guard/phpunit/formatter.rb,
lib/guard/phpunit/inspector.rb

Overview

The PHPUnit guard gets notified about system events.

Defined Under Namespace

Modules: Formatter, Inspector, Notifier, Runner

Constant Summary collapse

DEFAULT_OPTIONS =
{
  :all_on_start   => true,
  :all_after_pass => true,
  :keep_failed    => true,
  :cli            => nil,
  :tests_path     => Dir.pwd
}

Instance Method Summary collapse

Constructor Details

#initialize(watchers = [], options = {}) ⇒ PHPUnit

Initialize Guard::PHPUnit.

Parameters:

  • watchers (Array<Guard::Watcher>) (defaults to: [])

    the watchers in the Guard block

  • options (Hash) (defaults to: {})

    the options for the Guard

Options Hash (options):

  • :all_on_start (Boolean)

    run all tests on start

  • :all_after_pass (Boolean)

    run all tests after failed tests pass

  • :keep_failed (Boolean)

    remember failed tests or not

  • :cli (String)

    The CLI arguments passed to phpunit

  • :tests_path (String)

    the path where all tests exist



34
35
36
37
38
39
40
41
42
43
# File 'lib/guard/phpunit.rb', line 34

def initialize(watchers = [], options = {})
  defaults = DEFAULT_OPTIONS.clone
  @options = defaults.merge(options)
  super(watchers, @options)

  @failed_paths     = []
  @previous_failed = false

  Inspector.tests_path = @options[:tests_path]
end

Instance Method Details

#run_allObject

Gets called when all tests should be run.

Raises:

  • (:task_has_failed)

    when stop has failed



57
58
59
60
61
62
63
64
# File 'lib/guard/phpunit.rb', line 57

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) ⇒ Object

Gets called when the watched tests have changes.

Parameters:

  • paths (Array<String>)

    to the changed tests

Raises:

  • (:task_has_failed)

    when stop has failed



71
72
73
74
75
76
77
78
# File 'lib/guard/phpunit.rb', line 71

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

#startObject

Gets called once when Guard starts.

Raises:

  • (:task_has_failed)

    when stop has failed



49
50
51
# File 'lib/guard/phpunit.rb', line 49

def start
  run_all if options[:all_on_start]
end