@@ -170,7 +170,7 @@ private function setMockStockStateResultToQuoteItemOptions($quoteItem, $resultMo
170
170
* Tests quantity verifications for configurable product.
171
171
*
172
172
* @param int $quantity - quantity of configurable option.
173
- * @param string $errorMessage - expected error message.
173
+ * @param string $errorMessageRegexp - expected error message regexp .
174
174
* @return void
175
175
* @throws CouldNotSaveException
176
176
* @throws LocalizedException
@@ -179,7 +179,7 @@ private function setMockStockStateResultToQuoteItemOptions($quoteItem, $resultMo
179
179
* @magentoDbIsolation enabled
180
180
* @magentoAppIsolation enabled
181
181
*/
182
- public function testConfigurableWithOptions (int $ quantity , string $ errorMessage ): void
182
+ public function testConfigurableWithOptions (int $ quantity , string $ errorMessageRegexp ): void
183
183
{
184
184
/** @var ProductRepositoryInterface $productRepository */
185
185
$ productRepository = $ this ->objectManager ->create (ProductRepositoryInterface::class);
@@ -217,17 +217,16 @@ public function testConfigurableWithOptions(int $quantity, string $errorMessage)
217
217
]
218
218
);
219
219
220
- if (!empty ($ errorMessage )) {
221
- $ this ->expectException (LocalizedException::class);
222
- $ this ->expectExceptionMessage ($ errorMessage );
223
- }
224
-
225
- /** @var Quote $cart */
226
- $ cart = $ this ->objectManager ->create (CartInterface::class);
227
- $ result = $ cart ->addProduct ($ product , $ request );
220
+ try {
221
+ /** @var Quote $cart */
222
+ $ cart = $ this ->objectManager ->create (CartInterface::class);
223
+ $ result = $ cart ->addProduct ($ product , $ request );
228
224
229
- if (empty ($ errorMessage )) {
230
- self ::assertEquals ('Configurable Product ' , $ result ->getName ());
225
+ if (empty ($ errorMessageRegexp )) {
226
+ self ::assertEquals ('Configurable Product ' , $ result ->getName ());
227
+ }
228
+ } catch (LocalizedException $ e ) {
229
+ self ::assertEquals (1 , preg_match ($ errorMessageRegexp , $ e ->getMessage ()));
231
230
}
232
231
}
233
232
@@ -239,18 +238,20 @@ public function testConfigurableWithOptions(int $quantity, string $errorMessage)
239
238
*/
240
239
public function quantityDataProvider (): array
241
240
{
241
+ $ qtyRegexp = '/You can buy (this product|Configurable OptionOption 1) only in quantities of 500 at a time/ ' ;
242
+
242
243
return [
243
244
[
244
245
'quantity ' => 1 ,
245
- 'error ' => 'The fewest you may purchase is 500. '
246
+ 'error_regexp ' => '/ The fewest you may purchase is 500\./ '
246
247
],
247
248
[
248
249
'quantity ' => 501 ,
249
- 'error ' => ' You can buy Configurable OptionOption 1 only in quantities of 500 at a time '
250
+ 'error_regexp ' => $ qtyRegexp
250
251
],
251
252
[
252
253
'quantity ' => 1000 ,
253
- 'error ' => ''
254
+ 'error_regexp ' => ''
254
255
],
255
256
256
257
];
0 commit comments