From 23a3b9155f3cfa5f45fa9390c3ac22a8e270e92f Mon Sep 17 00:00:00 2001 From: Lukas Mencl Date: Mon, 10 Feb 2020 21:04:28 +0100 Subject: [PATCH 1/3] fixed compatibility with symfony 5 --- Command/CreateCaptureTokenCommand.php | 2 + Command/CreateNotifyTokenCommand.php | 4 +- Command/DebugGatewayCommand.php | 2 + Command/StatusCommand.php | 2 + Controller/CaptureController.php | 6 +-- Controller/PayumController.php | 6 +-- DependencyInjection/MainConfiguration.php | 12 ++--- EventListener/ReplyToHttpResponseListener.php | 21 +++----- .../GatewayFactoriesChoiceTypeExtension.php | 3 +- Profiler/PayumCollector.php | 2 +- Resources/config/validation.xml | 5 +- Resources/doc/storages.md | 4 +- Tests/Controller/AuthorizeControllerTest.php | 4 +- Tests/Controller/CancelControllerTest.php | 4 +- Tests/Controller/CaptureControllerTest.php | 6 +-- Tests/Controller/NotifyControllerTest.php | 6 +-- Tests/Controller/PayoutControllerTest.php | 7 +-- Tests/Controller/RefundControllerTest.php | 4 +- .../Factory/AbstractStorageFactoryTest.php | 6 +-- .../Factory/CustomStorageFactoryTest.php | 20 ++++---- .../Factory/DoctrineStorageFactoryTest.php | 14 ++--- .../Factory/FilesystemStorageFactoryTest.php | 14 ++--- .../ReplyToHttpResponseListenerTest.php | 51 +++++-------------- Tests/Functional/app/config/config.yml | 6 +-- 24 files changed, 86 insertions(+), 125 deletions(-) diff --git a/Command/CreateCaptureTokenCommand.php b/Command/CreateCaptureTokenCommand.php index 4d3edf9e..792569e5 100644 --- a/Command/CreateCaptureTokenCommand.php +++ b/Command/CreateCaptureTokenCommand.php @@ -58,6 +58,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $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; } /** diff --git a/Command/CreateNotifyTokenCommand.php b/Command/CreateNotifyTokenCommand.php index b3b96f1f..ca79c53d 100644 --- a/Command/CreateNotifyTokenCommand.php +++ b/Command/CreateNotifyTokenCommand.php @@ -40,7 +40,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $modelId = $input->getOption('model-id'); $model = null; - if ($modelClass && $modelId) { + if ($modelClass && $modelId) { if (false == $model = $this->getPayum()->getStorage($modelClass)->find($modelId)) { throw new RuntimeException(sprintf( 'Cannot find model with class %s and id %s.', @@ -55,6 +55,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $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; } /** diff --git a/Command/DebugGatewayCommand.php b/Command/DebugGatewayCommand.php index 6cf06421..94bc191f 100644 --- a/Command/DebugGatewayCommand.php +++ b/Command/DebugGatewayCommand.php @@ -121,6 +121,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln(sprintf("\t%s", get_class($api))); } } + + return 0; } /** diff --git a/Command/StatusCommand.php b/Command/StatusCommand.php index 21175db5..9c189859 100644 --- a/Command/StatusCommand.php +++ b/Command/StatusCommand.php @@ -54,6 +54,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->getPayum()->getGateway($gatewayName)->execute($status); $output->writeln(sprintf('Status: %s', $status->getValue())); + + return 0; } /** diff --git a/Controller/CaptureController.php b/Controller/CaptureController.php index 9ef7deb4..5a1be0ba 100644 --- a/Controller/CaptureController.php +++ b/Controller/CaptureController.php @@ -10,11 +10,11 @@ class CaptureController extends PayumController { public function doSessionTokenAction(Request $request) { - if (false == $request->getSession()) { + if (false === $request->hasSession()) { throw new HttpException(400, 'This controller requires session to be started.'); } - if (false == $hash = $request->getSession()->get('payum_token')) { + if (null === $hash = $request->getSession()->get('payum_token')) { throw new HttpException(400, 'This controller requires token hash to be stored in the session.'); } @@ -45,4 +45,4 @@ public function doAction(Request $request) return $this->redirect($token->getAfterUrl()); } -} \ No newline at end of file +} diff --git a/Controller/PayumController.php b/Controller/PayumController.php index 7237a5e4..7387e3dc 100644 --- a/Controller/PayumController.php +++ b/Controller/PayumController.php @@ -4,9 +4,9 @@ use Payum\Core\Payum; use Payum\Core\Security\GenericTokenFactoryInterface; use Payum\Core\Security\HttpRequestVerifierInterface; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; -abstract class PayumController extends Controller +abstract class PayumController extends AbstractController { /** * @return Payum @@ -35,4 +35,4 @@ protected function getTokenFactory() { return $this->getPayum()->getTokenFactory(); } -} \ No newline at end of file +} diff --git a/DependencyInjection/MainConfiguration.php b/DependencyInjection/MainConfiguration.php index 5640160e..f33c7a78 100644 --- a/DependencyInjection/MainConfiguration.php +++ b/DependencyInjection/MainConfiguration.php @@ -29,14 +29,8 @@ public function __construct(array $storageFactories) */ public function getConfigTreeBuilder() { - if (method_exists(TreeBuilder::class, 'getRootNode')) { - $tb = new TreeBuilder('payum'); - $rootNode = $tb->getRootNode(); - } else { - // BC layer for symfony/config 4.1 and older - $tb = new TreeBuilder(); - $rootNode = $tb->root('payum'); - } + $tb = new TreeBuilder('payum'); + $rootNode = $tb->getRootNode(); $securityNode = $rootNode->children() ->arrayNode('security')->isRequired() @@ -260,4 +254,4 @@ protected function addDynamicGatewaysSection(ArrayNodeDefinition $dynamicGateway ); } } -} \ No newline at end of file +} diff --git a/EventListener/ReplyToHttpResponseListener.php b/EventListener/ReplyToHttpResponseListener.php index e2b9375a..43875a9d 100644 --- a/EventListener/ReplyToHttpResponseListener.php +++ b/EventListener/ReplyToHttpResponseListener.php @@ -3,7 +3,7 @@ use Payum\Core\Bridge\Symfony\ReplyToSymfonyResponseConverter; use Payum\Core\Reply\ReplyInterface; -use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; +use Symfony\Component\HttpKernel\Event\ExceptionEvent; class ReplyToHttpResponseListener { @@ -21,24 +21,17 @@ public function __construct(ReplyToSymfonyResponseConverter $replyToSymfonyRespo } /** - * @param GetResponseForExceptionEvent $event + * @param ExceptionEvent $event */ - public function onKernelException(GetResponseForExceptionEvent $event) + public function onKernelException(ExceptionEvent $event) { - if (false == $event->getException() instanceof ReplyInterface) { + if (false === $event->getThrowable() instanceof ReplyInterface) { return; } - $response = $this->replyToSymfonyResponseConverter->convert($event->getException()); - - // BC for SF < 3.3 - if (!method_exists($event, 'allowCustomResponseCode')) { - if (false === $response->headers->has('X-Status-Code')) { - $response->headers->set('X-Status-Code', $response->getStatusCode()); - } - } else { - $event->allowCustomResponseCode(); - } + $response = $this->replyToSymfonyResponseConverter->convert($event->getThrowable()); + + $event->allowCustomResponseCode(); $event->setResponse($response); } diff --git a/Form/Extension/GatewayFactoriesChoiceTypeExtension.php b/Form/Extension/GatewayFactoriesChoiceTypeExtension.php index 294bbe72..656b6778 100644 --- a/Form/Extension/GatewayFactoriesChoiceTypeExtension.php +++ b/Form/Extension/GatewayFactoriesChoiceTypeExtension.php @@ -4,7 +4,6 @@ use Payum\Core\Bridge\Symfony\Form\Type\GatewayFactoriesChoiceType; use Payum\Core\Registry\GatewayFactoryRegistryInterface; use Symfony\Component\Form\AbstractTypeExtension; -use Symfony\Component\Form\Exception; use Symfony\Component\OptionsResolver\OptionsResolver; class GatewayFactoriesChoiceTypeExtension extends AbstractTypeExtension @@ -53,7 +52,7 @@ public function getExtendedType() /** * {@inheritdoc} */ - public static function getExtendedTypes() + public static function getExtendedTypes(): iterable { return [GatewayFactoriesChoiceType::class]; } diff --git a/Profiler/PayumCollector.php b/Profiler/PayumCollector.php index 114ad8ba..ba4026f6 100644 --- a/Profiler/PayumCollector.php +++ b/Profiler/PayumCollector.php @@ -23,7 +23,7 @@ class PayumCollector extends DataCollector implements ExtensionInterface /** * {@inheritdoc} */ - public function collect(Request $request, Response $response, \Exception $exception = null) + public function collect(Request $request, Response $response, \Throwable $exception = null) { foreach ($this->contexts as $context) { $request = $context->getRequest(); diff --git a/Resources/config/validation.xml b/Resources/config/validation.xml index 95c0f0d6..8ad27194 100644 --- a/Resources/config/validation.xml +++ b/Resources/config/validation.xml @@ -37,7 +37,8 @@ - + + @@ -47,4 +48,4 @@ - \ No newline at end of file + diff --git a/Resources/doc/storages.md b/Resources/doc/storages.md index 36d3375e..3cd04c1d 100644 --- a/Resources/doc/storages.md +++ b/Resources/doc/storages.md @@ -130,10 +130,10 @@ doctrine_mongodb: payum: is_bundle: false type: xml - dir: %kernel.root_dir%/../vendor/payum/core/Payum/Core/Bridge/Doctrine/Resources/mapping + dir: %kernel.project_dir%/vendor/payum/core/Payum/Core/Bridge/Doctrine/Resources/mapping # set this dir instead if you use `payum/payum` library - #dir: %kernel.root_dir%/../vendor/payum/payum/src/Payum/Core/Bridge/Doctrine/Resources/mapping + #dir: %kernel.project_dir%/vendor/payum/payum/src/Payum/Core/Bridge/Doctrine/Resources/mapping prefix: Payum\Core\Model diff --git a/Tests/Controller/AuthorizeControllerTest.php b/Tests/Controller/AuthorizeControllerTest.php index 32133e43..59d79b3d 100644 --- a/Tests/Controller/AuthorizeControllerTest.php +++ b/Tests/Controller/AuthorizeControllerTest.php @@ -10,7 +10,7 @@ use Payum\Core\Security\GenericTokenFactoryInterface; use Payum\Core\Security\HttpRequestVerifierInterface; use Payum\Core\Storage\StorageInterface; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; @@ -24,7 +24,7 @@ public function shouldBeSubClassOfController() { $rc = new \ReflectionClass(AuthorizeController::class); - $this->assertTrue($rc->isSubclassOf(Controller::class)); + $this->assertTrue($rc->isSubclassOf(AbstractController::class)); } /** diff --git a/Tests/Controller/CancelControllerTest.php b/Tests/Controller/CancelControllerTest.php index 33759634..9f9eba4c 100644 --- a/Tests/Controller/CancelControllerTest.php +++ b/Tests/Controller/CancelControllerTest.php @@ -10,7 +10,7 @@ use Payum\Core\Security\GenericTokenFactoryInterface; use Payum\Core\Security\HttpRequestVerifierInterface; use Payum\Core\Storage\StorageInterface; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; @@ -25,7 +25,7 @@ public function shouldBeSubClassOfController() { $rc = new \ReflectionClass(CancelController::class); - $this->assertTrue($rc->isSubclassOf(Controller::class)); + $this->assertTrue($rc->isSubclassOf(AbstractController::class)); } /** diff --git a/Tests/Controller/CaptureControllerTest.php b/Tests/Controller/CaptureControllerTest.php index 91587775..e272bfe7 100644 --- a/Tests/Controller/CaptureControllerTest.php +++ b/Tests/Controller/CaptureControllerTest.php @@ -10,7 +10,7 @@ use Payum\Core\Security\GenericTokenFactoryInterface; use Payum\Core\Security\HttpRequestVerifierInterface; use Payum\Core\Storage\StorageInterface; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; @@ -27,7 +27,7 @@ public function shouldBeSubClassOfController() { $rc = new \ReflectionClass(CaptureController::class); - $this->assertTrue($rc->isSubclassOf(Controller::class)); + $this->assertTrue($rc->isSubclassOf(AbstractController::class)); } /** @@ -43,7 +43,7 @@ public function throwBadRequestIfSessionNotStartedOnDoSessionAction() $request = Request::create('/'); //guard - $this->assertNull($request->getSession()); + $this->assertFalse($request->hasSession()); $controller->doSessionTokenAction($request); } diff --git a/Tests/Controller/NotifyControllerTest.php b/Tests/Controller/NotifyControllerTest.php index f6fe0115..7229c9ea 100644 --- a/Tests/Controller/NotifyControllerTest.php +++ b/Tests/Controller/NotifyControllerTest.php @@ -5,12 +5,10 @@ use Payum\Core\GatewayInterface; use Payum\Core\Registry\RegistryInterface; use Payum\Core\Request\Notify; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpFoundation\Session\Session; -use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; class NotifyControllerTest extends \PHPUnit\Framework\TestCase { @@ -21,7 +19,7 @@ public function shouldBeSubClassOfController() { $rc = new \ReflectionClass(NotifyController::class); - $this->assertTrue($rc->isSubclassOf(Controller::class)); + $this->assertTrue($rc->isSubclassOf(AbstractController::class)); } /** diff --git a/Tests/Controller/PayoutControllerTest.php b/Tests/Controller/PayoutControllerTest.php index fda91cc8..093b41f0 100644 --- a/Tests/Controller/PayoutControllerTest.php +++ b/Tests/Controller/PayoutControllerTest.php @@ -10,13 +10,10 @@ use Payum\Core\Security\GenericTokenFactoryInterface; use Payum\Core\Security\HttpRequestVerifierInterface; use Payum\Core\Storage\StorageInterface; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Session\Session; -use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; -use Symfony\Component\Routing\RouterInterface; class PayoutControllerTest extends \PHPUnit\Framework\TestCase { @@ -27,7 +24,7 @@ public function shouldBeSubClassOfController() { $rc = new \ReflectionClass(PayoutController::class); - $this->assertTrue($rc->isSubclassOf(Controller::class)); + $this->assertTrue($rc->isSubclassOf(AbstractController::class)); } /** diff --git a/Tests/Controller/RefundControllerTest.php b/Tests/Controller/RefundControllerTest.php index e0127171..d2a97a2f 100644 --- a/Tests/Controller/RefundControllerTest.php +++ b/Tests/Controller/RefundControllerTest.php @@ -10,7 +10,7 @@ use Payum\Core\Security\GenericTokenFactoryInterface; use Payum\Core\Security\HttpRequestVerifierInterface; use Payum\Core\Storage\StorageInterface; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; @@ -25,7 +25,7 @@ public function shouldBeSubClassOfController() { $rc = new \ReflectionClass(RefundController::class); - $this->assertTrue($rc->isSubclassOf(Controller::class)); + $this->assertTrue($rc->isSubclassOf(AbstractController::class)); } /** diff --git a/Tests/DependencyInjection/Factory/AbstractStorageFactoryTest.php b/Tests/DependencyInjection/Factory/AbstractStorageFactoryTest.php index 8a953588..1ee7eeab 100644 --- a/Tests/DependencyInjection/Factory/AbstractStorageFactoryTest.php +++ b/Tests/DependencyInjection/Factory/AbstractStorageFactoryTest.php @@ -37,8 +37,8 @@ public function shouldAllowAddConfiguration() { $factory = $this->createAbstractStorageFactory(); - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + $tb = new TreeBuilder('foo'); + $rootNode = $tb->getRootNode(); $factory->addConfiguration($rootNode); @@ -94,4 +94,4 @@ protected function createAbstractStorageFactory() { return $this->getMockForAbstractClass('Payum\Bundle\PayumBundle\DependencyInjection\Factory\Storage\AbstractStorageFactory'); } -} \ No newline at end of file +} diff --git a/Tests/DependencyInjection/Factory/CustomStorageFactoryTest.php b/Tests/DependencyInjection/Factory/CustomStorageFactoryTest.php index 2119f772..d45851a8 100644 --- a/Tests/DependencyInjection/Factory/CustomStorageFactoryTest.php +++ b/Tests/DependencyInjection/Factory/CustomStorageFactoryTest.php @@ -44,8 +44,8 @@ public function shouldAllowAddConfiguration() { $factory = new CustomStorageFactory(); - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + $tb = new TreeBuilder('foo'); + $rootNode = $tb->getRootNode(); $factory->addConfiguration($rootNode); @@ -68,8 +68,8 @@ public function shouldRequireServiceOption() { $factory = new CustomStorageFactory(); - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + $tb = new TreeBuilder('foo'); + $rootNode = $tb->getRootNode(); $factory->addConfiguration($rootNode); @@ -87,8 +87,8 @@ public function shouldNotAllowEmptyServiceOption() { $factory = new CustomStorageFactory(); - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + $tb = new TreeBuilder('foo'); + $rootNode = $tb->getRootNode(); $factory->addConfiguration($rootNode); @@ -108,8 +108,8 @@ public function shouldNotAllowNullServiceOption() { $factory = new CustomStorageFactory(); - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + $tb = new TreeBuilder('foo'); + $rootNode = $tb->getRootNode(); $factory->addConfiguration($rootNode); @@ -126,8 +126,8 @@ public function shouldAllowAddShortConfiguration() { $factory = new CustomStorageFactory; - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + $tb = new TreeBuilder('foo'); + $rootNode = $tb->getRootNode(); $factory->addConfiguration($rootNode); diff --git a/Tests/DependencyInjection/Factory/DoctrineStorageFactoryTest.php b/Tests/DependencyInjection/Factory/DoctrineStorageFactoryTest.php index 4b53d315..34641b5d 100644 --- a/Tests/DependencyInjection/Factory/DoctrineStorageFactoryTest.php +++ b/Tests/DependencyInjection/Factory/DoctrineStorageFactoryTest.php @@ -42,8 +42,8 @@ public function shouldAllowAddConfiguration() { $factory = new DoctrineStorageFactory; - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + $tb = new TreeBuilder('foo'); + $rootNode = $tb->getRootNode(); $factory->addConfiguration($rootNode); @@ -63,8 +63,8 @@ public function shouldAllowAddShortConfiguration() { $factory = new DoctrineStorageFactory; - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + $tb = new TreeBuilder('foo'); + $rootNode = $tb->getRootNode(); $factory->addConfiguration($rootNode); @@ -85,12 +85,12 @@ public function shouldRequireDriverOption() { $factory = new DoctrineStorageFactory; - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + $tb = new TreeBuilder('foo'); + $rootNode = $tb->getRootNode(); $factory->addConfiguration($rootNode); $processor = new Processor(); $processor->process($tb->buildTree(), array(array())); } -} \ No newline at end of file +} diff --git a/Tests/DependencyInjection/Factory/FilesystemStorageFactoryTest.php b/Tests/DependencyInjection/Factory/FilesystemStorageFactoryTest.php index 0209169b..3876e177 100644 --- a/Tests/DependencyInjection/Factory/FilesystemStorageFactoryTest.php +++ b/Tests/DependencyInjection/Factory/FilesystemStorageFactoryTest.php @@ -42,8 +42,8 @@ public function shouldAllowAddConfiguration() { $factory = new FilesystemStorageFactory; - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + $tb = new TreeBuilder('foo'); + $rootNode = $tb->getRootNode(); $factory->addConfiguration($rootNode); @@ -70,8 +70,8 @@ public function shouldRequireStorageDirOption() { $factory = new FilesystemStorageFactory; - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + $tb = new TreeBuilder('foo'); + $rootNode = $tb->getRootNode(); $factory->addConfiguration($rootNode); @@ -86,8 +86,8 @@ public function shouldSetIdPropertyToNull() { $factory = new FilesystemStorageFactory; - $tb = new TreeBuilder(); - $rootNode = $tb->root('foo'); + $tb = new TreeBuilder('foo'); + $rootNode = $tb->getRootNode(); $factory->addConfiguration($rootNode); @@ -99,4 +99,4 @@ public function shouldSetIdPropertyToNull() $this->assertArrayHasKey('id_property', $config); $this->assertNull($config['id_property']); } -} \ No newline at end of file +} diff --git a/Tests/EventListener/ReplyToHttpResponseListenerTest.php b/Tests/EventListener/ReplyToHttpResponseListenerTest.php index 4a59a4c5..b1e82697 100644 --- a/Tests/EventListener/ReplyToHttpResponseListenerTest.php +++ b/Tests/EventListener/ReplyToHttpResponseListenerTest.php @@ -7,7 +7,7 @@ use Symfony\Component\Config\Definition\Exception\Exception; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; +use Symfony\Component\HttpKernel\Event\ExceptionEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\Kernel; @@ -28,7 +28,7 @@ public function shouldDoNothingIfExceptionNotInstanceOfReply() { $expectedException = new Exception; - $event = new GetResponseForExceptionEvent( + $event = new ExceptionEvent( $this->createHttpKernelMock(), new Request, Kernel::MASTER_REQUEST, @@ -46,7 +46,7 @@ public function shouldDoNothingIfExceptionNotInstanceOfReply() $listener->onKernelException($event); $this->assertNull($event->getResponse()); - $this->assertSame($expectedException, $event->getException()); + $this->assertSame($expectedException, $event->getThrowable()); $this->assertFalse($event->isPropagationStopped()); } @@ -60,7 +60,7 @@ public function shouldSetResponseReturnedByConverterToEvent() $reply = new HttpRedirect($expectedUrl); $response = new Response(); - $event = new GetResponseForExceptionEvent( + $event = new ExceptionEvent( $this->createHttpKernelMock(), new Request, Kernel::MASTER_REQUEST, @@ -80,7 +80,7 @@ public function shouldSetResponseReturnedByConverterToEvent() $listener->onKernelException($event); $this->assertSame($response, $event->getResponse()); - $this->assertSame($reply, $event->getException()); + $this->assertSame($reply, $event->getThrowable()); } /** @@ -91,18 +91,13 @@ public function shouldSetXStatusFromResponseStatusCode() $reply = new HttpRedirect('/foo/bar'); $response = new Response('', 302); - $event = new GetResponseForExceptionEvent( + $event = new ExceptionEvent( $this->createHttpKernelMock(), new Request, Kernel::MASTER_REQUEST, $reply ); - // BC for SF < 3.3 - if (method_exists($event, 'allowCustomResponseCode')) { - $this->markTestSkipped('BC for SF < 3.3'); - } - $converterMock = $this->createReplyToSymfonyResponseConverterMock(); $converterMock ->expects($this->once()) @@ -130,18 +125,13 @@ public function shouldNotSetXStatusIfAlreadySet() 'X-Status-Code' => 666, )); - $event = new GetResponseForExceptionEvent( + $event = new ExceptionEvent( $this->createHttpKernelMock(), new Request, Kernel::MASTER_REQUEST, $reply ); - // BC for SF < 3.3 - if (method_exists($event, 'allowCustomResponseCode')) { - $this->markTestSkipped('BC for SF < 3.3'); - } - $converterMock = $this->createReplyToSymfonyResponseConverterMock(); $converterMock ->expects($this->once()) @@ -167,19 +157,7 @@ public function shouldCallAllowCustomResponseCode() $reply = new HttpRedirect('/foo/bar'); $response = new Response('', 302); - $eventMock = $this - ->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent') - ->setMethods(null) - ->setConstructorArgs([$this->createHttpKernelMock(), - new Request, - Kernel::MASTER_REQUEST, - $reply]) - ->getMock(); - - // BC for SF < 3.3 - if (!method_exists($eventMock, 'allowCustomResponseCode')) { - $this->markTestSkipped('BC for SF < 3.3'); - } + $event = new ExceptionEvent($this->createHttpKernelMock(), new Request, Kernel::MASTER_REQUEST, $reply); $converterMock = $this->createReplyToSymfonyResponseConverterMock(); $converterMock @@ -189,18 +167,13 @@ public function shouldCallAllowCustomResponseCode() ->will($this->returnValue($response)) ; - $eventMock - ->expects($this->once()) - ->method('allowCustomResponseCode') - ; - $listener = new ReplyToHttpResponseListener($converterMock); - $listener->onKernelException($eventMock); + $listener->onKernelException($event); - $this->assertInstanceOf(Response::class, $eventMock->getResponse()); - $this->assertEquals(302, $eventMock->getResponse()->getStatusCode()); - $this->assertEquals(true, $eventMock->isAllowingCustomResponseCode()); + $this->assertInstanceOf(Response::class, $event->getResponse()); + $this->assertEquals(302, $event->getResponse()->getStatusCode()); + $this->assertEquals(true, $event->isAllowingCustomResponseCode()); } /** diff --git a/Tests/Functional/app/config/config.yml b/Tests/Functional/app/config/config.yml index 574ae1ac..1938bae6 100644 --- a/Tests/Functional/app/config/config.yml +++ b/Tests/Functional/app/config/config.yml @@ -9,10 +9,8 @@ framework: session: storage_id: 'session.storage.mock_file' secret: '%secret%' - router: { resource: '%kernel.root_dir%/config/routing.yml' } + router: { resource: '%kernel.project_dir%/Tests/Functional/app/config/routing.yml' } default_locale: '%locale%' - templating: - engines: [ 'twig'] form: true csrf_protection: true validation: { enable_annotations: true } @@ -41,4 +39,4 @@ payum: username: 'aUsername' password: 'aPassword' signature: 'aSignature' - sandbox: true \ No newline at end of file + sandbox: true From b5393452c4427b608d2f080abdf85f3c8a587d6e Mon Sep 17 00:00:00 2001 From: Lukas Mencl Date: Mon, 10 Feb 2020 21:31:57 +0100 Subject: [PATCH 2/3] fixed expected response --- Tests/EventListener/ReplyToHttpResponseListenerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/EventListener/ReplyToHttpResponseListenerTest.php b/Tests/EventListener/ReplyToHttpResponseListenerTest.php index b1e82697..500c0fba 100644 --- a/Tests/EventListener/ReplyToHttpResponseListenerTest.php +++ b/Tests/EventListener/ReplyToHttpResponseListenerTest.php @@ -89,7 +89,7 @@ public function shouldSetResponseReturnedByConverterToEvent() public function shouldSetXStatusFromResponseStatusCode() { $reply = new HttpRedirect('/foo/bar'); - $response = new Response('', 302); + $response = new Response('', 302, ['X-Status-Code' => 302]); $event = new ExceptionEvent( $this->createHttpKernelMock(), From ff705037e69ece38faf604fdff7dd2c421f92ed3 Mon Sep 17 00:00:00 2001 From: Lukas Mencl Date: Tue, 11 Feb 2020 19:55:22 +0100 Subject: [PATCH 3/3] removed tests for SF < 3.3 --- .../ReplyToHttpResponseListenerTest.php | 66 ------------------- 1 file changed, 66 deletions(-) diff --git a/Tests/EventListener/ReplyToHttpResponseListenerTest.php b/Tests/EventListener/ReplyToHttpResponseListenerTest.php index 500c0fba..05fb17f8 100644 --- a/Tests/EventListener/ReplyToHttpResponseListenerTest.php +++ b/Tests/EventListener/ReplyToHttpResponseListenerTest.php @@ -83,72 +83,6 @@ public function shouldSetResponseReturnedByConverterToEvent() $this->assertSame($reply, $event->getThrowable()); } - /** - * @test - */ - public function shouldSetXStatusFromResponseStatusCode() - { - $reply = new HttpRedirect('/foo/bar'); - $response = new Response('', 302, ['X-Status-Code' => 302]); - - $event = new ExceptionEvent( - $this->createHttpKernelMock(), - new Request, - Kernel::MASTER_REQUEST, - $reply - ); - - $converterMock = $this->createReplyToSymfonyResponseConverterMock(); - $converterMock - ->expects($this->once()) - ->method('convert') - ->with($this->identicalTo($reply)) - ->will($this->returnValue($response)) - ; - - $listener = new ReplyToHttpResponseListener($converterMock); - - $listener->onKernelException($event); - - $this->assertInstanceOf(Response::class, $event->getResponse()); - $this->assertTrue($event->getResponse()->headers->has('X-Status-Code')); - $this->assertEquals(302, $event->getResponse()->headers->get('X-Status-Code')); - } - - /** - * @test - */ - public function shouldNotSetXStatusIfAlreadySet() - { - $reply = new HttpRedirect('/foo/bar'); - $response = new Response('', 555, array( - 'X-Status-Code' => 666, - )); - - $event = new ExceptionEvent( - $this->createHttpKernelMock(), - new Request, - Kernel::MASTER_REQUEST, - $reply - ); - - $converterMock = $this->createReplyToSymfonyResponseConverterMock(); - $converterMock - ->expects($this->once()) - ->method('convert') - ->with($this->identicalTo($reply)) - ->will($this->returnValue($response)) - ; - - $listener = new ReplyToHttpResponseListener($converterMock); - - $listener->onKernelException($event); - - $this->assertInstanceOf(Response::class, $event->getResponse()); - $this->assertTrue($event->getResponse()->headers->has('X-Status-Code')); - $this->assertEquals(666, $event->getResponse()->headers->get('X-Status-Code')); - } - /** * @test */