From 6d6e4e040fc2c9de1b668294a325bd022e3cc1c3 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Fri, 25 Jul 2025 18:03:58 -0600 Subject: [PATCH] fix: wrong status code being used --- src/Result.php | 46 ++----------------- .../EnsureIgnorableTestCasesAreIgnored.php | 2 +- 2 files changed, 4 insertions(+), 44 deletions(-) diff --git a/src/Result.php b/src/Result.php index 4dcbe4a1..97eda17f 100644 --- a/src/Result.php +++ b/src/Result.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace Pest; -use NunoMaduro\Collision\Adapters\Phpunit\Support\ResultReflection; use PHPUnit\TestRunner\TestResult\TestResult; use PHPUnit\TextUI\Configuration\Configuration; +use PHPUnit\TextUI\ShellExitCodeCalculator; /** * @internal @@ -15,10 +15,6 @@ final class Result { private const int SUCCESS_EXIT = 0; - private const int FAILURE_EXIT = 1; - - private const int EXCEPTION_EXIT = 2; - /** * If the exit code is different from 0. */ @@ -40,44 +36,8 @@ final class Result */ public static function exitCode(Configuration $configuration, TestResult $result): int { - if ($result->wasSuccessful()) { - if ($configuration->failOnWarning()) { - $warnings = $result->numberOfTestsWithTestTriggeredPhpunitWarningEvents() - + count($result->warnings()) - + count($result->phpWarnings()); + $shell = new ShellExitCodeCalculator; - if ($warnings > 0) { - return self::FAILURE_EXIT; - } - } - - if (! $result->hasTestTriggeredPhpunitWarningEvents()) { - return self::SUCCESS_EXIT; - } - } - - if ($configuration->failOnEmptyTestSuite() && ResultReflection::numberOfTests($result) === 0) { - return self::FAILURE_EXIT; - } - - if ($result->wasSuccessful()) { - if ($configuration->failOnRisky() && $result->hasTestConsideredRiskyEvents()) { - $returnCode = self::FAILURE_EXIT; - } - - if ($configuration->failOnIncomplete() && $result->hasTestMarkedIncompleteEvents()) { - $returnCode = self::FAILURE_EXIT; - } - - if ($configuration->failOnSkipped() && $result->hasTestSkippedEvents()) { - $returnCode = self::FAILURE_EXIT; - } - } - - if ($result->hasTestErroredEvents()) { - return self::EXCEPTION_EXIT; - } - - return self::FAILURE_EXIT; + return $shell->calculate($configuration, $result); } } diff --git a/src/Subscribers/EnsureIgnorableTestCasesAreIgnored.php b/src/Subscribers/EnsureIgnorableTestCasesAreIgnored.php index 1cf3d55a..a6e837bf 100644 --- a/src/Subscribers/EnsureIgnorableTestCasesAreIgnored.php +++ b/src/Subscribers/EnsureIgnorableTestCasesAreIgnored.php @@ -35,7 +35,7 @@ final class EnsureIgnorableTestCasesAreIgnored implements StartedSubscriber /** @var array $testRunnerTriggeredWarningEvents */ $testRunnerTriggeredWarningEvents = $property->getValue($collector); - $testRunnerTriggeredWarningEvents = array_values(array_filter($testRunnerTriggeredWarningEvents, fn (WarningTriggered $event): bool => $event->message() !== 'No tests found in class "Pest\TestCases\IgnorableTestCase".')); + $testRunnerTriggeredWarningEvents = array_values(array_filter($testRunnerTriggeredWarningEvents, fn (WarningTriggered $event): bool => str_contains($event->message(), 'No tests found in class') === false)); $property->setValue($collector, $testRunnerTriggeredWarningEvents); }