Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ReplaceObjectManager.php
Go to the documentation of this file.
1 <?php
7 
10 
14 class ReplaceObjectManager extends \PHPUnit\Framework\BaseTestListener
15 {
28  public function startTest(\PHPUnit\Framework\Test $test)
29  {
30  if ($test instanceof \PHPUnit\Framework\TestCase) {
31  $objectManagerMock = $test->getMockBuilder(ObjectManagerInterface::class)
32  ->getMockForAbstractClass();
33  $createMockCallback = function ($type) use ($test) {
34  return $test->getMockBuilder($type)
35  ->disableOriginalConstructor()
36  ->getMockForAbstractClass();
37  };
38  $objectManagerMock->method('create')->willReturnCallback($createMockCallback);
39  $objectManagerMock->method('get')->willReturnCallback($createMockCallback);
40  ObjectManager::setInstance($objectManagerMock);
41  }
42  }
43 }
static setInstance(\Magento\Framework\ObjectManagerInterface $objectManager)
$type
Definition: item.phtml:13