Skip to content

Commit

Permalink
Changes to specs and behat tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arti0090 committed May 21, 2021
1 parent 1ba1e7c commit 7a15180
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ Feature: Preventing not available payment method selection
And I complete the addressing step
And I select "Free" shipping method
And I complete the shipping step
And I try to select inexistent "Free" payment method
And I try to select "Free" payment method
Then I should be informed that payment method with code "Free" does not exist
8 changes: 3 additions & 5 deletions src/Sylius/Behat/Context/Api/Shop/CheckoutContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,10 @@ public function iProceededWithShippingMethod(ShippingMethodInterface $shippingMe


/**
* @When /^I try to select inexistent "([^"]*)" payment method$/
* @When I try to select :paymentMethodCode payment method
*/
public function iTryToSelectInexistentPaymentMethod(string $code): void
public function iTryToSelectPaymentMethod(string $paymentMethodCode): void
{
$paymentMethod = new PaymentMethod();

$request = Request::customItemAction(
'shop',
'orders',
Expand All @@ -371,7 +369,7 @@ public function iTryToSelectInexistentPaymentMethod(string $code): void
sprintf('payments/%s', $this->getCart()['payments'][0]['id'])
);

$request->setContent(['paymentMethod' => $this->iriConverter->getItemIriFromResourceClass(\get_class($paymentMethod), ['code' => $code])]);
$request->setContent(['paymentMethod' => $this->iriConverter->getItemIriFromResourceClass(PaymentMethod::class, ['code' => $paymentMethodCode])]);

$this->ordersClient->executeCustomRequest($request);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Webmozart\Assert\Assert;

/** @experimental */
class ChoosePaymentMethodEligibilityValidator extends ConstraintValidator
final class ChoosePaymentMethodEligibilityValidator extends ConstraintValidator
{
/** @var PaymentMethodRepositoryInterface */
private $paymentMethodRepository;
Expand All @@ -41,7 +41,7 @@ public function validate($value, Constraint $constraint): void
if ($paymentMethod === null) {
$this->context->addViolation(
$constraint->paymentMethodNotExistMessage,
['%paymentMethodCode%' => $value->paymentMethodCode]
['%paymentMethodCode%' => $value->getPaymentMethodCode()]
);

return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function it_is_a_constraint_validator(): void
$this->shouldImplement(ConstraintValidatorInterface::class);
}

function it_throws_an_exception_if_constraint_does_not_extend_payment_method_code_aware_interface(): void
function it_throws_an_exception_if_value_does_not_extend_payment_method_code_aware_interface(): void
{
$this
->shouldThrow(\InvalidArgumentException::class)
Expand Down Expand Up @@ -70,20 +70,16 @@ function it_adds_violation_if_payment_does_not_exist(
): void {
$this->initialize($executionContext);

$constraint = new ChoosePaymentMethodEligibility();

$value = new ChoosePaymentMethod('code');

$paymentMethodRepository->findOneBy(['code' => $value->getPaymentMethodCode()])->willReturn(null);
$paymentMethodRepository->findOneBy(['code' => 'payment_method_code'])->willReturn(null);

$executionContext
->addViolation(
'sylius.payment_method.not_exist',
['%paymentMethodCode%' => 'code']
)
->addViolation('sylius.payment_method.not_exist', ['%paymentMethodCode%' => 'payment_method_code'])
->shouldBeCalled();

$this->validate($value, $constraint);
$this->validate(
new ChoosePaymentMethod('payment_method_code'),
new ChoosePaymentMethodEligibility()
);
}

function it_does_nothing_if_payment_method_is_eligible(
Expand All @@ -93,19 +89,15 @@ function it_does_nothing_if_payment_method_is_eligible(
): void {
$this->initialize($executionContext);

$constraint = new ChoosePaymentMethodEligibility();

$value = new ChoosePaymentMethod('code');

$paymentMethodRepository->findOneBy(['code' => $value->getPaymentMethodCode()])->willReturn($paymentMethod);
$paymentMethodRepository->findOneBy(['code' => 'payment_method_code'])->willReturn($paymentMethod);

$executionContext
->addViolation(
'sylius.payment_method.not_exist',
['%paymentMethodCode%' => 'code']
)
->addViolation('sylius.payment_method.not_exist', ['%paymentMethodCode%' => 'payment_method_code'])
->shouldNotBeCalled();

$this->validate($value, $constraint);
$this->validate(
new ChoosePaymentMethod('payment_method_code'),
new ChoosePaymentMethodEligibility()
);
}
}

0 comments on commit 7a15180

Please sign in to comment.