Git Product home page Git Product logo

behat-code-coverage's Introduction

Taps mic🎀, is thing on?

Hello!

In my day job I help to make awesome applications that help to empower people and bring the world a little closer together. With my open source hat on, I create and/or maintain some libraries that I've needed that otherwise wouldn't exist 🦾 Check them out!

Tell me more

Sometimes in my career, I've looked for a library to complete what I imagined to be a fairly common task and to my surprise have found that one either doesn't exist or has been abandoned by its original author. This makes me sad, sometimes sad enough that I've decided to do something about it πŸ˜‡.

Those libraries have now recorded over 2,500,000 downloads so I'm fairly confident that there are people out there using them to do all sorts of wonderful things.

πŸ“¦BoxPacker Download count

An original creation because nothing else that I could find was suitable. When you try and get a pricing quote from a courier, you're asked for the width/length/depth of the box and it's weight. When you're working in e-commerce, weight is easy: you simply add up the individual weights of the all the stuff the customer ordered.

But the dimensions of the box(es)? That's....more complex.

🌍PHPCoord Download count

If you have a latitude/longitude from GPS and just want to plot it on Google Maps or OpenStreetMap you probably don't need this. But if you have grid co-ordinates from a national mapping system e.g. the UK's Ordnance Survey and need to convert them, or have recently had your mind blown by discovering that the GPS latitude/longitude of a spot does not always agree with what national mapping authorities think it is then you need a conversion library. This project already existed when I first needed to do co-ordinate conversion, but was written for an old version of PHP. I polished it up, fixed some bugs and added some features.

Since then, the project has been completely rewritten and now supports over 6000 different coordinate systems, up from just 10 in previous versions.

My most recent pick-up, this is actually a fork of an abandoned fork of a long-abandoned project making me something of a 3rd-generation maintainer. This Behat extension allows you to generate code coverage reports when running a Behat test suite, just like those you can get when running PHPUnit.

In 2020 I did substantial work enhancing the code coverage statistics reported by PHPUnit's code coverage component, to (optionally) produce branch and path coverage alongside the traditional line-based metrics. As part of that work, I also contributed performance enhancements that make coverage generation quicker even when not using the new metrics.

An in-depth writeup of the changes is available to read here.

behat-code-coverage's People

Contributors

andreybolonin avatar chartinger avatar dannylewis-sheffield avatar darkside666 avatar dependabot[bot] avatar dvdoug avatar ek9 avatar grob42 avatar ostrolucky avatar robocoder avatar stof avatar thewilkybarkid avatar yosrib avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

behat-code-coverage's Issues

Always get the same results

Hi,
first of all, very thanks for this package !

I am using Behat for testing a Symfony API Platform REST API that I developed. As of now I have 3 tests suites involving ~200 scenarios. Whatever the tests I am running I always get the same results which are:

Code Coverage Report:     
  2022-02-05 11:10:25     
                          
 Summary:                 
  Classes:  0.00% (0/8)   
  Methods: 27.27% (15/55) 
  Lines:   11.89% (27/227)

App\Doctrine\DocumentAnnexListener
  Methods:  50.00% ( 2/ 4)   Lines:  18.18% (  4/ 22)
App\Doctrine\DocumentReceivedListener
  Methods:  50.00% ( 2/ 4)   Lines:  12.00% (  3/ 25)
App\Doctrine\DocumentStatusListener
  Methods:  50.00% ( 2/ 4)   Lines:  11.43% (  4/ 35)
App\Doctrine\HashPasswordListener
  Methods:  40.00% ( 2/ 5)   Lines:  16.67% (  4/ 24)
App\Entity\User
  Methods:  14.29% ( 4/28)   Lines:  13.95% (  6/ 43)
App\Repository\ContactRepository
  Methods:  33.33% ( 1/ 3)   Lines:   6.45% (  2/ 31)
App\Repository\DocumentHistoryRepository
  Methods:  50.00% ( 1/ 2)   Lines:  18.18% (  2/ 11)
App\Repository\UserRepository
  Methods:  20.00% ( 1/ 5)   Lines:   5.56% (  2/ 36)

Any idea about this behaviour ?

Indeed I have more than 10 tested Doctrine 'entites' located in the App\Entity but the only one that is in the report is my User class that is used for login on the API ...

Has no coverage for application code

The application has one simple feature file:

Feature: Foo
  Szenario: Bar
    Given I am on the homepage

This succeeds and runs all the code in the file "src/index.php". But the following Behat configuration does not measure the application coverage:

    DVDoug\Behat\CodeCoverage\Extension:
      filter:
        include:
          directories:
            'src': ~
      reports:
        html:
          target: "tmp/behat/coverage"

It is missing the connection between Behat and the actual code that runs.
Is there a solution for that?

If not, then please consider adding a "bootstrap.php"-like file that could be included in the actual application. Such file could measure the actual coverage for each time the application is run during the test.

Possible to split branchAndPathCoverage

Hello πŸ‘‹

Thank you for this amazing library. I Started using it at work for GitLab coberturra coverage reports. Recently I noticed this Path coverage, and I thought I'd dig in a little more as even with high branch and line coverage, our Path coverage is quite low.

Big Picture, the coders on my team should stop writing long, winding methods. I'm with you; but I'm not sure how practical it is to say "You should have known and not been doing this in the past".

Just found the setting branchAndPathCoverage. I like Branch coverage, but would like to disable path coverage. In the worst case scenario I will turn off both branch and path coverage to see if it improves the coverage reports we generate; as other teams are using pcov, which isn't xdebug and so should not be generating path coverage anyhow. But will I lose branch coverage? Is there a possibility to have each of the two independently configurable?

Thanks for your time reading.

Optionally fail Behat run when coverage is below threshold

Hello πŸ‘‹,

First of all thank you very much for your hard work! I recently (re)started dabbling with Behat and was lucky enough to find this extension.

I would like to propose a feature request: optionally allow to fail tests below a certain threshold, similar to Infection with their --min-msi and --min-covered-msi options (see their docs).

Is this something worth considering? If so I think I can give it a shot as PR the feature.

Thank you for your time!

Give suggestion for Xdebug 'coverage' not on

Related: #1

Was debugging a bit as the throw error with message No code coverage driver is available is a bit non-descriptive when you've never thought about it ;)

Suggestion:

File: src/Driver/Selector.php
Line: 43

Change:

$driver = new Xdebug3Driver($filter);

to:

try {
    $driver = new Xdebug3Driver($filter);
} catch (Xdebug3NotEnabledException) {
    throw new NoCodeCoverageDriverAvailableException('Xdebug 3 was found enabled, but "mode" does not include "coverage", did you forget to enable this?');
}

Subsequent required update to NoCodeCoverageDriverAvailableException :

final class NoCodeCoverageDriverAvailableException extends RuntimeException implements Exception
{
    private const DEFAULT_MESSAGE = 'No code coverage driver available';

    public function __construct(string $message = null)
    {
        parent::__construct($message ?? self::DEFAULT_MESSAGE);
    }
}

Suggested changes would make finding why it's not working (initially) easier. (Admittedly: I did do a "doh, that makes sense" after I found it :p )

Suggested changes would also allow the same for other coverage drivers to have similar messages with minimal effort (try/catch blocks).


If you would like some help doing such changes, let me know and I'll see if I can spare some time outside of work.

Handle XDebug 3 configuration better

I've just found your package and fell in love immediately. But there's one more thing I'd like to see: on my local machine, I run Behat tests before commiting. Sometimes, I have to debug them using XDebug. With the extension enabled, this fails, as I usually don't run XDebug in coverage mode, and the driver throws an exception for this in https://github.com/sebastianbergmann/php-code-coverage/blob/0b4ce85a86040303d93beddf4f31f2ab07775e9a/src/Driver/Xdebug3Driver.php#L65.

You properly catch errors based on SebastianBergmann\CodeCoverage\NoCodeCoverageDriverAvailableException (when absolutely no driver is available), but I think you could extend the catch block with SebastianBergmann\CodeCoverage\Driver\Xdebug3NotEnabledException. This could help to always enable the extension and run whenever possible. In case of any error, display an information like "No code coverage driver is available" or "Code coverage driver not configured properly", but keep on running the testsuite

How to configure the extension when the test suite is in another directory ?

The project I'm working on has the following shape (I simplified it):

β”œβ”€β”€ projects
β”‚Β Β  β”œβ”€β”€ api
β”‚Β Β  β”œβ”€β”€ backend
β”‚Β Β  β”œβ”€β”€ cdn
β”‚Β Β  β”œβ”€β”€ common-lib
β”‚Β Β  β”œβ”€β”€ frontend
β”‚Β Β  └── worker
β”œβ”€β”€ tests
β”‚Β Β  β”œβ”€β”€ behat.yml
β”‚Β Β  β”œβ”€β”€ features

How can I tell this extension that the code is in ../projects/*/src ?


Note: I tried the following configuration, but the coverage is always 0% (but files are good)

        DVDoug\Behat\CodeCoverage\Extension:
            filter:
                include:
                    directories:
                        '../projects/*/src/': ~

Thanks

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.