peridot-php / leo

Next level assertion and matcher library for PHP
http://peridot-php.github.io/leo/
MIT License
35 stars 7 forks source link

[question]peridot-php code coverage #5

Closed gong023 closed 9 years ago

gong023 commented 9 years ago

Hi all, Thank you for your creating all peridot-php libraries. The libraries are brilliant.

I have a question. I want to get test coverage in my src directory.

First I added peridot libraries below

    "require-dev": {
        "mockery/mockery": "0.9.*",
        "fabpot/php-cs-fixer": "1.*",
        "peridot-php/peridot": "1.9.0",
        "peridot-php/leo": "1.2.0",
        "peridot-php/peridot-prophecy-plugin": "~1.0",
        "peridot-php/peridot-code-coverage-reporters": "1.0.2",
        "satooshi/php-coveralls": "~0.6"
    },

created peridot.php below.

<?php

use Evenement\EventEmitterInterface;
use Peridot\Reporter\CodeCoverage\AbstractCodeCoverageReporter;
use Peridot\Reporter\CodeCoverageReporters;

/**
 * Configure peridot.
 *
 * @param EventEmitterInterface $eventEmitter
 */
return function (EventEmitterInterface $eventEmitter) {
    (new CodeCoverageReporters($eventEmitter))->register();

    $eventEmitter->on('peridot.start', function (\Peridot\Console\Environment $environment) {
        $environment->getDefinition()->getArgument('path')->setDefault('spec');
    });

    $eventEmitter->on('code-coverage.start', function (AbstractCodeCoverageReporter $reporter) {
        $reporter->addDirectoryToWhitelist(__DIR__ . '/src')->addDirectoryToWhitelist(__DIR__ . '/spec');
    });
};

and run peridot

./vendor/bin/peridot spec/ -r clover-code-coverage --code-coverage-path "build/logs/clover.xml"

But I got exception below.

[PHP_CodeCoverage_Exception]
No code coverage driver available
peridot [options] [files]

It may be thrown at phpunit/php-code-coverage/src/CodeCoverage.php:142.

I tried to

git clone git@github.com:peridot-php/leo.git
composer install
./vendor/bin/peridot specs/ # it passes
./vendor/bin/peridot specs/ -r clover-code-coverage --code-coverage-path "build/logs/clover.xml"

But I got same exception about PHP_CodeCoverage_Exception.

Do you have any advices to get test coverage?

brianium commented 9 years ago

@gong023 thank you for your kind words. PHP_CodeCoverage leverages the xdebug extension internally. It looks like it also has support for the HHVM debugger, but I am not sure how well supported that is.

I think your problem will be solved if you install and enable the xdebug extension for your version of PHP.

gong023 commented 9 years ago

I was able to solve this problem by installing xdebug extension. Thank you!

brianium commented 9 years ago

@gong023 glad I could help!