RelationTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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\Address;
  7. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  8. class RelationTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var \Magento\Framework\Model\AbstractModel | \PHPUnit_Framework_MockObject_MockObject
  12. */
  13. private $modelMock;
  14. /**
  15. * @var \Magento\Quote\Model\Quote\Address\Relation
  16. */
  17. private $relation;
  18. protected function setUp()
  19. {
  20. $objectManager = new ObjectManager($this);
  21. $this->modelMock = $this->createPartialMock(\Magento\Framework\Model\AbstractModel::class, [
  22. 'getItemsCollection',
  23. 'getShippingRatesCollection',
  24. 'itemsCollectionWasSet',
  25. 'shippingRatesCollectionWasSet'
  26. ]);
  27. $this->relation = $objectManager->getObject(\Magento\Quote\Model\Quote\Address\Relation::class, []);
  28. }
  29. public function testProcessRelation()
  30. {
  31. $itemsCollection = $this->createMock(
  32. \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection::class
  33. );
  34. $shippingRatesCollection = $this->createMock(
  35. \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection::class
  36. );
  37. $this->modelMock->expects($this->once())->method('itemsCollectionWasSet')->willReturn(true);
  38. $this->modelMock->expects($this->once())->method('getItemsCollection')->willReturn($itemsCollection);
  39. $this->modelMock->expects($this->once())->method('shippingRatesCollectionWasSet')->willReturn(true);
  40. $this->modelMock->expects($this->once())
  41. ->method('getShippingRatesCollection')
  42. ->willReturn($shippingRatesCollection);
  43. $itemsCollection->expects($this->once())->method('save');
  44. $shippingRatesCollection->expects($this->once())->method('save');
  45. $this->relation->processRelation($this->modelMock);
  46. }
  47. }