Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GridPoolTest.php
Go to the documentation of this file.
1 <?php
8 
12 class GridPoolTest extends \PHPUnit\Framework\TestCase
13 {
17  protected $gridPool;
21  protected $orderGridMock;
25  protected $invoiceGridMock;
29  protected $shipmentGridMock;
37  protected $statementMock;
38 
42  protected function setUp()
43  {
44  $this->orderGridMock = $this->createMock(\Magento\Sales\Model\ResourceModel\Grid::class);
45  $this->invoiceGridMock = $this->createMock(\Magento\Sales\Model\ResourceModel\Grid::class);
46  $this->shipmentGridMock = $this->createMock(\Magento\Sales\Model\ResourceModel\Grid::class);
47  $this->creditmemoGridMock = $this->createMock(\Magento\Sales\Model\ResourceModel\Grid::class);
48  $this->statementMock = $this->getMockForAbstractClass(\Zend_Db_Statement_Interface::class);
49  $grids = [
50  'order_grid' => $this->orderGridMock,
51  'invoice_grid' => $this->invoiceGridMock,
52  'shipment_grid' => $this->shipmentGridMock,
53  'creditmemo_grid' => $this->creditmemoGridMock
54  ];
55  $this->gridPool = new \Magento\Sales\Model\ResourceModel\GridPool($grids);
56  }
57 
61  public function testRefreshByOrderId()
62  {
63  $orderId = 1;
64 
65  $this->orderGridMock->expects($this->once())
66  ->method('getOrderIdField')
67  ->willReturn('sfo.entity_id');
68  $this->invoiceGridMock->expects($this->once())
69  ->method('getOrderIdField')
70  ->willReturn('sfo.entity_id');
71  $this->shipmentGridMock->expects($this->once())
72  ->method('getOrderIdField')
73  ->willReturn('sfo.entity_id');
74  $this->creditmemoGridMock->expects($this->once())
75  ->method('getOrderIdField')
76  ->willReturn('sfo.entity_id');
77 
78  $this->orderGridMock->expects($this->once())
79  ->method('refresh')
80  ->with($this->equalTo($orderId), $this->equalTo('sfo.entity_id'))
81  ->will($this->returnValue($this->statementMock));
82  $this->invoiceGridMock->expects($this->once())
83  ->method('refresh')
84  ->with($this->equalTo($orderId), $this->equalTo('sfo.entity_id'))
85  ->will($this->returnValue($this->statementMock));
86  $this->shipmentGridMock->expects($this->once())
87  ->method('refresh')
88  ->with($this->equalTo($orderId), $this->equalTo('sfo.entity_id'))
89  ->will($this->returnValue($this->statementMock));
90  $this->creditmemoGridMock->expects($this->once())
91  ->method('refresh')
92  ->with($this->equalTo($orderId), $this->equalTo('sfo.entity_id'))
93  ->will($this->returnValue($this->statementMock));
94  $this->assertEquals($this->gridPool, $this->gridPool->refreshByOrderId($orderId));
95  }
96 }