Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractFactoryTestCase.php
Go to the documentation of this file.
1 <?php
7 
14 abstract class AbstractFactoryTestCase extends \PHPUnit\Framework\TestCase
15 {
19  protected $objectManager;
20 
24  protected $factoryClassName;
25 
29  protected $instanceClassName;
30 
34  protected $objectManagerMock;
35 
39  protected $factory;
40 
44  protected function setUp()
45  {
46  $this->objectManager = new Helper\ObjectManager($this);
47  $this->objectManagerMock = $this->getMockBuilder(\Magento\Framework\ObjectManagerInterface::class)
48  ->disableOriginalConstructor()
49  ->getMock();
50  $this->factory = $this->objectManager->getObject(
51  $this->factoryClassName,
52  ['objectManager' => $this->objectManagerMock]
53  );
54  }
55 
59  public function testCreate()
60  {
61  $instanceMock = $this->getMockBuilder($this->instanceClassName)
62  ->disableOriginalConstructor()
63  ->getMock();
64  $this->objectManagerMock->expects($this->once())
65  ->method('create')
66  ->will($this->returnValue($instanceMock));
67  $this->assertSame($instanceMock, $this->factory->create());
68  }
69 }