diff --git a/composer.json b/composer.json index 3685d4df..c7140ad6 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "require": { "php": "^8.1.0", "brianium/paratest": "^7.1.2", - "nunomaduro/collision": "^7.3.1", + "nunomaduro/collision": "^7.3.2", "nunomaduro/termwind": "^1.15.1", "pestphp/pest-plugin": "^2.0.0", "pestphp/pest-plugin-arch": "^2.0.1", diff --git a/src/Kernel.php b/src/Kernel.php index b56d32bd..0aeb8155 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -11,7 +11,9 @@ use Pest\Plugins\Actions\CallsBoot; use Pest\Plugins\Actions\CallsHandleArguments; use Pest\Plugins\Actions\CallsShutdown; use Pest\Support\Container; +use PHPUnit\TestRunner\TestResult\Facade; use PHPUnit\TextUI\Application; +use PHPUnit\TextUI\Configuration\Registry; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -90,8 +92,11 @@ final class Kernel ]); } + $configuration = Registry::get(); + $result = Facade::result(); + return CallsAddsOutput::execute( - Result::exitCode(), + Result::exitCode($configuration, $result), ); } diff --git a/src/Plugins/Parallel/Paratest/WrapperRunner.php b/src/Plugins/Parallel/Paratest/WrapperRunner.php index 717dfcb9..bec0dd5a 100644 --- a/src/Plugins/Parallel/Paratest/WrapperRunner.php +++ b/src/Plugins/Parallel/Paratest/WrapperRunner.php @@ -20,13 +20,13 @@ use ParaTest\Options; use ParaTest\RunnerInterface; use ParaTest\WrapperRunner\SuiteLoader; use ParaTest\WrapperRunner\WrapperWorker; +use Pest\Result; use Pest\TestSuite; use PHPUnit\Event\Facade as EventFacade; use PHPUnit\Runner\CodeCoverage; use PHPUnit\TestRunner\TestResult\Facade as TestResultFacade; use PHPUnit\TestRunner\TestResult\TestResult; use PHPUnit\TextUI\Configuration\CodeCoverageFilterRegistry; -use PHPUnit\TextUI\ShellExitCodeCalculator; use PHPUnit\Util\ExcludeList; use function realpath; use SebastianBergmann\Timer\Timer; @@ -330,14 +330,7 @@ final class WrapperRunner implements RunnerInterface $this->generateCodeCoverageReports(); $this->generateLogs(); - $exitCode = (new ShellExitCodeCalculator())->calculate( - $this->options->configuration->failOnEmptyTestSuite(), - $this->options->configuration->failOnRisky(), - $this->options->configuration->failOnWarning(), - $this->options->configuration->failOnIncomplete(), - $this->options->configuration->failOnSkipped(), - $testResultSum, - ); + $exitCode = Result::exitCode($this->options->configuration, $testResultSum); $this->clearFiles($this->testresultFiles); $this->clearFiles($this->coverageFiles); diff --git a/src/Result.php b/src/Result.php index 4a613d29..9f0b6382 100644 --- a/src/Result.php +++ b/src/Result.php @@ -4,8 +4,8 @@ declare(strict_types=1); namespace Pest; -use PHPUnit\TestRunner\TestResult\Facade; -use PHPUnit\TextUI\Configuration\Registry; +use PHPUnit\TestRunner\TestResult\TestResult; +use PHPUnit\TextUI\Configuration\Configuration; /** * @internal @@ -21,26 +21,24 @@ final class Result /** * If the exit code is different from 0. */ - public static function failed(): bool + public static function failed(Configuration $configuration, TestResult $result): bool { - return ! self::ok(); + return ! self::ok($configuration, $result); } /** * If the exit code is exactly 0. */ - public static function ok(): bool + public static function ok(Configuration $configuration, TestResult $result): bool { - return self::exitCode() === self::SUCCESS_EXIT; + return self::exitCode($configuration, $result) === self::SUCCESS_EXIT; } /** * Get the test execution's exit code. */ - public static function exitCode(): int + public static function exitCode(Configuration $configuration, TestResult $result): int { - $result = Facade::result(); - $returnCode = self::FAILURE_EXIT; if ($result->wasSuccessfulIgnoringPhpunitWarnings() @@ -48,8 +46,6 @@ final class Result $returnCode = self::SUCCESS_EXIT; } - $configuration = Registry::get(); - if ($configuration->failOnEmptyTestSuite() && $result->numberOfTests() === 0) { $returnCode = self::FAILURE_EXIT; } diff --git a/tests/.snapshots/Failure.php.inc b/tests/.snapshots/Failure.php.inc index 419c3b5d..ee55ce3d 100644 --- a/tests/.snapshots/Failure.php.inc +++ b/tests/.snapshots/Failure.php.inc @@ -1,6 +1,6 @@ ##teamcity[testSuiteStarted name='Tests/tests/Failure' locationHint='file://tests/.tests/Failure.php' flowId='1234'] ##teamcity[testStarted name='it can fail with comparison' locationHint='pest_qn://tests/.tests/Failure.php::it can fail with comparison' flowId='1234'] -##teamcity[testFailed name='it can fail with comparison' message='Failed asserting that true matches expected false.' details='at src/Mixins/Expectation.php:342|nat src/Support/ExpectationPipeline.php:75|nat src/Support/ExpectationPipeline.php:79|nat src/Expectation.php:300|nat tests/.tests/Failure.php:6|nat src/Factories/TestCaseMethodFactory.php:100|nat src/Concerns/Testable.php:272|nat src/Support/ExceptionTrace.php:28|nat src/Concerns/Testable.php:272|nat src/Concerns/Testable.php:215|nat src/Kernel.php:84' type='comparisonFailure' actual='true' expected='false' flowId='1234'] +##teamcity[testFailed name='it can fail with comparison' message='Failed asserting that true matches expected false.' details='at src/Mixins/Expectation.php:342|nat src/Support/ExpectationPipeline.php:75|nat src/Support/ExpectationPipeline.php:79|nat src/Expectation.php:300|nat tests/.tests/Failure.php:6|nat src/Factories/TestCaseMethodFactory.php:100|nat src/Concerns/Testable.php:272|nat src/Support/ExceptionTrace.php:28|nat src/Concerns/Testable.php:272|nat src/Concerns/Testable.php:215|nat src/Kernel.php:86' type='comparisonFailure' actual='true' expected='false' flowId='1234'] ##teamcity[testFinished name='it can fail with comparison' duration='100000' flowId='1234'] ##teamcity[testStarted name='it can be ignored because of no assertions' locationHint='pest_qn://tests/.tests/Failure.php::it can be ignored because of no assertions' flowId='1234'] ##teamcity[testIgnored name='it can be ignored because of no assertions' message='This test did not perform any assertions' details='' flowId='1234'] @@ -9,7 +9,7 @@ ##teamcity[testIgnored name='it can be ignored because it is skipped' message='This test was ignored.' details='' flowId='1234'] ##teamcity[testFinished name='it can be ignored because it is skipped' duration='100000' flowId='1234'] ##teamcity[testStarted name='it can fail' locationHint='pest_qn://tests/.tests/Failure.php::it can fail' flowId='1234'] -##teamcity[testFailed name='it can fail' message='oh noo' details='at tests/.tests/Failure.php:18|nat src/Factories/TestCaseMethodFactory.php:100|nat src/Concerns/Testable.php:272|nat src/Support/ExceptionTrace.php:28|nat src/Concerns/Testable.php:272|nat src/Concerns/Testable.php:215|nat src/Kernel.php:84' flowId='1234'] +##teamcity[testFailed name='it can fail' message='oh noo' details='at tests/.tests/Failure.php:18|nat src/Factories/TestCaseMethodFactory.php:100|nat src/Concerns/Testable.php:272|nat src/Support/ExceptionTrace.php:28|nat src/Concerns/Testable.php:272|nat src/Concerns/Testable.php:215|nat src/Kernel.php:86' flowId='1234'] ##teamcity[testFinished name='it can fail' duration='100000' flowId='1234'] ##teamcity[testStarted name='it is not done yet' locationHint='pest_qn://tests/.tests/Failure.php::it is not done yet' flowId='1234'] ##teamcity[testIgnored name='it is not done yet' message='This test was ignored.' details='' flowId='1234']