Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BuilderFactoryTest.php
Go to the documentation of this file.
1 <?php
8 
10 
11 class BuilderFactoryTest extends \PHPUnit\Framework\TestCase
12 {
17 
21  protected $objectManagerMock;
22 
26  protected $buildFactory;
27 
28  protected function setUp()
29  {
30  $this->objectManagerHelper = new ObjectManagerHelper($this);
31 
32  $this->objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
33 
34  $this->buildFactory = $this->objectManagerHelper->getObject(
35  \Magento\Framework\View\Layout\BuilderFactory::class,
36  [
37  'objectManager' => $this->objectManagerMock,
38  'typeMap' => [
39  [
40  'type' => 'invalid_type',
41  'class' => \Magento\Framework\View\Layout\BuilderFactory::class,
42  ],
43  ]
44  ]
45  );
46  }
47 
54  public function testCreate($type, $arguments, $layoutBuilderClass)
55  {
56  $layoutBuilderMock = $this->getMockBuilder(\Magento\Framework\View\Layout\Builder::class)
57  ->disableOriginalConstructor()
58  ->getMock();
59 
60  $this->objectManagerMock->expects($this->once())
61  ->method('create')
62  ->with($layoutBuilderClass, $arguments)
63  ->willReturn($layoutBuilderMock);
64 
65  $this->buildFactory->create($type, $arguments);
66  }
67 
71  public function createDataProvider()
72  {
73  return [
74  'layout_type' => [
75  'type' => \Magento\Framework\View\Layout\BuilderFactory::TYPE_LAYOUT,
76  'arguments' => ['key' => 'val'],
77  'layoutBuilderClass' => \Magento\Framework\View\Layout\Builder::class,
78  ]
79  ];
80  }
81 
85  public function testCreateInvalidData()
86  {
87  $this->buildFactory->create('some_wrong_type', []);
88  }
89 
94  {
95  $wrongClass = $this->getMockBuilder(\Magento\Framework\View\Layout\BuilderFactory::class)
96  ->disableOriginalConstructor()
97  ->getMock();
98 
99  $this->objectManagerMock->expects($this->once())
100  ->method('create')
101  ->willReturn($wrongClass);
102 
103  $this->buildFactory->create('invalid_type', []);
104  }
105 }
$type
Definition: item.phtml:13
$arguments