Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BlockFactoryTest.php
Go to the documentation of this file.
1 <?php
7 
8 class BlockFactoryTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $blockFactory;
14 
18  protected $objectManagerMock;
19 
20  protected function setUp()
21  {
22  $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
23 
24  $this->objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
25 
26  $this->blockFactory = $objectManagerHelper->getObject(
27  \Magento\Framework\View\Element\BlockFactory::class,
28  ['objectManager' => $this->objectManagerMock]
29  );
30  }
31 
32  public function testCreateBlock()
33  {
34  $className = \Magento\Framework\View\Element\Template::class;
35  $argumentsResult = ['arg1', 'arg2'];
36 
37  $templateMock = $this->getMockBuilder(\Magento\Framework\View\Element\Template::class)
38  ->disableOriginalConstructor()->getMock();
39 
40  $this->objectManagerMock->expects($this->once())
41  ->method('create')
42  ->with($className, $argumentsResult)
43  ->will($this->returnValue($templateMock));
44 
45  $this->assertInstanceOf(
46  \Magento\Framework\View\Element\BlockInterface::class,
47  $this->blockFactory->createBlock($className, $argumentsResult)
48  );
49  }
50 
54  public function testCreateBlockWithException()
55  {
56  $this->blockFactory->createBlock('invalid_class_name');
57  }
58 }
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31