PhpUnitWrapper_Generic.php
1.66 KB
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
<?php
/**
 * Generic PhpUnitWrapper.
 * Originally intended for use with Composer based installations, but will work
 * with any fully functional autoloader.
 */
class PhpUnitWrapper_Generic extends PhpUnitWrapper {
	/**
	 * Returns a version string, like 3.7.34 or 4.2-dev.
	 * @return string
	 */
	public function getVersion() {
		return PHPUnit_Runner_Version::id();
	}
	
	protected $coverage = null;
	protected static $test_name = 'SapphireTest';
	public static function get_test_name() {
		return static::$test_name;
	}
	
	/**
	 * Overwrites beforeRunTests. Initiates coverage-report generation if 
	 * $coverage has been set to true (@see setCoverageStatus).
	 */
	protected function beforeRunTests() {
		
		if($this->getCoverageStatus()) {			
			$this->coverage = new PHP_CodeCoverage();
			$coverage = $this->coverage;
			$filter = $coverage->filter();
			$modules = $this->moduleDirectories();
			foreach(TestRunner::config()->coverage_filter_dirs as $dir) {
				if($dir[0] == '*') {
					$dir = substr($dir, 1);
					foreach ($modules as $module) {
						$filter->addDirectoryToBlacklist(BASE_PATH . "/$module/$dir");
					}
				} else {
					$filter->addDirectoryToBlacklist(BASE_PATH . '/' . $dir);
				}
			}
			$filter->addFileToBlacklist(__FILE__, 'PHPUNIT');
			
			$coverage->start(self::get_test_name());
		}
	}
	/**
	 * Overwrites afterRunTests. Creates coverage report and clover report
	 * if required.
	 */
	protected function afterRunTests() {
		if($this->getCoverageStatus()) {
			$coverage = $this->coverage;
			$coverage->stop();
				
			$writer = new PHP_CodeCoverage_Report_HTML();
			$writer->process($coverage, ASSETS_PATH.'/code-coverage-report');
		}
	}
}