gridAggregatorMock = $this->getMockBuilder(\Magento\Sales\Model\ResourceModel\GridInterface::class) ->getMockForAbstractClass(); $this->eventObserverMock = $this->getMockBuilder(\Magento\Framework\Event\Observer::class) ->disableOriginalConstructor() ->setMethods( [ 'getObject', 'getDataObject' ] ) ->getMock(); $this->salesModelMock = $this->getMockBuilder(\Magento\Sales\Model\AbstractModel::class) ->disableOriginalConstructor() ->setMethods( [ 'getId' ] ) ->getMockForAbstractClass(); $this->scopeConfigurationMock = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class) ->getMockForAbstractClass(); $this->unit = new \Magento\Sales\Observer\GridSyncInsertObserver( $this->gridAggregatorMock, $this->scopeConfigurationMock ); } public function testSyncInsert() { $this->eventObserverMock->expects($this->once()) ->method('getObject') ->willReturn($this->salesModelMock); $this->salesModelMock->expects($this->once()) ->method('getId') ->willReturn('sales-id-value'); $this->scopeConfigurationMock->expects($this->once()) ->method('getValue') ->with('dev/grid/async_indexing', 'default', null) ->willReturn(false); $this->gridAggregatorMock->expects($this->once()) ->method('refresh') ->with('sales-id-value'); $this->unit->execute($this->eventObserverMock); } public function testSyncInsertDisabled() { $this->scopeConfigurationMock->expects($this->once()) ->method('getValue') ->with('dev/grid/async_indexing', 'default', null) ->willReturn(true); $this->gridAggregatorMock->expects($this->never()) ->method('refresh') ->with('sales-id-value'); $this->unit->execute($this->eventObserverMock); } }