Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Classes/Loader/ClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
21 changes: 21 additions & 0 deletions Tests/Functional/Loader/ClassLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down