Skip to content

Commit

Permalink
changed steps that check name and province to use one private function
Browse files Browse the repository at this point in the history
  • Loading branch information
arti0090 committed Sep 17, 2020
1 parent 29497b7 commit 6a54f31
Showing 1 changed file with 39 additions and 61 deletions.
100 changes: 39 additions & 61 deletions src/Sylius/Behat/Context/Api/Shop/CheckoutContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -618,74 +618,22 @@ public function iShouldNotSeeTheThankYouPage(): void
}

/**
* @Then address to :fullName should be used for both shipping and billing of my order
* @Then address to :fullName should be used for both :addressType1 and :addressType2 of my order
* @Then my order's :addressType address should be to :fullName
*/
public function iShouldSeeThisShippingAddressAsShippingAndBillingAddress($fullName): void
public function iShouldSeeThisShippingAddressAsShippingAndBillingAddress(string $fullName, string ...$addressTypes): void
{
$this->iShouldSeeThisShippingAddressAsShippingAddress($fullName);
$this->iShouldSeeThisBillingAddressAsBillingAddress($fullName);
}

/**
* @Then my order's shipping address should be to :fullName
*/
public function iShouldSeeThisShippingAddressAsShippingAddress(string $fullName): void
{
/** @var Response $response */
$response = $this->client->getResponse();
$name = explode(" ",$fullName);

Assert::same($this->responseChecker->getResponseContent($response)['shippingAddress']['firstName'],
$name[0]
);
Assert::same(
$this->responseChecker->getResponseContent($response)['shippingAddress']['lastName'],
$name[1]
);
}

/**
* @Then my order's billing address should be to :fullName
*/
public function iShouldSeeThisBillingAddressAsBillingAddress(string $fullName): void
{
/** @var Response $response */
$response = $this->client->getResponse();
$name = explode(" ",$fullName);

Assert::same($this->responseChecker->getResponseContent($response)['billingAddress']['firstName'],
$name[0]
);
Assert::same(
$this->responseChecker->getResponseContent($response)['billingAddress']['lastName'],
$name[1]
);
}

/**
* @Then I should see :provinceName in the shipping address
*/
public function iShouldSeeInTheShippingAddress(string $provinceName): void
{
/** @var Response $response */
$response = $this->client->getResponse();
Assert::same(
$this->responseChecker->getResponseContent($response)['shippingAddress']['provinceName'],
$provinceName
);
foreach($addressTypes as $addressType){
$this->hasFullNameInAddress($fullName, $addressType);
}
}

/**
* @Then I should see :provinceName in the billing address
* @Then I should see :provinceName in the :addressType address
*/
public function iShouldSeeInTheBillingAddress(string $provinceName): void
public function iShouldSeeInTheBillingAddress(string $provinceName, string $addressType): void
{
/** @var Response $response */
$response = $this->client->getResponse();
Assert::same(
$this->responseChecker->getResponseContent($response)['billingAddress']['provinceName'],
$provinceName
);
$this->hasProvinceNameInAddress($provinceName, $addressType);
}

private function isViolationWithMessageInResponse(Response $response, string $message): bool
Expand Down Expand Up @@ -842,4 +790,34 @@ private function getViolation(array $violations, string $element): array
{
return $violations[array_search($element, array_column($violations, 'propertyPath'))];
}

private function hasFullNameInAddress(string $fullName, string $addressType): void
{
/** @var Response $response */
$response = $this->client->getResponse();
$name = explode(' ', $fullName);
$addressType .= 'Address';

Assert::same($this->responseChecker->getResponseContent($response)[$addressType]
['firstName'],
$name[0]
);
Assert::same(
$this->responseChecker->getResponseContent($response)[$addressType]
['lastName'],
$name[1]
);
}

private function hasProvinceNameInAddress(string $provinceName, string $addressType): void
{
/** @var Response $response */
$response = $this->client->getResponse();
$addressType .= 'Address';

Assert::same(
$this->responseChecker->getResponseContent($response)[$addressType]['provinceName'],
$provinceName
);
}
}

0 comments on commit 6a54f31

Please sign in to comment.