18
18
use Magento \Quote \Model \Quote ;
19
19
use Magento \Quote \Model \Quote \Item as QuoteItem ;
20
20
use Magento \Store \Model \ScopeInterface ;
21
+ use Magento \Store \Model \StoreManagerInterface ;
21
22
use PHPUnit \Framework \MockObject \MockObject ;
22
23
use PHPUnit \Framework \TestCase ;
23
24
27
28
class IsAllowedGuestCheckoutObserverTest extends TestCase
28
29
{
29
30
private const XML_PATH_DISABLE_GUEST_CHECKOUT = 'catalog/downloadable/disable_guest_checkout ' ;
30
-
31
+
32
+ private const STUB_STORE_ID = 1 ;
33
+
31
34
/** @var IsAllowedGuestCheckoutObserver */
32
35
private $ isAllowedGuestCheckoutObserver ;
33
36
@@ -56,6 +59,11 @@ class IsAllowedGuestCheckoutObserverTest extends TestCase
56
59
*/
57
60
private $ storeMock ;
58
61
62
+ /**
63
+ * @var MockObject|StoreManagerInterface
64
+ */
65
+ private $ storeManagerMock ;
66
+
59
67
/**
60
68
* Sets up the fixture, for example, open a network connection.
61
69
* This method is called before a test is executed.
@@ -86,12 +94,20 @@ protected function setUp(): void
86
94
->disableOriginalConstructor ()
87
95
->getMock ();
88
96
89
- $ this ->isAllowedGuestCheckoutObserver = (new ObjectManagerHelper ($ this ))->getObject (
90
- IsAllowedGuestCheckoutObserver::class,
91
- [
92
- 'scopeConfig ' => $ this ->scopeConfigMock ,
93
- ]
94
- );
97
+ $ this ->storeManagerMock = $ this ->getMockForAbstractClass (StoreManagerInterface::class);
98
+ $ this ->storeManagerMock
99
+ ->method ('getStore ' )
100
+ ->with (self ::STUB_STORE_ID )
101
+ ->willReturn ($ this ->storeMock );
102
+
103
+ $ this ->isAllowedGuestCheckoutObserver = (new ObjectManagerHelper ($ this ))
104
+ ->getObject (
105
+ IsAllowedGuestCheckoutObserver::class,
106
+ [
107
+ 'scopeConfig ' => $ this ->scopeConfigMock ,
108
+ 'storeManager ' => $ this ->storeManagerMock
109
+ ]
110
+ );
95
111
}
96
112
97
113
/**
@@ -103,8 +119,6 @@ protected function setUp(): void
103
119
*/
104
120
public function testIsAllowedGuestCheckoutConfigSetToTrue ($ productType , $ isAllowed ): void
105
121
{
106
- $ storeId = 1 ;
107
-
108
122
if ($ isAllowed ) {
109
123
$ this ->resultMock ->expects ($ this ->at (0 ))
110
124
->method ('setIsAllowed ' )
@@ -144,7 +158,7 @@ public function testIsAllowedGuestCheckoutConfigSetToTrue($productType, $isAllow
144
158
145
159
$ this ->storeMock ->expects ($ this ->any ())
146
160
->method ('getId ' )
147
- ->willReturn ($ storeId );
161
+ ->willReturn (self :: STUB_STORE_ID );
148
162
149
163
$ this ->eventMock ->expects ($ this ->once ())
150
164
->method ('getResult ' )
@@ -159,7 +173,7 @@ public function testIsAllowedGuestCheckoutConfigSetToTrue($productType, $isAllow
159
173
->with (
160
174
self ::XML_PATH_DISABLE_GUEST_CHECKOUT ,
161
175
ScopeInterface::SCOPE_STORE ,
162
- $ storeId
176
+ self :: STUB_STORE_ID
163
177
)
164
178
->willReturn (true );
165
179
@@ -186,8 +200,6 @@ public function dataProviderForTestisAllowedGuestCheckoutConfigSetToTrue(): arra
186
200
187
201
public function testIsAllowedGuestCheckoutConfigSetToFalse (): void
188
202
{
189
- $ storeId = 1 ;
190
-
191
203
$ product = $ this ->getMockBuilder (Product::class)
192
204
->disableOriginalConstructor ()
193
205
->setMethods (['getTypeId ' ])
@@ -218,10 +230,10 @@ public function testIsAllowedGuestCheckoutConfigSetToFalse(): void
218
230
$ this ->eventMock ->expects ($ this ->once ())
219
231
->method ('getStore ' )
220
232
->willReturn ($ this ->storeMock );
221
-
233
+
222
234
$ this ->storeMock ->expects ($ this ->any ())
223
235
->method ('getId ' )
224
- ->willReturn ($ storeId );
236
+ ->willReturn (self :: STUB_STORE_ID );
225
237
226
238
$ this ->eventMock ->expects ($ this ->once ())
227
239
->method ('getResult ' )
@@ -236,7 +248,7 @@ public function testIsAllowedGuestCheckoutConfigSetToFalse(): void
236
248
->with (
237
249
self ::XML_PATH_DISABLE_GUEST_CHECKOUT ,
238
250
ScopeInterface::SCOPE_STORE ,
239
- $ storeId
251
+ self :: STUB_STORE_ID
240
252
)
241
253
->willReturn (false );
242
254
0 commit comments