Skip to content

Argument $linesToBeIgnored of CodeCoverage::stop() has no effect for files that are not executed at all #994

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

Closed
sebastianbergmann opened this issue Apr 17, 2023 · 0 comments
Assignees
Labels

Comments

@sebastianbergmann
Copy link
Owner

sebastianbergmann commented Apr 17, 2023

src/A.php

<?php declare(strict_types=1);
final class A
{
    public function doSomething(): bool
    {
        return true;
    }
}

src/B.php

<?php declare(strict_types=1);
final class B
{
    public function doSomething(): bool
    {
        return true;
    }
}

test.php

<?php declare(strict_types=1);
use SebastianBergmann\CodeCoverage\Filter;
use SebastianBergmann\CodeCoverage\Driver\Selector;
use SebastianBergmann\CodeCoverage\CodeCoverage;
use SebastianBergmann\CodeCoverage\Report\Html\Facade as HtmlReport;

require __DIR__ . '/vendor/autoload.php';

$filter = new Filter;
$filter->includeFiles(
    [
        __DIR__ . '/src/A.php',
        __DIR__ . '/src/B.php',
    ]
);

$coverage = new CodeCoverage(
    (new Selector)->forLineCoverage($filter),
    $filter
);

$coverage->start('test');

$a = new A;
$a->doSomething();

#$b = new B;
#$b->doSomething();

$coverage->stop(
    linesToBeIgnored: [
        __DIR__ . '/src/B.php' => range(1, 8)
    ]
);

(new HtmlReport)->process($coverage, '/tmp/code-coverage');

HTML Code Coverage Report

grafik

When

#$b = new B;
#$b->doSomething();

is changed to

$b = new B;
$b->doSomething();

then the lines of code that make up class B are ignored as requested:

grafik

@sebastianbergmann sebastianbergmann self-assigned this Apr 17, 2023
@sebastianbergmann sebastianbergmann changed the title Argument $linesToBeIgnored of CodeCoverage::stop() does not have an effect for files that are not executed at all Argument $linesToBeIgnored of CodeCoverage::stop() has no effect for files that are not executed at all Apr 17, 2023
sebastianbergmann added a commit that referenced this issue Apr 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant