Skip to content

[TASK] Reset GeneralUtility::$container in UnitTestCase::tearDown() #673

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sbuerk
Copy link
Collaborator

@sbuerk sbuerk commented Apr 27, 2025

It could be possible that unit tests sets dependency injection
container calling GeneralUtility::setContainer() to provide
service instances or mocked service instances specific bound
to that test, keeping a dirty state for following unit tests.

Executing unit tests in other orders, only as a subset or for
example randomized can reveal these pullation and eventualy
wrong expectation for other tests. [1]

This change adds a automatic cleanup to the tearDown for
unit tests ensuring a clean state, because there isn't a
easy way to reset that within tests without using native
php reflection API. So do it in a general place.

It may be possible to let the specific test setting such
a container intance to fail with the recommendation to
refactor the test into a functional test, but is left out
for now.

[1] https://review.typo3.org/c/Packages/TYPO3.CMS/+/88839

Releases: main, 8, 7

It could be possible that unit tests sets dependency injection
container calling `GeneralUtility::setContainer()` to provide
service instances or mocked service instances specific bound
to that test, keeping a dirty state for following unit tests.

Executing unit tests in other orders, only as a subset or for
example randomized can reveal these pullation and eventualy
wrong expectation for other tests. [1]

This change adds a automatic cleanup to the tearDown for
unit tests ensuring a clean state, because there isn't a
easy way to reset that within tests without using native
php reflection API. So do it in a general place.

It may be possible to let the specific test setting such
a container intance to fail with the recommendation to
refactor the test into a functional test, but is left out
for now.

[1] https://review.typo3.org/c/Packages/TYPO3.CMS/+/88839

Releases: main, 8, 7
@sbuerk sbuerk changed the title [TASK] Reset GeneraulUtility::$container in UnitTestCase::tearDown() [TASK] Reset GeneralUtility::$container in UnitTestCase::tearDown() Apr 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant