Skip to content

Commit 038a418

Browse files
committed
CodeCoverage driver for PCOV
1 parent afe4b8a commit 038a418

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ env:
1717
matrix:
1818
- DRIVER="xdebug" DEPENDENCIES="high"
1919
- DRIVER="phpdbg" DEPENDENCIES="high"
20+
- DRIVER="pcov" DEPENDENCIES="high"
2021
- DRIVER="xdebug" DEPENDENCIES="low"
2122
- DRIVER="phpdbg" DEPENDENCIES="low"
23+
- DRIVER="pcov" DEPENDENCIES="low"
2224
global:
2325
- DEFAULT_COMPOSER_FLAGS="--no-interaction --no-ansi --no-progress --no-suggest"
2426

@@ -30,9 +32,14 @@ install:
3032
- if [[ "$DEPENDENCIES" = 'high' ]]; then travis_retry composer update $DEFAULT_COMPOSER_FLAGS; fi
3133
- if [[ "$DEPENDENCIES" = 'low' ]]; then travis_retry composer update $DEFAULT_COMPOSER_FLAGS --prefer-lowest; fi
3234

35+
before_script:
36+
- if [[ "$DRIVER" = 'pcov' ]]; then pecl install channel://pecl.php.net/pcov-0.9.0; fi
37+
- if [[ "$DRIVER" = 'pcov' ]]; then echo > $HOME/.phpenv/versions/$TRAVIS_PHP_VERSION/etc/conf.d/xdebug.ini; fi
38+
3339
script:
3440
- if [[ "$DRIVER" = 'phpdbg' ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi
3541
- if [[ "$DRIVER" = 'xdebug' ]]; then vendor/bin/phpunit --coverage-clover=coverage.xml; fi
42+
- if [[ "$DRIVER" = 'pcov' ]]; then vendor/bin/phpunit --coverage-clover=coverage.xml; fi
3643

3744
after_success:
3845
- bash <(curl -s https://codecov.io/bash)

src/CodeCoverage.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Util\Test;
1515
use SebastianBergmann\CodeCoverage\Driver\Driver;
1616
use SebastianBergmann\CodeCoverage\Driver\PHPDBG;
17+
use SebastianBergmann\CodeCoverage\Driver\PCOV;
1718
use SebastianBergmann\CodeCoverage\Driver\Xdebug;
1819
use SebastianBergmann\CodeCoverage\Node\Builder;
1920
use SebastianBergmann\CodeCoverage\Node\Directory;
@@ -905,6 +906,10 @@ private function selectDriver(Filter $filter): Driver
905906
return new Xdebug($filter);
906907
}
907908

909+
if ($runtime->hasPCOV()) {
910+
return new PCOV($filter);
911+
}
912+
908913
throw new RuntimeException('No code coverage driver available');
909914
}
910915

src/Driver/PCOV.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/*
3+
* This file is part of the php-code-coverage package.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace SebastianBergmann\CodeCoverage\Driver;
11+
12+
use SebastianBergmann\CodeCoverage\RuntimeException;
13+
use SebastianBergmann\CodeCoverage\Filter;
14+
15+
/**
16+
* Driver for PCOV code coverage functionality.
17+
*
18+
* @codeCoverageIgnore
19+
*/
20+
final class PCOV implements Driver
21+
{
22+
/**
23+
* @throws RuntimeException
24+
*/
25+
public function __construct(Filter $filter = null)
26+
{
27+
28+
}
29+
30+
/**
31+
* Start collection of code coverage information.
32+
*/
33+
public function start(bool $determineUnusedAndDead = true): void
34+
{
35+
\pcov\start();
36+
}
37+
38+
/**
39+
* Stop collection of code coverage information.
40+
*/
41+
public function stop(): array
42+
{
43+
static $collected = [];
44+
45+
\pcov\stop();
46+
47+
$includes = \pcov\includes();
48+
$collect = [];
49+
50+
if ($collected == []) {
51+
$collect = \pcov\collect(
52+
\pcov\inclusive, $includes);
53+
} else {
54+
if ($includes) {
55+
$collect = \pcov\collect(
56+
\pcov\inclusive,
57+
\array_merge($collected, $includes));
58+
}
59+
}
60+
61+
if ($collect != []) {
62+
$collected = \array_keys($collect);
63+
64+
\pcov\clear();
65+
}
66+
67+
return $collect;
68+
}
69+
}

tests/tests/CodeCoverageTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use SebastianBergmann\CodeCoverage\Driver\Driver;
1313
use SebastianBergmann\CodeCoverage\Driver\PHPDBG;
14+
use SebastianBergmann\CodeCoverage\Driver\PCOV;
1415
use SebastianBergmann\CodeCoverage\Driver\Xdebug;
1516
use SebastianBergmann\Environment\Runtime;
1617

0 commit comments

Comments
 (0)