StateTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Indexer\Test\Unit\Model\Indexer;
  7. class StateTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Indexer\Model\Indexer\State
  11. */
  12. protected $model;
  13. /**
  14. * @var \Magento\Framework\Model\Context|\PHPUnit_Framework_MockObject_MockObject
  15. */
  16. protected $_contextMock;
  17. /**
  18. * @var \Magento\Framework\Registry|\PHPUnit_Framework_MockObject_MockObject
  19. */
  20. protected $_registryMock;
  21. /**
  22. * @var \Magento\Indexer\Model\ResourceModel\Indexer\State|\PHPUnit_Framework_MockObject_MockObject
  23. */
  24. protected $_resourceMock;
  25. /**
  26. * @var \Magento\Indexer\Model\ResourceModel\Indexer\State\Collection|\PHPUnit_Framework_MockObject_MockObject
  27. */
  28. protected $_resourceCollectionMock;
  29. protected function setUp()
  30. {
  31. $this->_contextMock = $this->createPartialMock(\Magento\Framework\Model\Context::class, ['getEventDispatcher']);
  32. $eventManagerMock = $this->createMock(\Magento\Framework\Event\ManagerInterface::class);
  33. $this->_contextMock->expects($this->any())->method('getEventDispatcher')->willReturn($eventManagerMock);
  34. $this->_registryMock = $this->createMock(\Magento\Framework\Registry::class);
  35. $this->_resourceMock = $this->createMock(\Magento\Indexer\Model\ResourceModel\Indexer\State::class);
  36. $this->_resourceCollectionMock = $this->createMock(
  37. \Magento\Indexer\Model\ResourceModel\Indexer\State\Collection::class
  38. );
  39. $this->model = new \Magento\Indexer\Model\Indexer\State(
  40. $this->_contextMock,
  41. $this->_registryMock,
  42. $this->_resourceMock,
  43. $this->_resourceCollectionMock
  44. );
  45. }
  46. public function testLoadByIndexer()
  47. {
  48. $indexerId = 'indexer_id';
  49. $this->_resourceMock->expects($this->once())->method('load')->with($this->model, $indexerId)->willReturnSelf();
  50. $this->model->loadByIndexer($indexerId);
  51. $this->assertEquals($indexerId, $this->model->getIndexerId());
  52. }
  53. public function testBeforeSave()
  54. {
  55. $this->assertEquals(null, $this->model->getUpdated());
  56. $this->model->beforeSave();
  57. $this->assertTrue(($this->model->getUpdated() != null));
  58. }
  59. public function testSetStatus()
  60. {
  61. $setData = 'data';
  62. $this->model->setStatus($setData);
  63. $this->assertEquals($setData, $this->model->getStatus());
  64. }
  65. }