20 private $customerRegistry;
25 private $customerFactory;
41 $this->customerFactory = $this->getMockBuilder(\
Magento\
Customer\Model\CustomerFactory::class)
42 ->setMethods([
'create'])
43 ->disableOriginalConstructor()
48 [
'customerFactory' => $this->customerFactory]
50 $this->customer = $this->getMockBuilder(\
Magento\
Customer\Model\Customer::class)
51 ->disableOriginalConstructor()
69 $this->customer->expects($this->once())
71 ->with(self::CUSTOMER_ID)
72 ->will($this->returnValue($this->customer));
73 $this->customer->expects($this->any())
75 ->will($this->returnValue(self::CUSTOMER_ID));
76 $this->customerFactory->expects($this->once())
78 ->will($this->returnValue($this->customer));
79 $actual = $this->customerRegistry->retrieve(self::CUSTOMER_ID);
80 $this->assertEquals($this->customer, $actual);
81 $actualCached = $this->customerRegistry->retrieve(self::CUSTOMER_ID);
82 $this->assertEquals($this->customer, $actualCached);
87 $this->customer->expects($this->once())
88 ->method(
'loadByEmail')
89 ->with(self::CUSTOMER_EMAIL)
90 ->will($this->returnValue($this->customer));
91 $this->customer->expects($this->any())
93 ->will($this->returnValue(self::CUSTOMER_ID));
94 $this->customer->expects($this->any())
96 ->will($this->returnValue(self::CUSTOMER_EMAIL));
97 $this->customer->expects($this->any())
98 ->method(
'getWebsiteId')
99 ->will($this->returnValue(self::WEBSITE_ID));
100 $this->customer->expects($this->any())
102 ->will($this->returnValue($this->customer));
103 $this->customer->expects($this->any())
104 ->method(
'setWebsiteId')
105 ->will($this->returnValue($this->customer));
106 $this->customerFactory->expects($this->once())
108 ->will($this->returnValue($this->customer));
109 $actual = $this->customerRegistry->retrieveByEmail(self::CUSTOMER_EMAIL, self::WEBSITE_ID);
110 $this->assertEquals($this->customer, $actual);
111 $actualCached = $this->customerRegistry->retrieveByEmail(self::CUSTOMER_EMAIL, self::WEBSITE_ID);
112 $this->assertEquals($this->customer, $actualCached);
120 $this->customer->expects($this->once())
122 ->with(self::CUSTOMER_ID)
123 ->will($this->returnValue($this->customer));
124 $this->customer->expects($this->any())
126 ->will($this->returnValue(
null));
127 $this->customerFactory->expects($this->once())
129 ->will($this->returnValue($this->customer));
130 $this->customerRegistry->retrieve(self::CUSTOMER_ID);
138 $this->customer->expects($this->once())
139 ->method(
'loadByEmail')
140 ->with(self::CUSTOMER_EMAIL)
141 ->will($this->returnValue($this->customer));
142 $this->customer->expects($this->any())
144 ->will($this->returnValue(
null));
145 $this->customer->expects($this->any())
146 ->method(
'getWebsiteId')
147 ->will($this->returnValue(
null));
148 $this->customer->expects($this->any())
150 ->will($this->returnValue($this->customer));
151 $this->customer->expects($this->any())
152 ->method(
'setWebsiteId')
153 ->will($this->returnValue($this->customer));
154 $this->customerFactory->expects($this->once())
156 ->will($this->returnValue($this->customer));
157 $this->customerRegistry->retrieveByEmail(self::CUSTOMER_EMAIL, self::WEBSITE_ID);
162 $this->customer->expects($this->exactly(2))
164 ->with(self::CUSTOMER_ID)
165 ->will($this->returnValue($this->customer));
166 $this->customer->expects($this->any())
168 ->will($this->returnValue(self::CUSTOMER_ID));
169 $this->customerFactory->expects($this->exactly(2))
171 ->will($this->returnValue($this->customer));
172 $actual = $this->customerRegistry->retrieve(self::CUSTOMER_ID);
173 $this->assertEquals($this->customer, $actual);
174 $this->customerRegistry->remove(self::CUSTOMER_ID);
175 $actual = $this->customerRegistry->retrieve(self::CUSTOMER_ID);
176 $this->assertEquals($this->customer, $actual);
181 $this->customer->expects($this->exactly(2))
182 ->method(
'loadByEmail')
183 ->with(self::CUSTOMER_EMAIL)
184 ->will($this->returnValue($this->customer));
185 $this->customer->expects($this->any())
187 ->will($this->returnValue(self::CUSTOMER_ID));
188 $this->customer->expects($this->any())
190 ->will($this->returnValue(self::CUSTOMER_EMAIL));
191 $this->customer->expects($this->any())
192 ->method(
'getWebsiteId')
193 ->will($this->returnValue(self::WEBSITE_ID));
194 $this->customer->expects($this->any())
196 ->will($this->returnValue($this->customer));
197 $this->customer->expects($this->any())
198 ->method(
'setWebsiteId')
199 ->will($this->returnValue($this->customer));
200 $this->customerFactory->expects($this->exactly(2))
202 ->will($this->returnValue($this->customer));
203 $actual = $this->customerRegistry->retrieveByEmail(self::CUSTOMER_EMAIL, self::WEBSITE_ID);
204 $this->assertEquals($this->customer, $actual);
205 $this->customerRegistry->removeByEmail(self::CUSTOMER_EMAIL, self::WEBSITE_ID);
206 $actual = $this->customerRegistry->retrieveByEmail(self::CUSTOMER_EMAIL, self::WEBSITE_ID);
207 $this->assertEquals($this->customer, $actual);
testRetrieveByEmailException()