diff --git a/phpunit.xml b/phpunit.xml index 9a3e9e6..a5e607f 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,28 +1,16 @@ - - - tests - - - - - src - - - - - - + + + + src + + + + + + + + tests + + diff --git a/src/functions.php b/src/functions.php index dfcbf85..9245902 100644 --- a/src/functions.php +++ b/src/functions.php @@ -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)); diff --git a/tests/PhpunitDiffFilterTest.php b/tests/PhpunitDiffFilterTest.php index 20d8e74..227f26d 100644 --- a/tests/PhpunitDiffFilterTest.php +++ b/tests/PhpunitDiffFilterTest.php @@ -20,7 +20,7 @@ public function testWrongArgs() require(__DIR__ . "/../src/Runners/generic.php"); } - public function testWorkingCorrectly() + public function testInvalidFileReturnsNoLinesFound() { $GLOBALS['argv'] = [ 'diffFilter', @@ -28,10 +28,16 @@ public function testWorkingCorrectly() __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() @@ -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"); } }