Skip to content

Commit

Permalink
[BUGFIX] Enforce classic mode in created TYPO3 entrypoint files
Browse files Browse the repository at this point in the history
`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
  • Loading branch information
sbuerk committed Dec 3, 2024
1 parent 4d4fc36 commit 4d0c36f
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions Classes/Core/Testbase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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),
Expand Down

0 comments on commit 4d0c36f

Please sign in to comment.