fix: test result on parallel

This commit is contained in:
Nuno Maduro
2023-03-21 21:05:11 +00:00
parent 077ed287b7
commit 14dd5cb57b
5 changed files with 18 additions and 24 deletions

View File

@ -19,7 +19,7 @@
"require": { "require": {
"php": "^8.1.0", "php": "^8.1.0",
"brianium/paratest": "^7.1.2", "brianium/paratest": "^7.1.2",
"nunomaduro/collision": "^7.3.1", "nunomaduro/collision": "^7.3.2",
"nunomaduro/termwind": "^1.15.1", "nunomaduro/termwind": "^1.15.1",
"pestphp/pest-plugin": "^2.0.0", "pestphp/pest-plugin": "^2.0.0",
"pestphp/pest-plugin-arch": "^2.0.1", "pestphp/pest-plugin-arch": "^2.0.1",

View File

@ -11,7 +11,9 @@ use Pest\Plugins\Actions\CallsBoot;
use Pest\Plugins\Actions\CallsHandleArguments; use Pest\Plugins\Actions\CallsHandleArguments;
use Pest\Plugins\Actions\CallsShutdown; use Pest\Plugins\Actions\CallsShutdown;
use Pest\Support\Container; use Pest\Support\Container;
use PHPUnit\TestRunner\TestResult\Facade;
use PHPUnit\TextUI\Application; use PHPUnit\TextUI\Application;
use PHPUnit\TextUI\Configuration\Registry;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
@ -90,8 +92,11 @@ final class Kernel
]); ]);
} }
$configuration = Registry::get();
$result = Facade::result();
return CallsAddsOutput::execute( return CallsAddsOutput::execute(
Result::exitCode(), Result::exitCode($configuration, $result),
); );
} }

View File

@ -20,13 +20,13 @@ use ParaTest\Options;
use ParaTest\RunnerInterface; use ParaTest\RunnerInterface;
use ParaTest\WrapperRunner\SuiteLoader; use ParaTest\WrapperRunner\SuiteLoader;
use ParaTest\WrapperRunner\WrapperWorker; use ParaTest\WrapperRunner\WrapperWorker;
use Pest\Result;
use Pest\TestSuite; use Pest\TestSuite;
use PHPUnit\Event\Facade as EventFacade; use PHPUnit\Event\Facade as EventFacade;
use PHPUnit\Runner\CodeCoverage; use PHPUnit\Runner\CodeCoverage;
use PHPUnit\TestRunner\TestResult\Facade as TestResultFacade; use PHPUnit\TestRunner\TestResult\Facade as TestResultFacade;
use PHPUnit\TestRunner\TestResult\TestResult; use PHPUnit\TestRunner\TestResult\TestResult;
use PHPUnit\TextUI\Configuration\CodeCoverageFilterRegistry; use PHPUnit\TextUI\Configuration\CodeCoverageFilterRegistry;
use PHPUnit\TextUI\ShellExitCodeCalculator;
use PHPUnit\Util\ExcludeList; use PHPUnit\Util\ExcludeList;
use function realpath; use function realpath;
use SebastianBergmann\Timer\Timer; use SebastianBergmann\Timer\Timer;
@ -330,14 +330,7 @@ final class WrapperRunner implements RunnerInterface
$this->generateCodeCoverageReports(); $this->generateCodeCoverageReports();
$this->generateLogs(); $this->generateLogs();
$exitCode = (new ShellExitCodeCalculator())->calculate( $exitCode = Result::exitCode($this->options->configuration, $testResultSum);
$this->options->configuration->failOnEmptyTestSuite(),
$this->options->configuration->failOnRisky(),
$this->options->configuration->failOnWarning(),
$this->options->configuration->failOnIncomplete(),
$this->options->configuration->failOnSkipped(),
$testResultSum,
);
$this->clearFiles($this->testresultFiles); $this->clearFiles($this->testresultFiles);
$this->clearFiles($this->coverageFiles); $this->clearFiles($this->coverageFiles);

View File

@ -4,8 +4,8 @@ declare(strict_types=1);
namespace Pest; namespace Pest;
use PHPUnit\TestRunner\TestResult\Facade; use PHPUnit\TestRunner\TestResult\TestResult;
use PHPUnit\TextUI\Configuration\Registry; use PHPUnit\TextUI\Configuration\Configuration;
/** /**
* @internal * @internal
@ -21,26 +21,24 @@ final class Result
/** /**
* If the exit code is different from 0. * 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. * 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. * 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; $returnCode = self::FAILURE_EXIT;
if ($result->wasSuccessfulIgnoringPhpunitWarnings() if ($result->wasSuccessfulIgnoringPhpunitWarnings()
@ -48,8 +46,6 @@ final class Result
$returnCode = self::SUCCESS_EXIT; $returnCode = self::SUCCESS_EXIT;
} }
$configuration = Registry::get();
if ($configuration->failOnEmptyTestSuite() && $result->numberOfTests() === 0) { if ($configuration->failOnEmptyTestSuite() && $result->numberOfTests() === 0) {
$returnCode = self::FAILURE_EXIT; $returnCode = self::FAILURE_EXIT;
} }

View File

@ -1,6 +1,6 @@
##teamcity[testSuiteStarted name='Tests/tests/Failure' locationHint='file://tests/.tests/Failure.php' flowId='1234'] ##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[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[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[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'] ##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[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[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[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[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[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'] ##teamcity[testIgnored name='it is not done yet' message='This test was ignored.' details='' flowId='1234']