Skip to content

Commit 421e472

Browse files
Merge branch 'master' into refactoring/preparation-for-branch-path-opcode-coverage
2 parents 34ac5ed + a995604 commit 421e472

File tree

9 files changed

+166
-9
lines changed

9 files changed

+166
-9
lines changed

src/CodeCoverage.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,15 @@ public function filter()
190190

191191
/**
192192
* Returns the collected code coverage data.
193+
* Set $raw = true to bypass all filters.
193194
*
195+
* @param bool $raw
194196
* @return array
195197
* @since Method available since Release 1.1.0
196198
*/
197-
public function getData()
199+
public function getData($raw = false)
198200
{
199-
if ($this->addUncoveredFilesFromWhitelist) {
201+
if (!$raw && $this->addUncoveredFilesFromWhitelist) {
200202
$this->addUncoveredFilesFromWhitelist();
201203
}
202204

src/CodeCoverage/Filter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ public function isFile($filename)
242242
*/
243243
public function isFiltered($filename)
244244
{
245+
if (!$this->isFile($filename)) {
246+
return true;
247+
}
248+
245249
$filename = realpath($filename);
246250

247251
if (!empty($this->whitelistedFiles)) {

src/CodeCoverage/Report/Factory.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,28 @@ private function reducePaths(&$files)
277277

278278
ksort($files);
279279

280-
return substr($commonPath, 0, -1);
280+
return $this->removeTailingDirectorySeparator($commonPath);
281+
}
282+
283+
/**
284+
* @param $commonPath
285+
* @return bool
286+
*/
287+
private function isNotRoot($commonPath)
288+
{
289+
return strlen($commonPath) > 1;
290+
}
291+
292+
/**
293+
* @param $commonPath
294+
* @return string
295+
*/
296+
private function removeTailingDirectorySeparator($commonPath)
297+
{
298+
if ($this->isNotRoot($commonPath)) {
299+
$commonPath = substr($commonPath, 0, -1);
300+
return $commonPath;
301+
}
302+
return $commonPath;
281303
}
282304
}

src/CodeCoverage/Report/HTML/Renderer/Dashboard.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ public function render(PHP_CodeCoverage_Report_Node_Directory $node, $file)
8383
'complexity_class' => $complexity['class'],
8484
'complexity_method' => $complexity['method'],
8585
'class_coverage_distribution' => $coverageDistribution['class'],
86-
'method_coverage_distribution' => $coverageDistribution['method'],
87-
'backlink' => basename(str_replace('.dashboard', '', $file))
86+
'method_coverage_distribution' => $coverageDistribution['method']
8887
)
8988
);
9089

@@ -325,9 +324,8 @@ protected function projectRisks(array $classes)
325324
protected function getActiveBreadcrumb(PHP_CodeCoverage_Report_Node $node)
326325
{
327326
return sprintf(
328-
' <li><a href="%s.html">%s</a></li>' . "\n" .
327+
' <li><a href="index.html">%s</a></li>' . "\n" .
329328
' <li class="active">(Dashboard)</li>' . "\n",
330-
$node->getId(),
331329
$node->getName()
332330
);
333331
}

src/CodeCoverage/Report/Node.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ abstract class PHP_CodeCoverage_Report_Node implements Countable
8989
*/
9090
public function __construct($name, PHP_CodeCoverage_Report_Node $parent = null)
9191
{
92-
if (substr($name, -1) == '/') {
92+
if ($this->hasTailingSlashAndIsNotRoot($name)) {
9393
$name = substr($name, 0, -1);
9494
}
9595

@@ -377,4 +377,13 @@ abstract public function getNumFunctions();
377377
* @return integer
378378
*/
379379
abstract public function getNumTestedFunctions();
380+
381+
/**
382+
* @param $name
383+
* @return bool
384+
*/
385+
private function hasTailingSlashAndIsNotRoot($name)
386+
{
387+
return substr($name, -1) == '/' && strlen($name) > 1;
388+
}
380389
}

src/CodeCoverage/Report/PHP.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function process(PHP_CodeCoverage $coverage, $target = null)
7777
$filter->setWhitelistedFiles(%s);
7878
7979
return $coverage;',
80-
var_export($coverage->getData(), 1),
80+
var_export($coverage->getData(true), 1),
8181
var_export($coverage->getTests(), 1),
8282
var_export($filter->getBlacklistedFiles(), 1),
8383
var_export($filter->getWhitelistedFiles(), 1)

tests/PHP/CodeCoverage/FilterTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,4 +300,17 @@ public function testNotWhitelistedFileIsFiltered()
300300
$this->filter->addFileToWhitelist($this->files[0]);
301301
$this->asserttrue($this->filter->isFiltered($this->files[1]));
302302
}
303+
304+
/**
305+
* @covers PHP_CodeCoverage_Filter::isFiltered
306+
* @covers PHP_CodeCoverage_Filter::isFile
307+
*/
308+
public function testNonFilesAreFiltered()
309+
{
310+
$this->assertTrue($this->filter->isFiltered('eval()\'d code'));
311+
$this->assertTrue($this->filter->isFiltered('runtime-created function'));
312+
$this->assertTrue($this->filter->isFiltered('assert code'));
313+
$this->assertTrue($this->filter->isFiltered('regexp code'));
314+
$this->assertFalse($this->filter->isFiltered('filename'));
315+
}
303316
}

tests/PHP/CodeCoverage/Report/FactoryTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,17 @@ public function reducePathsProvider()
231231
'/home/sb/Money/MoneyBag.php' => array()
232232
)
233233
),
234+
array(
235+
array(
236+
'driveA/Money.php' => array(),
237+
'driveB/MoneyBag.php' => array()
238+
),
239+
'/',
240+
array(
241+
'/driveA/Money.php' => array(),
242+
'/driveB/MoneyBag.php' => array()
243+
)
244+
),
234245
array(
235246
array(
236247
'Money.php' => array()
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
/**
3+
* PHP_CodeCoverage
4+
*
5+
* Copyright (c) 2009-2014, Sebastian Bergmann <[email protected]>.
6+
* All rights reserved.
7+
*
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions
10+
* are met:
11+
*
12+
* * Redistributions of source code must retain the above copyright
13+
* notice, this list of conditions and the following disclaimer.
14+
*
15+
* * Redistributions in binary form must reproduce the above copyright
16+
* notice, this list of conditions and the following disclaimer in
17+
* the documentation and/or other materials provided with the
18+
* distribution.
19+
*
20+
* * Neither the name of Sebastian Bergmann nor the names of his
21+
* contributors may be used to endorse or promote products derived
22+
* from this software without specific prior written permission.
23+
*
24+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34+
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35+
* POSSIBILITY OF SUCH DAMAGE.
36+
*
37+
* @category PHP
38+
* @package CodeCoverage
39+
* @subpackage Tests
40+
* @author Sebastian Bergmann <[email protected]>
41+
* @copyright 2009-2014 Sebastian Bergmann <[email protected]>
42+
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
43+
* @link http://github.com/sebastianbergmann/php-code-coverage
44+
*/
45+
46+
/**
47+
* Tests for the PHP_CodeCoverage_Report_Node class.
48+
*
49+
* @category PHP
50+
* @package CodeCoverage
51+
* @subpackage Tests
52+
* @author Sebastian Bergmann <[email protected]>
53+
* @copyright 2009-2014 Sebastian Bergmann <[email protected]>
54+
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
55+
* @link http://github.com/sebastianbergmann/php-code-coverage
56+
*/
57+
class PHP_CodeCoverage_Report_NodeTest extends PHPUnit_Framework_TestCase
58+
{
59+
public function testTrimsTailingSlashes()
60+
{
61+
$node = $this->getInstance('/SomeName.php/');
62+
$this->assertEquals('/SomeName.php', $node->getPath());
63+
}
64+
65+
public function testNodeAcceptsRootScope()
66+
{
67+
$node = $this->getInstance('/');
68+
$this->assertEquals('/', $node->getPath());
69+
}
70+
71+
/**
72+
* @param $path
73+
* @return PHP_CodeCoverage_Report_Node
74+
*/
75+
private function getInstance($path)
76+
{
77+
$builder = $this->getMockBuilder('PHP_CodeCoverage_Report_Node')
78+
->setConstructorArgs(array($path));
79+
80+
$this->mockMethods($builder);
81+
return $builder->getMock();
82+
}
83+
84+
/**
85+
* @param $builder
86+
*/
87+
private function mockMethods($builder)
88+
{
89+
$reflectionClass = new \ReflectionClass('PHP_CodeCoverage_Report_Node');
90+
$methods = array();
91+
foreach ($reflectionClass->getMethods() as $method) {
92+
if ($method->isAbstract()) {
93+
$methods[] = $method->getName();
94+
}
95+
}
96+
$builder->setMethods($methods);
97+
}
98+
}

0 commit comments

Comments
 (0)