/** * @test */ public function checkAutoloaderSetsNamespacedClassnamesInExtAutoloadAreWrittenToCache() { $extKey = $this->createFakeExtension(); $extPath = PATH_site . 'typo3temp/' . $extKey . '/'; $pathSegment = 'Foo' . uniqid(); $fileName = 'Bar' . uniqid(); $autoloaderFile = $extPath . 'ext_autoload.php'; // A case sensitive key (FooBar) in ext_autoload file $namespacedClass = '\\Tx\\' . $extKey . '\\' . $pathSegment . '\\' . $fileName; $classFile = 'EXT:someExt/Classes/Foo/bar.php'; file_put_contents($autoloaderFile, '<?php' . LF . 'return ' . var_export(array($namespacedClass => $classFile), TRUE) . ';' . LF . '?>'); // Inject a dummy for the core_phpcode cache to force the autoloader // to re calculate the registry $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE); $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache')); $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache)); // Expect that the lower case version of the class name is written to cache $mockCache->expects($this->at(2))->method('set')->with($this->anything(), $this->stringContains(strtolower(addslashes($namespacedClass)), FALSE)); // Re-initialize autoloader registry to force it to recognize the new extension \TYPO3\CMS\Core\Core\ClassLoader::unregisterAutoloader(); \TYPO3\CMS\Core\Core\ClassLoader::registerAutoloader(); \TYPO3\CMS\Core\Core\ClassLoader::unregisterAutoloader(); }
/** * Things that should be performed to shut down the framework. * This method is called in all important scripts for a clean * shut down of the system. * * @return \TYPO3\CMS\Core\Core\Bootstrap * @internal This is not a public API method, do not use in own extensions */ public function shutdown() { if (PHP_VERSION_ID < 50307) { \TYPO3\CMS\Core\Compatibility\CompatbilityClassLoaderPhpBelow50307::unregisterAutoloader(); } else { \TYPO3\CMS\Core\Core\ClassLoader::unregisterAutoloader(); } return $this; }
/** * Unload TYPO3 autoloader and write any additional classes * found during the script run to the cache file. * * This method is called during shutdown of the framework. * * @return boolean TRUE in case of success */ public static function unregisterAutoloader() { return parent::unregisterAutoloader(); }