GridAsyncInsertTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Test\Unit\Model;
  7. /**
  8. * Class GridAsyncInsertTest
  9. */
  10. class GridAsyncInsertTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var \Magento\Sales\Model\GridAsyncInsert
  14. */
  15. protected $unit;
  16. /**
  17. * @var \Magento\Sales\Model\ResourceModel\GridInterface|\PHPUnit_Framework_MockObject_MockObject
  18. */
  19. protected $gridAggregatorMock;
  20. /**
  21. * @var \Magento\Sales\Model\AbstractModel|\PHPUnit_Framework_MockObject_MockObject
  22. */
  23. protected $salesModelMock;
  24. /**
  25. * @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
  26. */
  27. protected $scopeConfigurationMock;
  28. protected function setUp()
  29. {
  30. $this->gridAggregatorMock = $this->getMockBuilder(\Magento\Sales\Model\ResourceModel\GridInterface::class)
  31. ->getMockForAbstractClass();
  32. $this->salesModelMock = $this->getMockBuilder(\Magento\Sales\Model\AbstractModel::class)
  33. ->disableOriginalConstructor()
  34. ->setMethods(
  35. [
  36. 'getId'
  37. ]
  38. )
  39. ->getMockForAbstractClass();
  40. $this->scopeConfigurationMock = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class)
  41. ->getMockForAbstractClass();
  42. $this->unit = new \Magento\Sales\Model\GridAsyncInsert(
  43. $this->gridAggregatorMock,
  44. $this->scopeConfigurationMock
  45. );
  46. }
  47. public function testAsyncInsert()
  48. {
  49. $this->scopeConfigurationMock->expects($this->once())
  50. ->method('getValue')
  51. ->with('dev/grid/async_indexing', 'default', null)
  52. ->willReturn(true);
  53. $this->gridAggregatorMock->expects($this->once())
  54. ->method('refreshBySchedule');
  55. $this->unit->asyncInsert();
  56. }
  57. public function testAsyncInsertDisabled()
  58. {
  59. $this->scopeConfigurationMock->expects($this->once())
  60. ->method('getValue')
  61. ->with('dev/grid/async_indexing', 'default', null)
  62. ->willReturn(false);
  63. $this->gridAggregatorMock->expects($this->never())
  64. ->method('refreshBySchedule');
  65. $this->unit->asyncInsert();
  66. }
  67. }