summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/ExecutionTimeTestListener.php
blob: 6d541b28fd2445c0e1b1335dfcb4f23a37eb0b9d (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php

namespace SMW\Tests;

use Exception;
use PHPUnit_Framework_AssertionFailedError;
use PHPUnit_Framework_Test;
use PHPUnit_Framework_TestListener;
use PHPUnit_Framework_TestSuite;
use PHPUnit_Framework_Warning;

class ExecutionTimeTestListener implements PHPUnit_Framework_TestListener {

	protected $testCollector = [];
	protected $executionTimeThresholdInSeconds = 10;
	protected $isEnabledToListen = true;

	public function __construct( $isEnabledToListen, $executionTimeThresholdInSeconds ) {
		$this->isEnabledToListen = $isEnabledToListen;
		$this->executionTimeThresholdInSeconds = $executionTimeThresholdInSeconds;
	}

	/**
	 * @see PHPUnit_Framework_TestListener::startTest
	 */
	public function startTest( PHPUnit_Framework_Test $test ) {
	}

	/**
	 * @see PHPUnit_Framework_TestListener::endTest
	 */
	public function endTest( PHPUnit_Framework_Test $test, $length ) {
		if ( $this->isEnabledToListen && ( $length > $this->executionTimeThresholdInSeconds ) ) {
			$this->testCollector[$test->getName()] = round( $length, 3 );
		}
	}

	/**
	 * @see PHPUnit_Framework_TestListener::addError
	 */
	public function addError( PHPUnit_Framework_Test $test, Exception $e, $time ) {
	}

	/**
	 * @see PHPUnit_Framework_TestListener::addError
	 */
	public function addWarning( PHPUnit_Framework_Test $test, PHPUnit_Framework_Warning $e, $time) {

	}

	/**
	 * @see PHPUnit_Framework_TestListener::addFailure
	 */
	public function addFailure( PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time ) {
	}

	/**
	 * @see PHPUnit_Framework_TestListener::addError
	 */
	public function addIncompleteTest( PHPUnit_Framework_Test $test, Exception $e, $time ) {
	}

	/**
	 * @see PHPUnit_Framework_TestListener::addRiskyTest
	 * @since 4.0.0
	 */
	public function addRiskyTest( PHPUnit_Framework_Test $test, Exception $e, $time ) {
	}

	/**
	 * @see PHPUnit_Framework_TestListener::addSkippedTest
	 */
	public function addSkippedTest( PHPUnit_Framework_Test $test, Exception $e, $time ) {
	}

	/**
	 * @see PHPUnit_Framework_TestListener::startTestSuite
	 */
	public function startTestSuite( PHPUnit_Framework_TestSuite $suite ) {
	}

	/**
	 * @see PHPUnit_Framework_TestListener::endTestSuite
	 */
	public function endTestSuite( PHPUnit_Framework_TestSuite $suite ) {
		foreach ( $this->testCollector as $name => $length ) {
			print ( "\n" . $suite->getName() . " {$name} ran for {$length} seconds" . "\n" );
			unset( $this->testCollector[$name] );
		}
	}

}