Skip to content

Commit

Permalink
Refactor to merge two similar methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Prometee committed May 18, 2024
1 parent 0de0c7a commit 557fc96
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 23 deletions.
13 changes: 2 additions & 11 deletions tests/Behat/Context/Admin/ManagingOrdersContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,13 @@ public function tryToCreateNewOrderForNewCustomerWithoutEmail(): void

/**
* @When I add :product to this order
*/
public function addProductToThisOrder(ProductInterface $product): void
{
/** @var ProductVariantInterface $productVariant */
$productVariant = $product->getVariants()->first();
$this->orderCreateFormElement->addProduct($productVariant->getDescriptor());
}

/**
* @When I add :quantity of :product to this order
*/
public function addMultipleProductsToThisOrder(int $quantity, ProductInterface $product): void
public function addProductToThisOrder(ProductInterface $product, int $quantity = 1): void
{
/** @var ProductVariantInterface $productVariant */
$productVariant = $product->getVariants()->first();
$this->orderCreateFormElement->addMultipleProducts($productVariant->getDescriptor(), $quantity);
$this->orderCreateFormElement->addProductWithQuantity($productVariant->getDescriptor(), $quantity);
}

/**
Expand Down
10 changes: 1 addition & 9 deletions tests/Behat/Element/Admin/OrderCreateFormElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,7 @@ public function __construct(
parent::__construct($session, $parameters);
}

public function addProduct(string $productVariantDescriptor): void
{
$this->clickOnTabAndWait('Items');

$item = $this->addItemAndReturnIt();
$this->autoCompleteSelector->selectOption($this->getSession(), $item, $productVariantDescriptor);
}

public function addMultipleProducts(string $productVariantDescriptor, int $quantity): void
public function addProductWithQuantity(string $productVariantDescriptor, int $quantity): void
{
$this->clickOnTabAndWait('Items');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

interface OrderCreateFormElementInterface
{
public function addProduct(string $productVariantDescriptor): void;

public function addMultipleProducts(string $productVariantDescriptor, int $quantity): void;
public function addProductWithQuantity(string $productVariantDescriptor, int $quantity): void;

public function removeProduct(string $productVariantDescriptor): void;

Expand Down

0 comments on commit 557fc96

Please sign in to comment.