QuoteAddressTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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\ResourceModel\Quote;
  7. use Magento\Framework\Model\ResourceModel\Db\VersionControl\RelationComposite;
  8. /**
  9. * Class QuoteAddressTest
  10. */
  11. class QuoteAddressTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var \Magento\Quote\Model\ResourceModel\Quote\Address
  15. */
  16. protected $addressResource;
  17. /**
  18. * @var \Magento\Framework\App\ResourceConnection|\PHPUnit_Framework_MockObject_MockObject
  19. */
  20. protected $appResourceMock;
  21. /**
  22. * @var \Magento\Quote\Model\Quote\Address|\PHPUnit_Framework_MockObject_MockObject
  23. */
  24. protected $addressMock;
  25. /**
  26. * @var \Magento\Quote\Model\Quote|\PHPUnit_Framework_MockObject_MockObject
  27. */
  28. protected $quoteMock;
  29. /**
  30. * @var \Magento\Framework\DB\Adapter\AdapterInterface|\PHPUnit_Framework_MockObject_MockObject
  31. */
  32. protected $connectionMock;
  33. /**
  34. * @var \Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot|\PHPUnit_Framework_MockObject_MockObject
  35. */
  36. protected $entitySnapshotMock;
  37. /**
  38. * @var RelationComposite|\PHPUnit_Framework_MockObject_MockObject
  39. */
  40. protected $relationCompositeMock;
  41. /**
  42. * Init
  43. */
  44. protected function setUp()
  45. {
  46. $this->addressMock = $this->createPartialMock(
  47. \Magento\Quote\Model\Quote\Address::class,
  48. ['__wakeup', 'getOrderId', 'hasDataChanges', 'beforeSave', 'afterSave', 'validateBeforeSave', 'getOrder']
  49. );
  50. $this->quoteMock = $this->createPartialMock(\Magento\Quote\Model\Quote::class, ['__wakeup', 'getId']);
  51. $this->appResourceMock = $this->createMock(\Magento\Framework\App\ResourceConnection::class);
  52. $this->connectionMock = $this->createMock(\Magento\Framework\DB\Adapter\Pdo\Mysql::class);
  53. $this->entitySnapshotMock = $this->createMock(
  54. \Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot::class
  55. );
  56. $this->relationCompositeMock = $this->createMock(
  57. \Magento\Framework\Model\ResourceModel\Db\VersionControl\RelationComposite::class
  58. );
  59. $this->appResourceMock->expects($this->any())
  60. ->method('getConnection')
  61. ->will($this->returnValue($this->connectionMock));
  62. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  63. $this->connectionMock->expects($this->any())
  64. ->method('describeTable')
  65. ->will($this->returnValue([]));
  66. $this->connectionMock->expects($this->any())
  67. ->method('insert');
  68. $this->connectionMock->expects($this->any())
  69. ->method('lastInsertId');
  70. $this->addressResource = $objectManager->getObject(
  71. \Magento\Quote\Model\ResourceModel\Quote\Address::class,
  72. [
  73. 'resource' => $this->appResourceMock,
  74. 'entitySnapshot' => $this->entitySnapshotMock,
  75. 'entityRelationComposite' => $this->relationCompositeMock
  76. ]
  77. );
  78. }
  79. public function testSave()
  80. {
  81. $this->entitySnapshotMock->expects($this->once())
  82. ->method('isModified')
  83. ->with($this->addressMock)
  84. ->willReturn(true);
  85. $this->entitySnapshotMock->expects($this->once())
  86. ->method('registerSnapshot')
  87. ->with($this->addressMock);
  88. $this->relationCompositeMock->expects($this->once())
  89. ->method('processRelations')
  90. ->with($this->addressMock);
  91. $this->addressResource->save($this->addressMock);
  92. }
  93. }