64% of 626OPs |
82% of 89Lines |
61% of 70Branches |
1% of 2469Paths |
| # | |
|---|---|
| 1 |
<?php |
| 2 |
|
| 3 |
namespace mageekguy\atoum\report\fields\runner\tests\coverage; |
| 4 |
|
| 5 |
use |
| 6 |
mageekguy\atoum, |
| 7 |
mageekguy\atoum\locale, |
| 8 |
mageekguy\atoum\cli\prompt, |
| 9 |
mageekguy\atoum\cli\colorizer, |
| 10 |
mageekguy\atoum\report |
| 11 |
; |
| 12 |
|
| 13 |
class cli extends report\fields\runner\tests\coverage |
| 14 |
{
|
| 15 |
protected $titlePrompt = null; |
| 16 |
protected $classPrompt = null; |
| 17 |
protected $methodPrompt = null; |
| 18 |
protected $titleColorizer = null; |
| 19 |
protected $coverageColorizer = null; |
| 20 |
|
| 21 |
public function __construct()100% |
| 22 |
{
|
| 23 |
parent::__construct(); |
| 24 |
|
| 25 |
$this |
| 26 |
->setTitlePrompt() |
| 27 |
->setClassPrompt() |
| 28 |
->setMethodPrompt() |
| 29 |
->setTitleColorizer() |
| 30 |
->setCoverageColorizer() |
| 31 |
; |
| 32 |
} |
| 33 |
|
| 34 |
public function __toString()76% |
| 35 |
{
|
| 36 |
$string = ''; |
| 37 |
|
| 38 |
if ($this->coverage !== null && sizeof($this->coverage) > 0) |
| 39 |
{
|
| 40 |
$string .= $this->titlePrompt . |
| 41 |
sprintf( |
| 42 |
$this->locale->_('%s: %s'),
|
| 43 |
$this->titleColorizer->colorize($this->locale->_('Code coverage value')),
|
| 44 |
$this->coverageColorizer->colorize(sprintf('%3.2f%%', $this->coverage->getValue() * 100.0))
|
| 45 |
) . |
| 46 |
PHP_EOL |
| 47 |
; |
| 48 |
|
| 49 |
if (sizeof($this->coverage->getPaths()) > 0) |
| 50 |
{
|
| 51 |
$string .= $this->titlePrompt . |
| 52 |
sprintf( |
| 53 |
$this->locale->_('%s: %s'),
|
| 54 |
$this->titleColorizer->colorize($this->locale->_('Path coverage value')),
|
| 55 |
$this->coverageColorizer->colorize(sprintf('%3.2f%%', $this->coverage->getPathsCoverageValue() * 100.0))
|
| 56 |
) . |
| 57 |
PHP_EOL |
| 58 |
; |
| 59 |
} |
| 60 |
|
| 61 |
if (sizeof($this->coverage->getBranches()) > 0) |
| 62 |
{
|
| 63 |
$string .= $this->titlePrompt . |
| 64 |
sprintf( |
| 65 |
$this->locale->_('%s: %s'),
|
| 66 |
$this->titleColorizer->colorize($this->locale->_('Branch coverage value')),
|
| 67 |
$this->coverageColorizer->colorize(sprintf('%3.2f%%', $this->coverage->getBranchesCoverageValue() * 100.0))
|
| 68 |
) . |
| 69 |
PHP_EOL |
| 70 |
; |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
foreach ($this->coverage->getMethods() as $class => $methods) |
| 75 |
{
|
| 76 |
$classCoverage = $this->coverage->getValueForClass($class); |
| 77 |
$classPathsCoverage = $this->coverage->getPathsCoverageValueForClass($class); |
| 78 |
$classBranchesCoverage = $this->coverage->getBranchesCoverageValueForClass($class); |
| 79 |
|
| 80 |
if ($classCoverage < 1.0) |
| 81 |
{
|
| 82 |
$string .= $this->classPrompt . |
| 83 |
sprintf( |
| 84 |
$this->locale->_('%s: %s%s%s'),
|
| 85 |
$this->titleColorizer->colorize(sprintf($this->locale->_('Class %s'), $class)),
|
| 86 |
$this->coverageColorizer->colorize(sprintf('%s%3.2f%%', ($classPathsCoverage !== null || $classBranchesCoverage !== null ? 'Line: ' : ''), $classCoverage * 100.0)),
|
| 87 |
$classPathsCoverage !== null ? $this->coverageColorizer->colorize(sprintf(' Path: %3.2f%%', $classPathsCoverage * 100.0)) : '',
|
| 88 |
$classBranchesCoverage !== null ? $this->coverageColorizer->colorize(sprintf(' Branch: %3.2f%%', $classBranchesCoverage * 100.0)) : ''
|
| 89 |
) . |
| 90 |
PHP_EOL |
| 91 |
; |
| 92 |
|
| 93 |
foreach (array_keys($methods) as $method) |
| 94 |
{
|
| 95 |
$methodCoverage = $this->coverage->getValueForMethod($class, $method); |
| 96 |
$methodPathsCoverage = $this->coverage->getPathsCoverageValueForMethod($class, $method); |
| 97 |
$methodBranchesCoverage = $this->coverage->getBranchesCoverageValueForMethod($class, $method); |
| 98 |
|
| 99 |
if ($methodCoverage < 1.0) |
| 100 |
{
|
| 101 |
$string .= $this->methodPrompt . |
| 102 |
sprintf( |
| 103 |
$this->locale->_('%s: %s%s%s'),
|
| 104 |
$this->titleColorizer->colorize(sprintf($this->locale->_('%s::%s()'), $class, $method)),
|
| 105 |
$this->coverageColorizer->colorize(sprintf('%s%3.2f%%', ($methodPathsCoverage !== null || $methodBranchesCoverage !== null ? 'Line: ' : ''), $methodCoverage * 100.0)),
|
| 106 |
$methodPathsCoverage !== null ? $this->coverageColorizer->colorize(sprintf(', Path: %3.2f%%', $methodPathsCoverage * 100.0)) : '',
|
| 107 |
$methodBranchesCoverage !== null ? $this->coverageColorizer->colorize(sprintf(', Branch: %3.2f%%', $methodBranchesCoverage * 100.0)) : ''
|
| 108 |
) . |
| 109 |
PHP_EOL |
| 110 |
; |
| 111 |
} |
| 112 |
} |
| 113 |
} |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
return $string; |
| 118 |
} |
| 119 |
|
| 120 |
public function setTitlePrompt(prompt $prompt = null)100% |
| 121 |
{
|
| 122 |
$this->titlePrompt = $prompt ?: new prompt(); |
| 123 |
|
| 124 |
return $this; |
| 125 |
} |
| 126 |
|
| 127 |
public function getTitlePrompt()100% |
| 128 |
{
|
| 129 |
return $this->titlePrompt; |
| 130 |
} |
| 131 |
|
| 132 |
public function setClassPrompt(prompt $prompt = null)100% |
| 133 |
{
|
| 134 |
$this->classPrompt = $prompt ?: new prompt(); |
| 135 |
|
| 136 |
return $this; |
| 137 |
} |
| 138 |
|
| 139 |
public function getClassPrompt()100% |
| 140 |
{
|
| 141 |
return $this->classPrompt; |
| 142 |
} |
| 143 |
|
| 144 |
public function setMethodPrompt(prompt $prompt = null)100% |
| 145 |
{
|
| 146 |
$this->methodPrompt = $prompt ?: new prompt(); |
| 147 |
|
| 148 |
return $this; |
| 149 |
} |
| 150 |
|
| 151 |
public function getMethodPrompt()100% |
| 152 |
{
|
| 153 |
return $this->methodPrompt; |
| 154 |
} |
| 155 |
|
| 156 |
public function setTitleColorizer(colorizer $colorizer = null)100% |
| 157 |
{
|
| 158 |
$this->titleColorizer = $colorizer ?: new colorizer(); |
| 159 |
|
| 160 |
return $this; |
| 161 |
} |
| 162 |
|
| 163 |
public function getTitleColorizer()100% |
| 164 |
{
|
| 165 |
return $this->titleColorizer; |
| 166 |
} |
| 167 |
|
| 168 |
public function setCoverageColorizer(colorizer $colorizer = null)100% |
| 169 |
{
|
| 170 |
$this->coverageColorizer = $colorizer ?: new colorizer(); |
| 171 |
|
| 172 |
return $this; |
| 173 |
} |
| 174 |
|
| 175 |
public function getCoverageColorizer()100% |
| 176 |
{
|
| 177 |
return $this->coverageColorizer; |
| 178 |
} |
| 179 |
} |