Skip to content

Commit 99ba838

Browse files
PHPUnit 12: Fix RendererListTest - use createMock for LayoutInterface
Fixed fatal error: 'Class MockObject_LayoutInterface contains 32 abstract methods' LayoutInterface has 32 abstract methods. Using getMockBuilder()->onlyMethods() with only 2 methods ['getBlock', 'getChildName'] causes a fatal error in PHPUnit 12. Solution: Replace with createMock(LayoutInterface::class) which automatically handles all 32 interface methods. The methods we need (getBlock, getChildName) can be configured on the mock created by createMock(). This is the same pattern as AdapterInterface (94 methods) and other large interfaces: For interfaces with 30+ methods, ALWAYS use createMock() or createStub(), never onlyMethods() with a partial list.
1 parent 9fabeb8 commit 99ba838

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

lib/internal/Magento/Framework/View/Test/Unit/Element/RendererListTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ protected function setUp(): void
5050
['setRenderedBlock', 'getTemplate', 'setTemplate']
5151
);
5252

53-
$this->layoutMock = $this->getMockBuilder(LayoutInterface::class)
54-
->onlyMethods(['getBlock', 'getChildName'])
55-
->getMock();
53+
// LayoutInterface has 32 abstract methods - use createMock() instead of onlyMethods()
54+
$this->layoutMock = $this->createMock(LayoutInterface::class);
5655

5756
$this->layoutMock->expects($this->any())
5857
->method('getBlock')

0 commit comments

Comments
 (0)