Module: Guard::PHPUnit::Formatter

Defined in:
lib/guard/phpunit/formatter.rb

Overview

The Guard::PHPUnit formatter parses the output of phpunit which gets printed by the progress printer.

Class Method Summary (collapse)

Class Method Details

+ (Integer) look_for_duration_in(text) (private)

Searches for the duration in the tests output

Parameters:

  • text (String)

    the tests output

Returns:

  • (Integer)

    the duration



57
58
59
60
# File 'lib/guard/phpunit/formatter.rb', line 57

def look_for_duration_in(text)
  text =~ %r{Finished in (\d)+ seconds?.*\Z}m
  $1.nil? ? 0 : $1.to_i
end

+ (Integer) look_for_words_in(strings_list, text) (private)

Searches for a list of strings in the tests output and returns the total number assigned to these strings.

Parameters:

  • string_list (String, Array<String>)

    the words

  • text (String)

    the tests output

Returns:

  • (Integer)

    the total number assigned to the words



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/guard/phpunit/formatter.rb', line 36

def look_for_words_in(strings_list, text)
  count = 0
  strings_list = Array(strings_list)
  strings_list.each do |s|
    text =~ %r{
      (\d+)   # count of what we are looking for 
      [ ]     # then a space
      #{s}s?  # then the string 
      .*      # then whatever
      \Z      # start looking at the end of the text
    }x
    count += $1.to_i unless $1.nil?
  end
  count
end

+ (Hash) parse_output(text)

Parses the tests output.

Parameters:

  • text (String)

    the output of phpunit.

Returns:

  • (Hash)

    the parsed results



16
17
18
19
20
21
22
23
24
25
# File 'lib/guard/phpunit/formatter.rb', line 16

def parse_output(text)
  results = {
    :tests    => look_for_words_in('test',    text),
    :failures => look_for_words_in('failure', text),
    :errors   => look_for_words_in('error', text),
    :pending  => look_for_words_in(['skipped', 'incomplete'], text),
    :duration => look_for_duration_in(text)
  }
  results.freeze
end