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

Return error exit code for "No lines…" error. #74

Open
wants to merge 7 commits into
base: master
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
40 changes: 14 additions & 26 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/5.4/phpunit.xsd"
bootstrap="tests/bootstrap.php"
backupGlobals="false"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutTodoAnnotatedTests="true"
verbose="true">
<testsuite name="coverageChecker">
<directory suffix="Test.php">tests</directory>
</testsuite>

<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<logging>
<log
type="coverage-html"
target="report"
lowUpperBound="90"
highLowerBound="95"/>
<log type="coverage-clover" target="report/coverage.xml"/>
</logging>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="tests/bootstrap.php" backupGlobals="false" beStrictAboutCoversAnnotation="true" beStrictAboutOutputDuringTests="true" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutTodoAnnotatedTests="true" verbose="true">
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
<report>
<clover outputFile="report/coverage.xml"/>
<html outputDirectory="report" lowUpperBound="90" highLowerBound="95"/>
</report>
</coverage>
<testsuite name="coverageChecker">
<directory suffix="Test.php">tests</directory>
</testsuite>
<logging/>
</phpunit>
8 changes: 5 additions & 3 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,16 @@ function handleOutput(array $lines, float $minimumPercentCovered, Output $output


if ($coveredLines + $uncoveredLines == 0) {
error_log('No lines found!');

$output->output(
$lines['uncoveredLines'],
100,
$minimumPercentCovered
);
return;

throw new Exception(
'No lines found!',
3
);
}

$percentCovered = 100 * ($coveredLines / ($coveredLines + $uncoveredLines));
Expand Down
31 changes: 22 additions & 9 deletions tests/PhpunitDiffFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,24 @@ public function testWrongArgs()
require(__DIR__ . "/../src/Runners/generic.php");
}

public function testWorkingCorrectly()
public function testInvalidFileReturnsNoLinesFound()
{
$GLOBALS['argv'] = [
'diffFilter',
'--phpunit',
__DIR__ . '/fixtures/change.txt',
__DIR__ . '/fixtures/coverage.xml'
];
ob_start();
require(__DIR__ . "/../src/Runners/generic.php");
$output = ob_get_clean();
$this->assertContainsString('No lines found', $output);

try {
ob_start();
require(__DIR__ . "/../src/Runners/generic.php");
} catch (Exception $e) {
ob_end_clean();
$this->assertContainsString('No lines found', $e->getMessage());
return;
}
$this->fail("No Exception thrown");
}

public function testFailingBuild()
Expand Down Expand Up @@ -83,9 +89,16 @@ public function testNoCoveredLines()
__DIR__ . '/fixtures/coverage-change.xml',
];

ob_start();
require(__DIR__ . '/../src/Runners/generic.php');
$output = ob_get_clean();
$this->assertContainsString('No lines found', $output);

try {
ob_start();
require(__DIR__ . '/../src/Runners/generic.php');
} catch (Exception $e) {
ob_end_clean();
$this->assertEquals(3, $e->getCode());
return;
}

$this->fail("no exception thrown");
}
}