Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AddressRegistryTest.php
Go to the documentation of this file.
1 <?php
9 
10 class AddressRegistryTest extends \PHPUnit\Framework\TestCase
11 {
15  private $unit;
16 
20  private $addressFactory;
21 
22  protected function setUp()
23  {
24  $this->addressFactory = $this->getMockBuilder(\Magento\Customer\Model\AddressFactory::class)
25  ->disableOriginalConstructor()
26  ->setMethods(['create'])
27  ->getMock();
28  $this->unit = new \Magento\Customer\Model\AddressRegistry($this->addressFactory);
29  }
30 
31  public function testRetrieve()
32  {
33  $addressId = 1;
34  $address = $this->getMockBuilder(\Magento\Customer\Model\Address::class)
35  ->disableOriginalConstructor()
36  ->setMethods(['load', 'getId', '__wakeup'])
37  ->getMock();
38  $address->expects($this->once())
39  ->method('load')
40  ->with($addressId)
41  ->will($this->returnValue($address));
42  $address->expects($this->once())
43  ->method('getId')
44  ->will($this->returnValue($addressId));
45  $this->addressFactory->expects($this->once())
46  ->method('create')
47  ->will($this->returnValue($address));
48  $actual = $this->unit->retrieve($addressId);
49  $this->assertEquals($address, $actual);
50  $actualCached = $this->unit->retrieve($addressId);
51  $this->assertEquals($address, $actualCached);
52  }
53 
57  public function testRetrieveException()
58  {
59  $addressId = 1;
60  $address = $this->getMockBuilder(\Magento\Customer\Model\Address::class)
61  ->setMethods(['load', 'getId', '__wakeup'])
62  ->disableOriginalConstructor()
63  ->getMock();
64  $address->expects($this->once())
65  ->method('load')
66  ->with($addressId)
67  ->will($this->returnValue($address));
68  $address->expects($this->once())
69  ->method('getId')
70  ->will($this->returnValue(null));
71  $this->addressFactory->expects($this->once())
72  ->method('create')
73  ->will($this->returnValue($address));
74  $this->unit->retrieve($addressId);
75  }
76 
77  public function testRemove()
78  {
79  $addressId = 1;
80  $address = $this->getMockBuilder(\Magento\Customer\Model\Address::class)
81  ->disableOriginalConstructor()
82  ->setMethods(['load', 'getId', '__wakeup'])
83  ->getMock();
84  $address->expects($this->exactly(2))
85  ->method('load')
86  ->with($addressId)
87  ->will($this->returnValue($address));
88  $address->expects($this->exactly(2))
89  ->method('getId')
90  ->will($this->returnValue($addressId));
91  $this->addressFactory->expects($this->exactly(2))
92  ->method('create')
93  ->will($this->returnValue($address));
94  $actual = $this->unit->retrieve($addressId);
95  $this->assertEquals($address, $actual);
96  $this->unit->remove($addressId);
97  $actual = $this->unit->retrieve($addressId);
98  $this->assertEquals($address, $actual);
99  }
100 }
$address
Definition: customer.php:38