Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CollectionUpdaterTest.php
Go to the documentation of this file.
1 <?php
8 
9 class CollectionUpdaterTest extends \PHPUnit\Framework\TestCase
10 {
14  protected $collectionUpdater;
15 
19  protected $registryMock;
20 
21  protected function setUp()
22  {
23  $this->registryMock = $this->createMock(\Magento\Framework\Registry::class);
24 
25  $this->collectionUpdater = new \Magento\Sales\Model\Grid\CollectionUpdater(
26  $this->registryMock
27  );
28  }
29 
30  public function testUpdateIfOrderNotExists()
31  {
32  $collectionMock = $this->createMock(
33  \Magento\Sales\Model\ResourceModel\Order\Payment\Transaction\Collection::class
34  );
35  $this->registryMock
36  ->expects($this->once())
37  ->method('registry')
38  ->with('current_order')
39  ->will($this->returnValue(false));
40  $collectionMock->expects($this->never())->method('setOrderFilter');
41  $collectionMock
42  ->expects($this->once())
43  ->method('addOrderInformation')
44  ->with(['increment_id'])
45  ->will($this->returnSelf());
46  $this->assertEquals($collectionMock, $this->collectionUpdater->update($collectionMock));
47  }
48 
49  public function testUpdateIfOrderExists()
50  {
51  $collectionMock = $this->createMock(
52  \Magento\Sales\Model\ResourceModel\Order\Payment\Transaction\Collection::class
53  );
54  $orderMock = $this->createMock(\Magento\Sales\Model\Order::class);
55  $this->registryMock
56  ->expects($this->once())
57  ->method('registry')
58  ->with('current_order')
59  ->will($this->returnValue($orderMock));
60  $orderMock->expects($this->once())->method('getId')->will($this->returnValue('orderId'));
61  $collectionMock->expects($this->once())->method('setOrderFilter')->with('orderId')->will($this->returnSelf());
62  $collectionMock
63  ->expects($this->once())
64  ->method('addOrderInformation')
65  ->with(['increment_id'])
66  ->will($this->returnSelf());
67  $this->assertEquals($collectionMock, $this->collectionUpdater->update($collectionMock));
68  }
69 }