9
9
10
10
use Magento \Customer \Block \Address \Renderer \RendererInterface as CustomerAddressBlockRenderer ;
11
11
use Magento \Customer \Model \Address \Config as CustomerAddressConfig ;
12
+ use Magento \Directory \Helper \Data ;
12
13
use Magento \Framework \App \Config \ScopeConfigInterface ;
13
14
use Magento \Framework \DataObject ;
14
15
use Magento \Framework \Event \ManagerInterface as EventManager ;
15
16
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
16
17
use Magento \Sales \Model \Order ;
17
18
use Magento \Sales \Model \Order \Address as OrderAddress ;
18
19
use Magento \Sales \Model \Order \Address \Renderer as OrderAddressRenderer ;
19
- use Magento \Store \Api \Data \StoreInterface ;
20
20
use Magento \Store \Model \StoreManagerInterface ;
21
+ use Magento \Store \Model \Store ;
21
22
use PHPUnit \Framework \MockObject \MockObject ;
22
23
use PHPUnit \Framework \TestCase ;
23
24
@@ -96,7 +97,7 @@ protected function setUp(): void
96
97
97
98
$ this ->storeConfigMock = $ this ->createMock (ScopeConfigInterface::class);
98
99
$ this ->storeManagerMck = $ this ->getMockBuilder (StoreManagerInterface::class)
99
- ->onlyMethods (['setCurrentStore ' ])
100
+ ->onlyMethods (['setCurrentStore ' , ' getStore ' ])
100
101
->disableOriginalConstructor ()
101
102
->getMockForAbstractClass ();
102
103
$ this ->objectManagerHelper = new ObjectManagerHelper ($ this );
@@ -106,7 +107,7 @@ protected function setUp(): void
106
107
'addressConfig ' => $ this ->customerAddressConfigMock ,
107
108
'eventManager ' => $ this ->eventManagerMock ,
108
109
'scopeConfig ' => $ this ->storeConfigMock ,
109
- 'storeManager ' => $ this ->storeManagerMck ,
110
+ 'storeManager ' => $ this ->storeManagerMck
110
111
]
111
112
);
112
113
}
@@ -131,7 +132,7 @@ public function testFormat(): void
131
132
->willReturn ($ addressData );
132
133
$ this ->storeConfigMock ->expects ($ this ->once ())
133
134
->method ('getValue ' )
134
- ->willReturn (1 );
135
+ ->willReturn (' 1 ' );
135
136
$ this ->customerAddressBlockRendererMock ->expects (static ::once ())
136
137
->method ('renderArray ' )
137
138
->with ($ addressData , null )
@@ -162,11 +163,34 @@ public function testFormatNoRenderer(): void
162
163
*/
163
164
private function setStoreExpectations (): void
164
165
{
165
- $ storeMock = $ this ->getMockBuilder (StoreInterface ::class)
166
+ $ originalStoreMock = $ this ->getMockBuilder (Store ::class)
166
167
->disableOriginalConstructor ()
167
168
->onlyMethods (['getId ' ])
168
169
->getMockForAbstractClass ();
170
+ $ storeMock = $ this ->getMockBuilder (Store::class)
171
+ ->disableOriginalConstructor ()
172
+ ->onlyMethods (['getId ' ])
173
+ ->getMockForAbstractClass ();
174
+
169
175
$ this ->orderMock ->expects (self ::once ())->method ('getStore ' )->willReturn ($ storeMock );
170
- $ this ->storeManagerMck ->expects (self ::once ())->method ('setCurrentStore ' )->with ($ storeMock );
176
+
177
+ // One call to setup the store from the order, and an other one to rollback to the original store value
178
+ $ expected = [$ storeMock , $ originalStoreMock ];
179
+ $ matcher = $ this ->exactly (count ($ expected ));
180
+ $ this ->storeManagerMck ->expects (self ::once ())->method ('getStore ' )->willReturn ($ originalStoreMock );
181
+ $ this ->storeManagerMck ->expects (self ::any ())->method ('setCurrentStore ' )->with (
182
+ $ this ->callback (function ($ store ) use ($ matcher , $ expected ) {
183
+ $ this ->assertEquals ($ store , $ expected [$ matcher ->getInvocationCount ()]);
184
+ return true ;
185
+ })
186
+ );
187
+
188
+ // One call to setup the store from the order, and an other one to rollback to the original store value
189
+ $ this ->customerAddressConfigMock ->expects (self ::any ())->method ('setStore ' )->with (
190
+ $ this ->callback (function ($ store ) use ($ matcher , $ expected ) {
191
+ $ this ->assertEquals ($ store , $ expected [$ matcher ->getInvocationCount ()]);
192
+ return true ;
193
+ })
194
+ );
171
195
}
172
196
}
0 commit comments