[PriceHistory][Behat] Add scenario improvements

This commit is contained in:
Rafikooo 2023-03-30 14:44:48 +02:00
parent 873226538c
commit 45c7410cda
No known key found for this signature in database
GPG key ID: 4A26D8327BC2442B
6 changed files with 26 additions and 18 deletions

View file

@ -9,12 +9,10 @@ Feature: Not seeing the lowest price for a product that has a taxon excluded on
And the store classifies its products as "Category"
And the "Category" taxon has children taxons "Groceries" and "Special offers"
And the "Groceries" taxon has child taxon "Vegetables"
And the store has a product "Broccoli" priced at "$20.00"
And it belongs to "Vegetables"
And the store has a product "Broccoli" priced at "$20.00" belonging to the "Vegetables" taxon
And this product's price changed to "$10.00" and original price changed to "$20.00"
And the store also has a product "Cauliflower" priced at "$25.00"
And it belongs to "Vegetables"
And it belongs to "Special offers"
And it belongs to "Vegetables" and "Special offers"
And this product's price changed to "$15.00" and original price changed to "$25.00"
And I am logged in as an administrator

View file

@ -24,7 +24,6 @@ use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\TaxonInterface;
use Sylius\Component\Currency\Model\CurrencyInterface;
use Sylius\Component\Locale\Model\LocaleInterface;
use Sylius\Component\Resource\Model\ResourceInterface;
use Webmozart\Assert\Assert;
final class ManagingChannelsContext implements Context

View file

@ -64,6 +64,7 @@ final class ProductContext implements Context
private SlugGeneratorInterface $slugGenerator,
private \ArrayAccess $minkParameters,
private MessageBusInterface $eventBus,
private ProductTaxonContext $productTaxonContext,
) {
}
@ -74,7 +75,7 @@ final class ProductContext implements Context
* @Given /^the store(?:| also) has a product "([^"]+)" priced at ("[^"]+")$/
* @Given /^the store(?:| also) has a product "([^"]+)" priced at ("[^"]+") in ("[^"]+" channel)$/
*/
public function storeHasAProductPricedAt($productName, int $price = 100, ChannelInterface $channel = null)
public function storeHasAProductPricedAt($productName, int $price = 100, ChannelInterface $channel = null): void
{
$product = $this->createProduct($productName, $price, $channel);
@ -88,10 +89,9 @@ final class ProductContext implements Context
string $productName,
int $price = 100,
TaxonInterface $taxon,
) {
$productTaxon = $this->createProductTaxon($taxon);
): void {
$product = $this->createProduct($productName, $price);
$product->addProductTaxon($taxon);
$this->productTaxonContext->itBelongsTo($product, $taxon);
$this->saveProduct($product);
}

View file

@ -43,6 +43,20 @@ final class ProductTaxonContext implements Context
$this->objectManager->flush();
}
/**
* @Given /^(it|this product) (belongs to "[^"]+" and "[^"]+")$/
*/
public function itBelongsToAnd(ProductInterface $product, iterable $taxons)
{
foreach ($taxons as $taxon) {
$productTaxon = $this->createProductTaxon($taxon, $product);
$product->addProductTaxon($productTaxon);
}
$this->objectManager->persist($product);
$this->objectManager->flush();
}
/**
* @Given the product :product has a main taxon :taxon
* @Given /^(this product) has a main (taxon "[^"]+")$/
@ -53,12 +67,7 @@ final class ProductTaxonContext implements Context
$this->objectManager->flush();
}
/**
* @param int|null $position
*
* @return ProductTaxonInterface
*/
private function createProductTaxon(TaxonInterface $taxon, ProductInterface $product, $position = null)
private function createProductTaxon(TaxonInterface $taxon, ProductInterface $product, ?int $position = null): ProductTaxonInterface
{
/** @var ProductTaxonInterface $productTaxon */
$productTaxon = $this->productTaxonFactory->createNew();

View file

@ -37,7 +37,7 @@ final class TaxonContext implements Context
* @Transform /^taxon "([^"]+)"$/
* @Transform :taxon
*/
public function getTaxonByName($name)
public function getTaxonByName(string $name)
{
$taxons = $this->taxonRepository->findByName($name, $this->locale);
@ -53,7 +53,7 @@ final class TaxonContext implements Context
/**
* @Transform /^taxon with "([^"]+)" code$/
*/
public function getTaxonByCode($code)
public function getTaxonByCode(string $code)
{
$taxon = $this->taxonRepository->findOneBy(['code' => $code]);
Assert::notNull($taxon, sprintf('Taxon with code "%s" does not exist.', $code));
@ -65,8 +65,9 @@ final class TaxonContext implements Context
* @Transform /^classified as "([^"]+)" or "([^"]+)"$/
* @Transform /^configured with "([^"]+)" and "([^"]+)"$/
* @Transform /^"([^"]+)" and "([^"]+)" taxons$/
* @Transform /^belongs to "([^"]+)" and "([^"]+)"/
*/
public function getTaxonsByNames(...$taxonNames): iterable
public function getTaxonsByNames(string ...$taxonNames): iterable
{
foreach ($taxonNames as $taxonName) {
yield $this->getTaxonByName($taxonName);

View file

@ -158,6 +158,7 @@
<argument type="service" id="sylius.generator.slug" />
<argument type="service" id="behat.mink.parameters" />
<argument type="service" id="sylius.event_bus" />
<argument type="service" id="sylius.behat.context.setup.product_taxon" />
</service>
<service id="sylius.behat.context.setup.product_association" class="Sylius\Behat\Context\Setup\ProductAssociationContext">