LayoutFactoryTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
  8. class LayoutFactoryTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /** @var \Magento\Framework\View\LayoutFactory */
  11. protected $layoutFactory;
  12. /** @var ObjectManagerHelper */
  13. protected $objectManagerHelper;
  14. /** @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
  15. protected $objectManagerMock;
  16. protected function setUp()
  17. {
  18. $this->objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
  19. $this->objectManagerHelper = new ObjectManagerHelper($this);
  20. $this->layoutFactory = $this->objectManagerHelper->getObject(
  21. \Magento\Framework\View\LayoutFactory::class,
  22. [
  23. 'objectManager' => $this->objectManagerMock
  24. ]
  25. );
  26. }
  27. public function testCreate()
  28. {
  29. $instance = \Magento\Framework\View\LayoutInterface::class;
  30. $layoutMock = $this->createMock($instance);
  31. $data = ['some' => 'data'];
  32. $this->objectManagerMock->expects($this->once())
  33. ->method('create')
  34. ->with($this->equalTo($instance), $this->equalTo($data))
  35. ->will($this->returnValue($layoutMock));
  36. $this->assertInstanceOf($instance, $this->layoutFactory->create($data));
  37. }
  38. /**
  39. * @expectedException \InvalidArgumentException
  40. * @expectedExceptionMessage stdClass must be an instance of LayoutInterface.
  41. */
  42. public function testCreateException()
  43. {
  44. $data = ['some' => 'other_data'];
  45. $this->objectManagerMock->expects($this->once())
  46. ->method('create')
  47. ->will($this->returnValue(new \stdClass()));
  48. $this->layoutFactory->create($data);
  49. }
  50. }