Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GridSyncRemoveObserverTest.php
Go to the documentation of this file.
1 <?php
8 
12 class GridSyncRemoveObserverTest extends \PHPUnit\Framework\TestCase
13 {
17  protected $unit;
18 
23 
27  protected $eventObserverMock;
28 
32  protected $salesModelMock;
33 
34  protected function setUp()
35  {
36  $this->gridAggregatorMock = $this->getMockBuilder(\Magento\Sales\Model\ResourceModel\GridInterface::class)
37  ->getMockForAbstractClass();
38  $this->eventObserverMock = $this->getMockBuilder(\Magento\Framework\Event\Observer::class)
39  ->disableOriginalConstructor()
40  ->setMethods(
41  [
42  'getObject',
43  'getDataObject'
44  ]
45  )
46  ->getMock();
47  $this->salesModelMock = $this->getMockBuilder(\Magento\Sales\Model\AbstractModel::class)
48  ->disableOriginalConstructor()
49  ->setMethods(
50  [
51  'getId'
52  ]
53  )
54  ->getMockForAbstractClass();
55  $this->unit = new \Magento\Sales\Observer\GridSyncRemoveObserver(
56  $this->gridAggregatorMock
57  );
58  }
59 
60  public function testSyncRemove()
61  {
62  $this->eventObserverMock->expects($this->once())
63  ->method('getDataObject')
64  ->willReturn($this->salesModelMock);
65  $this->salesModelMock->expects($this->once())
66  ->method('getId')
67  ->willReturn('sales-id-value');
68  $this->gridAggregatorMock->expects($this->once())
69  ->method('purge')
70  ->with('sales-id-value');
71  $this->unit->execute($this->eventObserverMock);
72  }
73 }