Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PCOV #663

Closed
wants to merge 6 commits into from
Closed

PCOV #663

Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,40 @@ env:
matrix:
- DRIVER="xdebug" DEPENDENCIES="high"
- DRIVER="phpdbg" DEPENDENCIES="high"
- DRIVER="pcov" DEPENDENCIES="high"
- DRIVER="xdebug" DEPENDENCIES="low"
- DRIVER="phpdbg" DEPENDENCIES="low"
- DRIVER="pcov" DEPENDENCIES="low"
global:
- DEFAULT_COMPOSER_FLAGS="--no-interaction --no-ansi --no-progress --no-suggest"

before_install:
- composer config github-oauth.github.com ${GH_TOKEN}
krakjoe marked this conversation as resolved.
Show resolved Hide resolved
- composer self-update
- composer clear-cache
- export COMPOSER_ROOT_VERSION=6.1.99

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this one is still needed, because we still have a circular dep, phpunit depends php-code-coverage


install:
- if [[ "$DEPENDENCIES" = 'high' ]]; then travis_retry composer update $DEFAULT_COMPOSER_FLAGS; fi
- if [[ "$DEPENDENCIES" = 'low' ]]; then travis_retry composer update $DEFAULT_COMPOSER_FLAGS --prefer-lowest; fi

before_script:
- |
if [[ "$DRIVER" = 'pcov' ]]; then
echo > $HOME/.phpenv/versions/$TRAVIS_PHP_VERSION/etc/conf.d/xdebug.ini
git clone https://github.com/krakjoe/pcov
cd pcov
phpize
./configure
make clean install
echo "extension=pcov.so" > $HOME/.phpenv/versions/$TRAVIS_PHP_VERSION/etc/conf.d/pcov.ini
cd $TRAVIS_BUILD_DIR
fi

script:
- if [[ "$DRIVER" = 'phpdbg' ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi
- if [[ "$DRIVER" = 'xdebug' ]]; then vendor/bin/phpunit --coverage-clover=coverage.xml; fi
- if [[ "$DRIVER" = 'pcov' ]]; then vendor/bin/phpunit --coverage-clover=coverage.xml; fi

after_success:
- bash <(curl -s https://codecov.io/bash)
Expand Down
11 changes: 9 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
"optimize-autoloader": true,
"sort-packages": true
},
"repositories": {
krakjoe marked this conversation as resolved.
Show resolved Hide resolved
"environment": {
"type": "vcs",
"url": "https://github.com/krakjoe/environment"
}
},
"prefer-stable": true,
"require": {
"php": "^7.1",
Expand All @@ -32,7 +38,7 @@
"phpunit/php-token-stream": "^3.0.1",
"phpunit/php-text-template": "^1.2.1",
"sebastian/code-unit-reverse-lookup": "^1.0.1",
"sebastian/environment": "^4.0",
krakjoe marked this conversation as resolved.
Show resolved Hide resolved
"sebastian/environment": "dev-pcov as 4.0.1",
"sebastian/version": "^2.0.1",
"theseer/tokenizer": "^1.1"
},
Expand All @@ -57,5 +63,6 @@
"branch-alias": {
"dev-master": "6.1-dev"
}
}
},
"minimum-stability": "dev"
}
5 changes: 5 additions & 0 deletions src/CodeCoverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PHPUnit\Util\Test;
use SebastianBergmann\CodeCoverage\Driver\Driver;
use SebastianBergmann\CodeCoverage\Driver\PHPDBG;
use SebastianBergmann\CodeCoverage\Driver\PCOV;
use SebastianBergmann\CodeCoverage\Driver\Xdebug;
use SebastianBergmann\CodeCoverage\Node\Builder;
use SebastianBergmann\CodeCoverage\Node\Directory;
Expand Down Expand Up @@ -905,6 +906,10 @@ private function selectDriver(Filter $filter): Driver
return new Xdebug($filter);
}

if ($runtime->hasPCOV()) {
return new PCOV($filter);
}

throw new RuntimeException('No code coverage driver available');
}

Expand Down
58 changes: 58 additions & 0 deletions src/Driver/PCOV.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
/*
* This file is part of the php-code-coverage package.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\CodeCoverage\Driver;

use SebastianBergmann\CodeCoverage\RuntimeException;
use SebastianBergmann\CodeCoverage\Filter;

/**
* Driver for PCOV code coverage functionality.
*
* @codeCoverageIgnore
*/
final class PCOV implements Driver
{
/**
* @throws RuntimeException
krakjoe marked this conversation as resolved.
Show resolved Hide resolved
*/
public function __construct(Filter $filter = null)
{

}

/**
* Start collection of code coverage information.
*/
public function start(bool $determineUnusedAndDead = true): void
{
\pcov\start();
}

/**
* Stop collection of code coverage information.
*/
public function stop(): array
{
\pcov\stop();

$waiting = \pcov\waiting();
$collect = [];

if ($waiting) {
$collect = \pcov\collect(\pcov\inclusive, $waiting);

if ($collect) {
\pcov\clear();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the indentation is a bit off here, doesn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see it ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff --git a/src/CodeCoverage.php b/src/CodeCoverage.php
index 69b4bc0..62e28b4 100644
--- a/src/CodeCoverage.php
+++ b/src/CodeCoverage.php
@@ -13,8 +13,8 @@
 use PHPUnit\Runner\PhptTestCase;
 use PHPUnit\Util\Test;
 use SebastianBergmann\CodeCoverage\Driver\Driver;
-use SebastianBergmann\CodeCoverage\Driver\PHPDBG;
 use SebastianBergmann\CodeCoverage\Driver\PCOV;
+use SebastianBergmann\CodeCoverage\Driver\PHPDBG;
 use SebastianBergmann\CodeCoverage\Driver\Xdebug;
 use SebastianBergmann\CodeCoverage\Node\Builder;
 use SebastianBergmann\CodeCoverage\Node\Directory;
@@ -906,9 +906,9 @@ private function selectDriver(Filter $filter): Driver
             return new Xdebug($filter);
         }

-       if ($runtime->hasPCOV()) {
+        if ($runtime->hasPCOV()) {
             return new PCOV($filter);
-       }
+        }

         throw new RuntimeException('No code coverage driver available');
     }
diff --git a/src/Driver/PCOV.php b/src/Driver/PCOV.php
index 941650e..12f7643 100644
--- a/src/Driver/PCOV.php
+++ b/src/Driver/PCOV.php
@@ -9,7 +9,6 @@
  */
 namespace SebastianBergmann\CodeCoverage\Driver;

-use SebastianBergmann\CodeCoverage\RuntimeException;
 use SebastianBergmann\CodeCoverage\Filter;

 /**
@@ -21,7 +20,6 @@ final class PCOV implements Driver
 {
     public function __construct(Filter $filter = null)
     {
-
     }

     /**
@@ -37,19 +35,19 @@ public function start(bool $determineUnusedAndDead = true): void
      */
     public function stop(): array
     {
-       \pcov\stop();
+        \pcov\stop();

-       $waiting = \pcov\waiting();
-       $collect  = [];
+        $waiting  = \pcov\waiting();
+        $collect  = [];

-       if ($waiting) {
-               $collect = \pcov\collect(\pcov\inclusive, $waiting);
+        if ($waiting) {
+            $collect = \pcov\collect(\pcov\inclusive, $waiting);

-               if ($collect) {
-                       \pcov\clear();
-               }
-       }
+            if ($collect) {
+                \pcov\clear();
+            }
+        }

-       return $collect;
+        return $collect;
     }
 }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, sorry - I ran

$ composer global require friendsofphp/php-cs-fixer:^2.14.0

followed by

$ php-cs-fixer fix --diff --verbose

There were some unrelated fixes applied to a test case, which I have removed from the patch above.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is off for me too. I think it's caused by the mix of tabs and spaces. Same in CodeCoverage.php.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already fixed that locally in a branch where I am preparing this before merging.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks people, but I'm going to just let Sebastian fix this upon merge, since he has to make minor edits anyway, and I don't want to make any more noise.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly. Would make things easier for me if this PR would not be altered anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK

}

return $collect;
}
}
1 change: 1 addition & 0 deletions tests/tests/CodeCoverageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use SebastianBergmann\CodeCoverage\Driver\Driver;
use SebastianBergmann\CodeCoverage\Driver\PHPDBG;
use SebastianBergmann\CodeCoverage\Driver\PCOV;
use SebastianBergmann\CodeCoverage\Driver\Xdebug;
use SebastianBergmann\Environment\Runtime;

Expand Down