Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
LayoutFactoryTest.php
Go to the documentation of this file.
1 <?php
8 
10 
11 class LayoutFactoryTest extends \PHPUnit\Framework\TestCase
12 {
14  protected $layoutFactory;
15 
18 
20  protected $objectManagerMock;
21 
22  protected function setUp()
23  {
24  $this->objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
25 
26  $this->objectManagerHelper = new ObjectManagerHelper($this);
27  $this->layoutFactory = $this->objectManagerHelper->getObject(
28  \Magento\Framework\View\LayoutFactory::class,
29  [
30  'objectManager' => $this->objectManagerMock
31  ]
32  );
33  }
34 
35  public function testCreate()
36  {
37  $instance = \Magento\Framework\View\LayoutInterface::class;
38  $layoutMock = $this->createMock($instance);
39  $data = ['some' => 'data'];
40  $this->objectManagerMock->expects($this->once())
41  ->method('create')
42  ->with($this->equalTo($instance), $this->equalTo($data))
43  ->will($this->returnValue($layoutMock));
44  $this->assertInstanceOf($instance, $this->layoutFactory->create($data));
45  }
46 
51  public function testCreateException()
52  {
53  $data = ['some' => 'other_data'];
54  $this->objectManagerMock->expects($this->once())
55  ->method('create')
56  ->will($this->returnValue(new \stdClass()));
57  $this->layoutFactory->create($data);
58  }
59 }