getObject(\Magento\Framework\View\Element\Template::class); $childBlockB = $objectManagerHelper->getObject(\Magento\Framework\View\Element\Template::class); $func = function ($blockName) use ($childBlockA, $childBlockB) { switch ($blockName) { case 'payment.method.a': return $childBlockA; case 'payment.method.b': return $childBlockB; } return null; }; $block = $this->createPartialMock(\Magento\Payment\Block\Form\Container::class, ['getChildBlock']); $block->expects($this->atLeastOnce())->method('getChildBlock')->will($this->returnCallback($func)); $template = 'any_template.phtml'; $this->assertNotEquals($template, $childBlockA->getTemplate()); $this->assertNotEquals($template, $childBlockB->getTemplate()); $block->setMethodFormTemplate('a', $template); $this->assertEquals($template, $childBlockA->getTemplate()); // Template is set to the block $this->assertNotEquals($template, $childBlockB->getTemplate()); // Template is not propagated to other blocks } }