~ubuntu-branches/ubuntu/hardy/php5/hardy-updates

« back to all changes in this revision

Viewing changes to pear/tests/PEAR_ErrorStack/HTML_TestListener.php

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-10-09 03:14:32 UTC
  • Revision ID: james.westby@ubuntu.com-20051009031432-kspik3lobxstafv9
Tags: upstream-5.0.5
ImportĀ upstreamĀ versionĀ 5.0.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/**
 
4
 * Provides a nice HTML output for PHPUnit suite tests.
 
5
 * 
 
6
 * @version    $Id: HTML_TestListener.php,v 1.1 2004/03/19 00:48:39 cellog Exp $
 
7
 * @author     Laurent Laville <pear@laurent-laville.org>
 
8
 * @package    HTML_CSS
 
9
 */
 
10
 
 
11
class HTML_TestListener extends PHPUnit_TestListener {
 
12
 
 
13
    function HTML_TestListener() {
 
14
 
 
15
$report = <<<EOS
 
16
<table cellspacing="1" cellpadding="1" border="0" width="90%" align="center" class="details">
 
17
<tr><th>Class</th><th>Function</th><th>Success</th><th>Meta-result</th></tr>
 
18
EOS;
 
19
        echo $report;
 
20
    }
 
21
 
 
22
    function addError(&$test, &$t) {
 
23
        $this->_errors += 1;
 
24
    }
 
25
 
 
26
    function addFailure(&$test, &$t) {
 
27
        $this->_fails += 1;
 
28
    }
 
29
 
 
30
    function endTest(&$test) {
 
31
        /* Report both the test result and, for this special situation
 
32
           where some tests are expected to fail, a "meta" test result
 
33
           which indicates whether the test result matches the
 
34
           expected result. 
 
35
         */
 
36
        $expect_failure = preg_match('/fail/i', $test->getName());
 
37
        $test_passed = ($this->_fails == 0 && $this->_errors == 0);
 
38
 
 
39
        if ($this->_errors > 0) {
 
40
            $outcome = "<span class=\"Error\">ERROR</span>";
 
41
        } else if ($this->_fails > 0) {
 
42
            $outcome = "<span class=\"Failure\">FAIL</span>";
 
43
        } else {
 
44
            $outcome = "<span class=\"Pass\">OK</span>";
 
45
        }
 
46
        if ($this->_errors > 0) {
 
47
            $meta_outcome = '<span class="Unknown">unknown</span>';
 
48
        } else {
 
49
            $meta_outcome = ($expect_failure xor $test_passed)
 
50
                ? '<span class="Expected">as expected</span>'
 
51
                : '<span class="Unexpected">UNEXPECTED</span>';
 
52
        }
 
53
        printf("<td>$outcome</td><td>$meta_outcome</td></tr>");
 
54
    }
 
55
 
 
56
    function startTest(&$test) {
 
57
        $this->_fails = 0;
 
58
        $this->_errors = 0;
 
59
        printf("<tr><td>%s </td><td>%s </td>", get_class($test), $test->getName());
 
60
    }
 
61
 
 
62
 
 
63
}
 
64
?>
 
 
b'\\ No newline at end of file'