Skip to content

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

@sebastianbergmann

Description

@sebastianbergmann

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

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions