#110100Functional tests trigger PHP warning on shutdown: Extbase ReflectionService::__destruct() writes cache too late and HashService reads missing $TYPO3_CONF_VARS
Description
Environment
- TYPO3 v13 (Composer-based install) - PHP 8.3.21 - PHPUnit 11.5.55 - Functional test context (Build/phpunit/FunctionalTests.xml)
*Problem*
Functional tests pass successfully, but when the PHP process shuts down, warnings are emitted:
PHP Warning: Undefined global variable $TYPO3_CONF_VARS in vendor/typo3/cms-core/Classes/Crypto/HashService.php on line 42 PHP Warning: Trying to access array offset on null in vendor/typo3/cms-core/Classes/Crypto/HashService.php on line 42
This happens after the test run is already finished, during PHP shutdown.
*How to reproduce*
Run a TYPO3 functional test suite, for example:
TYPO3_CONTEXT=Testing \
typo3DatabaseDriver=pdo_sqlite \
vendor/bin/phpunit -c Build/phpunit/FunctionalTests.xml <functional-test-file>
In my case, the tests complete successfully and only then the warnings appear.
*Observed behavior*
The warnings are triggered during shutdown from this call chain:
TYPO3\CMS\Extbase\Reflection\ReflectionService::__destruct() -> TYPO3\CMS\Core\Cache\Frontend\VariableFrontend->set() -> TYPO3\CMS\Core\Serializer\AuthenticatedMessageDeserializer->serialize() -> TYPO3\CMS\Core\Crypto\HashService->appendHmac() -> TYPO3\CMS\Core\Crypto\HashService->hmac()
Relevant code locations:
- vendor/typo3/cms-extbase/Classes/Reflection/ReflectionService.php:62-66 - vendor/typo3/cms-core/Classes/Cache/Frontend/VariableFrontend.php:63-66 - vendor/typo3/cms-core/Classes/Serializer/AuthenticatedMessageDeserializer.php:36-41 - vendor/typo3/cms-core/Classes/Crypto/HashService.php:42
ReflectionService::__destruct() tries to persist updated class schema cache during object destruction. That cache write is HMAC-signed, which causes HashService to access:
$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']
At that late shutdown stage, $GLOBALS['TYPO3_CONF_VARS'] is no longer reliably available, so the warning is triggered.
*Expected behavior*
No warnings should be emitted after a successful functional test run. Cache persistence should not rely on TYPO3 globals from late destructor/shutdown context, or the relevant instances should be cleaned up before global state becomes unavailable.
*Notes*
This does not appear to be caused by install tool session shutdown handling. The actual shutdown caller is TYPO3\CMS\Extbase\Reflection\ReflectionService::__destruct() .
It looks like the underlying issue is that functional test teardown/process shutdown still allows ReflectionService to flush cache from its destructor, but by then the runtime state needed by HashService is already partially gone.
Reviews 5
- main 96068[WIP][TASK] Reproduce broken Extbase class schema cache entry
- 12.4 94723[TASK] Prevent PHPUnit warnings on ReflectionService destructor
- 14.3 94598[TASK] Prevent PHPUnit warnings on ReflectionService destructor
- 13.4 94597[TASK] Prevent PHPUnit warnings on ReflectionService destructor
- main 94505[TASK] Prevent PHPUnit warnings on ReflectionService destructor