From 5263197e5c02a3b8cd0392ab1c0915818e77782e Mon Sep 17 00:00:00 2001 From: Benjamin Franzke <bfr@qbus.de> Date: Fri, 6 Dec 2019 21:26:45 +0100 Subject: [PATCH] [TASK] Do not set GeneralUtility::$container in unit tests The GeneralUtility $container instance should only be set/used in functional tests as we a) can not reset the instance (which means other unit tests are affected) and b) should mock/inject dependencies in unit tests. TreeDataProviderFactoryTest is therefore changed to to use GeneralUtility::addInstance() (which is intended for unit tests) instead of GeneralUtility::setContainer(). Change-Id: I9fc0e76077cc1cc2a6935d025b97309efc315f4f Releases: master Resolves: #89890 Related: #89733 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/62573 Tested-by: TYPO3com <noreply@typo3.com> Tested-by: Susanne Moog <look@susi.dev> Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de> Reviewed-by: Susanne Moog <look@susi.dev> Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de> --- .../TableConfiguration/TreeDataProviderFactoryTest.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/typo3/sysext/core/Tests/Unit/Tree/TableConfiguration/TreeDataProviderFactoryTest.php b/typo3/sysext/core/Tests/Unit/Tree/TableConfiguration/TreeDataProviderFactoryTest.php index 880699637c01..bdc1f0a53139 100644 --- a/typo3/sysext/core/Tests/Unit/Tree/TableConfiguration/TreeDataProviderFactoryTest.php +++ b/typo3/sysext/core/Tests/Unit/Tree/TableConfiguration/TreeDataProviderFactoryTest.php @@ -15,7 +15,6 @@ namespace TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration; * The TYPO3 project - inspiring people to share! */ -use TYPO3\CMS\Core\DependencyInjection\FailsafeContainer; use TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration\Fixtures\TreeDataProviderFixture; use TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration\Fixtures\TreeDataProviderWithConfigurationFixture; use TYPO3\CMS\Core\Tree\TableConfiguration\DatabaseTreeDataProvider; @@ -93,10 +92,10 @@ class TreeDataProviderFactoryTest extends UnitTestCase */ public function factoryThrowsExceptionIfInvalidConfigurationIsGiven(array $tcaConfiguration, int $expectedExceptionCode): void { - $treeDataProvider = $this->prophesize(DatabaseTreeDataProvider::class); - GeneralUtility::setContainer(new FailsafeContainer([], [ - DatabaseTreeDataProvider::class => $treeDataProvider->reveal() - ])); + if ($tcaConfiguration['internal_type'] === 'db' && is_array($tcaConfiguration['treeConfig'] ?? null)) { + $treeDataProvider = $this->prophesize(DatabaseTreeDataProvider::class); + GeneralUtility::addInstance(DatabaseTreeDataProvider::class, $treeDataProvider->reveal()); + } $this->expectException(\InvalidArgumentException::class); $this->expectExceptionCode($expectedExceptionCode); -- GitLab