Git Product home page Git Product logo

behat-remote-code-coverage-extension's Introduction

Behat remote code coverage extension

This extension can be used to collect code coverage data from the web server that's called by Mink while running Behat.

To use this extension, enable it under extensions and for every suite that needs remote code coverage collection, set remote_coverage_enabled to true.

default:
    extensions:
        BehatRemoteCodeCoverage\RemoteCodeCoverageExtension:
            target_directory: '%paths.base%/var/coverage'
    suites:
        default:
            remote_coverage_enabled: true

Now modify the front controller of your web application to look like this:

use LiveCodeCoverage\RemoteCodeCoverage;

$shutDownCodeCoverage = RemoteCodeCoverage::bootstrap(
    (bool)getenv('CODE_COVERAGE_ENABLED'),
    sys_get_temp_dir(),
    __DIR__ . '/../phpunit.xml.dist'
);

// Run your web application now...

// This will save and store collected coverage data:
$shutDownCodeCoverage();

Make sure to modify the call to RemoteCodeCoverage::bootstrap() if needed:

  1. Provide your own logic to determine if code coverage should be enabled in the first place (this example uses an environment variable for that). This is important for security reasons. It helps you make sure that the production server won't expose any collected coverage data.
  2. Provide your own directory for storing the coverage data files (.cov).
  3. Provide the path to your own phpunit.xml(.dist) file. This file is only used for its code coverage filter configuration.

After a test run, the extension makes a special call (/?code_coverage_export=true&...) to the web application. The response to this call contains the serialized code coverage data. It will be stored as a file in target_directory, named after the test suite itself, e.g. default.cov.

You can use these .cov files to generate nice reports, using phpcov.

You could even configure PHPUnit to generate a .cov file in the same directory, so you can combine coverage data from PHPUnit and Behat in one report.

To (also) generate (local) code coverage during a Behat test run, use the LocalCodeCoverageExtension.

behat-remote-code-coverage-extension's People

Contributors

adrienbrault avatar ahocquard avatar exussum12 avatar magikid avatar matthiasnoback avatar webdevel avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.