Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[FrameworkBundle] KernelTestCase resets internal state on tearDown#45414

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
nicolas-grekas merged 1 commit intosymfony:4.4fromcore23:reset-kernel-test
Feb 18, 2022

Conversation

@core23
Copy link
Contributor

@core23core23 commentedFeb 13, 2022
edited by nicolas-grekas
Loading

QA
Branch?4.4
Bug fix?yes
New feature?no
Deprecations?no
Tickets
LicenseMIT
Doc PR

When using theKernelTestCase for multiple different test kernels, theKernelTestCase::$class is not reseted after the test has finished. All other class variables are set to the initial state, so this change should be a bugfix.

@carsonbotcarsonbot added this to the6.1 milestoneFeb 13, 2022
@carsonbotcarsonbot changed the titleKernelTestCase resets internal state on tearDown[FrameworkBundle] KernelTestCase resets internal state on tearDownFeb 13, 2022
@nicolas-grekas
Copy link
Member

Did you experience any nasty side effect of this not being reset? Can you add a corresponding test case?

@core23
Copy link
ContributorAuthor

Did you experience any nasty side effect of this not being reset?

IMHO it should only have a minimum performance impact, because the name is resolved for every test:

if (null ===static::$class) {
static::$class =static::getKernelClass();
}

@nicolas-grekas
Copy link
Member

It could have a performance impact. That's why I'm asking. Why do you want to reset this property, if everything is fine when it is not reset?

@core23
Copy link
ContributorAuthor

I have some projects that will perform web tests with different kernel configuration. This can also be the case, if you provide a bundle with optional dependencies that will result in a slightly different service configuration.

At the moment, I have to manuell reset the::$class after every test with a localtearDown method. When I don't do this, the first (randomly selected) test will reserve the kernel class and all other test will fail, because they expect a different kernel class.

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

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

Thanks for the explanation, that's what I was missing.

@nicolas-grekas
Copy link
Member

Thank you@core23.

@nicolas-grekasnicolas-grekas merged commit3e9a6e3 intosymfony:4.4Feb 18, 2022
@core23core23 deleted the reset-kernel-test branchFebruary 18, 2022 09:54
This was referencedFeb 28, 2022
@alexander-schranz
Copy link
Contributor

This currently is now breaking in our cases the tests as we are defining thestatic::$class once at the top of the testcases:https://github.com/sulu/sulu/blob/b45f91ff36b468d200b254f894368cb0c3380671/src/Sulu/Bundle/MediaBundle/Tests/Functional/Media/Storage/S3StorageTest.php#L22

And now as it is set tonull on teardown all tests after the first tests are failing.

@mwalczak
Copy link

Can this be related?
After update 6.0.3->6.0.5

LogicException : Could not find service "test.service_container". Try updating the "framework.test" config to "true". /var/www/symfony/vendor/symfony/framework-bundle/Test/KernelTestCase.php:98 /var/www/symfony/tests/Controller/DefaultControllerTest.php:70  Caused by Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: The "kernel" service is synthetic, it needs to be set at boot time before it can be used.

I have already framework.test=true.

@nicolas-grekas
Copy link
Member

@mwalczak nope, see#45580 for this issue.

mwalczak reacted with thumbs up emoji

@alexander-schranz
Copy link
Contributor

alexander-schranz commentedMar 2, 2022
edited
Loading

I could workaround my issue by changing:

-    protected static $class = S3Kernel::class;+    protected static function getKernelClass(): string+    {+        return S3Kernel::class;+    }

EDIT: for prefer lowest tests I had to readd thestatic $class so now both is required in our case:

+    protected static $class = S3Kernel::class;++    protected static function getKernelClass(): string+    {+        return S3Kernel::class;+    }
nicolas-grekas reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@lyrixxlyrixxAwaiting requested review from lyrixx

@ycerutoycerutoAwaiting requested review from yceruto

@wouterjwouterjAwaiting requested review from wouterj

@chalasrchalasrAwaiting requested review from chalasr

@dunglasdunglasAwaiting requested review from dunglas

@xabbuhxabbuhAwaiting requested review from xabbuh

Assignees

No one assigned

Projects

None yet

Milestone

4.4

Development

Successfully merging this pull request may close these issues.

5 participants

@core23@nicolas-grekas@alexander-schranz@mwalczak@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp