From cf4ee54879c90ab6903cfd6158e376e95a3fbf92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20Wytr=C4=99bowicz?= Date: Fri, 8 Jul 2022 14:15:00 +0200 Subject: [PATCH 1/6] =?UTF-8?q?Return=20error=20exit=20code=20for=20"No=20?= =?UTF-8?q?lines=E2=80=A6"=20error.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes https://github.com/exussum12/coverageChecker/issues/72 --- src/functions.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/functions.php b/src/functions.php index f30fe61..58252b4 100644 --- a/src/functions.php +++ b/src/functions.php @@ -91,8 +91,10 @@ function handleOutput(array $lines, float $minimumPercentCovered, Output $output if ($coveredLines + $uncoveredLines == 0) { - error_log('No lines found!'); - return; + throw new Exception( + 'No lines found!', + 3 + ); } $percentCovered = 100 * ($coveredLines / ($coveredLines + $uncoveredLines)); From f94270fccd7e81b19394d8e75d0ba359b54fa548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20Wytr=C4=99bowicz?= Date: Fri, 8 Jul 2022 15:47:44 +0200 Subject: [PATCH 2/6] Update `testNoCoveredLines` --- tests/PhpunitDiffFilterTest.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/PhpunitDiffFilterTest.php b/tests/PhpunitDiffFilterTest.php index 20d8e74..5716e02 100644 --- a/tests/PhpunitDiffFilterTest.php +++ b/tests/PhpunitDiffFilterTest.php @@ -83,9 +83,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) { + $output = ob_get_clean(); + $this->assertEquals(3, $e->getCode()); + return; + } + + $this->fail("no exception thrown"); } } From 4e60c83764214645a760770b4c58e2d506716cd3 Mon Sep 17 00:00:00 2001 From: Scott Dutton Date: Mon, 29 Aug 2022 22:42:27 +0100 Subject: [PATCH 3/6] Update functions.php --- src/functions.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/functions.php b/src/functions.php index 74adad3..83e6b06 100644 --- a/src/functions.php +++ b/src/functions.php @@ -91,7 +91,6 @@ function handleOutput(array $lines, float $minimumPercentCovered, Output $output if ($coveredLines + $uncoveredLines == 0) { - $output->output( $lines['uncoveredLines'], 100, @@ -101,8 +100,7 @@ function handleOutput(array $lines, float $minimumPercentCovered, Output $output throw new Exception( 'No lines found!', 3 - ); - + ); } $percentCovered = 100 * ($coveredLines / ($coveredLines + $uncoveredLines)); From f321cc9811ac9d44aabaffacdaf25ec4e49eb641 Mon Sep 17 00:00:00 2001 From: Scott Dutton Date: Mon, 29 Aug 2022 22:44:16 +0100 Subject: [PATCH 4/6] Update functions.php --- src/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions.php b/src/functions.php index 83e6b06..9245902 100644 --- a/src/functions.php +++ b/src/functions.php @@ -100,7 +100,7 @@ function handleOutput(array $lines, float $minimumPercentCovered, Output $output throw new Exception( 'No lines found!', 3 - ); + ); } $percentCovered = 100 * ($coveredLines / ($coveredLines + $uncoveredLines)); From fa95776c39ae5769cb4e14a0f754fe61c5adb41e Mon Sep 17 00:00:00 2001 From: Scott Dutton Date: Mon, 29 Aug 2022 22:46:54 +0100 Subject: [PATCH 5/6] Update PhpunitDiffFilterTest.php --- tests/PhpunitDiffFilterTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/PhpunitDiffFilterTest.php b/tests/PhpunitDiffFilterTest.php index 5716e02..2b1e8a2 100644 --- a/tests/PhpunitDiffFilterTest.php +++ b/tests/PhpunitDiffFilterTest.php @@ -88,7 +88,7 @@ public function testNoCoveredLines() ob_start(); require(__DIR__ . '/../src/Runners/generic.php'); } catch (Exception $e) { - $output = ob_get_clean(); + ob_clean(); $this->assertEquals(3, $e->getCode()); return; } From 2f6b25f73036eb9c15dd991d87135648a9d11a53 Mon Sep 17 00:00:00 2001 From: Scott Dutton Date: Mon, 29 Aug 2022 23:12:37 +0100 Subject: [PATCH 6/6] Fix tests --- phpunit.xml | 40 ++++++++++++--------------------- tests/PhpunitDiffFilterTest.php | 18 ++++++++++----- 2 files changed, 26 insertions(+), 32 deletions(-) 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/tests/PhpunitDiffFilterTest.php b/tests/PhpunitDiffFilterTest.php index 2b1e8a2..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() @@ -88,7 +94,7 @@ public function testNoCoveredLines() ob_start(); require(__DIR__ . '/../src/Runners/generic.php'); } catch (Exception $e) { - ob_clean(); + ob_end_clean(); $this->assertEquals(3, $e->getCode()); return; }