fix: modify Result::exitCode logic to address warning handling with --fail-on-warning

This commit is contained in:
Ariful Alam
2024-02-20 18:24:37 +06:00
parent 602b696348
commit a136231503

View File

@ -40,9 +40,20 @@ final class Result
*/ */
public static function exitCode(Configuration $configuration, TestResult $result): int public static function exitCode(Configuration $configuration, TestResult $result): int
{ {
if ($result->wasSuccessfulIgnoringPhpunitWarnings() if ($result->wasSuccessfulIgnoringPhpunitWarnings()) {
&& ! $result->hasTestTriggeredPhpunitWarningEvents()) { if ($configuration->failOnWarning()) {
return self::SUCCESS_EXIT; $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) { if ($configuration->failOnEmptyTestSuite() && ResultReflection::numberOfTests($result) === 0) {
@ -54,14 +65,6 @@ final class Result
$returnCode = self::FAILURE_EXIT; $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()) { if ($configuration->failOnIncomplete() && $result->hasTestMarkedIncompleteEvents()) {
$returnCode = self::FAILURE_EXIT; $returnCode = self::FAILURE_EXIT;
} }