OrderGridUpdaterTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Signifyd\Test\Unit\Model\SalesOrderGrid;
  7. use Magento\Framework\App\Config\ScopeConfigInterface;
  8. use Magento\Sales\Model\ResourceModel\GridInterface;
  9. use Magento\Signifyd\Model\SalesOrderGrid\OrderGridUpdater;
  10. use PHPUnit_Framework_MockObject_MockObject as MockObject;
  11. class OrderGridUpdaterTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var GridInterface|MockObject
  15. */
  16. private $orderGrid;
  17. /**
  18. * @var ScopeConfigInterface|MockObject
  19. */
  20. private $globalConfig;
  21. /**
  22. * @var OrderGridUpdater
  23. */
  24. private $model;
  25. /**
  26. * Sets up testing class and dependency mocks.
  27. */
  28. protected function setUp()
  29. {
  30. $this->orderGrid = $this->getMockBuilder(GridInterface::class)
  31. ->getMockForAbstractClass();
  32. $this->globalConfig = $this->getMockBuilder(ScopeConfigInterface::class)
  33. ->getMockForAbstractClass();
  34. $this->model = new OrderGridUpdater($this->orderGrid, $this->globalConfig);
  35. }
  36. public function testUpdateInSyncMode()
  37. {
  38. $orderId = 1;
  39. $this->globalConfig->expects($this->once())
  40. ->method('getValue')
  41. ->with('dev/grid/async_indexing', 'default', null)
  42. ->willReturn(false);
  43. $this->orderGrid->expects($this->once())
  44. ->method('refresh')
  45. ->with($orderId);
  46. $this->model->update($orderId);
  47. }
  48. public function testUpdateInAsyncMode()
  49. {
  50. $orderId = 1;
  51. $this->globalConfig->expects($this->once())
  52. ->method('getValue')
  53. ->with('dev/grid/async_indexing', 'default', null)
  54. ->willReturn(true);
  55. $this->orderGrid->expects($this->never())
  56. ->method('refresh')
  57. ->with($orderId);
  58. $this->model->update($orderId);
  59. }
  60. }