Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GridSyncInsertObserverTest.php
Go to the documentation of this file.
1 <?php
8 
12 class GridSyncInsertObserverTest extends \PHPUnit\Framework\TestCase
13 {
17  protected $unit;
18 
23 
27  protected $eventObserverMock;
28 
32  protected $salesModelMock;
33 
38 
39  protected function setUp()
40  {
41  $this->gridAggregatorMock = $this->getMockBuilder(\Magento\Sales\Model\ResourceModel\GridInterface::class)
42  ->getMockForAbstractClass();
43  $this->eventObserverMock = $this->getMockBuilder(\Magento\Framework\Event\Observer::class)
44  ->disableOriginalConstructor()
45  ->setMethods(
46  [
47  'getObject',
48  'getDataObject'
49  ]
50  )
51  ->getMock();
52  $this->salesModelMock = $this->getMockBuilder(\Magento\Sales\Model\AbstractModel::class)
53  ->disableOriginalConstructor()
54  ->setMethods(
55  [
56  'getId'
57  ]
58  )
59  ->getMockForAbstractClass();
60  $this->scopeConfigurationMock = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class)
61  ->getMockForAbstractClass();
62 
63  $this->unit = new \Magento\Sales\Observer\GridSyncInsertObserver(
64  $this->gridAggregatorMock,
65  $this->scopeConfigurationMock
66  );
67  }
68 
69  public function testSyncInsert()
70  {
71  $this->eventObserverMock->expects($this->once())
72  ->method('getObject')
73  ->willReturn($this->salesModelMock);
74  $this->salesModelMock->expects($this->once())
75  ->method('getId')
76  ->willReturn('sales-id-value');
77  $this->scopeConfigurationMock->expects($this->once())
78  ->method('getValue')
79  ->with('dev/grid/async_indexing', 'default', null)
80  ->willReturn(false);
81  $this->gridAggregatorMock->expects($this->once())
82  ->method('refresh')
83  ->with('sales-id-value');
84  $this->unit->execute($this->eventObserverMock);
85  }
86 
87  public function testSyncInsertDisabled()
88  {
89  $this->scopeConfigurationMock->expects($this->once())
90  ->method('getValue')
91  ->with('dev/grid/async_indexing', 'default', null)
92  ->willReturn(true);
93  $this->gridAggregatorMock->expects($this->never())
94  ->method('refresh')
95  ->with('sales-id-value');
96  $this->unit->execute($this->eventObserverMock);
97  }
98 }