Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
QuoteAddressTest.php
Go to the documentation of this file.
1 <?php
7 
9 
13 class QuoteAddressTest extends \PHPUnit\Framework\TestCase
14 {
18  protected $addressResource;
19 
23  protected $appResourceMock;
24 
28  protected $addressMock;
29 
33  protected $quoteMock;
34 
38  protected $connectionMock;
39 
44 
49 
53  protected function setUp()
54  {
55  $this->addressMock = $this->createPartialMock(
56  \Magento\Quote\Model\Quote\Address::class,
57  ['__wakeup', 'getOrderId', 'hasDataChanges', 'beforeSave', 'afterSave', 'validateBeforeSave', 'getOrder']
58  );
59  $this->quoteMock = $this->createPartialMock(\Magento\Quote\Model\Quote::class, ['__wakeup', 'getId']);
60  $this->appResourceMock = $this->createMock(\Magento\Framework\App\ResourceConnection::class);
61  $this->connectionMock = $this->createMock(\Magento\Framework\DB\Adapter\Pdo\Mysql::class);
62  $this->entitySnapshotMock = $this->createMock(
63  \Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot::class
64  );
65  $this->relationCompositeMock = $this->createMock(
66  \Magento\Framework\Model\ResourceModel\Db\VersionControl\RelationComposite::class
67  );
68  $this->appResourceMock->expects($this->any())
69  ->method('getConnection')
70  ->will($this->returnValue($this->connectionMock));
71  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
72  $this->connectionMock->expects($this->any())
73  ->method('describeTable')
74  ->will($this->returnValue([]));
75  $this->connectionMock->expects($this->any())
76  ->method('insert');
77  $this->connectionMock->expects($this->any())
78  ->method('lastInsertId');
79  $this->addressResource = $objectManager->getObject(
80  \Magento\Quote\Model\ResourceModel\Quote\Address::class,
81  [
82  'resource' => $this->appResourceMock,
83  'entitySnapshot' => $this->entitySnapshotMock,
84  'entityRelationComposite' => $this->relationCompositeMock
85  ]
86  );
87  }
88 
89  public function testSave()
90  {
91  $this->entitySnapshotMock->expects($this->once())
92  ->method('isModified')
93  ->with($this->addressMock)
94  ->willReturn(true);
95  $this->entitySnapshotMock->expects($this->once())
96  ->method('registerSnapshot')
97  ->with($this->addressMock);
98  $this->relationCompositeMock->expects($this->once())
99  ->method('processRelations')
100  ->with($this->addressMock);
101  $this->addressResource->save($this->addressMock);
102  }
103 }
$objectManager
Definition: bootstrap.php:17