Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TemplateEngineFactoryTest.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Framework\View\TemplateEngineFactory;
9 
10 class TemplateEngineFactoryTest extends \PHPUnit\Framework\TestCase
11 {
14 
16  protected $_factory;
17 
21  protected function setUp()
22  {
23  $this->_objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
24  $this->_factory = new TemplateEngineFactory(
25  $this->_objectManagerMock,
26  ['test' => \Fixture\Module\Model\TemplateEngine::class]
27  );
28  }
29 
30  public function testCreateKnownEngine()
31  {
32  $engine = $this->createMock(\Magento\Framework\View\TemplateEngineInterface::class);
33  $this->_objectManagerMock->expects(
34  $this->once()
35  )->method(
36  'create'
37  )->with(
38  \Fixture\Module\Model\TemplateEngine::class
39  )->will(
40  $this->returnValue($engine)
41  );
42  $this->assertSame($engine, $this->_factory->create('test'));
43  }
44 
49  public function testCreateUnknownEngine()
50  {
51  $this->_objectManagerMock->expects($this->never())->method('create');
52  $this->_factory->create('non_existing');
53  }
54 
59  public function testCreateInvalidEngine()
60  {
61  $this->_objectManagerMock->expects(
62  $this->once()
63  )->method(
64  'create'
65  )->with(
66  \Fixture\Module\Model\TemplateEngine::class
67  )->will(
68  $this->returnValue(new \stdClass())
69  );
70  $this->_factory->create('test');
71  }
72 }