diff --git a/.gitignore b/.gitignore index 5999cc3bf..196fcbfd3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ /.php-cs-fixer.cache -/.phpunit.result.cache +/.phpunit.cache /composer.lock /fake /phpunit.xml diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 3f9307b89..5f45214e7 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -2,34 +2,42 @@ + + - - tests/ + + tests/Maker + + + tests tests/Maker tests/fixtures tests/tmp - - tests/Maker - - - - ./src/ - - + + + src + + diff --git a/src/Test/MakerTestCase.php b/src/Test/MakerTestCase.php index 3584250d1..40539826f 100644 --- a/src/Test/MakerTestCase.php +++ b/src/Test/MakerTestCase.php @@ -50,16 +50,12 @@ protected function executeMakerCommand(MakerTestDetails $testDetails) throw new \LogicException('The MakerTestCase cannot be run as the Process component is not installed. Try running "compose require --dev symfony/process".'); } - if (!$testDetails->isSupportedByCurrentPhpVersion()) { - $this->markTestSkipped(); + if ($testDetails->isTestSkipped() || !$testDetails->isSupportedByCurrentPhpVersion()) { + $this->markTestSkipped($testDetails->getSkippedTestMessage()); } $testEnv = MakerTestEnvironment::create($testDetails); - if ('7.0.x-dev' === $testEnv->getTargetSkeletonVersion() && $testDetails->getSkipOnSymfony7()) { - $this->markTestSkipped('This test is skipped on Symfony 7'); - } - // prepare environment to test $testEnv->prepareDirectory(); diff --git a/src/Test/MakerTestDetails.php b/src/Test/MakerTestDetails.php index 16bdadec2..3d174028b 100644 --- a/src/Test/MakerTestDetails.php +++ b/src/Test/MakerTestDetails.php @@ -26,6 +26,16 @@ final class MakerTestDetails private int $blockedPhpVersionLower = 0; private bool $skipOnSymfony7 = false; + /** + * @internal + */ + private bool $skipTest = false; + + /** + * @internal + */ + private string $skipTestMessage = ''; + public function __construct( private MakerInterface $maker, ) { @@ -179,6 +189,12 @@ public function getPreRunCallbacks(): array public function skipOnSymfony7(): self { + @trigger_deprecation( + 'symfony/maker-bundle', + 'v1.53.0', + sprintf('%s() will be removed in a future version, use MakerTestDetails::skipTest() instead.', __METHOD__) + ); + $this->skipOnSymfony7 = true; return $this; @@ -186,6 +202,49 @@ public function skipOnSymfony7(): self public function getSkipOnSymfony7(): bool { + @trigger_deprecation( + 'symfony/maker-bundle', + 'v1.53.0', + sprintf('%s() will be removed in a future version, use MakerTestDetails::isTestSkipped() instead.', __METHOD__) + ); + return $this->skipOnSymfony7; } + + /** + * Skip an application test by calling this method and providing an optional + * message. + * + * This method should not be removed even if it is not being used, it may be + * needed in the future. + * + * @internal + */ + public function skipTest(string $message = '', bool $skipped = true): self + { + $this->skipTestMessage = $message; + $this->skipTest = $skipped; + + return $this; + } + + /** + * MakerTestCase uses this to determine if a test should be skipped. + * + * @internal + */ + public function isTestSkipped(): bool + { + return $this->skipTest; + } + + /** + * MakerTestCase uses this to get the skipped test message. + * + * @internal + */ + public function getSkippedTestMessage(): string + { + return $this->skipTestMessage; + } } diff --git a/tests/Maker/MakeEntityTest.php b/tests/Maker/MakeEntityTest.php index 7e58ae305..1b5156318 100644 --- a/tests/Maker/MakeEntityTest.php +++ b/tests/Maker/MakeEntityTest.php @@ -37,12 +37,26 @@ private function createMakeEntityTest(bool $withDatabase = true): MakerTestDetai private function createMakeEntityTestForMercure(): MakerTestDetails { + if (getenv('MAKER_SKIP_MERCURE_TEST')) { + // This test is skipped, don't worry about persistence + return $this->createMakerTest() + ->skipTest('MAKER_SKIP_MERCURE_TEST set to true') + ; + } + + // @legacy - MakeEntity uses ux-turbo-mercure (archived), it needs to use ux-turbo (mercure built in) for Symfony 7.0 + if ('7.0.x-dev' === $_SERVER['SYMFONY_VERSION']) { + return $this->createMakerTest() + ->skipTest('symfony/ux-turbo-mercure is not supported on Symfony 7.') + ; + } + return $this->createMakeEntityTest() - ->skipOnSymfony7() // legacy remove when ux-turbo-mercure supports Symfony 7 ->preRun(function (MakerTestRunner $runner) { // installed manually later so that the compatibility check can run first $runner->runProcess('composer require symfony/ux-turbo-mercure'); - }); + }) + ; } public function getTestDetails(): \Generator @@ -535,10 +549,7 @@ public function getTestDetails(): \Generator $this->assertStringContainsString('use Symfony\UX\Turbo\Attribute\Broadcast;', $content); $this->assertStringContainsString('#[Broadcast]', $content); - $skipMercureTest = $_SERVER['MAKER_SKIP_MERCURE_TEST'] ?? false; - if (!$skipMercureTest) { - $this->runEntityTest($runner); - } + $this->runEntityTest($runner); }), ];