Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dx] require >= PHPUnit 9.6, update phpunit schema, deprecate skipOnSymfony7() #1425

Merged
merged 12 commits into from
Feb 1, 2024
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/.php-cs-fixer.cache
/.phpunit.result.cache
/.phpunit.cache
/composer.lock
/fake
/phpunit.xml
Expand Down
34 changes: 21 additions & 13 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,42 @@

<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/phpunit.xsd"
backupGlobals="false"
colors="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
failOnIncomplete="true"
failOnRisky="true"
failOnWarning="true"
beStrictAboutTodoAnnotatedTests="true"
>
<php>
<ini name="error_reporting" value="-1" />
<env name="TEST_DATABASE_DSN" value="mysql://root:root@127.0.0.1:3306/test_maker?serverVersion=5.7" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0"/>
<env name="SYMFONY_PHPUNIT_VERSION" value="9.6" />
<env name="MAKER_SKIP_MERCURE_TEST" value="false"/>
</php>

<testsuites>
<testsuite name="Project Test Suite">
<directory>tests/</directory>
<testsuite name="makers">
<directory>tests/Maker</directory>
</testsuite>
<testsuite name="utils">
<directory>tests</directory>
<exclude>tests/Maker</exclude>
<exclude>tests/fixtures</exclude>
<exclude>tests/tmp</exclude>
</testsuite>
<testsuite name="Maker Test Suite">
<directory>tests/Maker</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
<coverage
cacheDirectory=".phpunit.cache/coverage"
processUncoveredFiles="true"
>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</phpunit>
8 changes: 2 additions & 6 deletions src/Test/MakerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
59 changes: 59 additions & 0 deletions src/Test/MakerTestDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
Expand Down Expand Up @@ -179,13 +189,62 @@ 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;
}

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;
}
}
23 changes: 17 additions & 6 deletions tests/Maker/MakeEntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chicken or the egg... MakeEntity needs to be refactored to use ux-turbo and at first glance doesn't appear to be a "1 for 1" swap with ux-turbo-mercure. To keep the entire test suite from blowing up due to a deprecation - this skip conditional was moved here for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok for now for me

;
}

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
Expand Down Expand Up @@ -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);
}),
];

Expand Down
Loading