mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
feat: basic PHPUnit 10 support
This commit is contained in:
22
src/Subscribers/EnsureConfigurationDefaults.php
Normal file
22
src/Subscribers/EnsureConfigurationDefaults.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Subscribers;
|
||||
|
||||
use PHPUnit\Event\TestRunner\Configured;
|
||||
use PHPUnit\Event\TestRunner\ConfiguredSubscriber;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class EnsureConfigurationDefaults implements ConfiguredSubscriber
|
||||
{
|
||||
/**
|
||||
* Runs the subscriber.
|
||||
*/
|
||||
public function notify(Configured $event): void
|
||||
{
|
||||
$configuration = $event->configuration();
|
||||
}
|
||||
}
|
||||
27
src/Subscribers/EnsureConfigurationIsValid.php
Normal file
27
src/Subscribers/EnsureConfigurationIsValid.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Subscribers;
|
||||
|
||||
use Pest\Exceptions\AttributeNotSupportedYet;
|
||||
use PHPUnit\Event\TestRunner\Configured;
|
||||
use PHPUnit\Event\TestRunner\ConfiguredSubscriber;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class EnsureConfigurationIsValid implements ConfiguredSubscriber
|
||||
{
|
||||
/**
|
||||
* Runs the subscriber.
|
||||
*/
|
||||
public function notify(Configured $event): void
|
||||
{
|
||||
$configuration = $event->configuration();
|
||||
|
||||
if ($configuration->processIsolation()) {
|
||||
throw new AttributeNotSupportedYet('processIsolation', 'true');
|
||||
}
|
||||
}
|
||||
}
|
||||
79
src/Subscribers/EnsureTestsAreLoaded.php
Normal file
79
src/Subscribers/EnsureTestsAreLoaded.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Subscribers;
|
||||
|
||||
use PHPUnit\Event\TestSuite\Loaded;
|
||||
use PHPUnit\Event\TestSuite\LoadedSubscriber;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Framework\TestSuite;
|
||||
use PHPUnit\Framework\WarningTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class EnsureTestsAreLoaded implements LoadedSubscriber
|
||||
{
|
||||
/**
|
||||
* The current test suite, if any.
|
||||
*/
|
||||
private static ?TestSuite $testSuite;
|
||||
|
||||
/**
|
||||
* Runs the subscriber.
|
||||
*/
|
||||
public function notify(Loaded $event): void
|
||||
{
|
||||
$this->removeWarnings(self::$testSuite);
|
||||
|
||||
$testSuites = [];
|
||||
|
||||
$testSuite = \Pest\TestSuite::getInstance();
|
||||
$testSuite->tests->build($testSuite, function (TestCase $testCase) use (&$testSuites): void {
|
||||
$testCaseClass = get_class($testCase);
|
||||
if (!array_key_exists($testCaseClass, $testSuites)) {
|
||||
$testSuites[$testCaseClass] = [];
|
||||
}
|
||||
|
||||
$testSuites[$testCaseClass][] = $testCase;
|
||||
});
|
||||
|
||||
foreach ($testSuites as $testCaseName => $testCases) {
|
||||
$testTestSuite = new TestSuite($testCaseName);
|
||||
$testTestSuite->setTests([]);
|
||||
foreach ($testCases as $testCase) {
|
||||
$testTestSuite->addTest($testCase, $testCase->groups());
|
||||
}
|
||||
self::$testSuite->addTestSuite($testTestSuite);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current test suite.
|
||||
*/
|
||||
public static function setTestSuite(TestSuite $testSuite): void
|
||||
{
|
||||
self::$testSuite = $testSuite;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the test case that have "empty" warnings.
|
||||
*/
|
||||
private function removeWarnings(TestSuite $testSuite): void
|
||||
{
|
||||
$tests = $testSuite->tests();
|
||||
|
||||
foreach ($tests as $key => $test) {
|
||||
if ($test instanceof TestSuite) {
|
||||
$this->removeWarnings($test);
|
||||
}
|
||||
|
||||
if ($test instanceof WarningTestCase) {
|
||||
unset($tests[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$testSuite->setTests(array_values($tests));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user