ActionFactoryTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Indexer\Test\Unit;
  7. class ActionFactoryTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Framework\Indexer\ActionFactory|\PHPUnit_Framework_MockObject_MockObject
  11. */
  12. protected $model;
  13. /**
  14. * @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
  15. */
  16. protected $objectManagerMock;
  17. protected function setUp()
  18. {
  19. $this->objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
  20. $this->model = new \Magento\Framework\Indexer\ActionFactory($this->objectManagerMock);
  21. }
  22. /**
  23. * @expectedException \InvalidArgumentException
  24. * @expectedExceptionMessage NotAction doesn't implement \Magento\Framework\Indexer\ActionInterface
  25. */
  26. public function testGetWithException()
  27. {
  28. $notActionInterfaceMock = $this->getMockBuilder('NotAction')->getMock();
  29. $this->objectManagerMock->expects($this->once())
  30. ->method('create')
  31. ->with('NotAction', [])
  32. ->willReturn($notActionInterfaceMock);
  33. $this->model->create('NotAction');
  34. }
  35. public function testCreate()
  36. {
  37. $actionInterfaceMock = $this->getMockForAbstractClass(
  38. \Magento\Framework\Indexer\ActionInterface::class,
  39. [],
  40. '',
  41. false
  42. );
  43. $this->objectManagerMock->expects($this->once())
  44. ->method('create')
  45. ->with(\Magento\Framework\Indexer\ActionInterface::class, [])
  46. ->willReturn($actionInterfaceMock);
  47. $this->model->create(\Magento\Framework\Indexer\ActionInterface::class);
  48. $this->assertInstanceOf(\Magento\Framework\Indexer\ActionInterface::class, $actionInterfaceMock);
  49. }
  50. }