1313use Magento \CheckoutAgreements \Model \AgreementsProvider ;
1414use Magento \CheckoutAgreements \Model \Api \SearchCriteria \ActiveStoreAgreementsFilter ;
1515use Magento \CheckoutAgreements \Model \Checkout \Plugin \GuestValidation ;
16- use Magento \CheckoutAgreements \Model \EmulateStore ;
1716use Magento \Framework \Api \SearchCriteria ;
1817use Magento \Framework \App \Config \ScopeConfigInterface ;
1918use Magento \Quote \Api \CartRepositoryInterface ;
2019use Magento \Quote \Api \Data \AddressInterface ;
21- use Magento \Quote \Api \Data \PaymentExtension ;
2220use Magento \Quote \Api \Data \PaymentExtensionInterface ;
2321use Magento \Quote \Api \Data \PaymentInterface ;
22+ use Magento \Quote \Api \GuestCartRepositoryInterface ;
2423use Magento \Quote \Model \MaskedQuoteIdToQuoteId ;
2524use Magento \Quote \Model \Quote ;
25+ use Magento \Store \Model \App \Emulation ;
2626use Magento \Store \Model \ScopeInterface ;
2727use PHPUnit \Framework \MockObject \MockObject ;
2828use PHPUnit \Framework \MockObject \RuntimeException ;
@@ -94,9 +94,9 @@ class GuestValidationTest extends TestCase
9494 private CartRepositoryInterface |MockObject $ cartRepositoryMock ;
9595
9696 /**
97- * @var EmulateStore |MockObject
97+ * @var Emulation |MockObject
9898 */
99- private EmulateStore |MockObject $ emulateStoreMock ;
99+ private Emulation |MockObject $ storeEmulationMock ;
100100
101101 protected function setUp (): void
102102 {
@@ -114,29 +114,25 @@ protected function setUp(): void
114114 );
115115 $ this ->quoteMock = $ this ->createMock (Quote::class);
116116 $ this ->maskedQuoteIdToQuoteIdMock = $ this ->createMock (MaskedQuoteIdToQuoteId::class);
117- $ this ->cartRepositoryMock = $ this ->createMock (CartRepositoryInterface ::class);
118- $ this ->emulateStoreMock = $ this ->createMock (EmulateStore ::class);
117+ $ this ->cartRepositoryMock = $ this ->createMock (GuestCartRepositoryInterface ::class);
118+ $ this ->storeEmulationMock = $ this ->createMock (Emulation ::class);
119119
120120 $ storeId = 1 ;
121121 $ this ->quoteMock ->expects ($ this ->once ())
122122 ->method ('getStoreId ' )
123123 ->willReturn ($ storeId );
124- $ this ->maskedQuoteIdToQuoteIdMock ->expects ($ this ->once ())
125- ->method ('execute ' )
126- ->with ('0CQwCntNHR4yN9P5PUAzbxatvDvBXOce ' )
127- ->willReturn (1000 );
128124 $ this ->cartRepositoryMock ->expects ($ this ->once ())
129125 ->method ('get ' )
126+ ->with ('0CQwCntNHR4yN9P5PUAzbxatvDvBXOce ' )
130127 ->willReturn ($ this ->quoteMock );
131128
132129 $ this ->model = new GuestValidation (
133130 $ this ->agreementsValidatorMock ,
134131 $ this ->scopeConfigMock ,
135132 $ this ->checkoutAgreementsListMock ,
136133 $ this ->agreementsFilterMock ,
137- $ this ->maskedQuoteIdToQuoteIdMock ,
138134 $ this ->cartRepositoryMock ,
139- $ this ->emulateStoreMock
135+ $ this ->storeEmulationMock
140136 );
141137 }
142138
@@ -160,15 +156,15 @@ public function testBeforeSavePaymentInformationAndPlaceOrder()
160156 ->with ($ searchCriteriaMock )
161157 ->willReturn ([1 ]);
162158 $ this ->extensionAttributesMock ->expects ($ this ->once ())->method ('getAgreementIds ' )->willReturn ($ agreements );
159+ $ this ->agreementsValidatorMock ->expects ($ this ->once ())->method ('isValid ' )->with ($ agreements )->willReturn (true );
163160 $ this ->paymentMock ->expects (static ::atLeastOnce ())
164161 ->method ('getExtensionAttributes ' )
165162 ->willReturn ($ this ->extensionAttributesMock );
166- $ this ->emulateStoreMock ->expects ($ this ->once ())
167- ->method ('execute ' )
168- ->with ($ storeId , $ this ->callback (function ($ callback ) {
169- return is_callable ($ callback );
170- }))
171- ->willReturn (true );
163+ $ this ->storeEmulationMock ->expects ($ this ->once ())
164+ ->method ('startEnvironmentEmulation ' )
165+ ->with ($ storeId );
166+ $ this ->storeEmulationMock ->expects ($ this ->once ())
167+ ->method ('stopEnvironmentEmulation ' );
172168 $ this ->model ->beforeSavePaymentInformationAndPlaceOrder (
173169 $ this ->subjectMock ,
174170 $ cartId ,
@@ -185,12 +181,6 @@ public function testBeforeSavePaymentInformationAndPlaceOrderIfAgreementsNotVali
185181 $ cartId = '0CQwCntNHR4yN9P5PUAzbxatvDvBXOce ' ;
186182 $ email = 'email@example.com ' ;
187183 $ agreements = [1 , 2 , 3 ];
188- $ this ->emulateStoreMock ->expects ($ this ->once ())
189- ->method ('execute ' )
190- ->with ($ storeId , $ this ->callback (function ($ callback ) {
191- return is_callable ($ callback );
192- }))
193- ->willReturn (false );
194184 $ this ->scopeConfigMock
195185 ->expects ($ this ->once ())
196186 ->method ('isSetFlag ' )
@@ -205,9 +195,15 @@ public function testBeforeSavePaymentInformationAndPlaceOrderIfAgreementsNotVali
205195 ->with ($ searchCriteriaMock )
206196 ->willReturn ([1 ]);
207197 $ this ->extensionAttributesMock ->expects ($ this ->once ())->method ('getAgreementIds ' )->willReturn ($ agreements );
198+ $ this ->agreementsValidatorMock ->expects ($ this ->once ())->method ('isValid ' )->with ($ agreements )->willReturn (false );
208199 $ this ->paymentMock ->expects (static ::atLeastOnce ())
209200 ->method ('getExtensionAttributes ' )
210201 ->willReturn ($ this ->extensionAttributesMock );
202+ $ this ->storeEmulationMock ->expects ($ this ->once ())
203+ ->method ('startEnvironmentEmulation ' )
204+ ->with ($ storeId );
205+ $ this ->storeEmulationMock ->expects ($ this ->once ())
206+ ->method ('stopEnvironmentEmulation ' );
211207 $ this ->model ->beforeSavePaymentInformationAndPlaceOrder (
212208 $ this ->subjectMock ,
213209 $ cartId ,
0 commit comments