Skip to content
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

fixed issue that happens when modifying only lines not covered by code-coverage #123

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/PatchCoverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function execute(string $coverageFile, string $patchFile, string $pathPre
$result = [
'numChangedLinesThatAreExecutable' => 0,
'numChangedLinesThatWereExecuted' => 0,
'numChangedLinesNotCovered' => 0,
'changedLinesThatWereNotExecuted' => [],
];

Expand Down Expand Up @@ -77,6 +78,9 @@ public function execute(string $coverageFile, string $patchFile, string $pathPre
$result['numChangedLinesThatWereExecuted']++;
}
}
if (isset($coverage[$key]) && !isset($coverage[$key][$line])) {
$result['numChangedLinesNotCovered']++;
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/cli/PatchCoverageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public function run(Arguments $arguments): int
);

if ($patchCoverage['numChangedLinesThatWereExecuted'] === 0 &&
$patchCoverage['numChangedLinesThatAreExecutable'] === 0) {
$patchCoverage['numChangedLinesThatAreExecutable'] === 0 &&
$patchCoverage['numChangedLinesNotCovered'] === 0) {
print 'Unable to detect executable lines that were changed.' . PHP_EOL;

if ($pathPrefix === '') {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
phpcov patch-coverage --path-prefix /path/prefix ../../fixture/example2/coverage/testGreetsWorld2.cov ../../fixture/example2/patch2
--INI--
xdebug.overload_var_dump=0
--FILE--
<?php declare(strict_types=1);
require __DIR__ . '/../../../vendor/autoload.php';

$_SERVER['argv'][1] = 'patch-coverage';
$_SERVER['argv'][2] = '--path-prefix';
$_SERVER['argv'][3] = '/tmp/tmp.eeK19HW3Mj/phpcov/';
$_SERVER['argv'][4] = __DIR__ . '/../../fixture/example2/coverage/testGreetsWorld2.cov';
$_SERVER['argv'][5] = __DIR__ . '/../../fixture/example2/patch2';

var_dump((new SebastianBergmann\PHPCOV\Application)->run($_SERVER['argv']));
--EXPECTF--
phpcov %s by Sebastian Bergmann.

0 / 0 changed executable lines covered ()
int(0)
Binary file not shown.
13 changes: 13 additions & 0 deletions tests/fixture/example2/patch2
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/tests/fixture/example2/src/Greeter2.php b/tests/fixture/example2/src/Greeter2.php
index 36e0a2e..ab7b878 100644
--- a/tests/fixture/example2/src/Greeter2.php
+++ b/tests/fixture/example2/src/Greeter2.php
@@ -4,7 +4,7 @@

final class Greeter2
{
- public const GREETING='Hello world!';
+ public const GREETING='Hello wonderful world!';

public function greetWorld(): string
{
18 changes: 18 additions & 0 deletions tests/fixture/example2/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
bootstrap="src/autoload.php"
failOnRisky="true"
failOnWarning="true">
<testsuites>
<testsuite name="default">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>

<coverage>
<include>
<directory>src</directory>
</include>
</coverage>
</phpunit>
13 changes: 13 additions & 0 deletions tests/fixture/example2/src/Greeter2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace fixture\example2\src;

final class Greeter2
{
public const GREETING='Hello world!';

public function greetWorld(): string
{
return self::GREETING;
}
}
4 changes: 4 additions & 0 deletions tests/fixture/example2/src/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php declare(strict_types=1);

require __DIR__ . '/Greeter2.php';

17 changes: 17 additions & 0 deletions tests/fixture/example2/tests/Greeter2Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace fixture\example2\tests;

use fixture\example2\src\Greeter2;
use PHPUnit\Framework\TestCase;

/**
* @covers \fixture\example2\src\Greeter2
*/
final class Greeter2Test extends TestCase
{
public function testGreetsWorld(): void
{
$this->assertSame(Greeter2::GREETING, (new Greeter2())->greetWorld());
}
}