From a1362315039abc3c7f9f173854379266b8d2cc4f Mon Sep 17 00:00:00 2001 From: Ariful Alam Date: Tue, 20 Feb 2024 18:24:37 +0600 Subject: [PATCH] fix: modify `Result::exitCode` logic to address warning handling with `--fail-on-warning` --- src/Result.php | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/Result.php b/src/Result.php index 9b3a83e5..98e9e8b6 100644 --- a/src/Result.php +++ b/src/Result.php @@ -40,9 +40,20 @@ final class Result */ public static function exitCode(Configuration $configuration, TestResult $result): int { - if ($result->wasSuccessfulIgnoringPhpunitWarnings() - && ! $result->hasTestTriggeredPhpunitWarningEvents()) { - return self::SUCCESS_EXIT; + if ($result->wasSuccessfulIgnoringPhpunitWarnings()) { + if ($configuration->failOnWarning()) { + $warnings = $result->numberOfTestsWithTestTriggeredPhpunitWarningEvents() + + count($result->warnings()) + + count($result->phpWarnings()); + + if ($warnings > 0) { + return self::FAILURE_EXIT; + } + } + + if (! $result->hasTestTriggeredPhpunitWarningEvents()) { + return self::SUCCESS_EXIT; + } } if ($configuration->failOnEmptyTestSuite() && ResultReflection::numberOfTests($result) === 0) { @@ -54,14 +65,6 @@ final class Result $returnCode = self::FAILURE_EXIT; } - $warnings = $result->numberOfTestsWithTestTriggeredPhpunitWarningEvents() - + count($result->warnings()) - + count($result->phpWarnings()); - - if ($configuration->failOnWarning() && $warnings > 0) { - $returnCode = self::FAILURE_EXIT; - } - if ($configuration->failOnIncomplete() && $result->hasTestMarkedIncompleteEvents()) { $returnCode = self::FAILURE_EXIT; }