From d1e5fedcbfa97dbb10dd2c48d33494a28a8863ce Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Sun, 6 Mar 2022 10:09:39 +0100 Subject: [PATCH 01/25] feat: support symfony 6 --- .github/workflows/tests.yaml | 3 +- CHANGELOG.md | 8 +++ Command/CreateCaptureTokenCommand.php | 28 ++++------- Command/CreateNotifyTokenCommand.php | 28 ++++------- Command/DebugGatewayCommand.php | 47 +++++++----------- Command/StatusCommand.php | 37 ++++++-------- Controller/AuthorizeController.php | 6 +-- Controller/CancelController.php | 9 ++-- Controller/CaptureController.php | 6 +-- Controller/NotifyController.php | 8 +-- Controller/PayoutController.php | 8 +-- Controller/PayumController.php | 34 ++----------- Controller/RefundController.php | 11 +++-- Controller/SyncController.php | 8 +-- .../Compiler/BuildConfigsPass.php | 17 ++++--- .../BuildGatewayFactoriesBuilderPass.php | 2 +- .../Compiler/BuildGatewayFactoriesPass.php | 2 +- .../Compiler/BuildGatewaysPass.php | 2 +- .../Compiler/BuildStoragesPass.php | 2 +- .../Storage/AbstractStorageFactory.php | 2 +- .../Storage/StorageFactoryInterface.php | 12 ++--- DependencyInjection/MainConfiguration.php | 18 ++++--- DependencyInjection/PayumExtension.php | 7 +-- EventListener/ReplyToHttpResponseListener.php | 8 +-- .../GatewayFactoriesChoiceTypeExtension.php | 13 +---- Profiler/PayumCollector.php | 10 ++-- Resources/config/commands.xml | 22 ++------- Resources/config/controller.xml | 9 +++- Resources/config/debug.xml | 2 +- Resources/config/form.xml | 2 +- Resources/config/payum.xml | 2 +- Resources/config/routing/all.xml | 2 +- Resources/config/routing/authorize.xml | 2 +- Resources/config/routing/cancel.xml | 2 +- Resources/config/routing/capture.xml | 2 +- Resources/config/routing/notify.xml | 2 +- Resources/config/routing/payout.xml | 2 +- Resources/config/routing/refund.xml | 2 +- Resources/config/routing/sync.xml | 2 +- Resources/config/storage/doctrine.mongodb.xml | 2 +- Resources/config/storage/doctrine.orm.xml | 2 +- Resources/config/storage/filesystem.xml | 2 +- Resources/config/storage/propel1.xml | 2 +- Resources/config/storage/propel2.xml | 2 +- Resources/config/validation.xml | 2 +- Tests/Controller/AbstractControllerTest.php | 7 +-- Tests/Controller/AuthorizeControllerTest.php | 3 +- Tests/Controller/CancelControllerTest.php | 7 +-- Tests/Controller/CaptureControllerTest.php | 14 ++---- Tests/Controller/NotifyControllerTest.php | 21 ++++++-- Tests/Controller/PayoutControllerTest.php | 3 +- Tests/Controller/RefundControllerTest.php | 11 ++--- .../Compiler/BuildConfigsPassTest.php | 2 +- .../Factory/AbstractStorageFactoryTest.php | 15 +++--- .../Factory/CustomStorageFactoryTest.php | 13 ++--- .../MainConfigurationTest.php | 12 ++--- .../PayumExtensionTest.php | 2 +- .../ReplyToHttpResponseListenerTest.php | 24 ++++----- .../Command/CreateCaptureTokenCommandTest.php | 4 +- .../Command/CreateNotifyTokenCommandTest.php | 7 ++- .../Command/DebugGatewayCommandTest.php | 28 ++++++----- .../Functional/Command/StatusCommandTest.php | 8 +-- .../Type/CreditCardExpirationDateTypeTest.php | 10 ++-- .../Form/Type/CreditCardTypeTest.php | 14 +++--- .../Form/Type/GatewayConfigTypeTest.php | 14 +++--- .../Type/GatewayFactoriesChoiceTypeTest.php | 7 +-- Tests/Functional/WebTestCase.php | 6 +-- Tests/Functional/app/AppKernel.php | 49 ++++++++++++------- Tests/Functional/app/AppKernelShared.php | 44 ----------------- Tests/Functional/app/config/config.yml | 18 +++++-- Tests/Functional/app/config/config_sf4.yml | 4 -- Tests/Functional/app/config/config_sf5.yml | 7 --- Tests/bootstrap.php | 12 +---- UPGRADE.md | 7 +++ composer.json | 22 ++++----- 75 files changed, 333 insertions(+), 463 deletions(-) delete mode 100644 Tests/Functional/app/AppKernelShared.php delete mode 100644 Tests/Functional/app/config/config_sf4.yml delete mode 100644 Tests/Functional/app/config/config_sf5.yml diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index a5478731..a5175d5e 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -14,7 +14,6 @@ jobs: fail-fast: false matrix: include: - - php: 7.4 - php: 8.0 - php: 8.1 @@ -53,7 +52,7 @@ jobs: fail-fast: false matrix: include: - - php: 7.4 + - php: 8.0 steps: - name: Checkout diff --git a/CHANGELOG.md b/CHANGELOG.md index 55d8e144..ff0d055a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 3.0.0 (2022-03-xx) + +* Symfony < 5 support is dropped +* PHP < 8 support is dropped +* deprecated function `PayumController->getHttpRequestVerifier()` removed +* deprecated function `PayumController->getTokenFactory()` removed +* Please see UPGRADE.md + ## 2.3.1 (2018-08-19) * Make profiler dynamic diff --git a/Command/CreateCaptureTokenCommand.php b/Command/CreateCaptureTokenCommand.php index bd45a0a0..c0998827 100644 --- a/Command/CreateCaptureTokenCommand.php +++ b/Command/CreateCaptureTokenCommand.php @@ -3,19 +3,20 @@ use Payum\Core\Exception\RuntimeException; use Payum\Core\Payum; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\DependencyInjection\ContainerAwareInterface; -use Symfony\Component\DependencyInjection\ContainerAwareTrait; -class CreateCaptureTokenCommand extends Command implements ContainerAwareInterface +#[AsCommand(name: 'payum:security:create-capture-token')] +class CreateCaptureTokenCommand extends Command { - use ContainerAwareTrait; - - protected static $defaultName = 'payum:security:create-capture-token'; + public function __construct(protected Payum $payum) + { + parent::__construct(); + } /** * {@inheritDoc} @@ -23,7 +24,6 @@ class CreateCaptureTokenCommand extends Command implements ContainerAwareInterfa protected function configure(): void { $this - ->setName(static::$defaultName) ->addArgument('gateway-name', InputArgument::REQUIRED, 'The gateway name associated with the token') ->addOption('model-class', null, InputOption::VALUE_OPTIONAL, 'The model class associated with the token') ->addOption('model-id', null, InputOption::VALUE_OPTIONAL, 'The model id associated with the token') @@ -43,7 +43,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $model = null; if ($modelClass && $modelId) { - if (false == $model = $this->getPayum()->getStorage($modelClass)->find($modelId)) { + if (false === $model = $this->payum->getStorage($modelClass)->find($modelId)) { throw new RuntimeException(sprintf( 'Cannot find model with class %s and id %s.', $modelClass, @@ -52,21 +52,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int } } - $token = $this->getPayum()->getTokenFactory()->createCaptureToken($gatewayName, $model, $afterUrl); + $token = $this->payum->getTokenFactory()->createCaptureToken($gatewayName, $model, $afterUrl); $output->writeln(sprintf('Hash: %s', $token->getHash())); $output->writeln(sprintf('Url: %s', $token->getTargetUrl())); $output->writeln(sprintf('After Url: %s', $token->getAfterUrl() ?: 'null')); $output->writeln(sprintf('Details: %s', (string) $token->getDetails())); - return 0; - } - - /** - * @return Payum - */ - protected function getPayum() - { - return $this->container->get('payum'); + return Command::SUCCESS; } } diff --git a/Command/CreateNotifyTokenCommand.php b/Command/CreateNotifyTokenCommand.php index bfdf24c1..e69b574d 100644 --- a/Command/CreateNotifyTokenCommand.php +++ b/Command/CreateNotifyTokenCommand.php @@ -3,19 +3,20 @@ use Payum\Core\Exception\RuntimeException; use Payum\Core\Payum; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\DependencyInjection\ContainerAwareInterface; -use Symfony\Component\DependencyInjection\ContainerAwareTrait; -class CreateNotifyTokenCommand extends Command implements ContainerAwareInterface +#[AsCommand(name: 'payum:security:create-notify-token')] +class CreateNotifyTokenCommand extends Command { - use ContainerAwareTrait; - - protected static $defaultName = 'payum:security:create-notify-token'; + public function __construct(protected Payum $payum) + { + parent::__construct(); + } /** * {@inheritDoc} @@ -23,7 +24,6 @@ class CreateNotifyTokenCommand extends Command implements ContainerAwareInterfac protected function configure(): void { $this - ->setName(static::$defaultName) ->addArgument('gateway-name', InputArgument::REQUIRED, 'The gateway name associated with the token') ->addOption('model-class', null, InputOption::VALUE_OPTIONAL, 'The model class associated with the token') ->addOption('model-id', null, InputOption::VALUE_OPTIONAL, 'The model id associated with the token') @@ -41,7 +41,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $model = null; if ($modelClass && $modelId) { - if (false == $model = $this->getPayum()->getStorage($modelClass)->find($modelId)) { + if (false === $model = $this->payum->getStorage($modelClass)->find($modelId)) { throw new RuntimeException(sprintf( 'Cannot find model with class %s and id %s.', $modelClass, @@ -50,20 +50,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int } } - $token = $this->getPayum()->getTokenFactory()->createNotifyToken($gatewayName, $model); + $token = $this->payum->getTokenFactory()->createNotifyToken($gatewayName, $model); $output->writeln(sprintf('Hash: %s', $token->getHash())); $output->writeln(sprintf('Url: %s', $token->getTargetUrl())); $output->writeln(sprintf('Details: %s', (string) $token->getDetails() ?: 'null')); - return 0; - } - - /** - * @return Payum - */ - protected function getPayum() - { - return $this->container->get('payum'); + return Command::SUCCESS; } } diff --git a/Command/DebugGatewayCommand.php b/Command/DebugGatewayCommand.php index 9cf1f860..1fe01677 100644 --- a/Command/DebugGatewayCommand.php +++ b/Command/DebugGatewayCommand.php @@ -3,22 +3,23 @@ use Payum\Core\Extension\StorageExtension; use Payum\Core\Gateway; -use Payum\Core\Registry\RegistryInterface; +use Payum\Core\Payum; use Payum\Core\Storage\AbstractStorage; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ChoiceQuestion; -use Symfony\Component\DependencyInjection\ContainerAwareInterface; -use Symfony\Component\DependencyInjection\ContainerAwareTrait; -class DebugGatewayCommand extends Command implements ContainerAwareInterface +#[AsCommand(name: 'debug:payum:gateway', aliases: ['payum:gateway:debug'])] +class DebugGatewayCommand extends Command { - use ContainerAwareTrait; - - protected static $defaultName = 'debug:payum:gateway'; + public function __construct(protected Payum $payum) + { + parent::__construct(); + } /** * {@inheritDoc} @@ -26,8 +27,6 @@ class DebugGatewayCommand extends Command implements ContainerAwareInterface protected function configure(): void { $this - ->setName(static::$defaultName) - ->setAliases(['payum:gateway:debug']) ->addArgument('gateway-name', InputArgument::OPTIONAL, 'The gateway name you want to get information about.') ->addOption('show-supports', null, InputOption::VALUE_NONE, 'Show what actions supports.') ; @@ -35,15 +34,16 @@ protected function configure(): void /** * {@inheritDoc} + * @throws \ReflectionException */ protected function execute(InputInterface $input, OutputInterface $output): int { - $gateways = $this->getPayum()->getGateways(); + $gateways = $this->payum->getGateways(); if ($gatewayName = $input->getArgument('gateway-name')) { $gatewayName = $this->findProperGatewayName($input, $output, $gateways, $gatewayName); $gateways = array( - $gatewayName => $this->getPayum()->getGateway($gatewayName), + $gatewayName => $this->payum->getGateway($gatewayName), ); } @@ -55,7 +55,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln(''); $output->writeln(sprintf('%s (%s):', $name, get_class($gateway))); - if (false == $gateway instanceof Gateway) { + if (false === $gateway instanceof Gateway) { continue; } @@ -120,15 +120,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int } } - return 0; + return Command::SUCCESS; } - /** - * @param \ReflectionMethod $reflectionMethod - * - * @return array - */ - protected function getMethodCode(\ReflectionMethod $reflectionMethod) + protected function getMethodCode(\ReflectionMethod $reflectionMethod): array { $file = file($reflectionMethod->getFileName()); @@ -140,15 +135,7 @@ protected function getMethodCode(\ReflectionMethod $reflectionMethod) return array_values($methodCodeLines); } - /** - * @return RegistryInterface - */ - protected function getPayum() - { - return $this->container->get('payum'); - } - - private function findProperGatewayName(InputInterface $input, OutputInterface $output, $gateways, $name) + private function findProperGatewayName(InputInterface $input, OutputInterface $output, array $gateways, string $name) { $helperSet = $this->getHelperSet(); if (!$helperSet->has('question') || isset($gateways[$name]) || !$input->isInteractive()) { @@ -165,14 +152,14 @@ private function findProperGatewayName(InputInterface $input, OutputInterface $o return $this->getHelper('question')->ask($input, $output, $question); } - private function findGatewaysContaining($gateways, $name) + private function findGatewaysContaining(array $gateways, string $name): array { $threshold = 1e3; $foundGateways = array(); foreach ($gateways as $gatewayName => $gateway) { $lev = levenshtein($name, $gatewayName); - if ($lev <= strlen($name) / 3 || false !== strpos($gatewayName, $name)) { + if ($lev <= strlen($name) / 3 || str_contains($gatewayName, $name)) { $foundGateways[$gatewayName] = isset($foundGateways[$gatewayName]) ? $foundGateways[$gateway] - $lev : $lev; } } diff --git a/Command/StatusCommand.php b/Command/StatusCommand.php index 9c189859..1c097d1b 100644 --- a/Command/StatusCommand.php +++ b/Command/StatusCommand.php @@ -2,30 +2,29 @@ namespace Payum\Bundle\PayumBundle\Command; use Payum\Core\Exception\RuntimeException; -use Payum\Core\Registry\RegistryInterface; +use Payum\Core\Payum; use Payum\Core\Request\GetHumanStatus; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\DependencyInjection\ContainerAwareInterface; -use Symfony\Component\DependencyInjection\ContainerAwareTrait; -class StatusCommand extends Command implements ContainerAwareInterface +#[AsCommand(name: 'payum:status', description: 'Allows to get a payment status.')] +class StatusCommand extends Command { - use ContainerAwareTrait; - - protected static $defaultName = 'payum:status'; + public function __construct(protected Payum $payum) + { + parent::__construct(); + } /** * {@inheritdoc} */ - protected function configure() + protected function configure(): void { $this - ->setName(static::$defaultName) - ->setDescription('Allows to get a payment status.') ->addArgument('gateway-name', InputArgument::REQUIRED, 'The gateway name') ->addOption('model-class', null, InputOption::VALUE_REQUIRED, 'The model class') ->addOption('model-id', null, InputOption::VALUE_REQUIRED, 'The model id') @@ -35,14 +34,14 @@ protected function configure() /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $gatewayName = $input->getArgument('gateway-name'); $modelClass = $input->getOption('model-class'); $modelId = $input->getOption('model-id'); - $storage = $this->getPayum()->getStorage($modelClass); - if (false == $model = $storage->find($modelId)) { + $storage = $this->payum->getStorage($modelClass); + if (false === $model = $storage->find($modelId)) { throw new RuntimeException(sprintf( 'Cannot find model with class %s and id %s.', $modelClass, @@ -51,18 +50,10 @@ protected function execute(InputInterface $input, OutputInterface $output) } $status = new GetHumanStatus($model); - $this->getPayum()->getGateway($gatewayName)->execute($status); + $this->payum->getGateway($gatewayName)->execute($status); $output->writeln(sprintf('Status: %s', $status->getValue())); - return 0; - } - - /** - * @return RegistryInterface - */ - protected function getPayum() - { - return $this->container->get('payum'); + return Command::SUCCESS; } } diff --git a/Controller/AuthorizeController.php b/Controller/AuthorizeController.php index 67edd0cc..ddc3ef63 100644 --- a/Controller/AuthorizeController.php +++ b/Controller/AuthorizeController.php @@ -9,12 +9,12 @@ class AuthorizeController extends PayumController { public function doAction(Request $request): RedirectResponse { - $token = $this->getPayum()->getHttpRequestVerifier()->verify($request); + $token = $this->payum->getHttpRequestVerifier()->verify($request); - $gateway = $this->getPayum()->getGateway($token->getGatewayName()); + $gateway = $this->payum->getGateway($token->getGatewayName()); $gateway->execute(new Authorize($token)); - $this->getPayum()->getHttpRequestVerifier()->invalidate($token); + $this->payum->getHttpRequestVerifier()->invalidate($token); return $this->redirect($token->getAfterUrl()); } diff --git a/Controller/CancelController.php b/Controller/CancelController.php index 88af222b..35d0a7b1 100644 --- a/Controller/CancelController.php +++ b/Controller/CancelController.php @@ -2,6 +2,7 @@ namespace Payum\Bundle\PayumBundle\Controller; use Payum\Core\Request\Cancel; +use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -10,14 +11,14 @@ class CancelController extends PayumController /** * @throws \Exception */ - public function doAction(Request $request): Response + public function doAction(Request $request): Response|RedirectResponse { - $token = $this->getPayum()->getHttpRequestVerifier()->verify($request); + $token = $this->payum->getHttpRequestVerifier()->verify($request); - $gateway = $this->getPayum()->getGateway($token->getGatewayName()); + $gateway = $this->payum->getGateway($token->getGatewayName()); $gateway->execute(new Cancel($token)); - $this->getPayum()->getHttpRequestVerifier()->invalidate($token); + $this->payum->getHttpRequestVerifier()->invalidate($token); return $token->getAfterUrl() ? $this->redirect($token->getAfterUrl()) : diff --git a/Controller/CaptureController.php b/Controller/CaptureController.php index a52b3d1c..87ff0155 100644 --- a/Controller/CaptureController.php +++ b/Controller/CaptureController.php @@ -37,12 +37,12 @@ public function doSessionTokenAction(Request $request): RedirectResponse public function doAction(Request $request): RedirectResponse { - $token = $this->getPayum()->getHttpRequestVerifier()->verify($request); + $token = $this->payum->getHttpRequestVerifier()->verify($request); - $gateway = $this->getPayum()->getGateway($token->getGatewayName()); + $gateway = $this->payum->getGateway($token->getGatewayName()); $gateway->execute(new Capture($token)); - $this->getPayum()->getHttpRequestVerifier()->invalidate($token); + $this->payum->getHttpRequestVerifier()->invalidate($token); return $this->redirect($token->getAfterUrl()); } diff --git a/Controller/NotifyController.php b/Controller/NotifyController.php index adcd4cd3..723b0c0f 100644 --- a/Controller/NotifyController.php +++ b/Controller/NotifyController.php @@ -9,7 +9,7 @@ class NotifyController extends PayumController { public function doUnsafeAction(Request $request): Response { - $gateway = $this->getPayum()->getGateway($request->get('gateway')); + $gateway = $this->payum->getGateway($request->get('gateway')); $gateway->execute(new Notify(null)); @@ -18,12 +18,12 @@ public function doUnsafeAction(Request $request): Response public function doAction(Request $request): Response { - $token = $this->getPayum()->getHttpRequestVerifier()->verify($request); + $token = $this->payum->getHttpRequestVerifier()->verify($request); - $gateway = $this->getPayum()->getGateway($token->getGatewayName()); + $gateway = $this->payum->getGateway($token->getGatewayName()); $gateway->execute(new Notify($token)); return new Response('', 204); } -} \ No newline at end of file +} diff --git a/Controller/PayoutController.php b/Controller/PayoutController.php index 22614c26..4ff34683 100644 --- a/Controller/PayoutController.php +++ b/Controller/PayoutController.php @@ -9,13 +9,13 @@ class PayoutController extends PayumController { public function doAction(Request $request): RedirectResponse { - $token = $this->getPayum()->getHttpRequestVerifier()->verify($request); + $token = $this->payum->getHttpRequestVerifier()->verify($request); - $gateway = $this->getPayum()->getGateway($token->getGatewayName()); + $gateway = $this->payum->getGateway($token->getGatewayName()); $gateway->execute(new Payout($token)); - $this->getPayum()->getHttpRequestVerifier()->invalidate($token); + $this->payum->getHttpRequestVerifier()->invalidate($token); return $this->redirect($token->getAfterUrl()); } -} \ No newline at end of file +} diff --git a/Controller/PayumController.php b/Controller/PayumController.php index 84765efd..b0338b3b 100644 --- a/Controller/PayumController.php +++ b/Controller/PayumController.php @@ -2,45 +2,17 @@ namespace Payum\Bundle\PayumBundle\Controller; use Payum\Core\Payum; -use Payum\Core\Security\GenericTokenFactoryInterface; -use Payum\Core\Security\HttpRequestVerifierInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; abstract class PayumController extends AbstractController { - /** - * @return Payum - */ - protected function getPayum() - { - return $this->get('payum'); - } + public function __construct(protected ?Payum $payum) + {} - /** @return string[] */ - public static function getSubscribedServices() + public static function getSubscribedServices(): array { return array_merge(parent::getSubscribedServices(), [ 'payum' => Payum::class, ]); } - - /** - * @deprecated will be removed in 2.0. - * - * @return HttpRequestVerifierInterface - */ - protected function getHttpRequestVerifier() - { - return $this->getPayum()->getHttpRequestVerifier(); - } - - /** - * @deprecated will be removed in 2.0. - * - * @return GenericTokenFactoryInterface - */ - protected function getTokenFactory() - { - return $this->getPayum()->getTokenFactory(); - } } diff --git a/Controller/RefundController.php b/Controller/RefundController.php index f077bf83..a04f3293 100644 --- a/Controller/RefundController.php +++ b/Controller/RefundController.php @@ -2,6 +2,7 @@ namespace Payum\Bundle\PayumBundle\Controller; use Payum\Core\Request\Refund; +use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -10,18 +11,18 @@ class RefundController extends PayumController /** * @throws \Exception */ - public function doAction(Request $request): Response + public function doAction(Request $request): Response|RedirectResponse { - $token = $this->getPayum()->getHttpRequestVerifier()->verify($request); + $token = $this->payum->getHttpRequestVerifier()->verify($request); - $gateway = $this->getPayum()->getGateway($token->getGatewayName()); + $gateway = $this->payum->getGateway($token->getGatewayName()); $gateway->execute(new Refund($token)); - $this->getPayum()->getHttpRequestVerifier()->invalidate($token); + $this->payum->getHttpRequestVerifier()->invalidate($token); return $token->getAfterUrl() ? $this->redirect($token->getAfterUrl()) : new Response('', 204) ; } -} \ No newline at end of file +} diff --git a/Controller/SyncController.php b/Controller/SyncController.php index 797c6c33..a55e53cf 100644 --- a/Controller/SyncController.php +++ b/Controller/SyncController.php @@ -9,14 +9,14 @@ class SyncController extends PayumController { public function doAction(Request $request): RedirectResponse { - $token = $this->getPayum()->getHttpRequestVerifier()->verify($request); + $token = $this->payum->getHttpRequestVerifier()->verify($request); - $gateway = $this->getPayum()->getGateway($token->getGatewayName()); + $gateway = $this->payum->getGateway($token->getGatewayName()); $gateway->execute(new Sync($token)); - $this->getPayum()->getHttpRequestVerifier()->invalidate($token); + $this->payum->getHttpRequestVerifier()->invalidate($token); return $this->redirect($token->getAfterUrl()); } -} \ No newline at end of file +} diff --git a/DependencyInjection/Compiler/BuildConfigsPass.php b/DependencyInjection/Compiler/BuildConfigsPass.php index 272c609c..28e7c13d 100644 --- a/DependencyInjection/Compiler/BuildConfigsPass.php +++ b/DependencyInjection/Compiler/BuildConfigsPass.php @@ -3,6 +3,7 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Reference; class BuildConfigsPass implements CompilerPassInterface { @@ -23,12 +24,12 @@ public function process(ContainerBuilder $container): void $builder = $container->getDefinition('payum.builder'); if ($container->hasDefinition('twig')) { - $config = ['twig.env' => '@twig']; + $config = ['twig.env' => new Reference('twig')]; $builder->addMethodCall('addCoreGatewayFactoryConfig', [$config]); } - if (false == empty($configs[0])) { + if (false === empty($configs[0])) { $builder->addMethodCall('addCoreGatewayFactoryConfig', [$configs[0]]); } @@ -41,7 +42,7 @@ public function process(ContainerBuilder $container): void } } - protected function processTagData(array $tagData, $namePrefix, $prependKey): array + protected function processTagData(array $tagData, string $namePrefix, string $prependKey): array { $coreGatewayFactoryConfig = []; $gatewaysFactoriesConfigs = []; @@ -59,7 +60,7 @@ protected function processTagData(array $tagData, $namePrefix, $prependKey): arr $coreGatewayFactoryConfig[$name] = "@$serviceId"; if ($attributes['prepend']) { - if (false == isset($coreGatewayFactoryConfig[$prependKey])) { + if (false === isset($coreGatewayFactoryConfig[$prependKey])) { $coreGatewayFactoryConfig[$prependKey] = []; } @@ -67,28 +68,28 @@ protected function processTagData(array $tagData, $namePrefix, $prependKey): arr $coreGatewayFactoryConfig[$prependKey][] = $name; } } elseif ($attributes['factory']) { - if (false == isset($gatewaysFactoriesConfigs[$attributes['factory']])) { + if (false === isset($gatewaysFactoriesConfigs[$attributes['factory']])) { $gatewaysFactoriesConfigs[$attributes['factory']] = []; } $gatewaysFactoriesConfigs[$attributes['factory']][$name] = "@$serviceId"; if ($attributes['prepend']) { - if (false == isset($gatewaysFactoriesConfigs[$attributes['factory']][$prependKey])) { + if (false === isset($gatewaysFactoriesConfigs[$attributes['factory']][$prependKey])) { $gatewaysFactoriesConfigs[$attributes['factory']][$prependKey] = []; } $gatewaysFactoriesConfigs[$attributes['factory']][$prependKey][] = $name; } } elseif ($attributes['gateway']) { - if (false == isset($gatewaysConfigs[$attributes['gateway']])) { + if (false === isset($gatewaysConfigs[$attributes['gateway']])) { $gatewaysConfigs[$attributes['gateway']] = []; } $gatewaysConfigs[$attributes['gateway']][$name] = "@$serviceId"; if ($attributes['prepend']) { - if (false == isset($gatewaysConfigs[$attributes['gateway']][$prependKey])) { + if (false === isset($gatewaysConfigs[$attributes['gateway']][$prependKey])) { $gatewaysConfigs[$attributes['gateway']][$prependKey] = []; } diff --git a/DependencyInjection/Compiler/BuildGatewayFactoriesBuilderPass.php b/DependencyInjection/Compiler/BuildGatewayFactoriesBuilderPass.php index e966b615..e430600f 100644 --- a/DependencyInjection/Compiler/BuildGatewayFactoriesBuilderPass.php +++ b/DependencyInjection/Compiler/BuildGatewayFactoriesBuilderPass.php @@ -16,7 +16,7 @@ public function process(ContainerBuilder $container): void $builder = $container->getDefinition('payum.builder'); foreach ($container->findTaggedServiceIds('payum.gateway_factory_builder') as $serviceId => $tagAttributes) { foreach ($tagAttributes as $attributes) { - if (false == isset($attributes['factory'])) { + if (false === isset($attributes['factory'])) { throw new LogicException('The payum.gateway_factory tag require factory attribute.'); } diff --git a/DependencyInjection/Compiler/BuildGatewayFactoriesPass.php b/DependencyInjection/Compiler/BuildGatewayFactoriesPass.php index 35d6ed7c..5e8f8c24 100644 --- a/DependencyInjection/Compiler/BuildGatewayFactoriesPass.php +++ b/DependencyInjection/Compiler/BuildGatewayFactoriesPass.php @@ -18,7 +18,7 @@ public function process(ContainerBuilder $container): void $servicesIds = []; foreach ($container->findTaggedServiceIds('payum.gateway_factory') as $serviceId => $tagAttributes) { foreach ($tagAttributes as $attributes) { - if (false == isset($attributes['factory'])) { + if (false === isset($attributes['factory'])) { throw new LogicException('The payum.gateway_factory tag require factory attribute.'); } diff --git a/DependencyInjection/Compiler/BuildGatewaysPass.php b/DependencyInjection/Compiler/BuildGatewaysPass.php index 6419f942..7c568c4e 100644 --- a/DependencyInjection/Compiler/BuildGatewaysPass.php +++ b/DependencyInjection/Compiler/BuildGatewaysPass.php @@ -17,7 +17,7 @@ public function process(ContainerBuilder $container): void $servicesIds = []; foreach ($container->findTaggedServiceIds('payum.gateway') as $serviceId => $tagAttributes) { foreach ($tagAttributes as $attributes) { - if (false == isset($attributes['gateway'])) { + if (false === isset($attributes['gateway'])) { throw new LogicException('The payum.gateway tag require gateway attribute.'); } diff --git a/DependencyInjection/Compiler/BuildStoragesPass.php b/DependencyInjection/Compiler/BuildStoragesPass.php index 3f0c9ad7..4e3062dd 100644 --- a/DependencyInjection/Compiler/BuildStoragesPass.php +++ b/DependencyInjection/Compiler/BuildStoragesPass.php @@ -17,7 +17,7 @@ public function process(ContainerBuilder $container): void $servicesIds = []; foreach ($container->findTaggedServiceIds('payum.storage') as $serviceId => $tagAttributes) { foreach ($tagAttributes as $attributes) { - if (false == isset($attributes['model_class'])) { + if (false === isset($attributes['model_class'])) { throw new LogicException('The payum.storage tag require model_class attribute.'); } diff --git a/DependencyInjection/Factory/Storage/AbstractStorageFactory.php b/DependencyInjection/Factory/Storage/AbstractStorageFactory.php index e75fe751..0b4e514a 100644 --- a/DependencyInjection/Factory/Storage/AbstractStorageFactory.php +++ b/DependencyInjection/Factory/Storage/AbstractStorageFactory.php @@ -27,4 +27,4 @@ public function addConfiguration(ArrayNodeDefinition $builder): void } abstract protected function createStorage(ContainerBuilder $container, string $modelClass, array $config): Definition; -} \ No newline at end of file +} diff --git a/DependencyInjection/Factory/Storage/StorageFactoryInterface.php b/DependencyInjection/Factory/Storage/StorageFactoryInterface.php index 30047da5..6adc55a3 100644 --- a/DependencyInjection/Factory/Storage/StorageFactoryInterface.php +++ b/DependencyInjection/Factory/Storage/StorageFactoryInterface.php @@ -7,21 +7,15 @@ interface StorageFactoryInterface { /** - * @param string $modelClass * @return string The payment serviceId */ - function create(ContainerBuilder $container, $modelClass, array $config); + public function create(ContainerBuilder $container, string $modelClass, array $config): string; /** * The storage name, * For example filesystem, doctrine, propel etc. - * - * @return string */ - function getName(); + public function getName(): string; - /** - * @return void - */ - function addConfiguration(ArrayNodeDefinition $builder); + public function addConfiguration(ArrayNodeDefinition $builder): void; } diff --git a/DependencyInjection/MainConfiguration.php b/DependencyInjection/MainConfiguration.php index 0e889db2..e3f690c4 100644 --- a/DependencyInjection/MainConfiguration.php +++ b/DependencyInjection/MainConfiguration.php @@ -6,6 +6,8 @@ use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; +use Payum\Core\Model\GatewayConfigInterface; +use Payum\Core\Security\TokenInterface; class MainConfiguration implements ConfigurationInterface { @@ -65,7 +67,7 @@ protected function addStoragesSection(ArrayNodeDefinition $rootPrototypeNode): v unset($storages['extension']); foreach($storages as $key => $value) { - if (false == class_exists($key)) { + if (false === class_exists($key)) { throw new LogicException(sprintf( 'The storage entry must be a valid model class. It is set %s', $key @@ -87,7 +89,7 @@ protected function addStoragesSection(ArrayNodeDefinition $rootPrototypeNode): v $storages = $v; unset($storages['extension']); - if (count($storages) == 0) { + if (count($storages) === 0) { throw new LogicException('At least one storage must be configured.'); } if (count($storages) > 1) { @@ -132,7 +134,7 @@ protected function addSecuritySection(ArrayNodeDefinition $securityNode): void ->validate() ->ifTrue(function($v) { foreach($v as $key => $value) { - if (false == class_exists($key)) { + if (false === class_exists($key)) { throw new LogicException(sprintf( 'The storage entry must be a valid model class. It is set %s', $key @@ -140,7 +142,7 @@ protected function addSecuritySection(ArrayNodeDefinition $securityNode): void } $rc = new \ReflectionClass($key); - if (false == $rc->implementsInterface('Payum\Core\Security\TokenInterface')) { + if (false === $rc->implementsInterface(TokenInterface::class)) { throw new LogicException('The token class must implement `Payum\Core\Security\TokenInterface` interface'); } @@ -160,7 +162,7 @@ protected function addSecuritySection(ArrayNodeDefinition $securityNode): void $storageNode ->validate() ->ifTrue(function($v) { - if (count($v) == 0) { + if (count($v) === 0) { throw new LogicException('At least one storage must be configured.'); } if (count($v) > 1) { @@ -192,7 +194,7 @@ protected function addDynamicGatewaysSection(ArrayNodeDefinition $dynamicGateway ->validate() ->ifTrue(function($v) { foreach($v as $key => $value) { - if (false == class_exists($key)) { + if (false === class_exists($key)) { throw new LogicException(sprintf( 'The storage entry must be a valid model class. It is set %s', $key @@ -200,7 +202,7 @@ protected function addDynamicGatewaysSection(ArrayNodeDefinition $dynamicGateway } $rc = new \ReflectionClass($key); - if (false == $rc->implementsInterface('Payum\Core\Model\GatewayConfigInterface')) { + if (false === $rc->implementsInterface(GatewayConfigInterface::class)) { throw new LogicException('The config class must implement `Payum\Core\Model\GatewayConfigInterface` interface'); } @@ -220,7 +222,7 @@ protected function addDynamicGatewaysSection(ArrayNodeDefinition $dynamicGateway $storageNode ->validate() ->ifTrue(function($v) { - if (count($v) == 0) { + if (count($v) === 0) { throw new LogicException('At least one storage must be configured.'); } if (count($v) > 1) { diff --git a/DependencyInjection/PayumExtension.php b/DependencyInjection/PayumExtension.php index d09b9aa9..748ecad4 100644 --- a/DependencyInjection/PayumExtension.php +++ b/DependencyInjection/PayumExtension.php @@ -11,6 +11,7 @@ use Payum\Core\Registry\DynamicRegistry; use Payum\Core\Storage\CryptoStorageDecorator; use Sonata\AdminBundle\Admin\AbstractAdmin; +use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; @@ -143,7 +144,7 @@ protected function loadStorages(array $config, ContainerBuilder $container): voi $container->getDefinition($storageId)->addTag('payum.storage', array('model_class' => $modelClass)); - if (false !== strpos($storageId, '.storage.')) { + if (str_contains($storageId, '.storage.')) { $storageExtensionId = str_replace('.storage.', '.extension.storage.', $storageId); } else { throw new LogicException(sprintf('In order to add storage to extension the storage "%s" has to contains ".storage." inside.', $storageId)); @@ -226,7 +227,7 @@ protected function loadDynamicGateways(array $dynamicGatewaysConfig, ContainerBu if ($dynamicGatewaysConfig['sonata_admin']) { throw new \LogicException('Not supported. Has to wait till Sonata Admin 4.x will be released.'); - if (false == class_exists(AbstractAdmin::class)) { + if (false === class_exists(AbstractAdmin::class)) { throw new LogicException('Admin class does not exists. Did you install SonataAdmin bundle?'); } @@ -273,7 +274,7 @@ public function addStorageFactory(StorageFactoryInterface $factory): void /** * {@inheritDoc} */ - public function getConfiguration(array $config, ContainerBuilder $container) + public function getConfiguration(array $config, ContainerBuilder $container): ConfigurationInterface|MainConfiguration|null { return new MainConfiguration($this->storagesFactories); } diff --git a/EventListener/ReplyToHttpResponseListener.php b/EventListener/ReplyToHttpResponseListener.php index 6019471e..7d62b42d 100644 --- a/EventListener/ReplyToHttpResponseListener.php +++ b/EventListener/ReplyToHttpResponseListener.php @@ -7,12 +7,8 @@ class ReplyToHttpResponseListener { - private ReplyToSymfonyResponseConverter $replyToSymfonyResponseConverter; - - public function __construct(ReplyToSymfonyResponseConverter $replyToSymfonyResponseConverter) - { - $this->replyToSymfonyResponseConverter = $replyToSymfonyResponseConverter; - } + public function __construct(private ReplyToSymfonyResponseConverter $replyToSymfonyResponseConverter) + {} public function onKernelException(ExceptionEvent $event): void { diff --git a/Form/Extension/GatewayFactoriesChoiceTypeExtension.php b/Form/Extension/GatewayFactoriesChoiceTypeExtension.php index 9ea6eef3..d129f946 100644 --- a/Form/Extension/GatewayFactoriesChoiceTypeExtension.php +++ b/Form/Extension/GatewayFactoriesChoiceTypeExtension.php @@ -8,12 +8,8 @@ class GatewayFactoriesChoiceTypeExtension extends AbstractTypeExtension { - private GatewayFactoryRegistryInterface $gatewayFactoryRegistry; - - public function __construct(GatewayFactoryRegistryInterface $gatewayFactoryRegistry) - { - $this->gatewayFactoryRegistry = $gatewayFactoryRegistry; - } + public function __construct(private GatewayFactoryRegistryInterface $gatewayFactoryRegistry) + {} /** * {@inheritdoc} @@ -35,11 +31,6 @@ public function configureOptions(OptionsResolver $resolver): void } } - public function getExtendedType(): string - { - return GatewayFactoriesChoiceType::class; - } - /** * {@inheritdoc} */ diff --git a/Profiler/PayumCollector.php b/Profiler/PayumCollector.php index 3de5b224..e0c375ba 100644 --- a/Profiler/PayumCollector.php +++ b/Profiler/PayumCollector.php @@ -43,9 +43,7 @@ public function collect(Request $request, Response $response, \Throwable $except ]; if ($request instanceof Generic) { - $contextData['model_class'] = is_object($request->getModel()) ? - get_class($request->getModel()) : - gettype($request->getModel()) + $contextData['model_class'] = get_debug_type($request->getModel()) ; $contextData['model_short_class'] = is_object($request->getModel()) ? @@ -114,7 +112,7 @@ public function dump(): string $previousContext = null; foreach ($this->data as $index => $contextData) { - if ($contextData['deep'] == 0) { + if ($contextData['deep'] === 0) { $str .= $this->formatRequest($contextData).PHP_EOL; continue; @@ -124,11 +122,11 @@ public function dump(): string $str .= $this->formatAction($contextData).PHP_EOL; } - if (false == array_key_exists($index + 1, $this->data) && $contextData['reply_class']) { + if (false === array_key_exists($index + 1, $this->data) && $contextData['reply_class']) { $str .= $this->formatReply($contextData).PHP_EOL; } - if (false == array_key_exists($index + 1, $this->data) && $contextData['exception_class']) { + if (false === array_key_exists($index + 1, $this->data) && $contextData['exception_class']) { $str .= $this->formatException($contextData).PHP_EOL; } } diff --git a/Resources/config/commands.xml b/Resources/config/commands.xml index 02bd3890..d7dfabf0 100644 --- a/Resources/config/commands.xml +++ b/Resources/config/commands.xml @@ -2,38 +2,26 @@ + xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd"> - - - - + - - - - + - - - - + - - - - + diff --git a/Resources/config/controller.xml b/Resources/config/controller.xml index e2d42478..dfd326da 100644 --- a/Resources/config/controller.xml +++ b/Resources/config/controller.xml @@ -2,36 +2,43 @@ + xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd"> + + + + + + + diff --git a/Resources/config/debug.xml b/Resources/config/debug.xml index a395b35a..951ee775 100644 --- a/Resources/config/debug.xml +++ b/Resources/config/debug.xml @@ -2,7 +2,7 @@ + xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd"> diff --git a/Resources/config/form.xml b/Resources/config/form.xml index d8497c58..0ff079df 100644 --- a/Resources/config/form.xml +++ b/Resources/config/form.xml @@ -2,7 +2,7 @@ + xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd"> diff --git a/Resources/config/payum.xml b/Resources/config/payum.xml index 7ddae8ac..15c1de81 100644 --- a/Resources/config/payum.xml +++ b/Resources/config/payum.xml @@ -2,7 +2,7 @@ + xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd"> payum_capture_do diff --git a/Resources/config/routing/all.xml b/Resources/config/routing/all.xml index a17310ba..408e4b42 100644 --- a/Resources/config/routing/all.xml +++ b/Resources/config/routing/all.xml @@ -1,6 +1,6 @@ - + diff --git a/Resources/config/routing/authorize.xml b/Resources/config/routing/authorize.xml index 74b0f545..5ffa0952 100644 --- a/Resources/config/routing/authorize.xml +++ b/Resources/config/routing/authorize.xml @@ -1,6 +1,6 @@ - + Payum\Bundle\PayumBundle\Controller\AuthorizeController::doAction diff --git a/Resources/config/routing/cancel.xml b/Resources/config/routing/cancel.xml index d770fa2c..c02e946c 100644 --- a/Resources/config/routing/cancel.xml +++ b/Resources/config/routing/cancel.xml @@ -1,6 +1,6 @@ - + Payum\Bundle\PayumBundle\Controller\CancelController::doAction diff --git a/Resources/config/routing/capture.xml b/Resources/config/routing/capture.xml index b3e2620f..a79fdd88 100644 --- a/Resources/config/routing/capture.xml +++ b/Resources/config/routing/capture.xml @@ -1,6 +1,6 @@ - + Payum\Bundle\PayumBundle\Controller\CaptureController::doSessionTokenAction diff --git a/Resources/config/routing/notify.xml b/Resources/config/routing/notify.xml index 219417d4..aea2818a 100644 --- a/Resources/config/routing/notify.xml +++ b/Resources/config/routing/notify.xml @@ -1,6 +1,6 @@ - + Payum\Bundle\PayumBundle\Controller\NotifyController::doUnsafeAction diff --git a/Resources/config/routing/payout.xml b/Resources/config/routing/payout.xml index 10a8e68a..9a82facb 100644 --- a/Resources/config/routing/payout.xml +++ b/Resources/config/routing/payout.xml @@ -1,6 +1,6 @@ - + Payum\Bundle\PayumBundle\Controller\PayoutController::doAction diff --git a/Resources/config/routing/refund.xml b/Resources/config/routing/refund.xml index 527b6c7e..5ad10966 100644 --- a/Resources/config/routing/refund.xml +++ b/Resources/config/routing/refund.xml @@ -1,6 +1,6 @@ - + Payum\Bundle\PayumBundle\Controller\RefundController::doAction diff --git a/Resources/config/routing/sync.xml b/Resources/config/routing/sync.xml index b608ae6a..402ac937 100644 --- a/Resources/config/routing/sync.xml +++ b/Resources/config/routing/sync.xml @@ -1,6 +1,6 @@ - + Payum\Bundle\PayumBundle\Controller\SyncController::doAction diff --git a/Resources/config/storage/doctrine.mongodb.xml b/Resources/config/storage/doctrine.mongodb.xml index d2032862..56d12e0f 100644 --- a/Resources/config/storage/doctrine.mongodb.xml +++ b/Resources/config/storage/doctrine.mongodb.xml @@ -2,7 +2,7 @@ + xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd"> Payum\Core\Bridge\Doctrine\Storage\DoctrineStorage diff --git a/Resources/config/storage/doctrine.orm.xml b/Resources/config/storage/doctrine.orm.xml index 8163d672..079118c5 100644 --- a/Resources/config/storage/doctrine.orm.xml +++ b/Resources/config/storage/doctrine.orm.xml @@ -2,7 +2,7 @@ + xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd"> Payum\Core\Bridge\Doctrine\Storage\DoctrineStorage diff --git a/Resources/config/storage/filesystem.xml b/Resources/config/storage/filesystem.xml index b19fe4ed..6a78bbec 100644 --- a/Resources/config/storage/filesystem.xml +++ b/Resources/config/storage/filesystem.xml @@ -2,7 +2,7 @@ + xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd"> Payum\Core\Storage\FilesystemStorage diff --git a/Resources/config/storage/propel1.xml b/Resources/config/storage/propel1.xml index ae84eeef..6d5cba83 100644 --- a/Resources/config/storage/propel1.xml +++ b/Resources/config/storage/propel1.xml @@ -2,7 +2,7 @@ + xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd"> diff --git a/Resources/config/storage/propel2.xml b/Resources/config/storage/propel2.xml index ccc19344..d0e9bd0e 100644 --- a/Resources/config/storage/propel2.xml +++ b/Resources/config/storage/propel2.xml @@ -2,7 +2,7 @@ + xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd"> diff --git a/Resources/config/validation.xml b/Resources/config/validation.xml index 8ad27194..4e05aed0 100644 --- a/Resources/config/validation.xml +++ b/Resources/config/validation.xml @@ -3,7 +3,7 @@ + https://symfony.com/schema/dic/services/constraint-mapping-1.0.xsd"> diff --git a/Tests/Controller/AbstractControllerTest.php b/Tests/Controller/AbstractControllerTest.php index 021635b6..9677a113 100644 --- a/Tests/Controller/AbstractControllerTest.php +++ b/Tests/Controller/AbstractControllerTest.php @@ -45,13 +45,11 @@ protected function setUp(): void HttpRequestVerifierInterface::class ); $this->httpRequestVerifierMock - ->expects($this->any()) ->method('verify') ->with($this->identicalTo($this->request)) - ->will($this->returnValue($this->token)); + ->willReturn($this->token); $this->httpRequestVerifierMock - ->expects($this->any()) ->method('invalidate') ->with($this->identicalTo($this->token)); @@ -59,10 +57,9 @@ protected function setUp(): void $this->registryMock = $this->createMock(RegistryInterface::class); $this->registryMock - ->expects($this->any()) ->method('getGateway') ->with(self::GATEWAY_NAME) - ->will($this->returnValue($this->gatewayMock)); + ->willReturn($this->gatewayMock); $this->payum = new Payum( $this->registryMock, diff --git a/Tests/Controller/AuthorizeControllerTest.php b/Tests/Controller/AuthorizeControllerTest.php index fbab49ea..fa667789 100644 --- a/Tests/Controller/AuthorizeControllerTest.php +++ b/Tests/Controller/AuthorizeControllerTest.php @@ -25,8 +25,7 @@ public function shouldBeSubClassOfController(): void */ public function shouldExecuteAuthorizeRequest(): void { - $controller = new AuthorizeController(); - $controller->setContainer(new ServiceLocator(['payum' => function () { return $this->payum; }])); + $controller = new AuthorizeController($this->payum); $response = $controller->doAction($this->request); diff --git a/Tests/Controller/CancelControllerTest.php b/Tests/Controller/CancelControllerTest.php index a44d75b6..5714cebf 100644 --- a/Tests/Controller/CancelControllerTest.php +++ b/Tests/Controller/CancelControllerTest.php @@ -26,8 +26,7 @@ public function shouldBeSubClassOfController(): void */ public function shouldExecuteCancelRequest(): void { - $controller = new CancelController(); - $controller->setContainer(new ServiceLocator(['payum' => function () { return $this->payum; }])); + $controller = new CancelController($this->payum); $response = $controller->doAction($this->request); @@ -42,8 +41,7 @@ public function shouldExecuteCancelRequestWithoutAfterUrl(): void { $this->token->setAfterUrl(null); - $controller = new CancelController(); - $controller->setContainer(new ServiceLocator(['payum' => function () { return $this->payum; }])); + $controller = new CancelController($this->payum); $response = $controller->doAction($this->request); @@ -55,7 +53,6 @@ protected function initGatewayMock(): void { $this->gatewayMock = $this->createMock(GatewayInterface::class); $this->gatewayMock - ->expects($this->any()) ->method('execute') ->with($this->isInstanceOf(Cancel::class)) ; diff --git a/Tests/Controller/CaptureControllerTest.php b/Tests/Controller/CaptureControllerTest.php index 4be704eb..ea4a5960 100644 --- a/Tests/Controller/CaptureControllerTest.php +++ b/Tests/Controller/CaptureControllerTest.php @@ -38,8 +38,7 @@ public function throwBadRequestIfSessionNotStartedOnDoSessionAction(): void HttpRequestVerifierInterface::class ); - $controller = new CaptureController(); - $controller->setContainer(new ServiceLocator(['payum' => function () { return $this->payum; }])); + $controller = new CaptureController($this->payum); $request = Request::create('/'); @@ -61,8 +60,7 @@ public function throwBadRequestIfSessionNotContainPayumTokenOnDoSessionAction(): HttpRequestVerifierInterface::class ); - $controller = new CaptureController(); - $controller->setContainer(new ServiceLocator(['payum' => function () { return $this->payum; }])); + $controller = new CaptureController($this->payum); $request = Request::create('/'); $request->setSession(new Session(new MockArraySessionStorage())); @@ -83,7 +81,7 @@ public function shouldDoRedirectToCaptureWithTokenUrl(): void 'payum_token' => 'theToken', 'foo' => 'fooVal', )) - ->will($this->returnValue('/payment/capture/theToken?foo=fooVal')) + ->willReturn('/payment/capture/theToken?foo=fooVal') ; $locator = new ServiceLocator([ @@ -96,7 +94,7 @@ public function shouldDoRedirectToCaptureWithTokenUrl(): void HttpRequestVerifierInterface::class ); - $controller = new CaptureController(); + $controller = new CaptureController($this->payum); $controller->setContainer($locator); $this->request = Request::create('/'); @@ -116,8 +114,7 @@ public function shouldDoRedirectToCaptureWithTokenUrl(): void */ public function shouldExecuteCaptureRequest(): void { - $controller = new CaptureController(); - $controller->setContainer(new ServiceLocator(['payum' => function () { return $this->payum; }])); + $controller = new CaptureController($this->payum); $response = $controller->doAction($this->request); @@ -129,7 +126,6 @@ protected function initGatewayMock(): void { $this->gatewayMock = $this->createMock(GatewayInterface::class); $this->gatewayMock - ->expects($this->any()) ->method('execute') ->with($this->isInstanceOf(Capture::class)) ; diff --git a/Tests/Controller/NotifyControllerTest.php b/Tests/Controller/NotifyControllerTest.php index 50dcfc20..e8f7db3e 100644 --- a/Tests/Controller/NotifyControllerTest.php +++ b/Tests/Controller/NotifyControllerTest.php @@ -6,6 +6,9 @@ use Payum\Core\GatewayInterface; use Payum\Core\Payum; use Payum\Core\Request\Notify; +use Payum\Core\Security\GenericTokenFactoryInterface; +use Payum\Core\Security\HttpRequestVerifierInterface; +use Payum\Core\Storage\StorageInterface; use PHPUnit\Framework\TestCase; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\DependencyInjection\ServiceLocator; @@ -34,19 +37,27 @@ public function shouldExecuteNotifyRequestOnDoUnsafe(): void $gatewayMock = $this->createMock(GatewayInterface::class); $gatewayMock - ->expects($this->any()) ->method('execute') ->with($this->isInstanceOf(Notify::class)); $registryMock = $this->createMock(Payum::class); $registryMock - ->expects($this->any()) ->method('getGateway') ->with('theGatewayName') - ->will($this->returnValue($gatewayMock)); + ->willReturn($gatewayMock); - $controller = new NotifyController(); - $controller->setContainer(new ServiceLocator(['payum' => function () use ($registryMock) { return $registryMock; }])); + $this->httpRequestVerifierMock = $this->createMock( + HttpRequestVerifierInterface::class + ); + + $this->payum = new Payum( + $registryMock, + $this->httpRequestVerifierMock, + $this->createMock(GenericTokenFactoryInterface::class), + $this->createMock(StorageInterface::class) + ); + + $controller = new NotifyController($this->payum); $response = $controller->doUnsafeAction($request); diff --git a/Tests/Controller/PayoutControllerTest.php b/Tests/Controller/PayoutControllerTest.php index d07922f7..48bd5ad1 100644 --- a/Tests/Controller/PayoutControllerTest.php +++ b/Tests/Controller/PayoutControllerTest.php @@ -25,8 +25,7 @@ public function shouldBeSubClassOfController(): void */ public function shouldExecutePayoutRequest(): void { - $controller = new PayoutController(); - $controller->setContainer(new ServiceLocator(['payum' => function () { return $this->payum; }])); + $controller = new PayoutController($this->payum); $response = $controller->doAction($this->request); diff --git a/Tests/Controller/RefundControllerTest.php b/Tests/Controller/RefundControllerTest.php index 4a7da487..5cf688c3 100644 --- a/Tests/Controller/RefundControllerTest.php +++ b/Tests/Controller/RefundControllerTest.php @@ -27,8 +27,7 @@ public function shouldBeSubClassOfController(): void */ public function shouldExecuteRefundRequest(): void { - $controller = new RefundController(); - $controller->setContainer(new ServiceLocator(['payum' => function () { return $this->payum; }])); + $controller = new RefundController($this->payum); $response = $controller->doAction($this->request); @@ -43,8 +42,7 @@ public function shouldExecuteRefundRequestWithoutAfterUrl(): void { $this->token->setAfterUrl(null); - $controller = new RefundController(); - $controller->setContainer(new ServiceLocator(['payum' => function () { return $this->payum; }])); + $controller = new RefundController($this->payum); $response = $controller->doAction($this->request); @@ -56,9 +54,8 @@ protected function initGatewayMock(): void { $this->gatewayMock = $this->createMock(GatewayInterface::class); $this->gatewayMock - ->expects($this->any()) ->method('execute') - ->with($this->isInstanceOf(Refund::class)); - + ->with($this->isInstanceOf(Refund::class)) + ; } } diff --git a/Tests/DependencyInjection/Compiler/BuildConfigsPassTest.php b/Tests/DependencyInjection/Compiler/BuildConfigsPassTest.php index c7ff579e..79bd24d6 100644 --- a/Tests/DependencyInjection/Compiler/BuildConfigsPassTest.php +++ b/Tests/DependencyInjection/Compiler/BuildConfigsPassTest.php @@ -192,7 +192,7 @@ public function testShouldImplementCompilerPassInterface(): void /** * @dataProvider provideTags */ - public function testShouldAddConfig(array $tagAttributes, $expected): void + public function testShouldAddConfig(array $tagAttributes, mixed $expected): void { $tagName = $tagAttributes['name']; unset($tagAttributes['name']); diff --git a/Tests/DependencyInjection/Factory/AbstractStorageFactoryTest.php b/Tests/DependencyInjection/Factory/AbstractStorageFactoryTest.php index e4013894..7d6ba567 100644 --- a/Tests/DependencyInjection/Factory/AbstractStorageFactoryTest.php +++ b/Tests/DependencyInjection/Factory/AbstractStorageFactoryTest.php @@ -16,7 +16,7 @@ class AbstractStorageFactoryTest extends \PHPUnit\Framework\TestCase */ public function shouldImplementStorageFactoryInterface(): void { - $rc = new \ReflectionClass('Payum\Bundle\PayumBundle\DependencyInjection\Factory\Storage\AbstractStorageFactory'); + $rc = new \ReflectionClass(AbstractStorageFactory::class); $this->assertTrue($rc->implementsInterface(StorageFactoryInterface::class)); } @@ -60,9 +60,9 @@ public function shouldAllowCreateStorageAndReturnItsId(): void $factory ->expects($this->once()) ->method('createStorage') - ->will($this->returnCallback(function() use ($expectedStorage) { + ->willReturnCallback(function () use ($expectedStorage) { return $expectedStorage; - })) + }) ; $container = new ContainerBuilder; @@ -77,7 +77,7 @@ public function shouldAllowCreateStorageAndReturnItsId(): void protected function assertDefinitionContainsMethodCall(Definition $serviceDefinition, $expectedMethod, $expectedFirstArgument): void { foreach ($serviceDefinition->getMethodCalls() as $methodCall) { - if ($expectedMethod == $methodCall[0] && $expectedFirstArgument == $methodCall[1][0]) { + if ($expectedMethod === $methodCall[0] && $expectedFirstArgument === $methodCall[1][0]) { return; } } @@ -90,11 +90,8 @@ protected function assertDefinitionContainsMethodCall(Definition $serviceDefinit )); } - /** - * @return AbstractStorageFactory|MockObject - */ - protected function createAbstractStorageFactory() + protected function createAbstractStorageFactory(): AbstractStorageFactory|MockObject { - return $this->getMockForAbstractClass('Payum\Bundle\PayumBundle\DependencyInjection\Factory\Storage\AbstractStorageFactory'); + return $this->getMockForAbstractClass(AbstractStorageFactory::class); } } diff --git a/Tests/DependencyInjection/Factory/CustomStorageFactoryTest.php b/Tests/DependencyInjection/Factory/CustomStorageFactoryTest.php index 15cdbdef..b830fcd2 100644 --- a/Tests/DependencyInjection/Factory/CustomStorageFactoryTest.php +++ b/Tests/DependencyInjection/Factory/CustomStorageFactoryTest.php @@ -1,12 +1,12 @@ assertTrue($rc->isSubclassOf('Payum\Bundle\PayumBundle\DependencyInjection\Factory\Storage\AbstractStorageFactory')); + $this->assertTrue($rc->isSubclassOf(AbstractStorageFactory::class)); } /** @@ -153,11 +153,8 @@ public function shouldCreateServiceDefinition(): void $this->assertSame($serviceName, $containerBuilder->getDefinition($storageId)->getParent()); } - /** - * @return MockObject|\Symfony\Component\DependencyInjection\ContainerBuilder - */ - protected function createContainerBuilderMock() + protected function createContainerBuilderMock(): ContainerBuilder|MockObject { - return $this->createMock('Symfony\Component\DependencyInjection\ContainerBuilder', array(), array(), '', false); + return $this->createMock(ContainerBuilder::class); } } diff --git a/Tests/DependencyInjection/MainConfigurationTest.php b/Tests/DependencyInjection/MainConfigurationTest.php index 6269be02..a0a1d14d 100644 --- a/Tests/DependencyInjection/MainConfigurationTest.php +++ b/Tests/DependencyInjection/MainConfigurationTest.php @@ -710,17 +710,17 @@ public function shouldAllowPutAnythingToGatewaysV2AndNotPerformAnyValidations(): class FooStorageFactory implements StorageFactoryInterface { - public function create(ContainerBuilder $container, $modelClass, array $config) + public function create(ContainerBuilder $container, string $modelClass, array $config): string { return 'aStorageId'; } - public function getName() + public function getName(): string { return 'foo_storage'; } - public function addConfiguration(ArrayNodeDefinition $builder) + public function addConfiguration(ArrayNodeDefinition $builder): void { $builder ->children() @@ -732,17 +732,17 @@ public function addConfiguration(ArrayNodeDefinition $builder) class BarStorageFactory implements StorageFactoryInterface { - public function create(ContainerBuilder $container, $modelClass, array $config) + public function create(ContainerBuilder $container, string $modelClass, array $config): string { return 'serviceId'; } - public function getName() + public function getName(): string { return 'bar_storage'; } - public function addConfiguration(ArrayNodeDefinition $builder) + public function addConfiguration(ArrayNodeDefinition $builder): void { $builder ->children() diff --git a/Tests/DependencyInjection/PayumExtensionTest.php b/Tests/DependencyInjection/PayumExtensionTest.php index 18061ba8..190fd8f3 100644 --- a/Tests/DependencyInjection/PayumExtensionTest.php +++ b/Tests/DependencyInjection/PayumExtensionTest.php @@ -297,7 +297,7 @@ public function shouldAddGatewaysToBuilder(): void class FeeStorageFactory implements StorageFactoryInterface { - public function create(ContainerBuilder $container, $modelClass, array $config) + public function create(ContainerBuilder $container, string $modelClass, array $config): string { return 'aStorageId'; } diff --git a/Tests/EventListener/ReplyToHttpResponseListenerTest.php b/Tests/EventListener/ReplyToHttpResponseListenerTest.php index 41572e34..8d9d1a1d 100644 --- a/Tests/EventListener/ReplyToHttpResponseListenerTest.php +++ b/Tests/EventListener/ReplyToHttpResponseListenerTest.php @@ -34,7 +34,7 @@ public function shouldDoNothingIfExceptionNotInstanceOfReply(): void $event = new ExceptionEvent( $this->createHttpKernelMock(), new Request, - Kernel::MASTER_REQUEST, + HttpKernelInterface::MAIN_REQUEST, $expectedException ); @@ -66,7 +66,7 @@ public function shouldSetResponseReturnedByConverterToEvent(): void $event = new ExceptionEvent( $this->createHttpKernelMock(), new Request, - Kernel::MASTER_REQUEST, + HttpKernelInterface::MAIN_REQUEST, $reply ); @@ -75,7 +75,7 @@ public function shouldSetResponseReturnedByConverterToEvent(): void ->expects($this->once()) ->method('convert') ->with($this->identicalTo($reply)) - ->will($this->returnValue($response)) + ->willReturn($response) ; $listener = new ReplyToHttpResponseListener($converterMock); @@ -94,14 +94,14 @@ public function shouldCallAllowCustomResponseCode(): void $reply = new HttpRedirect('/foo/bar'); $response = new Response('', 302); - $event = new ExceptionEvent($this->createHttpKernelMock(), new Request, Kernel::MASTER_REQUEST, $reply); + $event = new ExceptionEvent($this->createHttpKernelMock(), new Request, HttpKernelInterface::MAIN_REQUEST, $reply); $converterMock = $this->createReplyToSymfonyResponseConverterMock(); $converterMock ->expects($this->once()) ->method('convert') ->with($this->identicalTo($reply)) - ->will($this->returnValue($response)) + ->willReturn($response) ; $listener = new ReplyToHttpResponseListener($converterMock); @@ -113,19 +113,13 @@ public function shouldCallAllowCustomResponseCode(): void $this->assertEquals(true, $event->isAllowingCustomResponseCode()); } - /** - * @return MockObject|ReplyToSymfonyResponseConverter - */ - protected function createReplyToSymfonyResponseConverterMock() + protected function createReplyToSymfonyResponseConverterMock(): MockObject|ReplyToSymfonyResponseConverter { - return $this->createMock('Payum\Core\Bridge\Symfony\ReplyToSymfonyResponseConverter'); + return $this->createMock(ReplyToSymfonyResponseConverter::class); } - /** - * @return HttpKernelInterface|MockObject - */ - protected function createHttpKernelMock() + protected function createHttpKernelMock(): HttpKernelInterface|MockObject { - return $this->createMock('Symfony\Component\HttpKernel\HttpKernelInterface'); + return $this->createMock(HttpKernelInterface::class); } } diff --git a/Tests/Functional/Command/CreateCaptureTokenCommandTest.php b/Tests/Functional/Command/CreateCaptureTokenCommandTest.php index 6ef2e861..6d297683 100644 --- a/Tests/Functional/Command/CreateCaptureTokenCommandTest.php +++ b/Tests/Functional/Command/CreateCaptureTokenCommandTest.php @@ -27,7 +27,7 @@ public function shouldCreateCaptureTokenWithUrlAsAfterUrl(): void $modelId = $storage->identify($model)->getId(); - $output = $this->executeConsole(new CreateCaptureTokenCommand, array( + $output = $this->executeConsole(new CreateCaptureTokenCommand($payum), array( 'gateway-name' => 'fooGateway', '--model-class' => $modelClass, '--model-id' => $modelId, @@ -56,7 +56,7 @@ public function shouldCreateCaptureTokenWithRouteAsAfterUrl(): void $modelId = $storage->identify($model)->getId(); - $output = $this->executeConsole(new CreateCaptureTokenCommand, array( + $output = $this->executeConsole(new CreateCaptureTokenCommand($payum), array( 'gateway-name' => 'fooGateway', '--model-class' => $modelClass, '--model-id' => $modelId, diff --git a/Tests/Functional/Command/CreateNotifyTokenCommandTest.php b/Tests/Functional/Command/CreateNotifyTokenCommandTest.php index 11c2bd27..43545641 100644 --- a/Tests/Functional/Command/CreateNotifyTokenCommandTest.php +++ b/Tests/Functional/Command/CreateNotifyTokenCommandTest.php @@ -16,7 +16,10 @@ class CreateNotifyTokenCommandTest extends WebTestCase */ public function shouldCreateNotifyTokenWithoutModel(): void { - $output = $this->executeConsole(new CreateNotifyTokenCommand, array( + /** @var RegistryInterface $payum */ + $payum = $this->client->getContainer()->get('payum'); + + $output = $this->executeConsole(new CreateNotifyTokenCommand($payum), array( 'gateway-name' => 'fooGateway' )); @@ -41,7 +44,7 @@ public function shouldCreateNotifyTokenWithModel(): void $modelId = $storage->identify($model)->getId(); - $output = $this->executeConsole(new CreateNotifyTokenCommand, array( + $output = $this->executeConsole(new CreateNotifyTokenCommand($payum), array( 'gateway-name' => 'fooGateway', '--model-class' => $modelClass, '--model-id' => $modelId diff --git a/Tests/Functional/Command/DebugGatewayCommandTest.php b/Tests/Functional/Command/DebugGatewayCommandTest.php index 5795fc22..4d685eac 100644 --- a/Tests/Functional/Command/DebugGatewayCommandTest.php +++ b/Tests/Functional/Command/DebugGatewayCommandTest.php @@ -3,6 +3,7 @@ use Payum\Bundle\PayumBundle\Command\DebugGatewayCommand; use Payum\Bundle\PayumBundle\Tests\Functional\WebTestCase; +use Payum\Core\Registry\RegistryInterface; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Tester\CommandTester; @@ -15,7 +16,10 @@ class DebugGatewayCommandTest extends WebTestCase */ public function shouldOutputDebugInfoAboutSingleGateway(): void { - $output = $this->executeConsole(new DebugGatewayCommand(), array( + /** @var RegistryInterface $payum */ + $payum = $this->client->getContainer()->get('payum'); + + $output = $this->executeConsole(new DebugGatewayCommand($payum), array( 'gateway-name' => 'fooGateway', )); @@ -37,7 +41,10 @@ public function shouldOutputDebugInfoAboutSingleGateway(): void */ public function shouldOutputDebugInfoAboutAllGateways(): void { - $output = $this->executeConsole(new DebugGatewayCommand()); + /** @var RegistryInterface $payum */ + $payum = $this->client->getContainer()->get('payum'); + + $output = $this->executeConsole(new DebugGatewayCommand($payum)); $this->assertStringContainsString('Found 2 gateways', $output); $this->assertStringContainsString('fooGateway (Payum\Core\Gateway):', $output); @@ -49,7 +56,10 @@ public function shouldOutputDebugInfoAboutAllGateways(): void */ public function shouldOutputInfoWhatActionsSupports(): void { - $output = $this->executeConsole(new DebugGatewayCommand(), array( + /** @var RegistryInterface $payum */ + $payum = $this->client->getContainer()->get('payum'); + + $output = $this->executeConsole(new DebugGatewayCommand($payum), array( 'gateway-name' => 'fooGateway', '--show-supports' => true, )); @@ -66,7 +76,10 @@ public function shouldOutputInfoWhatActionsSupports(): void */ public function shouldOutputChoiceListGatewaysForNameGiven(): void { - $command = new DebugGatewayCommand(); + /** @var RegistryInterface $payum */ + $payum = $this->client->getContainer()->get('payum'); + + $command = new DebugGatewayCommand($payum); $command->setApplication(new Application($this->client->getKernel())); $output = $this->executeConsole($command, [ @@ -77,13 +90,6 @@ public function shouldOutputChoiceListGatewaysForNameGiven(): void $this->assertStringContainsString('[0] fooGateway', $output); } - /** - * @param Command $command - * @param string[] $arguments - * @param string[] $inputs - * - * @return string - */ protected function executeConsole(Command $command, array $arguments = [], array $inputs = []): string { if (!$command->getApplication()) { diff --git a/Tests/Functional/Command/StatusCommandTest.php b/Tests/Functional/Command/StatusCommandTest.php index f7bcf99f..a27b8061 100644 --- a/Tests/Functional/Command/StatusCommandTest.php +++ b/Tests/Functional/Command/StatusCommandTest.php @@ -27,7 +27,7 @@ public function shouldReturnNewStatus(): void $modelId = $storage->identify($model)->getId(); - $output = $this->executeConsole(new StatusCommand, array( + $output = $this->executeConsole(new StatusCommand($payum), array( 'gateway-name' => 'fooGateway', '--model-class' => $modelClass, '--model-id' => $modelId @@ -36,12 +36,6 @@ public function shouldReturnNewStatus(): void $this->assertStringContainsString("Status: new", $output); } - /** - * @param Command $command - * @param string[] $arguments - * - * @return string - */ protected function executeConsole(Command $command, array $arguments = array()): string { $command->setApplication(new Application($this->client->getKernel())); diff --git a/Tests/Functional/Form/Type/CreditCardExpirationDateTypeTest.php b/Tests/Functional/Form/Type/CreditCardExpirationDateTypeTest.php index df80f149..f43bf734 100644 --- a/Tests/Functional/Form/Type/CreditCardExpirationDateTypeTest.php +++ b/Tests/Functional/Form/Type/CreditCardExpirationDateTypeTest.php @@ -9,16 +9,13 @@ class CreditCardExpirationDateTypeTest extends WebTestCase { - /** - * @var FormFactoryInterface - */ - protected $formFactory; + protected ?FormFactoryInterface $formFactory; protected function setUp(): void { parent::setUp(); - $this->formFactory = static::$container->get('form.factory'); + $this->formFactory = static::getContainer()->get('form.factory'); } /** @@ -26,6 +23,7 @@ protected function setUp(): void */ public function couldBeCreatedByFormFactory(): void { + $this->markTestIncomplete('Symfony6 needs now a session. Rewrite in request-context'); $form = $this->formFactory->create(CreditCardExpirationDateType::class); $view = $form->createView(); @@ -44,7 +42,7 @@ public function shouldAllowSubmitExpireDateAsChoice(): void 'csrf_protection' => false, )); - $year = date('Y') + 2; + $year = (int) date('Y') + 2; $form->submit(array( 'day' => 1, diff --git a/Tests/Functional/Form/Type/CreditCardTypeTest.php b/Tests/Functional/Form/Type/CreditCardTypeTest.php index ff45c0c5..dba36a8c 100644 --- a/Tests/Functional/Form/Type/CreditCardTypeTest.php +++ b/Tests/Functional/Form/Type/CreditCardTypeTest.php @@ -10,16 +10,17 @@ class CreditCardTypeTest extends WebTestCase { - /** - * @var FormFactoryInterface - */ - protected $formFactory; + protected ?FormFactoryInterface $formFactory; protected function setUp(): void { parent::setUp(); - $this->formFactory = static::$container->get('form.factory'); + #$this->formFactory = static::$kernel->getContainer()->get('form.factory'); + #$this->formFactory = $this->client->getContainer()->get('form.factory'); + #$this->formFactory = static::$container->get('form.factory');static::getContainer()->get + $this->formFactory = static::getContainer()->get('form.factory'); + #dump($this->formFactory); } /** @@ -27,6 +28,7 @@ protected function setUp(): void */ public function couldBeCreatedByFormFactory(): void { + $this->markTestIncomplete('Symfony6 needs now a session. Rewrite in request-context'); $form = $this->formFactory->create(CreditCardType::class); $view = $form->createView(); @@ -43,7 +45,7 @@ public function shouldSubmitDataCorrectly(): void 'csrf_protection' => false, )); - $year = date('Y') + 2; + $year = (int) date('Y') + 2; $form->submit(array( 'holder' => 'John Doe', diff --git a/Tests/Functional/Form/Type/GatewayConfigTypeTest.php b/Tests/Functional/Form/Type/GatewayConfigTypeTest.php index bafcf72d..de86bf3a 100644 --- a/Tests/Functional/Form/Type/GatewayConfigTypeTest.php +++ b/Tests/Functional/Form/Type/GatewayConfigTypeTest.php @@ -10,16 +10,13 @@ class GatewayConfigTypeTest extends WebTestCase { - /** - * @var FormFactoryInterface - */ - protected $formFactory; + protected ?FormFactoryInterface $formFactory; protected function setUp(): void { parent::setUp(); - $this->formFactory = static::$container->get('form.factory'); + $this->formFactory = static::getContainer()->get('form.factory'); } /** @@ -27,9 +24,12 @@ protected function setUp(): void */ public function couldBeCreatedByFormFactory(): void { - $form = $this->formFactory->create(GatewayConfigType::class, null, array( + $this->markTestIncomplete('Symfony6 needs now a session. Rewrite in request-context'); + + $form = $this->formFactory->create(GatewayConfigType::class, null, [ 'data_class' => GatewayConfig::class, - )); + ]); + $view = $form->createView(); $this->assertInstanceOf(FormInterface::class, $form); diff --git a/Tests/Functional/Form/Type/GatewayFactoriesChoiceTypeTest.php b/Tests/Functional/Form/Type/GatewayFactoriesChoiceTypeTest.php index 3f3e89b3..09601cde 100644 --- a/Tests/Functional/Form/Type/GatewayFactoriesChoiceTypeTest.php +++ b/Tests/Functional/Form/Type/GatewayFactoriesChoiceTypeTest.php @@ -9,16 +9,13 @@ class GatewayFactoriesChoiceTypeTest extends WebTestCase { - /** - * @var FormFactoryInterface - */ - protected $formFactory; + protected ?FormFactoryInterface $formFactory; protected function setUp(): void { parent::setUp(); - $this->formFactory = static::$container->get('form.factory'); + $this->formFactory = static::getContainer()->get('form.factory'); } /** diff --git a/Tests/Functional/WebTestCase.php b/Tests/Functional/WebTestCase.php index 491f20e4..26082ebb 100644 --- a/Tests/Functional/WebTestCase.php +++ b/Tests/Functional/WebTestCase.php @@ -8,11 +8,7 @@ abstract class WebTestCase extends BaseWebTestCase { protected KernelBrowser $client; - - /** - * @var ContainerInterface - */ - protected static $container; + protected static ContainerInterface $container; protected function setUp(): void { diff --git a/Tests/Functional/app/AppKernel.php b/Tests/Functional/app/AppKernel.php index 444d8ff3..4b5b3f48 100644 --- a/Tests/Functional/app/AppKernel.php +++ b/Tests/Functional/app/AppKernel.php @@ -1,29 +1,44 @@ load(__DIR__ . '/config/config.yml'); + } +} diff --git a/Tests/Functional/app/AppKernelShared.php b/Tests/Functional/app/AppKernelShared.php deleted file mode 100644 index 0bf619f1..00000000 --- a/Tests/Functional/app/AppKernelShared.php +++ /dev/null @@ -1,44 +0,0 @@ -load(__DIR__ . '/config/config.yml'); - - if(Kernel::MAJOR_VERSION===4){ - $loader->load(__DIR__ . '/config/config_sf4.yml'); - } - else - { - $loader->load(__DIR__ . '/config/config_sf5.yml'); - } - } -} diff --git a/Tests/Functional/app/config/config.yml b/Tests/Functional/app/config/config.yml index 2feeb3a5..92193633 100644 --- a/Tests/Functional/app/config/config.yml +++ b/Tests/Functional/app/config/config.yml @@ -5,13 +5,25 @@ parameters: framework: #esi: ~ #translator: { fallback: %locale% } - test: ~ + test: true secret: '%secret%' router: { utf8: true, resource: '%kernel.project_dir%/Tests/Functional/app/config/routing.yml' } default_locale: '%locale%' - form: true - csrf_protection: true + form: true + csrf_protection: true assets: false + session: + handler_id: null + cookie_secure: auto + cookie_samesite: lax + storage_factory_id: session.storage.factory.mock_file + #validation: { enable_annotations: false } + +services: + _defaults: + autowire: true + autoconfigure: true + public: true payum: storages: diff --git a/Tests/Functional/app/config/config_sf4.yml b/Tests/Functional/app/config/config_sf4.yml deleted file mode 100644 index e23e7560..00000000 --- a/Tests/Functional/app/config/config_sf4.yml +++ /dev/null @@ -1,4 +0,0 @@ -framework: - session: - storage_id: 'session.storage.mock_file' - validation: { enable_annotations: true } \ No newline at end of file diff --git a/Tests/Functional/app/config/config_sf5.yml b/Tests/Functional/app/config/config_sf5.yml deleted file mode 100644 index f6c17d91..00000000 --- a/Tests/Functional/app/config/config_sf5.yml +++ /dev/null @@ -1,7 +0,0 @@ -framework: - session: - handler_id: null - cookie_secure: auto - cookie_samesite: lax - storage_factory_id: session.storage.factory.mock_file - validation: { enable_annotations: false } \ No newline at end of file diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php index 2e6e792b..10145a67 100644 --- a/Tests/bootstrap.php +++ b/Tests/bootstrap.php @@ -1,12 +1,2 @@ getHttpRequestVerifier()` removed. Use `payum->getHttpRequestVerifier()` +* deprecated function `PayumController->getTokenFactory()` removed. Use `payum->getTokenFactory()` + ## 2.0 to 2.1 * `payum.http_client` service was removed. Use gateway's config to overwrite it. diff --git a/composer.json b/composer.json index 0b6f53b1..d1624ec0 100644 --- a/composer.json +++ b/composer.json @@ -37,22 +37,22 @@ } ], "require": { - "php": "^7.4 || ^8.0", + "php": ">=8.0.2", "payum/core": "^1.6", - "symfony/framework-bundle": "^4.4 || ^5.0", - "symfony/form": "^4.4.20 || ^5.0", - "symfony/validator": "^4.4 || ^5.0", - "symfony/security-csrf": "^4.4 | ^5.0" + "symfony/framework-bundle": "^5.4 || ^6.0", + "symfony/form": "^5.4 || ^6.0", + "symfony/validator": "^5.4 || ^6.0", + "symfony/security-csrf": "^5.4 || ^6.0" }, "require-dev": { "phpunit/phpunit": "^9.5", "twig/twig": "^1.16 || ^2.0 || ^3.0", - "symfony/twig-bundle": "^4.4|^5", - "symfony/expression-language": "^4.4 || ^5.0", - "symfony/browser-kit": "^4.4 || ^5.0", - "symfony/phpunit-bridge": "6.0", - "symfony/templating": "^4.4 || ^5.0", - "symfony/yaml": "^4.4 || ^5.0 ", + "symfony/twig-bundle": "^5.4 || ^6.0", + "symfony/expression-language": "^5.4 || ^6.0", + "symfony/browser-kit": "^5.4 || ^6.0", + "symfony/phpunit-bridge": "^6.0", + "symfony/templating": "^5.4 || ^6.0", + "symfony/yaml": "^5.4 || ^6.0", "defuse/php-encryption": "^2", "doctrine/orm": "~2.5", "payum/omnipay-v3-bridge": "^1@alpha", From 19bb96f7c737f13003e62e450306c15cc0dc47c2 Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Sun, 6 Mar 2022 10:15:13 +0100 Subject: [PATCH 02/25] feat: support symfony 6 --- Tests/Functional/WebTestCase.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Tests/Functional/WebTestCase.php b/Tests/Functional/WebTestCase.php index 26082ebb..9b1fc373 100644 --- a/Tests/Functional/WebTestCase.php +++ b/Tests/Functional/WebTestCase.php @@ -8,7 +8,9 @@ abstract class WebTestCase extends BaseWebTestCase { protected KernelBrowser $client; - protected static ContainerInterface $container; + + /* @var $container ContainerInterface */ + protected static $container; protected function setUp(): void { From 71203975f9c3aad75611aab4f9b56d95334ec4b9 Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Sun, 6 Mar 2022 10:18:27 +0100 Subject: [PATCH 03/25] feat: support symfony 6 --- Tests/Functional/app/config/config.yml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/Tests/Functional/app/config/config.yml b/Tests/Functional/app/config/config.yml index 92193633..299eafb0 100644 --- a/Tests/Functional/app/config/config.yml +++ b/Tests/Functional/app/config/config.yml @@ -5,7 +5,7 @@ parameters: framework: #esi: ~ #translator: { fallback: %locale% } - test: true + test: ~ secret: '%secret%' router: { utf8: true, resource: '%kernel.project_dir%/Tests/Functional/app/config/routing.yml' } default_locale: '%locale%' @@ -17,13 +17,6 @@ framework: cookie_secure: auto cookie_samesite: lax storage_factory_id: session.storage.factory.mock_file - #validation: { enable_annotations: false } - -services: - _defaults: - autowire: true - autoconfigure: true - public: true payum: storages: From 5bbe1dd62b11b42be20d198274cd68e786beb4b8 Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Sun, 6 Mar 2022 10:22:06 +0100 Subject: [PATCH 04/25] feat: support symfony 6 --- Tests/Functional/Form/Type/CreditCardTypeTest.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Tests/Functional/Form/Type/CreditCardTypeTest.php b/Tests/Functional/Form/Type/CreditCardTypeTest.php index dba36a8c..5bfcc1dc 100644 --- a/Tests/Functional/Form/Type/CreditCardTypeTest.php +++ b/Tests/Functional/Form/Type/CreditCardTypeTest.php @@ -16,11 +16,7 @@ protected function setUp(): void { parent::setUp(); - #$this->formFactory = static::$kernel->getContainer()->get('form.factory'); - #$this->formFactory = $this->client->getContainer()->get('form.factory'); - #$this->formFactory = static::$container->get('form.factory');static::getContainer()->get $this->formFactory = static::getContainer()->get('form.factory'); - #dump($this->formFactory); } /** From 944dfcf8da82582126fc531f6fcd5792c1b31851 Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Sun, 6 Mar 2022 14:01:44 +0100 Subject: [PATCH 05/25] feat: support symfony 6 --- Profiler/PayumCollector.php | 3 ++- Resources/doc/get_it_started.md | 2 +- composer.json | 38 +++++++++++++++------------------ 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/Profiler/PayumCollector.php b/Profiler/PayumCollector.php index e0c375ba..42f59d4c 100644 --- a/Profiler/PayumCollector.php +++ b/Profiler/PayumCollector.php @@ -7,6 +7,7 @@ use Symfony\Component\HttpKernel\DataCollector\DataCollector; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\VarDumper\Cloner\Data; class PayumCollector extends DataCollector implements ExtensionInterface { @@ -16,7 +17,7 @@ class PayumCollector extends DataCollector implements ExtensionInterface private array $contexts = []; /** - * @var array + * @var array|Data */ protected $data = []; diff --git a/Resources/doc/get_it_started.md b/Resources/doc/get_it_started.md index 59d8b7a7..b97a733c 100644 --- a/Resources/doc/get_it_started.md +++ b/Resources/doc/get_it_started.md @@ -6,7 +6,7 @@ The preferred way to install the library is using [composer](http://getcomposer. Run composer require to add dependencies to _composer.json_: ```bash -php composer.phar require "payum/payum-bundle" "payum/offline" "php-http/guzzle6-adapter" +php composer.phar require "payum/payum-bundle" "payum/offline" "php-http/guzzle7-adapter" ``` _**Note**: Where payum/offline is a php payum extension, you can for example change it to payum/paypal-express-checkout-nvp or payum/stripe. Look at [supported gateways](https://github.com/Payum/Core/blob/master/Resources/docs/supported-gateways.md) to find out what you can use._ diff --git a/composer.json b/composer.json index d1624ec0..c67f9eec 100644 --- a/composer.json +++ b/composer.json @@ -38,38 +38,31 @@ ], "require": { "php": ">=8.0.2", - "payum/core": "^1.6", + "payum/core": "^1.6.1", "symfony/framework-bundle": "^5.4 || ^6.0", "symfony/form": "^5.4 || ^6.0", "symfony/validator": "^5.4 || ^6.0", "symfony/security-csrf": "^5.4 || ^6.0" }, "require-dev": { - "phpunit/phpunit": "^9.5", - "twig/twig": "^1.16 || ^2.0 || ^3.0", - "symfony/twig-bundle": "^5.4 || ^6.0", - "symfony/expression-language": "^5.4 || ^6.0", - "symfony/browser-kit": "^5.4 || ^6.0", - "symfony/phpunit-bridge": "^6.0", - "symfony/templating": "^5.4 || ^6.0", - "symfony/yaml": "^5.4 || ^6.0", "defuse/php-encryption": "^2", "doctrine/orm": "~2.5", - "payum/omnipay-v3-bridge": "^1@alpha", - "payum/payum": "^1.6.2", - "php-http/guzzle6-adapter": "1.1.1", + "omnipay/common": "^3@dev", "omnipay/dummy": "^3@alpha", "omnipay/paypal": "^3@dev", - "omnipay/common": "^3@dev", - "paypal/rest-api-sdk-php" : "0.5.*", - "klarna/checkout": "~1|~2.0", - "fp/klarna-invoice": "0.1.*", - "stripe/stripe-php": "~1.0", - "doctrine/annotations": "^1.9", + "payum/omnipay-v3-bridge": "^1@alpha", + "payum/payum": "^1.6.2", + "php-http/guzzle7-adapter": "^1.0", + "phpunit/phpunit": "^9.5", "psr/log": "^1 || ^2", - "ext-curl": "*", - "ext-pdo_sqlite": "*", - "ext-soap": "*" + "stripe/stripe-php": "~7.0", + "symfony/browser-kit": "^5.4 || ^6.0", + "symfony/expression-language": "^5.4 || ^6.0", + "symfony/phpunit-bridge": "^6.0", + "symfony/templating": "^5.4 || ^6.0", + "symfony/twig-bundle": "^5.4 || ^6.0", + "symfony/yaml": "^5.4 || ^6.0", + "twig/twig": "^2.0 || ^3.0" }, "suggest": { "sonata-project/admin-bundle": "^3 If you want to configure payments in the backend." @@ -77,6 +70,9 @@ "autoload": { "psr-4": { "Payum\\Bundle\\PayumBundle\\": "" } }, + "autoload-dev": { + "psr-4": { "Payum\\Bundle\\PayumBundle\\Tests\\": "Tests/" } + }, "extra": { "branch-alias": { "dev-master": "2.5-dev" From d78c6b1f9097832c1d9f0393c2438778a75449c6 Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Sun, 6 Mar 2022 23:21:59 +0100 Subject: [PATCH 06/25] feat: support symfony 6 --- CHANGELOG.md | 1 + UPGRADE.md | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff0d055a..8aea0b29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Symfony < 5 support is dropped * PHP < 8 support is dropped +* BC Break: Add more strong types to `StorageFactoryInterface` * deprecated function `PayumController->getHttpRequestVerifier()` removed * deprecated function `PayumController->getTokenFactory()` removed * Please see UPGRADE.md diff --git a/UPGRADE.md b/UPGRADE.md index 5a07ae94..8fd8dbaa 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -6,6 +6,7 @@ Library [upgrades](https://github.com/Payum/Payum/blob/master/UPGRADE.md). * Symfony < 5 support is dropped * PHP < 8 support is dropped +* BC Break: Add more strong types to `StorageFactoryInterface` * deprecated function `PayumController->getHttpRequestVerifier()` removed. Use `payum->getHttpRequestVerifier()` * deprecated function `PayumController->getTokenFactory()` removed. Use `payum->getTokenFactory()` From 162dc4133ec8ecadf3ab851453ee5d7c72dcec3b Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Mon, 4 Apr 2022 17:06:07 +0200 Subject: [PATCH 07/25] feat: support symfony 6 --- Tests/Functional/PayumTest.php | 2 +- composer.json | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Tests/Functional/PayumTest.php b/Tests/Functional/PayumTest.php index e904e9b1..a1c44085 100644 --- a/Tests/Functional/PayumTest.php +++ b/Tests/Functional/PayumTest.php @@ -79,7 +79,7 @@ public function testShouldReturnGatewaysFactories(): void $factories = $payum->getGatewayFactories(); $this->assertIsArray($factories); - $this->assertGreaterThan(10, count($factories)); + $this->assertGreaterThan(5, count($factories)); } public function testShouldReturnGatewayFactory(): void diff --git a/composer.json b/composer.json index c67f9eec..d0434140 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ ], "require": { "php": ">=8.0.2", - "payum/core": "^1.6.1", + "payum/core": "^1.7", "symfony/framework-bundle": "^5.4 || ^6.0", "symfony/form": "^5.4 || ^6.0", "symfony/validator": "^5.4 || ^6.0", @@ -46,12 +46,14 @@ }, "require-dev": { "defuse/php-encryption": "^2", - "doctrine/orm": "~2.5", + "doctrine/orm": "^2.8", "omnipay/common": "^3@dev", "omnipay/dummy": "^3@alpha", "omnipay/paypal": "^3@dev", + "payum/offline": "^1.7", + "payum/paypal-express-checkout-nvp": "^1.7", + "payum/stripe": "^1.7", "payum/omnipay-v3-bridge": "^1@alpha", - "payum/payum": "^1.6.2", "php-http/guzzle7-adapter": "^1.0", "phpunit/phpunit": "^9.5", "psr/log": "^1 || ^2", From 3f8b24a5bc122f8f8422a9144e31868bb8c57e6b Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Sun, 8 May 2022 11:32:12 +0200 Subject: [PATCH 08/25] feat: support symfony 6 (quicktest) --- composer.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index d0434140..ef721ecb 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ ], "require": { "php": ">=8.0.2", - "payum/core": "^1.7", + "payum/payum": "1.x-dev", "symfony/framework-bundle": "^5.4 || ^6.0", "symfony/form": "^5.4 || ^6.0", "symfony/validator": "^5.4 || ^6.0", @@ -63,6 +63,7 @@ "symfony/phpunit-bridge": "^6.0", "symfony/templating": "^5.4 || ^6.0", "symfony/twig-bundle": "^5.4 || ^6.0", + "symfony/web-profiler-bundle": "^5.4 || ^6.0", "symfony/yaml": "^5.4 || ^6.0", "twig/twig": "^2.0 || ^3.0" }, @@ -82,5 +83,7 @@ }, "config": { "bin-dir": "bin" - } + }, + "minimum-stability": "dev", + "prefer-stable": true } From e6b8a27aac7e03f8bcbcf3e14e5382174152ced4 Mon Sep 17 00:00:00 2001 From: Pierre du Plessis Date: Mon, 4 Jul 2022 14:59:33 +0200 Subject: [PATCH 09/25] Run tests on multiple Symfony and PHP versions --- .github/workflows/tests.yaml | 58 +++++++++++++----------------------- 1 file changed, 20 insertions(+), 38 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index a5175d5e..f8092646 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -7,15 +7,31 @@ env: jobs: unit-test: - name: Unit ( PHP ${{ matrix.php }} ) + name: Unit ( PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }} ) runs-on: ubuntu-latest strategy: fail-fast: false matrix: include: + - php: 7.4 + symfony: ^4.4 + - php: 7.4 + symfony: ^5.4 - php: 8.0 + symfony: ^4.4 + - php: 8.0 + symfony: ^5.4 + - php: 8.0 + symfony: 6.0 + - php: 8.1 + symfony: ^4.4 + - php: 8.1 + symfony: ^5.4 + - php: 8.1 + symfony: 6.0 - php: 8.1 + symfony: 6.1 steps: - name: Checkout @@ -38,45 +54,11 @@ jobs: key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json composer.lock') }} restore-keys: ${{ runner.os }}-php-${{ matrix.php }}-composer- - - name: Install dependencies - run: composer update - - - name: Run unit tests - run: bin/phpunit - - lowest: - name: Unit ( PHP ${{ matrix.php }} + Lowest ) - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - include: - - php: 8.0 - - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: intl, opcache, mysql, pdo_mysql, :xdebug - - - name: Get composer cache directory - id: composercache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - - name: Cache dependencies - uses: actions/cache@v2 - with: - path: ${{ steps.composercache.outputs.dir }} - key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json composer.lock') }} - restore-keys: ${{ runner.os }}-php-${{ matrix.php }}-composer- + - name: Install Symfony ${{ matrix.symfony }} + run: composer require --no-update ${{ matrix.symfony }} - name: Install dependencies - run: composer update --prefer-lowest --prefer-stable + run: composer update - name: Run unit tests run: bin/phpunit From 8bc3958c7962ba923414b0d449d2714dc4424b5e Mon Sep 17 00:00:00 2001 From: Pierre du Plessis Date: Mon, 4 Jul 2022 15:00:23 +0200 Subject: [PATCH 10/25] Revert some PHP 8 only functionality to keep compatibility with older PHP and Symfony versions --- CHANGELOG.md | 13 ++- Command/CreateCaptureTokenCommand.php | 11 ++- Command/CreateNotifyTokenCommand.php | 11 ++- Command/DebugGatewayCommand.php | 11 ++- Command/StatusCommand.php | 9 ++- Controller/AuthorizeController.php | 12 +-- Controller/CancelController.php | 15 ++-- Controller/CaptureController.php | 10 +-- Controller/NotifyController.php | 6 +- Controller/PayoutController.php | 10 +-- Controller/PayumController.php | 81 ++++++++++++++++++- Controller/RefundController.php | 13 ++- Controller/SyncController.php | 10 +-- .../Storage/StorageFactoryInterface.php | 10 ++- DependencyInjection/PayumExtension.php | 2 +- EventListener/ReplyToHttpResponseListener.php | 8 +- .../GatewayFactoriesChoiceTypeExtension.php | 13 ++- Resources/config/controller.xml | 71 ++++++++++++---- .../Compiler/BuildConfigsPassTest.php | 4 +- .../Factory/AbstractStorageFactoryTest.php | 11 ++- .../Factory/CustomStorageFactoryTest.php | 5 +- .../ReplyToHttpResponseListenerTest.php | 10 ++- .../Type/CreditCardExpirationDateTypeTest.php | 1 - .../Form/Type/CreditCardTypeTest.php | 1 - .../Form/Type/GatewayConfigTypeTest.php | 2 - Tests/Functional/WebTestCase.php | 4 +- UPGRADE.md | 7 +- composer.json | 33 +++++--- 28 files changed, 283 insertions(+), 111 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8aea0b29..5cbae576 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,10 @@ # Changelog -## 3.0.0 (2022-03-xx) - -* Symfony < 5 support is dropped -* PHP < 8 support is dropped -* BC Break: Add more strong types to `StorageFactoryInterface` -* deprecated function `PayumController->getHttpRequestVerifier()` removed -* deprecated function `PayumController->getTokenFactory()` removed -* Please see UPGRADE.md +## 2.5.0 (2022-07-xx) + +* Support for Symfony 5.0 - 5.3 dropped +* Added support for Symfony 6.0 +* Minimum Payum Core dependency updated to 1.7.2 ## 2.3.1 (2018-08-19) diff --git a/Command/CreateCaptureTokenCommand.php b/Command/CreateCaptureTokenCommand.php index c0998827..d2208094 100644 --- a/Command/CreateCaptureTokenCommand.php +++ b/Command/CreateCaptureTokenCommand.php @@ -13,8 +13,14 @@ #[AsCommand(name: 'payum:security:create-capture-token')] class CreateCaptureTokenCommand extends Command { - public function __construct(protected Payum $payum) + protected static $defaultName = 'payum:security:create-capture-token'; + + private Payum $payum; + + public function __construct(Payum $payum) { + $this->payum = $payum; + parent::__construct(); } @@ -24,6 +30,7 @@ public function __construct(protected Payum $payum) protected function configure(): void { $this + ->setName(static::$defaultName) ->addArgument('gateway-name', InputArgument::REQUIRED, 'The gateway name associated with the token') ->addOption('model-class', null, InputOption::VALUE_OPTIONAL, 'The model class associated with the token') ->addOption('model-id', null, InputOption::VALUE_OPTIONAL, 'The model id associated with the token') @@ -59,6 +66,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln(sprintf('After Url: %s', $token->getAfterUrl() ?: 'null')); $output->writeln(sprintf('Details: %s', (string) $token->getDetails())); - return Command::SUCCESS; + return 0; } } diff --git a/Command/CreateNotifyTokenCommand.php b/Command/CreateNotifyTokenCommand.php index e69b574d..90bed7a6 100644 --- a/Command/CreateNotifyTokenCommand.php +++ b/Command/CreateNotifyTokenCommand.php @@ -13,8 +13,14 @@ #[AsCommand(name: 'payum:security:create-notify-token')] class CreateNotifyTokenCommand extends Command { - public function __construct(protected Payum $payum) + protected static $defaultName = 'payum:security:create-notify-token'; + + private Payum $payum; + + public function __construct(Payum $payum) { + $this->payum = $payum; + parent::__construct(); } @@ -24,6 +30,7 @@ public function __construct(protected Payum $payum) protected function configure(): void { $this + ->setName(self::$defaultName) ->addArgument('gateway-name', InputArgument::REQUIRED, 'The gateway name associated with the token') ->addOption('model-class', null, InputOption::VALUE_OPTIONAL, 'The model class associated with the token') ->addOption('model-id', null, InputOption::VALUE_OPTIONAL, 'The model id associated with the token') @@ -56,6 +63,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln(sprintf('Url: %s', $token->getTargetUrl())); $output->writeln(sprintf('Details: %s', (string) $token->getDetails() ?: 'null')); - return Command::SUCCESS; + return 0; } } diff --git a/Command/DebugGatewayCommand.php b/Command/DebugGatewayCommand.php index 1fe01677..446e1cd4 100644 --- a/Command/DebugGatewayCommand.php +++ b/Command/DebugGatewayCommand.php @@ -16,8 +16,13 @@ #[AsCommand(name: 'debug:payum:gateway', aliases: ['payum:gateway:debug'])] class DebugGatewayCommand extends Command { - public function __construct(protected Payum $payum) + protected static $defaultName = 'debug:payum:gateway'; + + protected Payum $payum; + + public function __construct(Payum $payum) { + $this->payum = $payum; parent::__construct(); } @@ -27,6 +32,8 @@ public function __construct(protected Payum $payum) protected function configure(): void { $this + ->setName(self::$defaultName) + ->setAliases(['payum:gateway:debug']) ->addArgument('gateway-name', InputArgument::OPTIONAL, 'The gateway name you want to get information about.') ->addOption('show-supports', null, InputOption::VALUE_NONE, 'Show what actions supports.') ; @@ -120,7 +127,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } } - return Command::SUCCESS; + return 0; } protected function getMethodCode(\ReflectionMethod $reflectionMethod): array diff --git a/Command/StatusCommand.php b/Command/StatusCommand.php index 1c097d1b..e4d29460 100644 --- a/Command/StatusCommand.php +++ b/Command/StatusCommand.php @@ -14,8 +14,13 @@ #[AsCommand(name: 'payum:status', description: 'Allows to get a payment status.')] class StatusCommand extends Command { - public function __construct(protected Payum $payum) + protected static $defaultName = 'payum:status'; + + protected Payum $payum; + + public function __construct(Payum $payum) { + $this->payum = $payum; parent::__construct(); } @@ -25,6 +30,8 @@ public function __construct(protected Payum $payum) protected function configure(): void { $this + ->setName(static::$defaultName) + ->setDescription('Allows to get a payment status.') ->addArgument('gateway-name', InputArgument::REQUIRED, 'The gateway name') ->addOption('model-class', null, InputOption::VALUE_REQUIRED, 'The model class') ->addOption('model-id', null, InputOption::VALUE_REQUIRED, 'The model id') diff --git a/Controller/AuthorizeController.php b/Controller/AuthorizeController.php index ddc3ef63..b4d5bf68 100644 --- a/Controller/AuthorizeController.php +++ b/Controller/AuthorizeController.php @@ -9,13 +9,13 @@ class AuthorizeController extends PayumController { public function doAction(Request $request): RedirectResponse { - $token = $this->payum->getHttpRequestVerifier()->verify($request); + $token = $this->getPayum()->getHttpRequestVerifier()->verify($request); - $gateway = $this->payum->getGateway($token->getGatewayName()); + $gateway = $this->getPayum()->getGateway($token->getGatewayName()); $gateway->execute(new Authorize($token)); - - $this->payum->getHttpRequestVerifier()->invalidate($token); - + + $this->getPayum()->getHttpRequestVerifier()->invalidate($token); + return $this->redirect($token->getAfterUrl()); } -} \ No newline at end of file +} diff --git a/Controller/CancelController.php b/Controller/CancelController.php index 35d0a7b1..002c1d47 100644 --- a/Controller/CancelController.php +++ b/Controller/CancelController.php @@ -2,7 +2,6 @@ namespace Payum\Bundle\PayumBundle\Controller; use Payum\Core\Request\Cancel; -use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -11,18 +10,18 @@ class CancelController extends PayumController /** * @throws \Exception */ - public function doAction(Request $request): Response|RedirectResponse + public function doAction(Request $request): Response { - $token = $this->payum->getHttpRequestVerifier()->verify($request); + $token = $this->getPayum()->getHttpRequestVerifier()->verify($request); - $gateway = $this->payum->getGateway($token->getGatewayName()); + $gateway = $this->getPayum()->getGateway($token->getGatewayName()); $gateway->execute(new Cancel($token)); - - $this->payum->getHttpRequestVerifier()->invalidate($token); - + + $this->getPayum()->getHttpRequestVerifier()->invalidate($token); + return $token->getAfterUrl() ? $this->redirect($token->getAfterUrl()) : new Response('', 204) ; } -} \ No newline at end of file +} diff --git a/Controller/CaptureController.php b/Controller/CaptureController.php index 87ff0155..ff6d7a81 100644 --- a/Controller/CaptureController.php +++ b/Controller/CaptureController.php @@ -37,13 +37,13 @@ public function doSessionTokenAction(Request $request): RedirectResponse public function doAction(Request $request): RedirectResponse { - $token = $this->payum->getHttpRequestVerifier()->verify($request); + $token = $this->getPayum()->getHttpRequestVerifier()->verify($request); - $gateway = $this->payum->getGateway($token->getGatewayName()); + $gateway = $this->getPayum()->getGateway($token->getGatewayName()); $gateway->execute(new Capture($token)); - - $this->payum->getHttpRequestVerifier()->invalidate($token); - + + $this->getPayum()->getHttpRequestVerifier()->invalidate($token); + return $this->redirect($token->getAfterUrl()); } } diff --git a/Controller/NotifyController.php b/Controller/NotifyController.php index 723b0c0f..15a4870c 100644 --- a/Controller/NotifyController.php +++ b/Controller/NotifyController.php @@ -9,7 +9,7 @@ class NotifyController extends PayumController { public function doUnsafeAction(Request $request): Response { - $gateway = $this->payum->getGateway($request->get('gateway')); + $gateway = $this->getPayum()->getGateway($request->get('gateway')); $gateway->execute(new Notify(null)); @@ -18,9 +18,9 @@ public function doUnsafeAction(Request $request): Response public function doAction(Request $request): Response { - $token = $this->payum->getHttpRequestVerifier()->verify($request); + $token = $this->getPayum()->getHttpRequestVerifier()->verify($request); - $gateway = $this->payum->getGateway($token->getGatewayName()); + $gateway = $this->getPayum()->getGateway($token->getGatewayName()); $gateway->execute(new Notify($token)); diff --git a/Controller/PayoutController.php b/Controller/PayoutController.php index 4ff34683..ca211e23 100644 --- a/Controller/PayoutController.php +++ b/Controller/PayoutController.php @@ -9,13 +9,13 @@ class PayoutController extends PayumController { public function doAction(Request $request): RedirectResponse { - $token = $this->payum->getHttpRequestVerifier()->verify($request); + $token = $this->getPayum()->getHttpRequestVerifier()->verify($request); - $gateway = $this->payum->getGateway($token->getGatewayName()); + $gateway = $this->getPayum()->getGateway($token->getGatewayName()); $gateway->execute(new Payout($token)); - - $this->payum->getHttpRequestVerifier()->invalidate($token); - + + $this->getPayum()->getHttpRequestVerifier()->invalidate($token); + return $this->redirect($token->getAfterUrl()); } } diff --git a/Controller/PayumController.php b/Controller/PayumController.php index b0338b3b..7fe08ca0 100644 --- a/Controller/PayumController.php +++ b/Controller/PayumController.php @@ -2,12 +2,53 @@ namespace Payum\Bundle\PayumBundle\Controller; use Payum\Core\Payum; +use Payum\Core\Security\GenericTokenFactoryInterface; +use Payum\Core\Security\HttpRequestVerifierInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use function sprintf; +use function trigger_error; +use const E_USER_DEPRECATED; abstract class PayumController extends AbstractController { - public function __construct(protected ?Payum $payum) - {} + protected ?Payum $payum = null; + + public function __construct(?Payum $payum = null) + { + if ($payum === null) { + @trigger_error( + sprintf( + '%s requires an instance of %s asd the first argument. Not passing this object is deprecated and it will be required in payum/payum-bundle 2.0.', + __METHOD__, + Payum::class + ), + E_USER_DEPRECATED + ); + } + + $this->payum = $payum; + } + + /** + * @deprecated since 2.5 and will be removed in 3.0. Use $this->>payum instead. + */ + protected function getPayum() + { + $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); + + if (!str_starts_with($backtrace[1]['class'], 'Payum\\Bundle\\PayumBundle')) { + // Only trigger deprecation if called from outside the bundle + @trigger_error( + sprintf( + 'The method %s is deprecated since 2.5 and will be removed in 3.0. Use $this->payum instead', + __METHOD__, + ), + E_USER_DEPRECATED + ); + } + + return $this->payum ?? $this->container->get('payum'); + } public static function getSubscribedServices(): array { @@ -15,4 +56,40 @@ public static function getSubscribedServices(): array 'payum' => Payum::class, ]); } + + /** + * @deprecated will be removed in 3.0. + * + * @return HttpRequestVerifierInterface + */ + protected function getHttpRequestVerifier() + { + @trigger_error( + sprintf( + 'The method %s is deprecated since 2.5 and will be removed in 3.0. Use $this->payum->getHttpRequestVerifier() instead', + __METHOD__, + ), + E_USER_DEPRECATED + ); + + return $this->getPayum()->getHttpRequestVerifier(); + } + + /** + * @deprecated will be removed in 3.0. + * + * @return GenericTokenFactoryInterface + */ + protected function getTokenFactory() + { + @trigger_error( + sprintf( + 'The method %s is deprecated since 2.5 and will be removed in 3.0. Use $this->payum->getTokenFactory() instead', + __METHOD__, + ), + E_USER_DEPRECATED + ); + + return $this->getPayum()->getTokenFactory(); + } } diff --git a/Controller/RefundController.php b/Controller/RefundController.php index a04f3293..b1bfb7fe 100644 --- a/Controller/RefundController.php +++ b/Controller/RefundController.php @@ -2,7 +2,6 @@ namespace Payum\Bundle\PayumBundle\Controller; use Payum\Core\Request\Refund; -use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -11,15 +10,15 @@ class RefundController extends PayumController /** * @throws \Exception */ - public function doAction(Request $request): Response|RedirectResponse + public function doAction(Request $request): Response { - $token = $this->payum->getHttpRequestVerifier()->verify($request); + $token = $this->getPayum()->getHttpRequestVerifier()->verify($request); - $gateway = $this->payum->getGateway($token->getGatewayName()); + $gateway = $this->getPayum()->getGateway($token->getGatewayName()); $gateway->execute(new Refund($token)); - - $this->payum->getHttpRequestVerifier()->invalidate($token); - + + $this->getPayum()->getHttpRequestVerifier()->invalidate($token); + return $token->getAfterUrl() ? $this->redirect($token->getAfterUrl()) : new Response('', 204) diff --git a/Controller/SyncController.php b/Controller/SyncController.php index a55e53cf..3051b542 100644 --- a/Controller/SyncController.php +++ b/Controller/SyncController.php @@ -9,14 +9,14 @@ class SyncController extends PayumController { public function doAction(Request $request): RedirectResponse { - $token = $this->payum->getHttpRequestVerifier()->verify($request); + $token = $this->getPayum()->getHttpRequestVerifier()->verify($request); - $gateway = $this->payum->getGateway($token->getGatewayName()); + $gateway = $this->getPayum()->getGateway($token->getGatewayName()); $gateway->execute(new Sync($token)); - - $this->payum->getHttpRequestVerifier()->invalidate($token); - + + $this->getPayum()->getHttpRequestVerifier()->invalidate($token); + return $this->redirect($token->getAfterUrl()); } } diff --git a/DependencyInjection/Factory/Storage/StorageFactoryInterface.php b/DependencyInjection/Factory/Storage/StorageFactoryInterface.php index 6adc55a3..dc3e897c 100644 --- a/DependencyInjection/Factory/Storage/StorageFactoryInterface.php +++ b/DependencyInjection/Factory/Storage/StorageFactoryInterface.php @@ -7,15 +7,19 @@ interface StorageFactoryInterface { /** + * @param string $modelClass * @return string The payment serviceId */ - public function create(ContainerBuilder $container, string $modelClass, array $config): string; + public function create(ContainerBuilder $container, $modelClass, array $config); /** * The storage name, * For example filesystem, doctrine, propel etc. */ - public function getName(): string; + public function getName(); - public function addConfiguration(ArrayNodeDefinition $builder): void; + /** + * @return void + */ + public function addConfiguration(ArrayNodeDefinition $builder); } diff --git a/DependencyInjection/PayumExtension.php b/DependencyInjection/PayumExtension.php index 748ecad4..4c062718 100644 --- a/DependencyInjection/PayumExtension.php +++ b/DependencyInjection/PayumExtension.php @@ -274,7 +274,7 @@ public function addStorageFactory(StorageFactoryInterface $factory): void /** * {@inheritDoc} */ - public function getConfiguration(array $config, ContainerBuilder $container): ConfigurationInterface|MainConfiguration|null + public function getConfiguration(array $config, ContainerBuilder $container): MainConfiguration { return new MainConfiguration($this->storagesFactories); } diff --git a/EventListener/ReplyToHttpResponseListener.php b/EventListener/ReplyToHttpResponseListener.php index 7d62b42d..6019471e 100644 --- a/EventListener/ReplyToHttpResponseListener.php +++ b/EventListener/ReplyToHttpResponseListener.php @@ -7,8 +7,12 @@ class ReplyToHttpResponseListener { - public function __construct(private ReplyToSymfonyResponseConverter $replyToSymfonyResponseConverter) - {} + private ReplyToSymfonyResponseConverter $replyToSymfonyResponseConverter; + + public function __construct(ReplyToSymfonyResponseConverter $replyToSymfonyResponseConverter) + { + $this->replyToSymfonyResponseConverter = $replyToSymfonyResponseConverter; + } public function onKernelException(ExceptionEvent $event): void { diff --git a/Form/Extension/GatewayFactoriesChoiceTypeExtension.php b/Form/Extension/GatewayFactoriesChoiceTypeExtension.php index d129f946..9ea6eef3 100644 --- a/Form/Extension/GatewayFactoriesChoiceTypeExtension.php +++ b/Form/Extension/GatewayFactoriesChoiceTypeExtension.php @@ -8,8 +8,12 @@ class GatewayFactoriesChoiceTypeExtension extends AbstractTypeExtension { - public function __construct(private GatewayFactoryRegistryInterface $gatewayFactoryRegistry) - {} + private GatewayFactoryRegistryInterface $gatewayFactoryRegistry; + + public function __construct(GatewayFactoryRegistryInterface $gatewayFactoryRegistry) + { + $this->gatewayFactoryRegistry = $gatewayFactoryRegistry; + } /** * {@inheritdoc} @@ -31,6 +35,11 @@ public function configureOptions(OptionsResolver $resolver): void } } + public function getExtendedType(): string + { + return GatewayFactoriesChoiceType::class; + } + /** * {@inheritdoc} */ diff --git a/Resources/config/controller.xml b/Resources/config/controller.xml index dfd326da..4ef4f00c 100644 --- a/Resources/config/controller.xml +++ b/Resources/config/controller.xml @@ -5,40 +5,81 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd"> - - - + + + + - - + - - + - - + - - + - - + - - + diff --git a/Tests/DependencyInjection/Compiler/BuildConfigsPassTest.php b/Tests/DependencyInjection/Compiler/BuildConfigsPassTest.php index 79bd24d6..8234195c 100644 --- a/Tests/DependencyInjection/Compiler/BuildConfigsPassTest.php +++ b/Tests/DependencyInjection/Compiler/BuildConfigsPassTest.php @@ -192,7 +192,7 @@ public function testShouldImplementCompilerPassInterface(): void /** * @dataProvider provideTags */ - public function testShouldAddConfig(array $tagAttributes, mixed $expected): void + public function testShouldAddConfig(array $tagAttributes, $expected): void { $tagName = $tagAttributes['name']; unset($tagAttributes['name']); @@ -212,4 +212,4 @@ public function testShouldAddConfig(array $tagAttributes, mixed $expected): void $this->assertEquals($expected, $builder->getMethodCalls()); } -} \ No newline at end of file +} diff --git a/Tests/DependencyInjection/Factory/AbstractStorageFactoryTest.php b/Tests/DependencyInjection/Factory/AbstractStorageFactoryTest.php index 7d6ba567..f78a4756 100644 --- a/Tests/DependencyInjection/Factory/AbstractStorageFactoryTest.php +++ b/Tests/DependencyInjection/Factory/AbstractStorageFactoryTest.php @@ -17,7 +17,7 @@ class AbstractStorageFactoryTest extends \PHPUnit\Framework\TestCase public function shouldImplementStorageFactoryInterface(): void { $rc = new \ReflectionClass(AbstractStorageFactory::class); - + $this->assertTrue($rc->implementsInterface(StorageFactoryInterface::class)); } @@ -42,7 +42,7 @@ public function shouldAllowAddConfiguration(): void $tb = new TreeBuilder('foo'); $rootNode = $tb->getRootNode(); - + $factory->addConfiguration($rootNode); $processor = new Processor(); @@ -55,7 +55,7 @@ public function shouldAllowAddConfiguration(): void public function shouldAllowCreateStorageAndReturnItsId(): void { $expectedStorage = new Definition(); - + $factory = $this->createAbstractStorageFactory(); $factory ->expects($this->once()) @@ -90,7 +90,10 @@ protected function assertDefinitionContainsMethodCall(Definition $serviceDefinit )); } - protected function createAbstractStorageFactory(): AbstractStorageFactory|MockObject + /** + * @return AbstractStorageFactory|MockObject + */ + protected function createAbstractStorageFactory() { return $this->getMockForAbstractClass(AbstractStorageFactory::class); } diff --git a/Tests/DependencyInjection/Factory/CustomStorageFactoryTest.php b/Tests/DependencyInjection/Factory/CustomStorageFactoryTest.php index b830fcd2..733a4b5e 100644 --- a/Tests/DependencyInjection/Factory/CustomStorageFactoryTest.php +++ b/Tests/DependencyInjection/Factory/CustomStorageFactoryTest.php @@ -153,7 +153,10 @@ public function shouldCreateServiceDefinition(): void $this->assertSame($serviceName, $containerBuilder->getDefinition($storageId)->getParent()); } - protected function createContainerBuilderMock(): ContainerBuilder|MockObject + /** + * @return MockObject|\Symfony\Component\DependencyInjection\ContainerBuilder + */ + protected function createContainerBuilderMock() { return $this->createMock(ContainerBuilder::class); } diff --git a/Tests/EventListener/ReplyToHttpResponseListenerTest.php b/Tests/EventListener/ReplyToHttpResponseListenerTest.php index 8d9d1a1d..af0b46cd 100644 --- a/Tests/EventListener/ReplyToHttpResponseListenerTest.php +++ b/Tests/EventListener/ReplyToHttpResponseListenerTest.php @@ -113,12 +113,18 @@ public function shouldCallAllowCustomResponseCode(): void $this->assertEquals(true, $event->isAllowingCustomResponseCode()); } - protected function createReplyToSymfonyResponseConverterMock(): MockObject|ReplyToSymfonyResponseConverter + /** + * @return MockObject|ReplyToSymfonyResponseConverter + */ + protected function createReplyToSymfonyResponseConverterMock() { return $this->createMock(ReplyToSymfonyResponseConverter::class); } - protected function createHttpKernelMock(): HttpKernelInterface|MockObject + /** + * @return HttpKernelInterface|MockObject + */ + protected function createHttpKernelMock() { return $this->createMock(HttpKernelInterface::class); } diff --git a/Tests/Functional/Form/Type/CreditCardExpirationDateTypeTest.php b/Tests/Functional/Form/Type/CreditCardExpirationDateTypeTest.php index f43bf734..6bdefd2b 100644 --- a/Tests/Functional/Form/Type/CreditCardExpirationDateTypeTest.php +++ b/Tests/Functional/Form/Type/CreditCardExpirationDateTypeTest.php @@ -23,7 +23,6 @@ protected function setUp(): void */ public function couldBeCreatedByFormFactory(): void { - $this->markTestIncomplete('Symfony6 needs now a session. Rewrite in request-context'); $form = $this->formFactory->create(CreditCardExpirationDateType::class); $view = $form->createView(); diff --git a/Tests/Functional/Form/Type/CreditCardTypeTest.php b/Tests/Functional/Form/Type/CreditCardTypeTest.php index 5bfcc1dc..da825f59 100644 --- a/Tests/Functional/Form/Type/CreditCardTypeTest.php +++ b/Tests/Functional/Form/Type/CreditCardTypeTest.php @@ -24,7 +24,6 @@ protected function setUp(): void */ public function couldBeCreatedByFormFactory(): void { - $this->markTestIncomplete('Symfony6 needs now a session. Rewrite in request-context'); $form = $this->formFactory->create(CreditCardType::class); $view = $form->createView(); diff --git a/Tests/Functional/Form/Type/GatewayConfigTypeTest.php b/Tests/Functional/Form/Type/GatewayConfigTypeTest.php index de86bf3a..83e40512 100644 --- a/Tests/Functional/Form/Type/GatewayConfigTypeTest.php +++ b/Tests/Functional/Form/Type/GatewayConfigTypeTest.php @@ -24,8 +24,6 @@ protected function setUp(): void */ public function couldBeCreatedByFormFactory(): void { - $this->markTestIncomplete('Symfony6 needs now a session. Rewrite in request-context'); - $form = $this->formFactory->create(GatewayConfigType::class, null, [ 'data_class' => GatewayConfig::class, ]); diff --git a/Tests/Functional/WebTestCase.php b/Tests/Functional/WebTestCase.php index 9b1fc373..95405fa2 100644 --- a/Tests/Functional/WebTestCase.php +++ b/Tests/Functional/WebTestCase.php @@ -9,7 +9,9 @@ abstract class WebTestCase extends BaseWebTestCase { protected KernelBrowser $client; - /* @var $container ContainerInterface */ + /* + * @var $container ContainerInterface + */ protected static $container; protected function setUp(): void diff --git a/UPGRADE.md b/UPGRADE.md index 8fd8dbaa..1788cb39 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -2,11 +2,8 @@ Library [upgrades](https://github.com/Payum/Payum/blob/master/UPGRADE.md). -## 2.4.x to 3.0 - -* Symfony < 5 support is dropped -* PHP < 8 support is dropped -* BC Break: Add more strong types to `StorageFactoryInterface` +## 2.4 to 2.5 + * deprecated function `PayumController->getHttpRequestVerifier()` removed. Use `payum->getHttpRequestVerifier()` * deprecated function `PayumController->getTokenFactory()` removed. Use `payum->getTokenFactory()` diff --git a/composer.json b/composer.json index ef721ecb..6b17b8a2 100644 --- a/composer.json +++ b/composer.json @@ -36,13 +36,20 @@ "homepage": "https://github.com/Payum/PayumBundle/contributors" } ], + "repositories": [ + { + "type": "path", + "url": "../payum" + } + ], "require": { - "php": ">=8.0.2", - "payum/payum": "1.x-dev", - "symfony/framework-bundle": "^5.4 || ^6.0", - "symfony/form": "^5.4 || ^6.0", - "symfony/validator": "^5.4 || ^6.0", - "symfony/security-csrf": "^5.4 || ^6.0" + "php": "^7.4 || ^8.0", + "payum/core": "^1.7.2", + "symfony/framework-bundle": "^4.4 || ^5.4 || ^6.0", + "symfony/form": "^4.4.20 || ^5.4 || ^6.0", + "symfony/validator": "^4.4 || ^5.4 || ^6.0", + "symfony/security-csrf": "^4.4 || ^5.4 || ^6.0", + "symfony/polyfill-php80": "^1.26" }, "require-dev": { "defuse/php-encryption": "^2", @@ -58,13 +65,13 @@ "phpunit/phpunit": "^9.5", "psr/log": "^1 || ^2", "stripe/stripe-php": "~7.0", - "symfony/browser-kit": "^5.4 || ^6.0", - "symfony/expression-language": "^5.4 || ^6.0", - "symfony/phpunit-bridge": "^6.0", - "symfony/templating": "^5.4 || ^6.0", - "symfony/twig-bundle": "^5.4 || ^6.0", - "symfony/web-profiler-bundle": "^5.4 || ^6.0", - "symfony/yaml": "^5.4 || ^6.0", + "symfony/browser-kit": "^4.4 || ^5.4 || ^6.0", + "symfony/expression-language": "^4.4 || ^5.4 || ^6.0", + "symfony/phpunit-bridge": "^4.4 || ^5.4 || ^6.0", + "symfony/templating": "^4.4 || ^5.4 || ^6.0", + "symfony/twig-bundle": "^4.4 || ^5.4 || ^6.0", + "symfony/web-profiler-bundle": "^4.4 || ^5.4 || ^6.0", + "symfony/yaml": "^4.4 || ^5.4 || ^6.0", "twig/twig": "^2.0 || ^3.0" }, "suggest": { From 7c4208b83db0df7971d45ad275b99925021a8050 Mon Sep 17 00:00:00 2001 From: Pierre du Plessis Date: Mon, 4 Jul 2022 15:01:32 +0200 Subject: [PATCH 11/25] Revert some changes to composer.json --- composer.json | 6 ------ 1 file changed, 6 deletions(-) diff --git a/composer.json b/composer.json index 6b17b8a2..5e72cba5 100644 --- a/composer.json +++ b/composer.json @@ -36,12 +36,6 @@ "homepage": "https://github.com/Payum/PayumBundle/contributors" } ], - "repositories": [ - { - "type": "path", - "url": "../payum" - } - ], "require": { "php": "^7.4 || ^8.0", "payum/core": "^1.7.2", From 2118998474bae8ce42bdc819165d8e564bd3cb0b Mon Sep 17 00:00:00 2001 From: Pierre du Plessis Date: Mon, 4 Jul 2022 15:05:13 +0200 Subject: [PATCH 12/25] Set symfony require config to specific symfony version --- .github/workflows/tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index f8092646..4a6267c4 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -55,7 +55,7 @@ jobs: restore-keys: ${{ runner.os }}-php-${{ matrix.php }}-composer- - name: Install Symfony ${{ matrix.symfony }} - run: composer require --no-update ${{ matrix.symfony }} + run: composer config extra.symfony.require ${{ matrix.symfony-version }} - name: Install dependencies run: composer update From 2ce3e9e328b684b6d38eb9d1d1150c205304d5c7 Mon Sep 17 00:00:00 2001 From: Pierre du Plessis Date: Mon, 4 Jul 2022 15:06:55 +0200 Subject: [PATCH 13/25] Add symfony flex to workflows --- .github/workflows/tests.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 4a6267c4..9428cd9d 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -55,7 +55,10 @@ jobs: restore-keys: ${{ runner.os }}-php-${{ matrix.php }}-composer- - name: Install Symfony ${{ matrix.symfony }} - run: composer config extra.symfony.require ${{ matrix.symfony-version }} + run: composer config extra.symfony.require ${{ matrix.symfony }} + + - name: Install Symfony Flex + run: composer require symfony/flex --no-update - name: Install dependencies run: composer update From b90b850096bd9d96b5663c2e72dbc5da2f6ebac0 Mon Sep 17 00:00:00 2001 From: Pierre du Plessis Date: Mon, 4 Jul 2022 15:10:23 +0200 Subject: [PATCH 14/25] Fix overridden interfaces --- Tests/DependencyInjection/MainConfigurationTest.php | 4 ++-- Tests/DependencyInjection/PayumExtensionTest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/DependencyInjection/MainConfigurationTest.php b/Tests/DependencyInjection/MainConfigurationTest.php index a0a1d14d..d1b97d8b 100644 --- a/Tests/DependencyInjection/MainConfigurationTest.php +++ b/Tests/DependencyInjection/MainConfigurationTest.php @@ -710,7 +710,7 @@ public function shouldAllowPutAnythingToGatewaysV2AndNotPerformAnyValidations(): class FooStorageFactory implements StorageFactoryInterface { - public function create(ContainerBuilder $container, string $modelClass, array $config): string + public function create(ContainerBuilder $container, $modelClass, array $config): string { return 'aStorageId'; } @@ -732,7 +732,7 @@ public function addConfiguration(ArrayNodeDefinition $builder): void class BarStorageFactory implements StorageFactoryInterface { - public function create(ContainerBuilder $container, string $modelClass, array $config): string + public function create(ContainerBuilder $container, $modelClass, array $config): string { return 'serviceId'; } diff --git a/Tests/DependencyInjection/PayumExtensionTest.php b/Tests/DependencyInjection/PayumExtensionTest.php index 190fd8f3..2a74d43a 100644 --- a/Tests/DependencyInjection/PayumExtensionTest.php +++ b/Tests/DependencyInjection/PayumExtensionTest.php @@ -297,7 +297,7 @@ public function shouldAddGatewaysToBuilder(): void class FeeStorageFactory implements StorageFactoryInterface { - public function create(ContainerBuilder $container, string $modelClass, array $config): string + public function create(ContainerBuilder $container, $modelClass, array $config): string { return 'aStorageId'; } From de34c44b447bd5ddc0865a468a2de7aa0543819a Mon Sep 17 00:00:00 2001 From: Pierre du Plessis Date: Mon, 4 Jul 2022 15:12:49 +0200 Subject: [PATCH 15/25] Use .* for Symfony versions --- .github/workflows/tests.yaml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 9428cd9d..482ec607 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -15,23 +15,23 @@ jobs: matrix: include: - php: 7.4 - symfony: ^4.4 + symfony: 4.4.* - php: 7.4 - symfony: ^5.4 + symfony: 5.4.* - php: 8.0 - symfony: ^4.4 + symfony: 4.4.* - php: 8.0 - symfony: ^5.4 + symfony: 5.4.* - php: 8.0 symfony: 6.0 - php: 8.1 - symfony: ^4.4 + symfony: 4.4.* - php: 8.1 - symfony: ^5.4 + symfony: 5.4.* - php: 8.1 - symfony: 6.0 + symfony: 6.0.* - php: 8.1 - symfony: 6.1 + symfony: 6.1.* steps: - name: Checkout From 0d288a6c07993c200ff58573d6f39961b3a94612 Mon Sep 17 00:00:00 2001 From: Pierre du Plessis Date: Mon, 4 Jul 2022 15:21:40 +0200 Subject: [PATCH 16/25] Limit Symfony flex to version 1 --- .github/workflows/tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 482ec607..cd195e78 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -58,7 +58,7 @@ jobs: run: composer config extra.symfony.require ${{ matrix.symfony }} - name: Install Symfony Flex - run: composer require symfony/flex --no-update + run: composer require symfony/flex:^1 --no-update - name: Install dependencies run: composer update From 3ca358fabec10c4e739322fbb14a72c37562ffdf Mon Sep 17 00:00:00 2001 From: Pierre du Plessis Date: Mon, 4 Jul 2022 15:23:39 +0200 Subject: [PATCH 17/25] Update Symfony (After Flex install) --- .github/workflows/tests.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index cd195e78..a538d272 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -63,5 +63,8 @@ jobs: - name: Install dependencies run: composer update + - name: Update Symfony (After Flex install) + run: composer update symfony/* + - name: Run unit tests run: bin/phpunit From cc7dcbf11e707f7f6269f7908ad9c92b3e3604c2 Mon Sep 17 00:00:00 2001 From: Pierre du Plessis Date: Mon, 4 Jul 2022 15:25:37 +0200 Subject: [PATCH 18/25] Allow symfony/flex plugin --- .github/workflows/tests.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index a538d272..f23872af 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -58,7 +58,9 @@ jobs: run: composer config extra.symfony.require ${{ matrix.symfony }} - name: Install Symfony Flex - run: composer require symfony/flex:^1 --no-update + run: | + composer require symfony/flex:^1 --no-update + composer config --no-plugins allow-plugins.symfony/flex - name: Install dependencies run: composer update From d27b771fa52923fcbe8343fd43b7e9b84f82f0ff Mon Sep 17 00:00:00 2001 From: Pierre du Plessis Date: Mon, 4 Jul 2022 15:30:16 +0200 Subject: [PATCH 19/25] Allow symfony/flex plugin --- .github/workflows/tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index f23872af..01d1ad32 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -60,7 +60,7 @@ jobs: - name: Install Symfony Flex run: | composer require symfony/flex:^1 --no-update - composer config --no-plugins allow-plugins.symfony/flex + composer config --no-plugins allow-plugins.symfony/flex true - name: Install dependencies run: composer update From c273b409fcc709b1b571f3e6062fada0bccc269e Mon Sep 17 00:00:00 2001 From: Pierre du Plessis Date: Mon, 4 Jul 2022 15:49:13 +0200 Subject: [PATCH 20/25] Fix SF 4 & 5 compatibility --- Command/StatusCommand.php | 2 +- .../ReplyToHttpResponseListenerTest.php | 16 ++++++-- .../Type/CreditCardExpirationDateTypeTest.php | 2 +- .../Form/Type/CreditCardTypeTest.php | 2 +- .../Form/Type/GatewayConfigTypeTest.php | 2 +- .../Type/GatewayFactoriesChoiceTypeTest.php | 2 +- Tests/Functional/WebTestCase.php | 2 +- Tests/Functional/app/AppKernel.php | 41 ++++++------------- Tests/Functional/app/AppKernelShared.php | 38 +++++++++++++++++ Tests/Functional/app/config/config.yml | 7 +--- Tests/Functional/app/config/config_sf4.yml | 4 ++ Tests/Functional/app/config/config_sf5.yml | 7 ++++ 12 files changed, 81 insertions(+), 44 deletions(-) create mode 100644 Tests/Functional/app/AppKernelShared.php create mode 100644 Tests/Functional/app/config/config_sf4.yml create mode 100644 Tests/Functional/app/config/config_sf5.yml diff --git a/Command/StatusCommand.php b/Command/StatusCommand.php index e4d29460..c7f02876 100644 --- a/Command/StatusCommand.php +++ b/Command/StatusCommand.php @@ -61,6 +61,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln(sprintf('Status: %s', $status->getValue())); - return Command::SUCCESS; + return 0; } } diff --git a/Tests/EventListener/ReplyToHttpResponseListenerTest.php b/Tests/EventListener/ReplyToHttpResponseListenerTest.php index af0b46cd..934bfc64 100644 --- a/Tests/EventListener/ReplyToHttpResponseListenerTest.php +++ b/Tests/EventListener/ReplyToHttpResponseListenerTest.php @@ -11,7 +11,6 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\ExceptionEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; -use Symfony\Component\HttpKernel\Kernel; class ReplyToHttpResponseListenerTest extends TestCase { @@ -34,7 +33,7 @@ public function shouldDoNothingIfExceptionNotInstanceOfReply(): void $event = new ExceptionEvent( $this->createHttpKernelMock(), new Request, - HttpKernelInterface::MAIN_REQUEST, + $this->getRequestType(), $expectedException ); @@ -66,7 +65,7 @@ public function shouldSetResponseReturnedByConverterToEvent(): void $event = new ExceptionEvent( $this->createHttpKernelMock(), new Request, - HttpKernelInterface::MAIN_REQUEST, + $this->getRequestType(), $reply ); @@ -94,7 +93,7 @@ public function shouldCallAllowCustomResponseCode(): void $reply = new HttpRedirect('/foo/bar'); $response = new Response('', 302); - $event = new ExceptionEvent($this->createHttpKernelMock(), new Request, HttpKernelInterface::MAIN_REQUEST, $reply); + $event = new ExceptionEvent($this->createHttpKernelMock(), new Request, $this->getRequestType(), $reply); $converterMock = $this->createReplyToSymfonyResponseConverterMock(); $converterMock @@ -128,4 +127,13 @@ protected function createHttpKernelMock() { return $this->createMock(HttpKernelInterface::class); } + + private function getRequestType(): int + { + if (defined(HttpKernelInterface::class . '::MAIN_REQUEST')) { + return HttpKernelInterface::MAIN_REQUEST; + } + + return HttpKernelInterface::MASTER_REQUEST; + } } diff --git a/Tests/Functional/Form/Type/CreditCardExpirationDateTypeTest.php b/Tests/Functional/Form/Type/CreditCardExpirationDateTypeTest.php index 6bdefd2b..1e0e9c20 100644 --- a/Tests/Functional/Form/Type/CreditCardExpirationDateTypeTest.php +++ b/Tests/Functional/Form/Type/CreditCardExpirationDateTypeTest.php @@ -15,7 +15,7 @@ protected function setUp(): void { parent::setUp(); - $this->formFactory = static::getContainer()->get('form.factory'); + $this->formFactory = static::$container->get('form.factory'); } /** diff --git a/Tests/Functional/Form/Type/CreditCardTypeTest.php b/Tests/Functional/Form/Type/CreditCardTypeTest.php index da825f59..bf1f9871 100644 --- a/Tests/Functional/Form/Type/CreditCardTypeTest.php +++ b/Tests/Functional/Form/Type/CreditCardTypeTest.php @@ -16,7 +16,7 @@ protected function setUp(): void { parent::setUp(); - $this->formFactory = static::getContainer()->get('form.factory'); + $this->formFactory = static::$container->get('form.factory'); } /** diff --git a/Tests/Functional/Form/Type/GatewayConfigTypeTest.php b/Tests/Functional/Form/Type/GatewayConfigTypeTest.php index 83e40512..17b510bb 100644 --- a/Tests/Functional/Form/Type/GatewayConfigTypeTest.php +++ b/Tests/Functional/Form/Type/GatewayConfigTypeTest.php @@ -16,7 +16,7 @@ protected function setUp(): void { parent::setUp(); - $this->formFactory = static::getContainer()->get('form.factory'); + $this->formFactory = static::$container->get('form.factory'); } /** diff --git a/Tests/Functional/Form/Type/GatewayFactoriesChoiceTypeTest.php b/Tests/Functional/Form/Type/GatewayFactoriesChoiceTypeTest.php index 09601cde..55edc898 100644 --- a/Tests/Functional/Form/Type/GatewayFactoriesChoiceTypeTest.php +++ b/Tests/Functional/Form/Type/GatewayFactoriesChoiceTypeTest.php @@ -15,7 +15,7 @@ protected function setUp(): void { parent::setUp(); - $this->formFactory = static::getContainer()->get('form.factory'); + $this->formFactory = static::$container->get('form.factory'); } /** diff --git a/Tests/Functional/WebTestCase.php b/Tests/Functional/WebTestCase.php index 95405fa2..94f64831 100644 --- a/Tests/Functional/WebTestCase.php +++ b/Tests/Functional/WebTestCase.php @@ -9,7 +9,7 @@ abstract class WebTestCase extends BaseWebTestCase { protected KernelBrowser $client; - /* + /** * @var $container ContainerInterface */ protected static $container; diff --git a/Tests/Functional/app/AppKernel.php b/Tests/Functional/app/AppKernel.php index 4b5b3f48..2ff7ea81 100644 --- a/Tests/Functional/app/AppKernel.php +++ b/Tests/Functional/app/AppKernel.php @@ -1,6 +1,7 @@ load(__DIR__ . '/config/config.yml'); + public function handle(Request $request, int $type = HttpKernelInterface::MAIN_REQUEST, bool $catch = true): Response + { + return parent::handle($request, $type, false); + } } } diff --git a/Tests/Functional/app/AppKernelShared.php b/Tests/Functional/app/AppKernelShared.php new file mode 100644 index 00000000..f846204d --- /dev/null +++ b/Tests/Functional/app/AppKernelShared.php @@ -0,0 +1,38 @@ +load(__DIR__ . '/config/config.yml'); + + $loader->load(__DIR__ . '/config/config_sf' . Kernel::MAJOR_VERSION . '.yml'); + } +} diff --git a/Tests/Functional/app/config/config.yml b/Tests/Functional/app/config/config.yml index 299eafb0..7c01d920 100644 --- a/Tests/Functional/app/config/config.yml +++ b/Tests/Functional/app/config/config.yml @@ -1,7 +1,7 @@ parameters: locale: 'en' secret: 'ThisTokenIsNotSoSecretChangeIt' - + framework: #esi: ~ #translator: { fallback: %locale% } @@ -12,11 +12,6 @@ framework: form: true csrf_protection: true assets: false - session: - handler_id: null - cookie_secure: auto - cookie_samesite: lax - storage_factory_id: session.storage.factory.mock_file payum: storages: diff --git a/Tests/Functional/app/config/config_sf4.yml b/Tests/Functional/app/config/config_sf4.yml new file mode 100644 index 00000000..094e00c7 --- /dev/null +++ b/Tests/Functional/app/config/config_sf4.yml @@ -0,0 +1,4 @@ +framework: + session: + storage_id: 'session.storage.mock_file' + validation: { enable_annotations: false } diff --git a/Tests/Functional/app/config/config_sf5.yml b/Tests/Functional/app/config/config_sf5.yml new file mode 100644 index 00000000..23ffbdc7 --- /dev/null +++ b/Tests/Functional/app/config/config_sf5.yml @@ -0,0 +1,7 @@ +framework: + session: + handler_id: null + cookie_secure: auto + cookie_samesite: lax + storage_factory_id: session.storage.factory.mock_file + validation: { enable_annotations: false } From 91d53d99e1a68faf1a559f9da9d35e460f6a4474 Mon Sep 17 00:00:00 2001 From: Pierre du Plessis Date: Mon, 4 Jul 2022 16:02:36 +0200 Subject: [PATCH 21/25] Fix tests on Symfony 6 --- .github/workflows/tests.yaml | 5 +---- .../ReplyToHttpResponseListenerTest.php | 2 +- .../Type/CreditCardExpirationDateTypeTest.php | 13 +++++++++++- .../Form/Type/CreditCardTypeTest.php | 12 ++++++++++- .../Form/Type/GatewayConfigTypeTest.php | 12 ++++++++++- .../Type/GatewayFactoriesChoiceTypeTest.php | 2 +- Tests/Functional/PayumBuilderTest.php | 12 +++++------ Tests/Functional/PayumTest.php | 20 +++++++++---------- Tests/Functional/WebTestCase.php | 19 +++++++++++++++++- Tests/Functional/app/config/config_sf6.yml | 7 +++++++ 10 files changed, 78 insertions(+), 26 deletions(-) create mode 100644 Tests/Functional/app/config/config_sf6.yml diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 01d1ad32..d4a19142 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -23,7 +23,7 @@ jobs: - php: 8.0 symfony: 5.4.* - php: 8.0 - symfony: 6.0 + symfony: 6.0.* - php: 8.1 symfony: 4.4.* - php: 8.1 @@ -65,8 +65,5 @@ jobs: - name: Install dependencies run: composer update - - name: Update Symfony (After Flex install) - run: composer update symfony/* - - name: Run unit tests run: bin/phpunit diff --git a/Tests/Functional/EventListener/ReplyToHttpResponseListenerTest.php b/Tests/Functional/EventListener/ReplyToHttpResponseListenerTest.php index 3b7215b6..1325ac7a 100644 --- a/Tests/Functional/EventListener/ReplyToHttpResponseListenerTest.php +++ b/Tests/Functional/EventListener/ReplyToHttpResponseListenerTest.php @@ -10,7 +10,7 @@ class ReplyToHttpResponseListenerTest extends WebTestCase */ public function couldBeGetFromContainerAsService(): void { - $listener = static::$container->get('payum.listener.reply_to_http_response'); + $listener = static::getContainer()->get('payum.listener.reply_to_http_response'); $this->assertInstanceOf('Payum\Bundle\PayumBundle\EventListener\ReplyToHttpResponseListener', $listener); } diff --git a/Tests/Functional/Form/Type/CreditCardExpirationDateTypeTest.php b/Tests/Functional/Form/Type/CreditCardExpirationDateTypeTest.php index 1e0e9c20..cead5bc8 100644 --- a/Tests/Functional/Form/Type/CreditCardExpirationDateTypeTest.php +++ b/Tests/Functional/Form/Type/CreditCardExpirationDateTypeTest.php @@ -6,6 +6,11 @@ use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; +use Symfony\Component\Security\Csrf\TokenStorage\SessionTokenStorage; class CreditCardExpirationDateTypeTest extends WebTestCase { @@ -15,7 +20,7 @@ protected function setUp(): void { parent::setUp(); - $this->formFactory = static::$container->get('form.factory'); + $this->formFactory = static::getContainer()->get('form.factory'); } /** @@ -23,6 +28,12 @@ protected function setUp(): void */ public function couldBeCreatedByFormFactory(): void { + /** @var RequestStack $requestStack */ + $requestStack = self::getContainer()->get(RequestStack::class); + $request = Request::createFromGlobals(); + $request->setSession(new Session(new MockArraySessionStorage())); + $requestStack->push($request); + $form = $this->formFactory->create(CreditCardExpirationDateType::class); $view = $form->createView(); diff --git a/Tests/Functional/Form/Type/CreditCardTypeTest.php b/Tests/Functional/Form/Type/CreditCardTypeTest.php index bf1f9871..91f0e2e7 100644 --- a/Tests/Functional/Form/Type/CreditCardTypeTest.php +++ b/Tests/Functional/Form/Type/CreditCardTypeTest.php @@ -7,6 +7,10 @@ use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; class CreditCardTypeTest extends WebTestCase { @@ -16,7 +20,7 @@ protected function setUp(): void { parent::setUp(); - $this->formFactory = static::$container->get('form.factory'); + $this->formFactory = static::getContainer()->get('form.factory'); } /** @@ -24,6 +28,12 @@ protected function setUp(): void */ public function couldBeCreatedByFormFactory(): void { + /** @var RequestStack $requestStack */ + $requestStack = self::getContainer()->get(RequestStack::class); + $request = Request::createFromGlobals(); + $request->setSession(new Session(new MockArraySessionStorage())); + $requestStack->push($request); + $form = $this->formFactory->create(CreditCardType::class); $view = $form->createView(); diff --git a/Tests/Functional/Form/Type/GatewayConfigTypeTest.php b/Tests/Functional/Form/Type/GatewayConfigTypeTest.php index 17b510bb..776fe9c5 100644 --- a/Tests/Functional/Form/Type/GatewayConfigTypeTest.php +++ b/Tests/Functional/Form/Type/GatewayConfigTypeTest.php @@ -7,6 +7,10 @@ use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; class GatewayConfigTypeTest extends WebTestCase { @@ -16,7 +20,7 @@ protected function setUp(): void { parent::setUp(); - $this->formFactory = static::$container->get('form.factory'); + $this->formFactory = static::getContainer()->get('form.factory'); } /** @@ -24,6 +28,12 @@ protected function setUp(): void */ public function couldBeCreatedByFormFactory(): void { + /** @var RequestStack $requestStack */ + $requestStack = self::getContainer()->get(RequestStack::class); + $request = Request::createFromGlobals(); + $request->setSession(new Session(new MockArraySessionStorage())); + $requestStack->push($request); + $form = $this->formFactory->create(GatewayConfigType::class, null, [ 'data_class' => GatewayConfig::class, ]); diff --git a/Tests/Functional/Form/Type/GatewayFactoriesChoiceTypeTest.php b/Tests/Functional/Form/Type/GatewayFactoriesChoiceTypeTest.php index 55edc898..09601cde 100644 --- a/Tests/Functional/Form/Type/GatewayFactoriesChoiceTypeTest.php +++ b/Tests/Functional/Form/Type/GatewayFactoriesChoiceTypeTest.php @@ -15,7 +15,7 @@ protected function setUp(): void { parent::setUp(); - $this->formFactory = static::$container->get('form.factory'); + $this->formFactory = static::getContainer()->get('form.factory'); } /** diff --git a/Tests/Functional/PayumBuilderTest.php b/Tests/Functional/PayumBuilderTest.php index 24eaee9d..92157e5e 100644 --- a/Tests/Functional/PayumBuilderTest.php +++ b/Tests/Functional/PayumBuilderTest.php @@ -12,7 +12,7 @@ class PayumBuilderTest extends WebTestCase public function testCouldBeGetFromContainerAsService(): void { /** @var PayumBuilder $builder */ - $builder = static::$container->get('payum.builder'); + $builder = static::getContainer()->get('payum.builder'); $this->assertInstanceOf(PayumBuilder::class, $builder); } @@ -21,7 +21,7 @@ public function testCouldBeGetFromContainerAsService(): void public function testShouldContainCoreGatewayFactoryBuilder(): void { /** @var PayumBuilder $builder */ - $builder = static::$container->get('payum.builder'); + $builder = static::getContainer()->get('payum.builder'); $reflectedConstraint = (new \ReflectionObject($builder))->getProperty('coreGatewayFactory'); $reflectedConstraint->setAccessible(true); @@ -32,7 +32,7 @@ public function testShouldContainCoreGatewayFactoryBuilder(): void public function testShouldContainHttpRequestVerifierBuilder(): void { /** @var PayumBuilder $builder */ - $builder = static::$container->get('payum.builder'); + $builder = static::getContainer()->get('payum.builder'); $reflectedConstraint = (new \ReflectionObject($builder))->getProperty('httpRequestVerifier'); $reflectedConstraint->setAccessible(true); @@ -43,7 +43,7 @@ public function testShouldContainHttpRequestVerifierBuilder(): void public function testShouldContainTokenFactoryBuilder(): void { /** @var PayumBuilder $builder */ - $builder = static::$container->get('payum.builder'); + $builder = static::getContainer()->get('payum.builder'); $reflectedConstraint = (new \ReflectionObject($builder))->getProperty('tokenFactory'); $reflectedConstraint->setAccessible(true); @@ -54,7 +54,7 @@ public function testShouldContainTokenFactoryBuilder(): void public function testShouldContainMainRegistry(): void { /** @var PayumBuilder $builder */ - $builder = static::$container->get('payum.builder'); + $builder = static::getContainer()->get('payum.builder'); $reflectedConstraint = (new \ReflectionObject($builder))->getProperty('mainRegistry'); $reflectedConstraint->setAccessible(true); @@ -65,7 +65,7 @@ public function testShouldContainMainRegistry(): void public function testShouldContainGenericTokenFactoryPaths(): void { /** @var PayumBuilder $builder */ - $builder = static::$container->get('payum.builder'); + $builder = static::getContainer()->get('payum.builder'); $reflectedConstraint = (new \ReflectionObject($builder))->getProperty('genericTokenFactoryPaths'); $reflectedConstraint->setAccessible(true); diff --git a/Tests/Functional/PayumTest.php b/Tests/Functional/PayumTest.php index a1c44085..c5cb3559 100644 --- a/Tests/Functional/PayumTest.php +++ b/Tests/Functional/PayumTest.php @@ -16,7 +16,7 @@ class PayumTest extends WebTestCase public function testCouldBeGetFromContainerAsService(): void { /** @var Payum $payum */ - $payum = static::$container->get('payum'); + $payum = static::getContainer()->get('payum'); $this->assertInstanceOf(Payum::class, $payum); } @@ -24,7 +24,7 @@ public function testCouldBeGetFromContainerAsService(): void public function testShouldReturnHttpRequestVerifyRequest(): void { /** @var Payum $payum */ - $payum = static::$container->get('payum'); + $payum = static::getContainer()->get('payum'); $this->assertInstanceOf(HttpRequestVerifier::class, $payum->getHttpRequestVerifier()); } @@ -32,7 +32,7 @@ public function testShouldReturnHttpRequestVerifyRequest(): void public function testShouldReturnTokenFactory(): void { /** @var Payum $payum */ - $payum = static::$container->get('payum'); + $payum = static::getContainer()->get('payum'); $tokenFactory = $payum->getTokenFactory(); $this->assertInstanceOf(GenericTokenFactory::class, $tokenFactory); @@ -46,7 +46,7 @@ public function testShouldReturnTokenFactory(): void public function testShouldReturnTokenStorage(): void { /** @var Payum $payum */ - $payum = static::$container->get('payum'); + $payum = static::getContainer()->get('payum'); $storage = $payum->getTokenStorage(); $this->assertInstanceOf(StorageInterface::class, $storage); @@ -55,7 +55,7 @@ public function testShouldReturnTokenStorage(): void public function testShouldReturnStorages(): void { /** @var Payum $payum */ - $payum = static::$container->get('payum'); + $payum = static::getContainer()->get('payum'); $storages = $payum->getStorages(); $this->assertIsArray($storages); @@ -65,7 +65,7 @@ public function testShouldReturnStorages(): void public function testShouldReturnGateways(): void { /** @var Payum $payum */ - $payum = static::$container->get('payum'); + $payum = static::getContainer()->get('payum'); $gateways = $payum->getGateways(); $this->assertIsArray($gateways); @@ -75,7 +75,7 @@ public function testShouldReturnGateways(): void public function testShouldReturnGatewaysFactories(): void { /** @var Payum $payum */ - $payum = static::$container->get('payum'); + $payum = static::getContainer()->get('payum'); $factories = $payum->getGatewayFactories(); $this->assertIsArray($factories); @@ -85,7 +85,7 @@ public function testShouldReturnGatewaysFactories(): void public function testShouldReturnGatewayFactory(): void { /** @var Payum $payum */ - $payum = static::$container->get('payum'); + $payum = static::getContainer()->get('payum'); $this->assertInstanceOf(PaypalExpressCheckoutGatewayFactory::class, $payum->getGatewayFactory('paypal_express_checkout')); $this->assertInstanceOf(StripeJsGatewayFactory::class, $payum->getGatewayFactory('stripe_js')); @@ -94,7 +94,7 @@ public function testShouldReturnGatewayFactory(): void public function testShouldReturnGateway(): void { /** @var Payum $payum */ - $payum = static::$container->get('payum'); + $payum = static::getContainer()->get('payum'); $this->assertInstanceOf(GatewayInterface::class, $payum->getGateway('fooGateway')); $this->assertInstanceOf(GatewayInterface::class, $payum->getGateway('barGateway')); @@ -103,7 +103,7 @@ public function testShouldReturnGateway(): void public function testShouldReturnStorage(): void { /** @var Payum $payum */ - $payum = static::$container->get('payum'); + $payum = static::getContainer()->get('payum'); $this->assertInstanceOf(StorageInterface::class, $payum->getStorage(ArrayObject::class)); } diff --git a/Tests/Functional/WebTestCase.php b/Tests/Functional/WebTestCase.php index 94f64831..4eb3f10a 100644 --- a/Tests/Functional/WebTestCase.php +++ b/Tests/Functional/WebTestCase.php @@ -4,6 +4,8 @@ use Symfony\Bundle\FrameworkBundle\KernelBrowser; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase; use Symfony\Component\DependencyInjection\ContainerInterface; +use function get_parent_class; +use function method_exists; abstract class WebTestCase extends BaseWebTestCase { @@ -11,6 +13,7 @@ abstract class WebTestCase extends BaseWebTestCase /** * @var $container ContainerInterface + * @deprecated since version 2.5. use getContainer() instead */ protected static $container; @@ -19,7 +22,21 @@ protected function setUp(): void parent::setUp(); $this->client = static::createClient(); - static::$container = static::$kernel->getContainer(); + + if (method_exists(get_parent_class(self::class), 'getContainer')) { + static::$container = parent::getContainer(); + } else { + static::$container = static::$kernel->getContainer(); + } + } + + protected static function getContainer(): ContainerInterface + { + if (method_exists(get_parent_class(self::class), 'getContainer')) { + return parent::getContainer(); + } + + return self::$container; } public static function getKernelClass(): string diff --git a/Tests/Functional/app/config/config_sf6.yml b/Tests/Functional/app/config/config_sf6.yml new file mode 100644 index 00000000..23ffbdc7 --- /dev/null +++ b/Tests/Functional/app/config/config_sf6.yml @@ -0,0 +1,7 @@ +framework: + session: + handler_id: null + cookie_secure: auto + cookie_samesite: lax + storage_factory_id: session.storage.factory.mock_file + validation: { enable_annotations: false } From ba7442ccc335cca5bcacded95489e69ba4518fdb Mon Sep 17 00:00:00 2001 From: Pierre du Plessis Date: Mon, 4 Jul 2022 16:05:39 +0200 Subject: [PATCH 22/25] Only set request session for Symfony 6 --- .../Form/Type/CreditCardExpirationDateTypeTest.php | 13 ++++++++----- Tests/Functional/Form/Type/CreditCardTypeTest.php | 13 ++++++++----- .../Functional/Form/Type/GatewayConfigTypeTest.php | 13 ++++++++----- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/Tests/Functional/Form/Type/CreditCardExpirationDateTypeTest.php b/Tests/Functional/Form/Type/CreditCardExpirationDateTypeTest.php index cead5bc8..aa48859c 100644 --- a/Tests/Functional/Form/Type/CreditCardExpirationDateTypeTest.php +++ b/Tests/Functional/Form/Type/CreditCardExpirationDateTypeTest.php @@ -10,6 +10,7 @@ use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; +use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Security\Csrf\TokenStorage\SessionTokenStorage; class CreditCardExpirationDateTypeTest extends WebTestCase @@ -28,11 +29,13 @@ protected function setUp(): void */ public function couldBeCreatedByFormFactory(): void { - /** @var RequestStack $requestStack */ - $requestStack = self::getContainer()->get(RequestStack::class); - $request = Request::createFromGlobals(); - $request->setSession(new Session(new MockArraySessionStorage())); - $requestStack->push($request); + if (Kernel::MAJOR_VERSION === 6) { + /** @var RequestStack $requestStack */ + $requestStack = self::getContainer()->get(RequestStack::class); + $request = Request::createFromGlobals(); + $request->setSession(new Session(new MockArraySessionStorage())); + $requestStack->push($request); + } $form = $this->formFactory->create(CreditCardExpirationDateType::class); $view = $form->createView(); diff --git a/Tests/Functional/Form/Type/CreditCardTypeTest.php b/Tests/Functional/Form/Type/CreditCardTypeTest.php index 91f0e2e7..ad84cb39 100644 --- a/Tests/Functional/Form/Type/CreditCardTypeTest.php +++ b/Tests/Functional/Form/Type/CreditCardTypeTest.php @@ -11,6 +11,7 @@ use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; +use Symfony\Component\HttpKernel\Kernel; class CreditCardTypeTest extends WebTestCase { @@ -28,11 +29,13 @@ protected function setUp(): void */ public function couldBeCreatedByFormFactory(): void { - /** @var RequestStack $requestStack */ - $requestStack = self::getContainer()->get(RequestStack::class); - $request = Request::createFromGlobals(); - $request->setSession(new Session(new MockArraySessionStorage())); - $requestStack->push($request); + if (Kernel::MAJOR_VERSION === 6) { + /** @var RequestStack $requestStack */ + $requestStack = self::getContainer()->get(RequestStack::class); + $request = Request::createFromGlobals(); + $request->setSession(new Session(new MockArraySessionStorage())); + $requestStack->push($request); + } $form = $this->formFactory->create(CreditCardType::class); $view = $form->createView(); diff --git a/Tests/Functional/Form/Type/GatewayConfigTypeTest.php b/Tests/Functional/Form/Type/GatewayConfigTypeTest.php index 776fe9c5..63ff63ed 100644 --- a/Tests/Functional/Form/Type/GatewayConfigTypeTest.php +++ b/Tests/Functional/Form/Type/GatewayConfigTypeTest.php @@ -11,6 +11,7 @@ use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; +use Symfony\Component\HttpKernel\Kernel; class GatewayConfigTypeTest extends WebTestCase { @@ -28,11 +29,13 @@ protected function setUp(): void */ public function couldBeCreatedByFormFactory(): void { - /** @var RequestStack $requestStack */ - $requestStack = self::getContainer()->get(RequestStack::class); - $request = Request::createFromGlobals(); - $request->setSession(new Session(new MockArraySessionStorage())); - $requestStack->push($request); + if (Kernel::MAJOR_VERSION === 6) { + /** @var RequestStack $requestStack */ + $requestStack = self::getContainer()->get(RequestStack::class); + $request = Request::createFromGlobals(); + $request->setSession(new Session(new MockArraySessionStorage())); + $requestStack->push($request); + } $form = $this->formFactory->create(GatewayConfigType::class, null, [ 'data_class' => GatewayConfig::class, From 1a4fc832d0bcdbaa6c342c52001704d51bcfbaa1 Mon Sep 17 00:00:00 2001 From: Pierre du Plessis Date: Mon, 4 Jul 2022 18:16:00 +0200 Subject: [PATCH 23/25] Add ControllerTrait to allow multiple definitions of getSubscribedServices --- Controller/PayumController.php | 13 +++---------- Traits/ControllerTrait.php | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 Traits/ControllerTrait.php diff --git a/Controller/PayumController.php b/Controller/PayumController.php index 7fe08ca0..de33c7d8 100644 --- a/Controller/PayumController.php +++ b/Controller/PayumController.php @@ -1,16 +1,16 @@ payum ?? $this->container->get('payum'); } - public static function getSubscribedServices(): array - { - return array_merge(parent::getSubscribedServices(), [ - 'payum' => Payum::class, - ]); - } - /** * @deprecated will be removed in 3.0. * diff --git a/Traits/ControllerTrait.php b/Traits/ControllerTrait.php new file mode 100644 index 00000000..5fb20ba8 --- /dev/null +++ b/Traits/ControllerTrait.php @@ -0,0 +1,30 @@ + Payum::class, + ]); + } + } +} else { + trait ControllerTrait + { + public static function getSubscribedServices() + { + return array_merge(parent::getSubscribedServices(), [ + 'payum' => Payum::class, + ]); + } + } +} From 53db865946f9b3f65e9593dbdd9fd5c23351abda Mon Sep 17 00:00:00 2001 From: Pierre du Plessis Date: Mon, 4 Jul 2022 18:36:45 +0200 Subject: [PATCH 24/25] Various small fixes --- Command/CreateNotifyTokenCommand.php | 2 +- Command/DebugGatewayCommand.php | 2 +- Controller/PayumController.php | 2 +- UPGRADE.md | 5 ----- 4 files changed, 3 insertions(+), 8 deletions(-) diff --git a/Command/CreateNotifyTokenCommand.php b/Command/CreateNotifyTokenCommand.php index 90bed7a6..4021137a 100644 --- a/Command/CreateNotifyTokenCommand.php +++ b/Command/CreateNotifyTokenCommand.php @@ -30,7 +30,7 @@ public function __construct(Payum $payum) protected function configure(): void { $this - ->setName(self::$defaultName) + ->setName(static::$defaultName) ->addArgument('gateway-name', InputArgument::REQUIRED, 'The gateway name associated with the token') ->addOption('model-class', null, InputOption::VALUE_OPTIONAL, 'The model class associated with the token') ->addOption('model-id', null, InputOption::VALUE_OPTIONAL, 'The model id associated with the token') diff --git a/Command/DebugGatewayCommand.php b/Command/DebugGatewayCommand.php index 446e1cd4..4f14bbb0 100644 --- a/Command/DebugGatewayCommand.php +++ b/Command/DebugGatewayCommand.php @@ -32,7 +32,7 @@ public function __construct(Payum $payum) protected function configure(): void { $this - ->setName(self::$defaultName) + ->setName(static::$defaultName) ->setAliases(['payum:gateway:debug']) ->addArgument('gateway-name', InputArgument::OPTIONAL, 'The gateway name you want to get information about.') ->addOption('show-supports', null, InputOption::VALUE_NONE, 'Show what actions supports.') diff --git a/Controller/PayumController.php b/Controller/PayumController.php index de33c7d8..09a23238 100644 --- a/Controller/PayumController.php +++ b/Controller/PayumController.php @@ -18,7 +18,7 @@ public function __construct(?Payum $payum = null) if ($payum === null) { @trigger_error( sprintf( - '%s requires an instance of %s asd the first argument. Not passing this object is deprecated and it will be required in payum/payum-bundle 2.0.', + '%s requires an instance of %s asd the first argument. Not passing this object is deprecated and it will be required in payum/payum-bundle 3.0.', __METHOD__, Payum::class ), diff --git a/UPGRADE.md b/UPGRADE.md index 1788cb39..e0706cc3 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -2,11 +2,6 @@ Library [upgrades](https://github.com/Payum/Payum/blob/master/UPGRADE.md). -## 2.4 to 2.5 - -* deprecated function `PayumController->getHttpRequestVerifier()` removed. Use `payum->getHttpRequestVerifier()` -* deprecated function `PayumController->getTokenFactory()` removed. Use `payum->getTokenFactory()` - ## 2.0 to 2.1 * `payum.http_client` service was removed. Use gateway's config to overwrite it. From 82b09f23911c552b2e78af98631dfb4f7baefb85 Mon Sep 17 00:00:00 2001 From: Pierre du Plessis Date: Mon, 4 Jul 2022 18:49:40 +0200 Subject: [PATCH 25/25] Update documentation --- Resources/doc/authorize.md | 10 ++++--- Resources/doc/configure-payment-in-backend.md | 8 +++-- Resources/doc/custom_api_usage.md | 29 +++++++++---------- Resources/doc/get_it_started.md | 19 +++++++----- Resources/doc/iso4217-or-currency-details.md | 4 +-- Resources/doc/purchase_done_action.md | 10 +++---- Resources/doc/refund.md | 4 +-- 7 files changed, 45 insertions(+), 39 deletions(-) diff --git a/Resources/doc/authorize.md b/Resources/doc/authorize.md index cb797d34..b7daca5a 100644 --- a/Resources/doc/authorize.md +++ b/Resources/doc/authorize.md @@ -13,13 +13,15 @@ We have to caThe only difference from capture one example namespace Acme\PaymentBundle\Controller; -class PaymentController extends Controller +use Payum\Bundle\PayumBundle\Controller\PayumController; + +class PaymentController extends PayumController { public function prepareAction() { $gatewayName = 'offline'; - $storage = $this->get('payum')->getStorage('Acme\PaymentBundle\Entity\Payment'); + $storage = $this->payum->getStorage('Acme\PaymentBundle\Entity\Payment'); $payment = $storage->create(); $payment->setNumber(uniqid()); @@ -31,7 +33,7 @@ class PaymentController extends Controller $storage->update($payment); - $captureToken = $this->get('payum')->getTokenFactory()->createCaptureToken( + $captureToken = $this->payum->getTokenFactory()->createCaptureToken( $gatewayName, $payment, 'done' // the route to redirect after capture; @@ -40,4 +42,4 @@ class PaymentController extends Controller return $this->redirect($captureToken->getTargetUrl()) } } -``` \ No newline at end of file +``` diff --git a/Resources/doc/configure-payment-in-backend.md b/Resources/doc/configure-payment-in-backend.md index c05693ef..61090170 100644 --- a/Resources/doc/configure-payment-in-backend.md +++ b/Resources/doc/configure-payment-in-backend.md @@ -62,13 +62,15 @@ Let's say you created a gateway with name `paypal`. Here we will show you how to namespace Acme\PaymentBundle\Controller; -class PaymentController extends Controller +use Payum\Bundle\PayumBundle\Controller\PayumController; + +class PaymentController extends PayumController { public function prepareAction() { $gatewayName = 'paypal'; - $storage = $this->get('payum')->getStorage('Acme\PaymentBundle\Entity\Payment'); + $storage = $this->payum->getStorage('Acme\PaymentBundle\Entity\Payment'); $payment = $storage->create(); $payment->setNumber(uniqid()); @@ -80,7 +82,7 @@ class PaymentController extends Controller $storage->update($payment); - $captureToken = $this->get('payum')->getTokenFactory()->createCaptureToken( + $captureToken = $this->payum->getTokenFactory()->createCaptureToken( $gatewayName, $payment, 'done' // the route to redirect after capture diff --git a/Resources/doc/custom_api_usage.md b/Resources/doc/custom_api_usage.md index bce4b5a0..516eebf7 100644 --- a/Resources/doc/custom_api_usage.md +++ b/Resources/doc/custom_api_usage.md @@ -15,21 +15,18 @@ The factory would create the desired api using database or what ever else you wa namespace Acme\PaymentBundle\Payum\Api; use Payum\Paypal\ExpressCheckout\Nvp\Api; -use Symfony\Component\DependencyInjection\ContainerInterface; class Factory { - /** - * @var \Symfony\Component\DependencyInjection\ContainerInterface - */ - protected $container; - - /** - * @param ContainerInterface $container - */ - public function __construct(ContainerInterface $container) + private string $username; + private string $password; + private string $signature; + + public function __construct(string $username, string $password, string $signature) { - $this->container = $container; + $this->username = $username; + $this->password = $password; + $this->signature = $signature; } /** @@ -38,9 +35,9 @@ class Factory public function createPaypalExpressCheckoutApi() { return new Api(array( - 'username' => $this->container->getParameter('paypal.express_checkout.username'), - 'password' => $this->container->getParameter('paypal.express_checkout.password'), - 'signature' => $this->container->getParameter('paypal.express_checkout.signature'), + 'username' => $this->username, + 'password' => $this->password, + 'signature' => $this->signature, 'sandbox' => true )); } @@ -61,7 +58,9 @@ services: acme.payment.payum.api.factory: class: Acme\PaymentBundle\Payum\Api\Factory arguments: - - @service_container + $username: '%env(PAYPAL_EXPRESS_CHECKOUT_USERNAME)%' + $password: '%env(PAYPAL_EXPRESS_CHECKOUT_PASSWORD)%' + $signature: '%env(PAYPAL_EXPRESS_CHECKOUT_SIGNATURE)%' acme.payment.payum.paypal_express_checkout_api: class: Payum\Paypal\ExpressCheckout\Nvp\Api diff --git a/Resources/doc/get_it_started.md b/Resources/doc/get_it_started.md index a0619281..e408a5dd 100644 --- a/Resources/doc/get_it_started.md +++ b/Resources/doc/get_it_started.md @@ -108,13 +108,15 @@ Create a capture token and delegate the job to capture action. namespace Acme\PaymentBundle\Controller; -class PaymentController extends Controller +use Payum\Bundle\PayumBundle\Controller\PayumController; + +class PaymentController extends PayumController { public function prepareAction() { $gatewayName = 'offline'; - $storage = $this->get('payum')->getStorage('Acme\PaymentBundle\Entity\Payment'); + $storage = $this->payum->getStorage('Acme\PaymentBundle\Entity\Payment'); $payment = $storage->create(); $payment->setNumber(uniqid()); @@ -126,7 +128,7 @@ class PaymentController extends Controller $storage->update($payment); - $captureToken = $this->get('payum')->getTokenFactory()->createCaptureToken( + $captureToken = $this->payum->getTokenFactory()->createCaptureToken( $gatewayName, $payment, 'done' // the route to redirect after capture @@ -153,21 +155,22 @@ namespace Acme\PaymentBundle\Controller; use Payum\Core\Request\GetHumanStatus; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\JsonResponse; +use Payum\Bundle\PayumBundle\Controller\PayumController; -class PaymentController extends Controller +class PaymentController extends PayumController { public function doneAction(Request $request) { - $token = $this->get('payum')->getHttpRequestVerifier()->verify($request); + $token = $this->payum->getHttpRequestVerifier()->verify($request); - $gateway = $this->get('payum')->getGateway($token->getGatewayName()); + $gateway = $this->payum->getGateway($token->getGatewayName()); // you can invalidate the token. The url could not be requested any more. - // $this->get('payum')->getHttpRequestVerifier()->invalidate($token); + // $this->payum->getHttpRequestVerifier()->invalidate($token); // Once you have token you can get the model from the storage directly. //$identity = $token->getDetails(); - //$payment = $this->get('payum')->getStorage($identity->getClass())->find($identity); + //$payment = $this->payum->getStorage($identity->getClass())->find($identity); // or Payum can fetch the model for you while executing a request (Preferred). $gateway->execute($status = new GetHumanStatus($token)); diff --git a/Resources/doc/iso4217-or-currency-details.md b/Resources/doc/iso4217-or-currency-details.md index 26818358..c0b5d321 100644 --- a/Resources/doc/iso4217-or-currency-details.md +++ b/Resources/doc/iso4217-or-currency-details.md @@ -7,7 +7,7 @@ To get this information you have to execute a GetCurrency request with a currenc ```php get('payum')->getGatewayFactory('offline')->create(); +$gateway = $this->payum->getGatewayFactory('offline')->create(); $gateway->execute($currency = new \Payum\Core\GetCurrency('USD')); @@ -38,7 +38,7 @@ Or directly ISO4217 service: ```php get('payum.iso4217'); /** @var \Payum\ISO4216\Currency $currency **/ diff --git a/Resources/doc/purchase_done_action.md b/Resources/doc/purchase_done_action.md index 33c2c3e8..0707e822 100644 --- a/Resources/doc/purchase_done_action.md +++ b/Resources/doc/purchase_done_action.md @@ -8,7 +8,7 @@ Well, let's assume you created capture token this way while preparing payment. ```php get('payum')->getTokenFactory()->createCaptureToken( +$captureToken = $this->payum->getTokenFactory()->createCaptureToken( $gatewayName, $details, 'acme_payment_done' @@ -24,15 +24,15 @@ It is the route of url you will be redirected after capture done its job. Let's public function captureDoneAction(Request $request) { - $token = $this->get('payum')->getHttpRequestVerifier()->verify($request); + $token = $this->payum->getHttpRequestVerifier()->verify($request); $identity = $token->getDetails(); - $model = $this->get('payum')->getStorage($identity->getClass())->find($identity); + $model = $this->payum->getStorage($identity->getClass())->find($identity); - $gateway = $this->get('payum')->getGateway($token->getGatewayName()); + $gateway = $this->payum->getGateway($token->getGatewayName()); // you can invalidate the token. The url could not be requested any more. - // $this->get('payum')->getHttpRequestVerifier()->invalidate($token); + // $this->payum->getHttpRequestVerifier()->invalidate($token); // Once you have token you can get the model from the storage directly. //$identity = $token->getDetails(); diff --git a/Resources/doc/refund.md b/Resources/doc/refund.md index a893a9cf..3537db96 100644 --- a/Resources/doc/refund.md +++ b/Resources/doc/refund.md @@ -8,7 +8,7 @@ Let's say you already purchased an order and now you want to refund it. use Payum\Core\Request\Refund; use Payum\Core\Request\GetHumanStatus; -$gateway = $this->get('payum')->getGateway('offline'); +$gateway = $this->payum->getGateway('offline'); $gateway->execute(new Refund($payment)); $gateway->execute($status = new GetHumanStatus($payment)); @@ -20,4 +20,4 @@ if ($status->isRefunded()) { var_dump($payment->getDetails()); } -``` \ No newline at end of file +```