Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lruozzi9 committed Feb 7, 2024
1 parent 8800876 commit 361db1b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
6 changes: 3 additions & 3 deletions spec/Resolver/PagolightPaymentMethodsResolverSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public function let(
$payment->getOrder()->willReturn($order);
$payment->getMethod()->willReturn($pagolightPaymentMethod);

$pagolightGatewayConfig->getGatewayName()->willReturn(PagolightApi::PAGOLIGHT_GATEWAY_CODE);
$pagolightProGatewayConfig->getGatewayName()->willReturn(PagolightApi::PAGOLIGHT_PRO_GATEWAY_CODE);
$otherGatewayConfig->getGatewayName()->willReturn('other');
$pagolightGatewayConfig->getFactoryName()->willReturn(PagolightApi::PAGOLIGHT_GATEWAY_CODE);
$pagolightProGatewayConfig->getFactoryName()->willReturn(PagolightApi::PAGOLIGHT_PRO_GATEWAY_CODE);
$otherGatewayConfig->getFactoryName()->willReturn('other');

$pagolightPaymentMethod->getCode()->willReturn('PAGOLIGHT_PAYMENT_METHOD_CODE');
$pagolightPaymentMethod->getGatewayConfig()->willReturn($pagolightGatewayConfig);
Expand Down
1 change: 1 addition & 0 deletions src/Controller/PaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function statusAction(mixed $paymentId): Response
if (!$paymentGatewayConfig instanceof GatewayConfigInterface) {
throw $this->createAccessDeniedException();
}
/** @psalm-suppress DeprecatedMethod */
if (!in_array($paymentGatewayConfig->getFactoryName(), [PagolightApi::PAGOLIGHT_GATEWAY_CODE, PagolightApi::PAGOLIGHT_PRO_GATEWAY_CODE], true)) {
throw $this->createAccessDeniedException();
}
Expand Down
2 changes: 2 additions & 0 deletions src/Resolver/PagolightPaymentMethodsResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ static function (PaymentMethodInterface $paymentMethod) use ($billingAddress, $s
if ($gatewayConfig === null) {
return false;
}
/** @psalm-suppress DeprecatedMethod */
if (!in_array($gatewayConfig->getFactoryName(), [PagolightApi::PAGOLIGHT_GATEWAY_CODE, PagolightApi::PAGOLIGHT_PRO_GATEWAY_CODE], true)) {
return true;
}
Expand All @@ -69,6 +70,7 @@ static function (PaymentMethodInterface $paymentMethod) use ($billingAddress, $s
if (!in_array($currencyCode, Config::ALLOWED_CURRENCY_CODES, true)) {
return false;
}
/** @psalm-suppress DeprecatedMethod */
if ($orderAmount <= (Config::PAGOLIGHT_PRO_MINIMUM_AMOUNT * 100) &&
$gatewayConfig->getFactoryName() === PagolightApi::PAGOLIGHT_PRO_GATEWAY_CODE
) {
Expand Down
5 changes: 4 additions & 1 deletion src/Validator/PagolightPaymentMethodUniqueValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function validate(mixed $value, Constraint $constraint): void
}

$gatewayConfig = $value->getGatewayConfig();
/** @psalm-suppress DeprecatedMethod */
if ($gatewayConfig === null ||
!in_array($gatewayConfig->getFactoryName(), [
PagolightApi::PAGOLIGHT_GATEWAY_CODE,
Expand All @@ -44,10 +45,12 @@ public function validate(mixed $value, Constraint $constraint): void
return;
}

/** @var PaymentMethodInterface[] $paymentMethods */
$paymentMethods = $this->paymentMethodRepository->findAll();
/** @psalm-suppress DeprecatedMethod */
$paymentMethodsWithSameGatewayConfig = array_filter(
$paymentMethods,
static fn (PaymentMethodInterface $paymentMethod) => $paymentMethod->getGatewayConfig()?->getFactoryName() === $gatewayConfig->getFactoryName()
static fn (PaymentMethodInterface $paymentMethod) => $paymentMethod->getGatewayConfig()?->getFactoryName() === $gatewayConfig->getFactoryName(),
);
if (count($paymentMethodsWithSameGatewayConfig) > 1 ||
(count($paymentMethodsWithSameGatewayConfig) === 1 && reset($paymentMethodsWithSameGatewayConfig) !== $value)
Expand Down

0 comments on commit 361db1b

Please sign in to comment.