summaryrefslogtreecommitdiff
path: root/tests/selenium/SeleniumTestListener.php
blob: 9436f672717915c29604c242ca0afc3813e0b62c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php

class SeleniumTestListener implements PHPUnit_Framework_TestListener {
	private $logger;
	private $tests_ok = 0;
	private $tests_failed = 0;

	public function __construct( $loggerInstance ) {
		$this->logger = $loggerInstance;
	}

	public function addError( PHPUnit_Framework_Test $test, Exception $e, $time ) {
		$this->logger->write( 'Error: ' . $e->getMessage() );
		$this->tests_failed++;
	}

	public function addFailure( PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time )
	{
		$this->logger->write( 'Failed: ' . $e->getMessage() );
		$this->tests_failed++;
	}

	public function addIncompleteTest( PHPUnit_Framework_Test $test, Exception $e, $time )
	{
		$this->logger->write( 'Incomplete.' );
		$this->tests_failed++;
	}

	public function addSkippedTest( PHPUnit_Framework_Test $test, Exception $e, $time )
	{
		$this->logger->write( 'Skipped.' );
		$this->tests_failed++;
	}

	public function startTest( PHPUnit_Framework_Test $test ) {
		$this->logger->write(
			'Testing ' . $test->getName() . ' ... ',
			SeleniumTestSuite::CONTINUE_LINE
		);
	}

	public function endTest( PHPUnit_Framework_Test $test, $time ) {
		if ( !$test->hasFailed() ) {
			$this->logger->write( 'OK', SeleniumTestSuite::RESULT_OK );
			$this->tests_ok++;
		}
	}

	public function startTestSuite( PHPUnit_Framework_TestSuite $suite ) {
		$this->logger->write( 'Testsuite ' . $suite->getName() . ' started.' );
		$this->tests_ok = 0;
		$this->tests_failed = 0;
	}

	public function endTestSuite( PHPUnit_Framework_TestSuite $suite ) {
		$this->logger->write('Testsuite ' . $suite->getName() . ' ended.' );
		if ( $this->tests_ok > 0 || $this->tests_failed > 0 ) {
			$this->logger->write( ' OK: ' . $this->tests_ok . ' Failed: ' . $this->tests_failed );
		}
		$this->tests_ok = 0;
		$this->tests_failed = 0;
	}

	public function statusMessage( $message ) {
		$this->logger->write( $message );
	}
}