TemplateEngineFactoryTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\View\Test\Unit;
  7. use \Magento\Framework\View\TemplateEngineFactory;
  8. class TemplateEngineFactoryTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /** @var \PHPUnit_Framework_MockObject_MockObject */
  11. protected $_objectManagerMock;
  12. /** @var \Magento\Framework\View\TemplateEngineFactory */
  13. protected $_factory;
  14. /**
  15. * Setup a factory to test with an mocked object manager.
  16. */
  17. protected function setUp()
  18. {
  19. $this->_objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
  20. $this->_factory = new TemplateEngineFactory(
  21. $this->_objectManagerMock,
  22. ['test' => \Fixture\Module\Model\TemplateEngine::class]
  23. );
  24. }
  25. public function testCreateKnownEngine()
  26. {
  27. $engine = $this->createMock(\Magento\Framework\View\TemplateEngineInterface::class);
  28. $this->_objectManagerMock->expects(
  29. $this->once()
  30. )->method(
  31. 'create'
  32. )->with(
  33. \Fixture\Module\Model\TemplateEngine::class
  34. )->will(
  35. $this->returnValue($engine)
  36. );
  37. $this->assertSame($engine, $this->_factory->create('test'));
  38. }
  39. /**
  40. * @expectedException \InvalidArgumentException
  41. * @expectedExceptionMessage Unknown template engine type: 'non_existing'
  42. */
  43. public function testCreateUnknownEngine()
  44. {
  45. $this->_objectManagerMock->expects($this->never())->method('create');
  46. $this->_factory->create('non_existing');
  47. }
  48. /**
  49. * @expectedException \UnexpectedValueException
  50. * @expectedExceptionMessage Fixture\Module\Model\TemplateEngine has to implement the template engine interface
  51. */
  52. public function testCreateInvalidEngine()
  53. {
  54. $this->_objectManagerMock->expects(
  55. $this->once()
  56. )->method(
  57. 'create'
  58. )->with(
  59. \Fixture\Module\Model\TemplateEngine::class
  60. )->will(
  61. $this->returnValue(new \stdClass())
  62. );
  63. $this->_factory->create('test');
  64. }
  65. }