diff --git a/Classes/Loader/ClassLoader.php b/Classes/Loader/ClassLoader.php index 8fe95de..ef67d5c 100644 --- a/Classes/Loader/ClassLoader.php +++ b/Classes/Loader/ClassLoader.php @@ -48,7 +48,12 @@ public function loadClass(string $className): bool $this->classCacheManager->build($cacheEntryIdentifier, $className); } - $this->classCache->requireOnce($cacheEntryIdentifier); + // A concurrent cache flush may remove the cache entry after has() returned true. Without + // the merged file, composer would silently load the base class without the extending classes. + if ($this->classCache->requireOnce($cacheEntryIdentifier) === false) { + $this->classCacheManager->build($cacheEntryIdentifier, $className); + $this->classCache->requireOnce($cacheEntryIdentifier); + } $return = true; } diff --git a/Tests/Functional/Loader/ClassLoaderTest.php b/Tests/Functional/Loader/ClassLoaderTest.php index 9a180b0..339abc1 100644 --- a/Tests/Functional/Loader/ClassLoaderTest.php +++ b/Tests/Functional/Loader/ClassLoaderTest.php @@ -40,6 +40,27 @@ public function loadClass(): void ->getMock(); $cacheMock->expects($this->once())->method('has')->willReturn(true); $cacheMock->expects($this->once())->method('requireOnce')->willReturn(true); + $classCacheManager->expects($this->never())->method('build'); + + $subject = new ClassLoader($cacheMock, $classCacheManager, $classRegister); + + $condition = $subject->loadClass('test'); + + self::assertTrue($condition); + } + + #[Test] + public function loadClassRebuildsCacheEntryRemovedByConcurrentFlush(): void + { + $classRegister = new ClassRegister(['test' => []]); + $classCacheManager = $this->createMock(ClassCacheManager::class); + $cacheBackend = $this->createMock(FileBackend::class); + $cacheMock = $this->getMockBuilder(PhpFrontend::class) + ->setConstructorArgs(['extender', $cacheBackend]) + ->getMock(); + $cacheMock->expects($this->once())->method('has')->willReturn(true); + $cacheMock->expects($this->exactly(2))->method('requireOnce')->willReturnOnConsecutiveCalls(false, true); + $classCacheManager->expects($this->once())->method('build')->with('test', 'test'); $subject = new ClassLoader($cacheMock, $classCacheManager, $classRegister);