mageekguy\atoum\scripts\coverage: lines coverage

25% of 318

OPs

36% of 61

Lines

11% of 28

Branches

24% of 17

Paths
Method OPs OPs % Lines Line % Branches Branches % Paths Path %
mageekguy\atoum\scripts\coverage::__construct() 18 100% 3 100% 1 0% 1 100%
mageekguy\atoum\scripts\coverage::doRun() 209 0% 25 0% 19 0% 10 0%
mageekguy\atoum\scripts\coverage::setReportFormat() 13 100% 2 100% 1 100% 1 100%
mageekguy\atoum\scripts\coverage::getReportFormat() 6 100% 1 100% 1 100% 1 100%
mageekguy\atoum\scripts\coverage::setReportOutputPath() 9 0% 2 0% 1 0% 1 0%
mageekguy\atoum\scripts\coverage::reportOutputPathIsSet() 19 0% 4 0% 4 0% 2 0%
mageekguy\atoum\scripts\coverage::setArgumentHandlers() 44 100% 24 67% 1 100% 1 100%
#
1
<?php
2

                    
3
namespace mageekguy\atoum\scripts;
4

                    
5
require_once __DIR__ . '/../../constants.php';
6

                    
7
use
8
	mageekguy\atoum,
9
	mageekguy\atoum\cli,
10
	mageekguy\atoum\php,
11
	mageekguy\atoum\writers,
12
	mageekguy\atoum\exceptions
13
;
14

                    
15
class coverage extends runner
16
{
17
	const defaultReportFormat = 'xml';
18

                    
19
	protected $reportOutputPath;
20
	protected $reportFormat;
21

                    
22
	public function __construct($name, atoum\adapter $adapter = null)100%
23
	{
24
		parent::__construct($name, $adapter);
25

                    
26
		$this->setReportFormat();
27
	}
28

                    
29
	protected function doRun()0%
30
	{
31
		if (sizeof($this->getReports()) === 0)
32
		{
33
			$this->addDefaultReport();
34
		}
35

                    
36
		switch ($this->reportFormat)
37
		{
38
			case 'xml':
39
			case 'clover':
40
				$writer = new atoum\writers\file($this->reportOutputPathIsSet()->reportOutputPath);
41
				$report = new atoum\reports\asynchronous\clover();
42
				$this->addReport($report->addWriter($writer));
43
				break;
44

                    
45
			case 'html':
46
				$field = new atoum\report\fields\runner\coverage\html('Code coverage', $this->reportOutputPathIsSet()->reportOutputPath);
47
				$field->setRootUrl('file://' . realpath(rtrim($this->reportOutputPathIsSet()->reportOutputPath, DIRECTORY_SEPARATOR)) . '/index.html');
48
				current($this->getReports())->addField($field);
49
				break;
50

                    
51
			case 'treemap':
52
				$field = new atoum\report\fields\runner\coverage\treemap('Code coverage treemap', $this->reportOutputPathIsSet()->reportOutputPath);
53
				$field->setTreemapUrl('file://' . realpath(rtrim($this->reportOutputPathIsSet()->reportOutputPath, DIRECTORY_SEPARATOR)) . '/index.html');
54
				current($this->getReports())->addField($field);
55
				break;
56

                    
57
			default:
58
				throw new exceptions\logic\invalidArgument('Invalid format for coverage report');
59
		}
60

                    
61
		return parent::doRun();
62
	}
63

                    
64
	public function setReportFormat($format = null)100%
65
	{
66
		$this->reportFormat = $format ?: self::defaultReportFormat;
67

                    
68
		return $this;
69
	}
70

                    
71
	public function getReportFormat()100%
72
	{
73
		return $this->reportFormat;
74
	}
75

                    
76
	public function setReportOutputPath($path)0%
77
	{
78
		$this->reportOutputPath = $path;
79

                    
80
		return $this;
81
	}
82

                    
83
	protected function reportOutputPathIsSet()0%
84
	{
85
		if ($this->reportOutputPath === null)
86
		{
87
			throw new exceptions\runtime('Coverage report output path is not set');
88
		}
89

                    
90
		return $this;
91
	}
92

                    
93
	protected function setArgumentHandlers()67%
94
	{
95
		return parent::setArgumentHandlers()
96
			->addArgumentHandler(
97
					function($script, $argument, $values) {
98
						if (sizeof($values) === 0)
99
						{
100
							throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
101
						}
102

                    
103
						$script->setReportFormat(current($values));
104
					},
105
					array('-fmt', '--format'),
106
					'<xml|clover|html|treemap>',
107
					$this->locale->_('Coverage report format')
108
				)
109
			->addArgumentHandler(
110
					function($script, $argument, $values) {
111
						if (sizeof($values) === 0)
112
						{
113
							throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
114
						}
115

                    
116
						$script->setReportOutputPath(current($values));
117
					},
118
					array('-o', '--output'),
119
					'<path/to/file/or/directory>',
120
					$this->locale->_('Coverage report output path')
121
				)
122
		;
123
	}
124
}