Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BlockPoolTest.php
Go to the documentation of this file.
1 <?php
8 
9 use \Magento\Framework\View\BlockPool;
10 
14 class BlockPoolTest extends \PHPUnit\Framework\TestCase
15 {
19  protected $blockPool;
20 
25  protected $blockFactory;
26 
27  protected function setUp()
28  {
29  $this->blockFactory = $this->getMockBuilder(\Magento\Framework\View\Element\BlockFactory::class)
30  ->disableOriginalConstructor()
31  ->setMethods(['createBlock'])
32  ->getMock();
33  $this->blockPool = new BlockPool($this->blockFactory);
34  }
35 
36  public function testAdd()
37  {
38  $blockName = 'testName';
39  $blockClass = \Magento\Framework\View\Test\Unit\BlockPoolTestBlock::class;
40  $arguments = ['key' => 'value'];
41 
42  $block = $this->createMock(\Magento\Framework\View\Test\Unit\BlockPoolTestBlock::class);
43 
44  $this->blockFactory->expects($this->atLeastOnce())
45  ->method('createBlock')
46  ->with($blockClass, $arguments)
47  ->will($this->returnValue($block));
48 
49  $this->assertEquals($this->blockPool, $this->blockPool->add($blockName, $blockClass, $arguments));
50 
51  $this->assertEquals([$blockName => $block], $this->blockPool->get());
52  $this->assertEquals($block, $this->blockPool->get($blockName));
53  $this->assertNull($this->blockPool->get('someWrongName'));
54  }
55 
60  public function testAddWithException()
61  {
62  $this->blockPool->add('BlockPoolTestBlock', 'NotExistingBlockClass');
63  }
64 }
$block
Definition: block.php:8
$arguments