Fixes ignorable tests

This commit is contained in:
Nuno Maduro
2022-09-15 14:10:25 +01:00
parent b3a2e6026f
commit 0953ae431e
4 changed files with 73 additions and 14 deletions

View File

@ -4,13 +4,24 @@ declare(strict_types=1);
namespace Pest; namespace Pest;
use PHPUnit\TestRunner\TestResult\Facade;
use PHPUnit\TestRunner\TestResult\TestResult;
use PHPUnit\TextUI\Application; use PHPUnit\TextUI\Application;
use PHPUnit\TextUI\Configuration\Registry;
/** /**
* @internal * @internal
*/ */
final class Kernel final class Kernel
{ {
private const SUCCESS_EXIT = 0;
private const FAILURE_EXIT = 1;
private const EXCEPTION_EXIT = 2;
private const CRASH_EXIT = 255;
/** /**
* The Kernel bootstrappers. * The Kernel bootstrappers.
* *
@ -53,11 +64,15 @@ final class Kernel
{ {
$argv = (new Plugins\Actions\HandleArguments())->__invoke($argv); $argv = (new Plugins\Actions\HandleArguments())->__invoke($argv);
$result = $this->application->run( $this->application->run(
$argv, false, $argv, false,
); );
return (new Plugins\Actions\AddsOutput())->__invoke($result); $returnCode = $this->returnCode();
return (new Plugins\Actions\AddsOutput())->__invoke(
$returnCode,
);
} }
/** /**
@ -67,4 +82,55 @@ final class Kernel
{ {
// .. // ..
} }
/**
* Returns the exit code, based on the facade's result.
*/
private function returnCode(): int
{
$result = Facade::result();
$returnCode = self::FAILURE_EXIT;
if ($result->wasSuccessfulIgnoringPhpunitWarnings()
&& ! $result->hasTestTriggeredPhpunitWarningEvents()) {
$returnCode = self::SUCCESS_EXIT;
}
$configuration = Registry::get();
if ($configuration->failOnEmptyTestSuite() && $result->numberOfTests() === 0) {
$returnCode = self::FAILURE_EXIT;
}
if ($result->wasSuccessfulIgnoringPhpunitWarnings()) {
if ($configuration->failOnRisky() && $result->hasTestConsideredRiskyEvents()) {
$returnCode = self::FAILURE_EXIT;
}
$warnings = $result->numberOfTestsWithTestTriggeredPhpunitWarningEvents()
+ $result->numberOfTestsWithTestTriggeredWarningEvents()
+ $result->numberOfTestsWithTestTriggeredPhpWarningEvents();
if ($configuration->failOnWarning() && ! empty($warnings)) {
$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()) {
$returnCode = self::EXCEPTION_EXIT;
}
return $returnCode;
}
} }

View File

@ -9,13 +9,7 @@ use PHPUnit\Framework\TestCase;
/** /**
* @internal * @internal
*/ */
final class IgnorableTest extends TestCase class IgnorableTest extends TestCase
{ {
/**
* Creates a dummy assertion.
*/
public function testIgnorable(): void
{
self::assertTrue(true);
}
} }

View File

@ -692,9 +692,6 @@
✓ custom traits can be used ✓ custom traits can be used
✓ trait applied in this file ✓ trait applied in this file
WARN Tests\Playground
! basic → This test did not perform any assertions
PASS Tests\Plugins\Traits PASS Tests\Plugins\Traits
✓ it allows global uses ✓ it allows global uses
✓ it allows multiple global uses registered in the same path ✓ it allows multiple global uses registered in the same path
@ -770,5 +767,5 @@
WARN Tests\Visual\TeamCity WARN Tests\Visual\TeamCity
- it is can successfully call all public methods → Not supported yet. - it is can successfully call all public methods → Not supported yet.
Tests: 1 risky, 4 incompleted, 18 skipped, 514 passed Tests: 4 incompleted, 18 skipped, 514 passed

View File

@ -0,0 +1,2 @@
<?php