|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Tests\Loevgaard\SyliusBarcodePlugin\Behat\Context\Setup; |
| 6 | + |
| 7 | +use Behat\Behat\Context\Context; |
| 8 | +use Doctrine\Common\Persistence\ObjectManager; |
| 9 | +use Loevgaard\SyliusBarcodePlugin\Model\ProductVariantInterface; |
| 10 | +use Sylius\Component\Core\Model\ProductInterface; |
| 11 | +use Sylius\Component\Product\Resolver\ProductVariantResolverInterface; |
| 12 | + |
| 13 | +final class ProductContext implements Context |
| 14 | +{ |
| 15 | + /** @var ObjectManager */ |
| 16 | + private $objectManager; |
| 17 | + |
| 18 | + /** @var ProductVariantResolverInterface */ |
| 19 | + private $defaultVariantResolver; |
| 20 | + |
| 21 | + public function __construct( |
| 22 | + ObjectManager $objectManager, |
| 23 | + ProductVariantResolverInterface $defaultVariantResolver |
| 24 | + ) { |
| 25 | + $this->objectManager = $objectManager; |
| 26 | + $this->defaultVariantResolver = $defaultVariantResolver; |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * @Given :product has barcode :barcode |
| 31 | + * @Given /^(this product) has barcode "([^"]+)"$/ |
| 32 | + * @Given :product has no barcode |
| 33 | + * @Given /^(this product) has no barcode$/ |
| 34 | + */ |
| 35 | + public function productHasBarcode(ProductInterface $product, ?string $barcode = null) |
| 36 | + { |
| 37 | + /** @var ProductVariantInterface $productVariant */ |
| 38 | + $productVariant = $this->defaultVariantResolver->getVariant($product); |
| 39 | + $productVariant->setBarcode($barcode); |
| 40 | + |
| 41 | + $this->objectManager->flush(); |
| 42 | + } |
| 43 | +} |
0 commit comments