RelationTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Quote\Test\Unit\Model\Quote;
  7. use Magento\Quote\Model\Quote\Relation;
  8. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  9. class RelationTest extends \PHPUnit\Framework\TestCase
  10. {
  11. /**
  12. * @var Relation
  13. */
  14. private $model;
  15. /**
  16. * @var \Magento\Quote\Model\Quote|\PHPUnit_Framework_MockObject_MockObject
  17. */
  18. protected $quoteMock;
  19. /**
  20. * Mock class dependencies
  21. */
  22. protected function setUp()
  23. {
  24. $this->quoteMock = $this->createMock(\Magento\Quote\Model\Quote::class);
  25. $objectManager = new ObjectManager($this);
  26. $this->model = $objectManager->getObject(
  27. \Magento\Quote\Model\Quote\Relation::class
  28. );
  29. }
  30. /**
  31. * Test for processRelation
  32. */
  33. public function testProcessRelation()
  34. {
  35. $addressCollectionMock = $this->createMock(\Magento\Eav\Model\Entity\Collection\AbstractCollection::class);
  36. $this->quoteMock->expects($this->once())->method('addressCollectionWasSet')->willReturn(true);
  37. $this->quoteMock->expects($this->once())->method('getAddressesCollection')->willReturn($addressCollectionMock);
  38. $addressCollectionMock->expects($this->once())->method('save');
  39. $itemsCollectionMock = $this->createMock(\Magento\Eav\Model\Entity\Collection\AbstractCollection::class);
  40. $this->quoteMock->expects($this->once())->method('itemsCollectionWasSet')->willReturn(true);
  41. $this->quoteMock->expects($this->once())->method('getItemsCollection')->willReturn($itemsCollectionMock);
  42. $itemsCollectionMock->expects($this->once())->method('save');
  43. $paymentCollectionMock = $this->createMock(\Magento\Eav\Model\Entity\Collection\AbstractCollection::class);
  44. $this->quoteMock->expects($this->once())->method('paymentsCollectionWasSet')->willReturn(true);
  45. $this->quoteMock->expects($this->once())->method('getPaymentsCollection')->willReturn($paymentCollectionMock);
  46. $paymentCollectionMock->expects($this->once())->method('save');
  47. $paymentMock = $this->createMock(\Magento\Quote\Model\Quote\Payment::class);
  48. $this->quoteMock->expects($this->once())->method('currentPaymentWasSet')->willReturn(true);
  49. $this->quoteMock->expects($this->once())->method('getPayment')->willReturn($paymentMock);
  50. $paymentMock->expects($this->once())->method('save');
  51. $this->model->processRelation($this->quoteMock);
  52. }
  53. }