Merge pull request #1097 from arifszn/2.x

[2.x] Modify `Result::exitCode` logic to address warning handling with `--fail-on-warning`
This commit is contained in:
Nuno Maduro
2024-08-22 20:31:34 +01:00
committed by GitHub

View File

@ -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;
}