Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * $Id: PHPUnitTestRunner.php 361 2008-03-08 09:36:07Z mrook $
4
 *
5
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16
 *
17
 * This software consists of voluntary contributions made by many individuals
18
 * and is licensed under the LGPL. For more information please see
19
 * <http://phing.info>.
20
 */
21
 
22
require_once 'phing/tasks/ext/coverage/CoverageMerger.php';
23
 
24
require_once 'phing/system/util/Timer.php';
25
 
26
/**
27
 * Simple Testrunner for PHPUnit2/3 that runs all tests of a testsuite.
28
 *
29
 * @author Michiel Rook <michiel.rook@gmail.com>
30
 * @version $Id: PHPUnitTestRunner.php 361 2008-03-08 09:36:07Z mrook $
31
 * @package phing.tasks.ext.phpunit
32
 * @since 2.1.0
33
 */
34
class PHPUnitTestRunner
35
{
36
	const SUCCESS = 0;
37
	const FAILURES = 1;
38
	const ERRORS = 2;
39
	const INCOMPLETES = 3;
40
	const SKIPPED = 4;
41
 
42
	private $test = NULL;
43
	private $suite = NULL;
44
	private $retCode = 0;
45
	private $formatters = array();
46
 
47
	private $codecoverage = false;
48
 
49
	private $project = NULL;
50
 
51
	private $groups = array();
52
	private $excludeGroups = array();
53
 
54
	function __construct($suite, Project $project, $groups = array(), $excludeGroups = array())
55
	{
56
		$this->suite = $suite;
57
		$this->project = $project;
58
		$this->groups = $groups;
59
		$this->excludeGroups = $excludeGroups;
60
		$this->retCode = self::SUCCESS;
61
	}
62
 
63
	function setCodecoverage($codecoverage)
64
	{
65
		$this->codecoverage = $codecoverage;
66
	}
67
 
68
	function addFormatter($formatter)
69
	{
70
		$this->formatters[] = $formatter;
71
	}
72
 
73
	function run()
74
	{
75
		$res = NULL;
76
 
77
		if (PHPUnitUtil::$installedVersion == 3)
78
		{
79
			require_once 'PHPUnit/Framework/TestSuite.php';
80
			$res = new PHPUnit_Framework_TestResult();
81
		}
82
		else
83
		{
84
			require_once 'PHPUnit2/Framework/TestSuite.php';
85
			$res = new PHPUnit2_Framework_TestResult();
86
		}
87
 
88
		if ($this->codecoverage)
89
		{
90
			$res->collectCodeCoverageInformation(TRUE);
91
		}
92
 
93
		foreach ($this->formatters as $formatter)
94
		{
95
			$res->addListener($formatter);
96
		}
97
 
98
		$this->suite->run($res, false, $this->groups, $this->excludeGroups);
99
 
100
		if ($this->codecoverage)
101
		{
102
			$coverageInformation = $res->getCodeCoverageInformation();
103
 
104
			if (PHPUnitUtil::$installedVersion == 3)
105
			{
106
				foreach ($coverageInformation as $coverage_info)
107
				{
108
					CoverageMerger::merge($this->project, array($coverage_info['files']));
109
				}
110
			}
111
			else
112
			{
113
				CoverageMerger::merge($this->project, $coverageInformation);
114
			}
115
		}
116
 
117
		if ($res->errorCount() != 0)
118
		{
119
			$this->retCode = self::ERRORS;
120
		}
121
		else if ($res->failureCount() != 0)
122
		{
123
			$this->retCode = self::FAILURES;
124
		}
125
		else if ($res->notImplementedCount() != 0)
126
		{
127
			$this->retCode = self::INCOMPLETES;
128
		}
129
		else if (PHPUnitUtil::$installedVersion == 3 && $res->skippedCount() != 0)
130
		{
131
			$this->retCode = self::SKIPPED;
132
		}
133
	}
134
 
135
	function getRetCode()
136
	{
137
		return $this->retCode;
138
	}
139
}
140