8000 [HttpKernel] do not use the Test suffix for non test classes by xabbuh · Pull Request #58362 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpKernel] do not use the Test suffix for non test classes #58362

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

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Symfony/Component/Form/Test/FormPerformanceTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\Component\Form\Test;

use Symfony\Component\Form\Tests\VersionAwareTest;
use Symfony\Component\Form\Tests\VersionAwareTestTrait;

/**
* Base class for performance tests.
Expand All @@ -23,7 +23,7 @@
*/
abstract class FormPerformanceTestCase extends FormIntegrationTestCase
{
use VersionAwareTest;
use VersionAwareTestTrait;

protected int $maxRunningTime = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
namespace Symfony\Component\Form\Tests\Extension\Core\Type;

use Symfony\Component\Form\Test\TypeTestCase;
use Symfony\Component\Form\Tests\VersionAwareTest;
use Symfony\Component\Form\Tests\VersionAwareTestTrait;

/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
abstract class BaseTypeTestCase extends TypeTestCase
{
use VersionAwareTest;
use VersionAwareTestTrait;

public const TESTED_TYPE = '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* @deprecated since Symfony 7.2, use feature detection instead.
*/
trait VersionAwareTest
trait VersionAwareTestTrait
{
protected static int $supportedFeatureSetVersion = 404;

Expand All @@ -23,7 +23,7 @@ trait VersionAwareTest
*/
protected function requiresFeatureSet(int $requiredFeatureSetVersion)
{
trigger_deprecation('symfony/form', '7.2', 'The "%s" trait is deprecated, use feature detection instead.', VersionAwareTest::class);
trigger_deprecation('symfony/form', '7.2', 'The "%s" trait is deprecated, use feature detection instead.', VersionAwareTestTrait::class);

if ($requiredFeatureSetVersion > static::$supportedFeatureSetVersion) {
$this->markTestSkipped(\sprintf('Test requires features from symfony/form %.2f but only version %.2f is supported.', $requiredFeatureSetVersion / 100, static::$supportedFeatureSetVersion / 100));
Expand Down
57 changes: 0 additions & 57 deletions src/Symfony/Component/HttpKernel/Tests/Fixtures/KernelForTest.php

This file was deleted.

This file was deleted.

52 changes: 49 additions & 3 deletions src/Symfony/Component/HttpKernel/Tests/KernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest;
use Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTestWithLoadClassCache;
use Symfony\Component\HttpKernel\Tests\Fixtures\KernelWithoutBundles;
use Symfony\Component\HttpKernel\Tests\Fixtures\ResettableService;

Expand Down Expand Up @@ -247,7 +245,7 @@ public function testSerialize()
$env = 'test_env';
$debug = true;
$kernel = new KernelForTest($env, $debug);
$expected = "O:57:\"Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest\":2:{s:14:\"\0*\0environment\";s:8:\"test_env\";s:8:\"\0*\0debug\";b:1;}";
$expected = \sprintf("O:48:\"%s\":2:{s:14:\"\0*\0environment\";s:8:\"test_env\";s:8:\"\0*\0debug\";b:1;}", KernelForTest::class);
$this->assertEquals($expected, serialize($kernel));
}

Expand Down Expand Up @@ -661,3 +659,51 @@ public function process(ContainerBuilder $container): void
$container->setParameter('test.processed', true);
}
}

class KernelForTest extends Kernel
Copy link
Member

Choose a reason for hiding this comment

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

Don't we still have the issue as we still have the Test suffix here ?

Copy link
Member Author

Choose a reason for hiding this comment

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

That doesn't matter as the file is named KernelTest.php. Thus PHPUnit searches for a test named KernelTest.

Here is how it looks in practice without the changes with PHPUnit 11:

PHPUnit 11.3.5 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.9
Configuration: /Users/christianflothmann/symfony/phpunit.xml.dist

.............................................................   61 / 1293 (  4%)
.............................................................  122 / 1293 (  9%)
.............................................................  183 / 1293 ( 14%)
.............................................................  244 / 1293 ( 18%)
.............................................................  305 / 1293 ( 23%)
.............................................................  366 / 1293 ( 28%)
.............................................................  427 / 1293 ( 33%)
.............................................................  488 / 1293 ( 37%)
.............................................................  549 / 1293 ( 42%)
..................................................R..........  610 / 1293 ( 47%)
.............................................................  671 / 1293 ( 51%)
.............................................................  732 / 1293 ( 56%)
.............................................................  793 / 1293 ( 61%)
.............................................................  854 / 1293 ( 66%)
.............................................................  915 / 1293 ( 70%)
.............................................................  976 / 1293 ( 75%)
............................................................. 1037 / 1293 ( 80%)
............................................................. 1098 / 1293 ( 84%)
............................................................. 1159 / 1293 ( 89%)
............................................................. 1220 / 1293 ( 94%)
............................................................. 1281 / 1293 ( 99%)
............                                                  1293 / 1293 (100%)

Time: 00:05.271, Memory: 87.27 MB

There was 1 PHPUnit test runner warning:

1) Class Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest declared in /Users/christianflothmann/symfony/src/Symfony/Component/HttpKernel/Tests/Fixtures/KernelForTest.php does not extend PHPUnit\Framework\TestCase

--

There was 1 risky test:

1) Symfony\Component\HttpKernel\Tests\EventListener\RouterListenerTest::testWithBadRequest
Test code or tested code did not remove its own exception handlers

And this is how it is with the changes being done here:

PHPUnit 11.3.5 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.9
Configuration: /Users/christianflothmann/symfony/phpunit.xml.dist

.............................................................   61 / 1293 (  4%)
.............................................................  122 / 1293 (  9%)
.............................................................  183 / 1293 ( 14%)
.............................................................  244 / 1293 ( 18%)
.............................................................  305 / 1293 ( 23%)
.............................................................  366 / 1293 ( 28%)
.............................................................  427 / 1293 ( 33%)
.............................................................  488 / 1293 ( 37%)
.............................................................  549 / 1293 ( 42%)
..................................................R..........  610 / 1293 ( 47%)
.............................................................  671 / 1293 ( 51%)
.............................................................  732 / 1293 ( 56%)
.............................................................  793 / 1293 ( 61%)
.............................................................  854 / 1293 ( 66%)
.............................................................  915 / 1293 ( 70%)
.............................................................  976 / 1293 ( 75%)
............................................................. 1037 / 1293 ( 80%)
............................................................. 1098 / 1293 ( 84%)
............................................................. 1159 / 1293 ( 89%)
............................................................. 1220 / 1293 ( 94%)
............................................................. 1281 / 1293 ( 99%)
............                                                  1293 / 1293 (100%)

Time: 00:05.250, Memory: 87.27 MB

There was 1 risky test:

1) Symfony\Component\HttpKernel\Tests\EventListener\RouterListenerTest::testWithBadRequest
Test code or tested code did not remove its own exception handlers

{
public function __construct(string $environment, bool $debug, private readonly bool $fakeContainer = true)
{
parent::__construct($environment, $debug);
}

public function getBundleMap(): array
{
return [];
}

public function registerBundles(): iterable
{
return [];
}

public function registerContainerConfiguration(LoaderInterface $loader): void
{
}

public function isBooted(): bool
{
return $this->booted;
}

public function getProjectDir(): string
{
return __DIR__;
}

protected function initializeContainer(): void
{
if ($this->fakeContainer) {
$this->container = new ContainerBuilder();
} else {
parent::initializeContainer();
}
}
}

class KernelForTestWithLoadClassCache extends KernelForTest
{
public function doLoadClassCache(): void
{
}
}
0