CollectionUpdaterTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Test\Unit\Model\Grid;
  7. class CollectionUpdaterTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Sales\Model\Grid\CollectionUpdater
  11. */
  12. protected $collectionUpdater;
  13. /**
  14. * @var \PHPUnit_Framework_MockObject_MockObject
  15. */
  16. protected $registryMock;
  17. protected function setUp()
  18. {
  19. $this->registryMock = $this->createMock(\Magento\Framework\Registry::class);
  20. $this->collectionUpdater = new \Magento\Sales\Model\Grid\CollectionUpdater(
  21. $this->registryMock
  22. );
  23. }
  24. public function testUpdateIfOrderNotExists()
  25. {
  26. $collectionMock = $this->createMock(
  27. \Magento\Sales\Model\ResourceModel\Order\Payment\Transaction\Collection::class
  28. );
  29. $this->registryMock
  30. ->expects($this->once())
  31. ->method('registry')
  32. ->with('current_order')
  33. ->will($this->returnValue(false));
  34. $collectionMock->expects($this->never())->method('setOrderFilter');
  35. $collectionMock
  36. ->expects($this->once())
  37. ->method('addOrderInformation')
  38. ->with(['increment_id'])
  39. ->will($this->returnSelf());
  40. $this->assertEquals($collectionMock, $this->collectionUpdater->update($collectionMock));
  41. }
  42. public function testUpdateIfOrderExists()
  43. {
  44. $collectionMock = $this->createMock(
  45. \Magento\Sales\Model\ResourceModel\Order\Payment\Transaction\Collection::class
  46. );
  47. $orderMock = $this->createMock(\Magento\Sales\Model\Order::class);
  48. $this->registryMock
  49. ->expects($this->once())
  50. ->method('registry')
  51. ->with('current_order')
  52. ->will($this->returnValue($orderMock));
  53. $orderMock->expects($this->once())->method('getId')->will($this->returnValue('orderId'));
  54. $collectionMock->expects($this->once())->method('setOrderFilter')->with('orderId')->will($this->returnSelf());
  55. $collectionMock
  56. ->expects($this->once())
  57. ->method('addOrderInformation')
  58. ->with(['increment_id'])
  59. ->will($this->returnSelf());
  60. $this->assertEquals($collectionMock, $this->collectionUpdater->update($collectionMock));
  61. }
  62. }