2020use Sylius \Behat \Context \Api \Resources ;
2121use Sylius \Behat \Service \SharedStorageInterface ;
2222use Sylius \Component \Core \Model \ProductVariantInterface ;
23+ use Sylius \Component \Core \Repository \ProductVariantRepositoryInterface ;
2324use Symfony \Component \HttpFoundation \Request as HttpRequest ;
2425use Webmozart \Assert \Assert ;
2526
@@ -30,6 +31,7 @@ public function __construct(
3031 private readonly ApiClientInterface $ client ,
3132 private readonly RequestFactoryInterface $ requestFactory ,
3233 private readonly ResponseCheckerInterface $ responseChecker ,
34+ private readonly ProductVariantRepositoryInterface $ productVariantRepository ,
3335 ) {
3436 }
3537
@@ -116,8 +118,11 @@ public function iShouldHaveProductInBundledItems(ProductInterface $product): voi
116118 /**
117119 * @When I should have product variant :productVariant in bundled items
118120 */
119- public function iShouldHaveProductVariantInBundledItems (ProductVariantInterface $ productVariant ): void
121+ public function iShouldHaveProductVariantInBundledItems (string $ productVariant ): void
120122 {
123+ $ productVariant = $ this ->productVariantRepository ->findOneBy (['code ' => $ productVariant ]);
124+ Assert::isInstanceOf ($ productVariant , ProductVariantInterface::class);
125+
121126 $ response = $ this ->client ->show (Resources::ORDERS , $ this ->sharedStorage ->get ('cart_token ' ));
122127
123128 $ productBundleOrderItems = $ this ->responseChecker ->getValue ($ response , 'items ' )[0 ]['productBundleOrderItems ' ];
@@ -133,8 +138,11 @@ public function iShouldHaveProductVariantInBundledItems(ProductVariantInterface
133138 /**
134139 * @When I should not have product variant :productVariant in bundled items
135140 */
136- public function iShouldNotHaveProductVariantInBundledItems (ProductVariantInterface $ productVariant ): void
141+ public function iShouldNotHaveProductVariantInBundledItems (string $ productVariant ): void
137142 {
143+ $ productVariant = $ this ->productVariantRepository ->findOneBy (['code ' => $ productVariant ]);
144+ Assert::isInstanceOf ($ productVariant , ProductVariantInterface::class);
145+
138146 $ response = $ this ->client ->show (Resources::ORDERS , $ this ->sharedStorage ->get ('cart_token ' ));
139147
140148 $ productBundleOrderItems = $ this ->responseChecker ->getValue ($ response , 'items ' )[0 ]['productBundleOrderItems ' ];
0 commit comments