From 4d0c36feaf8533c9491fbe79719d3c002b4321b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BCrk?= Date: Mon, 2 Dec 2024 15:30:32 +0100 Subject: [PATCH] [BUGFIX] Enforce classic mode in created TYPO3 entrypoint files `typo3/testing-framework` provides a extended `SystemEnvironmentBuilder` to ensure correct instance initialization as classic mode in different test context environment, allowing to manual set the composer mode flag despite having the PHP define from parent composer installation as source. `Testbase->setUpInstanceCoreLinks()` additionally provides TYPO3 entrypoints in form of index.php files, calling the basic bootstrap, based on template files from system extensions and modified to use the `typo3/testing-framework` `SystemEnvironmentBuilder` but does not enforce non-composer (classic) mode. This does not hurt within functional tests but codeception based accceptance instances misses the enforced classic mode which can lead to several issues, for example normalizedParams path calculation as basis for additional path or link generation. This change modifies the entrypoint creation code to reflect this need and forces non-composer mode. Releases: main, 8 --- Classes/Core/Testbase.php | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/Classes/Core/Testbase.php b/Classes/Core/Testbase.php index 9ac06333..eafdb12f 100644 --- a/Classes/Core/Testbase.php +++ b/Classes/Core/Testbase.php @@ -228,14 +228,26 @@ public function setUpInstanceCoreLinks( // of the testing framework. $installPhpExists = file_exists($instancePath . '/typo3/sysext/install/Resources/Private/Php/install.php'); $entryPointsToSet = [ - $instancePath . '/typo3/sysext/core/Resources/Private/Php/index.php' => $instancePath . '/index.php', + [ + 'source' => $instancePath . '/typo3/sysext/core/Resources/Private/Php/index.php', + 'target' => $instancePath . '/index.php', + 'pattern' => '/\\\\TYPO3\\\\CMS\\\\Core\\\\Core\\\\SystemEnvironmentBuilder::run\(\);/', + 'replacement' => '\TYPO3\TestingFramework\Core\SystemEnvironmentBuilder::run(0, 0, false);', + ], ]; if ($installPhpExists && in_array('install', $coreExtensions, true)) { - $entryPointsToSet[$instancePath . '/typo3/sysext/install/Resources/Private/Php/install.php'] = $instancePath . '/typo3/install.php'; + $entryPointsToSet[] = [ + 'source' => $instancePath . '/typo3/sysext/install/Resources/Private/Php/install.php', + 'target' => $instancePath . '/typo3/install.php', + 'pattern' => '/\\\\TYPO3\\\\CMS\\\\Core\\\\Core\\\\SystemEnvironmentBuilder::run\(1\);/', + 'replacement' => '\TYPO3\TestingFramework\Core\SystemEnvironmentBuilder::run(1, 0, false);', + ]; } $autoloadFile = dirname(__DIR__, 4) . '/autoload.php'; - foreach ($entryPointsToSet as $source => $target) { + foreach ($entryPointsToSet as $entryPointToSet) { + $source = $entryPointToSet['source']; + $target = $entryPointToSet['target']; if (($entryPointContent = file_get_contents($source)) === false) { throw new \UnexpectedValueException(sprintf('Source file (%s) was not found.', $source), 1636244753); } @@ -244,11 +256,9 @@ public function setUpInstanceCoreLinks( $this->findShortestPathCode($target, $autoloadFile), $entryPointContent ); - $entryPointContent = (string)preg_replace( - '/\\\\TYPO3\\\\CMS\\\\Core\\\\Core\\\\SystemEnvironmentBuilder::run\(/', - '\TYPO3\TestingFramework\Core\SystemEnvironmentBuilder::run(', - $entryPointContent - ); + $pattern = $entryPointToSet['pattern']; + $replacement = $entryPointToSet['replacement']; + $entryPointContent = (string)preg_replace($pattern, $replacement, $entryPointContent); if ($entryPointContent === '') { throw new \UnexpectedValueException( sprintf('Error while customizing the source file (%s).', $source),