diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index a5478731..d4a19142 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -7,7 +7,7 @@ env: jobs: unit-test: - name: Unit ( PHP ${{ matrix.php }} ) + name: Unit ( PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }} ) runs-on: ubuntu-latest strategy: @@ -15,8 +15,23 @@ jobs: 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 @@ -39,45 +54,16 @@ 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: 7.4 - - 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: Install Symfony ${{ matrix.symfony }} + run: composer config extra.symfony.require ${{ matrix.symfony }} - - 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 Flex + run: | + composer require symfony/flex:^1 --no-update + composer config --no-plugins allow-plugins.symfony/flex true - name: Install dependencies - run: composer update --prefer-lowest --prefer-stable + run: composer update - name: Run unit tests run: bin/phpunit diff --git a/CHANGELOG.md b/CHANGELOG.md index 55d8e144..5cbae576 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 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) * Make profiler dynamic diff --git a/Command/CreateCaptureTokenCommand.php b/Command/CreateCaptureTokenCommand.php index bd45a0a0..d2208094 100644 --- a/Command/CreateCaptureTokenCommand.php +++ b/Command/CreateCaptureTokenCommand.php @@ -3,20 +3,27 @@ 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'; + private Payum $payum; + + public function __construct(Payum $payum) + { + $this->payum = $payum; + + parent::__construct(); + } + /** * {@inheritDoc} */ @@ -43,7 +50,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,7 +59,7 @@ 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())); @@ -61,12 +68,4 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 0; } - - /** - * @return Payum - */ - protected function getPayum() - { - return $this->container->get('payum'); - } } diff --git a/Command/CreateNotifyTokenCommand.php b/Command/CreateNotifyTokenCommand.php index bfdf24c1..4021137a 100644 --- a/Command/CreateNotifyTokenCommand.php +++ b/Command/CreateNotifyTokenCommand.php @@ -3,20 +3,27 @@ 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'; + private Payum $payum; + + public function __construct(Payum $payum) + { + $this->payum = $payum; + + parent::__construct(); + } + /** * {@inheritDoc} */ @@ -41,7 +48,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,7 +57,7 @@ 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())); @@ -58,12 +65,4 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 0; } - - /** - * @return Payum - */ - protected function getPayum() - { - return $this->container->get('payum'); - } } diff --git a/Command/DebugGatewayCommand.php b/Command/DebugGatewayCommand.php index 9cf1f860..4f14bbb0 100644 --- a/Command/DebugGatewayCommand.php +++ b/Command/DebugGatewayCommand.php @@ -3,23 +3,29 @@ 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'; + protected Payum $payum; + + public function __construct(Payum $payum) + { + $this->payum = $payum; + parent::__construct(); + } + /** * {@inheritDoc} */ @@ -35,15 +41,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 +62,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; } @@ -123,12 +130,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 0; } - /** - * @param \ReflectionMethod $reflectionMethod - * - * @return array - */ - protected function getMethodCode(\ReflectionMethod $reflectionMethod) + protected function getMethodCode(\ReflectionMethod $reflectionMethod): array { $file = file($reflectionMethod->getFileName()); @@ -140,15 +142,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 +159,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..c7f02876 100644 --- a/Command/StatusCommand.php +++ b/Command/StatusCommand.php @@ -2,26 +2,32 @@ 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'; + protected Payum $payum; + + public function __construct(Payum $payum) + { + $this->payum = $payum; + parent::__construct(); + } + /** * {@inheritdoc} */ - protected function configure() + protected function configure(): void { $this ->setName(static::$defaultName) @@ -35,14 +41,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 +57,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'); - } } diff --git a/Controller/AuthorizeController.php b/Controller/AuthorizeController.php index 67edd0cc..b4d5bf68 100644 --- a/Controller/AuthorizeController.php +++ b/Controller/AuthorizeController.php @@ -13,9 +13,9 @@ public function doAction(Request $request): RedirectResponse $gateway = $this->getPayum()->getGateway($token->getGatewayName()); $gateway->execute(new Authorize($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 88af222b..002c1d47 100644 --- a/Controller/CancelController.php +++ b/Controller/CancelController.php @@ -16,12 +16,12 @@ public function doAction(Request $request): Response $gateway = $this->getPayum()->getGateway($token->getGatewayName()); $gateway->execute(new Cancel($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 a52b3d1c..ff6d7a81 100644 --- a/Controller/CaptureController.php +++ b/Controller/CaptureController.php @@ -41,9 +41,9 @@ public function doAction(Request $request): RedirectResponse $gateway = $this->getPayum()->getGateway($token->getGatewayName()); $gateway->execute(new Capture($token)); - + $this->getPayum()->getHttpRequestVerifier()->invalidate($token); - + return $this->redirect($token->getAfterUrl()); } } diff --git a/Controller/NotifyController.php b/Controller/NotifyController.php index adcd4cd3..15a4870c 100644 --- a/Controller/NotifyController.php +++ b/Controller/NotifyController.php @@ -26,4 +26,4 @@ public function doAction(Request $request): Response return new Response('', 204); } -} \ No newline at end of file +} diff --git a/Controller/PayoutController.php b/Controller/PayoutController.php index 22614c26..ca211e23 100644 --- a/Controller/PayoutController.php +++ b/Controller/PayoutController.php @@ -13,9 +13,9 @@ public function doAction(Request $request): RedirectResponse $gateway = $this->getPayum()->getGateway($token->getGatewayName()); $gateway->execute(new Payout($token)); - + $this->getPayum()->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..09a23238 100644 --- a/Controller/PayumController.php +++ b/Controller/PayumController.php @@ -1,6 +1,7 @@ payum = $payum; + } + /** - * @return Payum + * @deprecated since 2.5 and will be removed in 3.0. Use $this->>payum instead. */ protected function getPayum() { - return $this->get('payum'); - } + $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); - /** @return string[] */ - public static function getSubscribedServices() - { - return array_merge(parent::getSubscribedServices(), [ - 'payum' => Payum::class, - ]); + 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'); } /** - * @deprecated will be removed in 2.0. + * @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 2.0. + * @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 f077bf83..b1bfb7fe 100644 --- a/Controller/RefundController.php +++ b/Controller/RefundController.php @@ -16,12 +16,12 @@ public function doAction(Request $request): Response $gateway = $this->getPayum()->getGateway($token->getGatewayName()); $gateway->execute(new Refund($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/SyncController.php b/Controller/SyncController.php index 797c6c33..3051b542 100644 --- a/Controller/SyncController.php +++ b/Controller/SyncController.php @@ -14,9 +14,9 @@ public function doAction(Request $request): RedirectResponse $gateway = $this->getPayum()->getGateway($token->getGatewayName()); $gateway->execute(new Sync($token)); - + $this->getPayum()->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..dc3e897c 100644 --- a/DependencyInjection/Factory/Storage/StorageFactoryInterface.php +++ b/DependencyInjection/Factory/Storage/StorageFactoryInterface.php @@ -10,18 +10,16 @@ interface StorageFactoryInterface * @param string $modelClass * @return string The payment serviceId */ - function create(ContainerBuilder $container, $modelClass, array $config); + public function create(ContainerBuilder $container, $modelClass, array $config); /** * The storage name, * For example filesystem, doctrine, propel etc. - * - * @return string */ - function getName(); + public function getName(); /** * @return void */ - function addConfiguration(ArrayNodeDefinition $builder); + public function addConfiguration(ArrayNodeDefinition $builder); } 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..4c062718 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): MainConfiguration { return new MainConfiguration($this->storagesFactories); } diff --git a/Profiler/PayumCollector.php b/Profiler/PayumCollector.php index 3de5b224..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 = []; @@ -43,9 +44,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 +113,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 +123,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..4ef4f00c 100644 --- a/Resources/config/controller.xml +++ b/Resources/config/controller.xml @@ -2,36 +2,84 @@ + 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/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 +``` 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..8234195c 100644 --- a/Tests/DependencyInjection/Compiler/BuildConfigsPassTest.php +++ b/Tests/DependencyInjection/Compiler/BuildConfigsPassTest.php @@ -212,4 +212,4 @@ public function testShouldAddConfig(array $tagAttributes, $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 e4013894..f78a4756 100644 --- a/Tests/DependencyInjection/Factory/AbstractStorageFactoryTest.php +++ b/Tests/DependencyInjection/Factory/AbstractStorageFactoryTest.php @@ -16,8 +16,8 @@ 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)); } @@ -42,7 +42,7 @@ public function shouldAllowAddConfiguration(): void $tb = new TreeBuilder('foo'); $rootNode = $tb->getRootNode(); - + $factory->addConfiguration($rootNode); $processor = new Processor(); @@ -55,14 +55,14 @@ public function shouldAllowAddConfiguration(): void public function shouldAllowCreateStorageAndReturnItsId(): void { $expectedStorage = new Definition(); - + $factory = $this->createAbstractStorageFactory(); $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; } } @@ -95,6 +95,6 @@ protected function assertDefinitionContainsMethodCall(Definition $serviceDefinit */ protected function createAbstractStorageFactory() { - 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..733a4b5e 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)); } /** @@ -158,6 +158,6 @@ public function shouldCreateServiceDefinition(): void */ protected function createContainerBuilderMock() { - 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..d1b97d8b 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, $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, $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..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, $modelClass, array $config) + public function create(ContainerBuilder $container, $modelClass, array $config): string { return 'aStorageId'; } diff --git a/Tests/EventListener/ReplyToHttpResponseListenerTest.php b/Tests/EventListener/ReplyToHttpResponseListenerTest.php index 41572e34..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, - Kernel::MASTER_REQUEST, + $this->getRequestType(), $expectedException ); @@ -66,7 +65,7 @@ public function shouldSetResponseReturnedByConverterToEvent(): void $event = new ExceptionEvent( $this->createHttpKernelMock(), new Request, - Kernel::MASTER_REQUEST, + $this->getRequestType(), $reply ); @@ -75,7 +74,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 +93,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, $this->getRequestType(), $reply); $converterMock = $this->createReplyToSymfonyResponseConverterMock(); $converterMock ->expects($this->once()) ->method('convert') ->with($this->identicalTo($reply)) - ->will($this->returnValue($response)) + ->willReturn($response) ; $listener = new ReplyToHttpResponseListener($converterMock); @@ -118,7 +117,7 @@ public function shouldCallAllowCustomResponseCode(): void */ protected function createReplyToSymfonyResponseConverterMock() { - return $this->createMock('Payum\Core\Bridge\Symfony\ReplyToSymfonyResponseConverter'); + return $this->createMock(ReplyToSymfonyResponseConverter::class); } /** @@ -126,6 +125,15 @@ protected function createReplyToSymfonyResponseConverterMock() */ protected function createHttpKernelMock() { - return $this->createMock('Symfony\Component\HttpKernel\HttpKernelInterface'); + 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/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/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 df80f149..aa48859c 100644 --- a/Tests/Functional/Form/Type/CreditCardExpirationDateTypeTest.php +++ b/Tests/Functional/Form/Type/CreditCardExpirationDateTypeTest.php @@ -6,19 +6,22 @@ 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\HttpKernel\Kernel; +use Symfony\Component\Security\Csrf\TokenStorage\SessionTokenStorage; 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 +29,14 @@ protected function setUp(): void */ public function couldBeCreatedByFormFactory(): void { + 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(); @@ -44,7 +55,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..ad84cb39 100644 --- a/Tests/Functional/Form/Type/CreditCardTypeTest.php +++ b/Tests/Functional/Form/Type/CreditCardTypeTest.php @@ -7,19 +7,21 @@ 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\HttpKernel\Kernel; 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::getContainer()->get('form.factory'); } /** @@ -27,6 +29,14 @@ protected function setUp(): void */ public function couldBeCreatedByFormFactory(): void { + 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(); @@ -43,7 +53,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..63ff63ed 100644 --- a/Tests/Functional/Form/Type/GatewayConfigTypeTest.php +++ b/Tests/Functional/Form/Type/GatewayConfigTypeTest.php @@ -7,19 +7,21 @@ 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\HttpKernel\Kernel; 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 +29,18 @@ protected function setUp(): void */ public function couldBeCreatedByFormFactory(): void { - $form = $this->formFactory->create(GatewayConfigType::class, null, array( + 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, - )); + ]); + $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/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 e904e9b1..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,17 +75,17 @@ 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); - $this->assertGreaterThan(10, count($factories)); + $this->assertGreaterThan(5, count($factories)); } 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 491f20e4..4eb3f10a 100644 --- a/Tests/Functional/WebTestCase.php +++ b/Tests/Functional/WebTestCase.php @@ -4,13 +4,16 @@ 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 { protected KernelBrowser $client; /** - * @var ContainerInterface + * @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/AppKernel.php b/Tests/Functional/app/AppKernel.php index 444d8ff3..2ff7ea81 100644 --- a/Tests/Functional/app/AppKernel.php +++ b/Tests/Functional/app/AppKernel.php @@ -1,14 +1,16 @@ 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'); - } + $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 2feeb3a5..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% } @@ -9,8 +9,8 @@ framework: 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 payum: diff --git a/Tests/Functional/app/config/config_sf4.yml b/Tests/Functional/app/config/config_sf4.yml index e23e7560..094e00c7 100644 --- a/Tests/Functional/app/config/config_sf4.yml +++ b/Tests/Functional/app/config/config_sf4.yml @@ -1,4 +1,4 @@ framework: session: storage_id: 'session.storage.mock_file' - validation: { enable_annotations: true } \ No newline at end of file + validation: { enable_annotations: false } diff --git a/Tests/Functional/app/config/config_sf5.yml b/Tests/Functional/app/config/config_sf5.yml index f6c17d91..23ffbdc7 100644 --- a/Tests/Functional/app/config/config_sf5.yml +++ b/Tests/Functional/app/config/config_sf5.yml @@ -4,4 +4,4 @@ framework: cookie_secure: auto cookie_samesite: lax storage_factory_id: session.storage.factory.mock_file - validation: { enable_annotations: false } \ No newline at end of file + validation: { enable_annotations: false } 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 } 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 @@ Payum::class, + ]); + } + } +} else { + trait ControllerTrait + { + public static function getSubscribedServices() + { + return array_merge(parent::getSubscribedServices(), [ + 'payum' => Payum::class, + ]); + } + } +} diff --git a/composer.json b/composer.json index 9604c635..5e72cba5 100644 --- a/composer.json +++ b/composer.json @@ -38,38 +38,35 @@ ], "require": { "php": "^7.4 || ^8.0", - "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" + "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": { - "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 ", "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", + "doctrine/orm": "^2.8", + "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/offline": "^1.7", + "payum/paypal-express-checkout-nvp": "^1.7", + "payum/stripe": "^1.7", + "payum/omnipay-v3-bridge": "^1@alpha", + "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": "^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": { "sonata-project/admin-bundle": "^3 If you want to configure payments in the backend." @@ -77,6 +74,9 @@ "autoload": { "psr-4": { "Payum\\Bundle\\PayumBundle\\": "" } }, + "autoload-dev": { + "psr-4": { "Payum\\Bundle\\PayumBundle\\Tests\\": "Tests/" } + }, "extra": { "branch-alias": { "dev-master": "2.5-dev" @@ -84,5 +84,7 @@ }, "config": { "bin-dir": "bin" - } + }, + "minimum-stability": "dev", + "prefer-stable": true }