From 27e2378929c5a639a77b7a6d9c12b466b3a710fc Mon Sep 17 00:00:00 2001 From: Karol Jonski Date: Mon, 28 Sep 2020 07:08:52 +0200 Subject: [PATCH 1/6] Update symfony/http-kernel --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 295de01..5ef26e3 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,7 @@ "phpstan/phpstan": "^0.12", "sebastian/phpcpd": "^4.0", "squizlabs/php_codesniffer": "^3.2", - "symfony/http-kernel": "^4.4|^5.0", + "symfony/http-kernel": "^4.4.13|^5.1.5", "sensio/framework-extra-bundle": "^5.1", "friendsofphp/php-cs-fixer": "^2.10", "phpunit/phpunit": "^7.0", From f44633ee75b0b1849e82eb2504017312918a1b26 Mon Sep 17 00:00:00 2001 From: Carlos Romero Date: Tue, 2 Nov 2021 10:12:23 +0100 Subject: [PATCH 2/6] add RequestMatcherInterface to RouterDecorator Original object Router implements RouterInterface and RequestMatcherInterface Some bundles (EasyCorp/EasyAdmin) expects a Router object that implements RequestMatcherInterface and throws an exception in other case. --- src/Decorator/RouterDecorator.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Decorator/RouterDecorator.php b/src/Decorator/RouterDecorator.php index 48dcd4c..daa8cc5 100644 --- a/src/Decorator/RouterDecorator.php +++ b/src/Decorator/RouterDecorator.php @@ -10,8 +10,9 @@ use Symfony\Component\Routing\RequestContext; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouterInterface; +use Symfony\Component\Routing\Matcher\RequestMatcherInterface; -class RouterDecorator implements RouterInterface, WarmableInterface +class RouterDecorator implements RouterInterface, WarmableInterface, RequestMatcherInterface { use DecoratorTrait; @@ -102,4 +103,13 @@ public function warmUp($cacheDir) $this->getRouter()->warmUp($cacheDir); } } + + /** + * @codeCoverageIgnore + */ + public function matchRequest($pathinfo) + { + return $this->getRouter()->matchRequest($pathinfo); + } + } From 6a8d89f98b86fe3f90bdf11c11ec9d2ad6732ea3 Mon Sep 17 00:00:00 2001 From: Carlos Romero Date: Tue, 2 Nov 2021 11:29:46 +0100 Subject: [PATCH 3/6] : Removed blank line --- src/Decorator/RouterDecorator.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Decorator/RouterDecorator.php b/src/Decorator/RouterDecorator.php index daa8cc5..1e7612c 100644 --- a/src/Decorator/RouterDecorator.php +++ b/src/Decorator/RouterDecorator.php @@ -111,5 +111,4 @@ public function matchRequest($pathinfo) { return $this->getRouter()->matchRequest($pathinfo); } - } From 101f5f094c06fe71eab0970dbfd44e78fc4320a3 Mon Sep 17 00:00:00 2001 From: Carlos Romero Date: Wed, 2 Mar 2022 09:16:23 +0100 Subject: [PATCH 4/6] : Update composer PHP 8.1.0 , fix errors --- composer.json | 16 ++++++------ phpstan.neon.dist | 5 ++++ .../AnnotationProviderTest.php | 6 ++--- tests/Decorator/RouterDecoratorTest.php | 2 +- .../EventSubscriberCompilerPassTest.php | 2 +- .../HashidsConverterCompilerPassTest.php | 2 +- .../AbstractEventSubscriberTest.php | 16 ++++++------ ...codeControllerParametersSubscriberTest.php | 2 +- .../ParametersProcessorFactoryTest.php | 2 +- tests/ParametersProcessor/NoOpTest.php | 2 +- .../DecodeControllerParametersTest.php | 25 ++++++++----------- tests/Traits/DecoratorTraitTest.php | 2 +- 12 files changed, 40 insertions(+), 42 deletions(-) create mode 100644 phpstan.neon.dist diff --git a/composer.json b/composer.json index 5ef26e3..dc4a75e 100644 --- a/composer.json +++ b/composer.json @@ -11,12 +11,12 @@ } ], "require": { - "php": "^7.2.5", - "symfony/dependency-injection": "^4.1.12|^5.0", - "symfony/config": "~4.4|~5.0", - "doctrine/annotations": "^1.6", - "hashids/hashids": ">=2.0", - "symfony/routing": "^5.0" + "php": "^8.1.0", + "symfony/dependency-injection": "^5.4|^6.0", + "symfony/config": "~5.0|~6.0", + "doctrine/annotations": "^1.11", + "hashids/hashids": "^4.1.0", + "symfony/routing": "^5.0|^6.0" }, "autoload": { "psr-4": { "Pgs\\HashIdBundle\\": "src/" } @@ -34,12 +34,12 @@ }, "require-dev": { "phpstan/phpstan": "^0.12", - "sebastian/phpcpd": "^4.0", + "sebastian/phpcpd": "^6.0", "squizlabs/php_codesniffer": "^3.2", "symfony/http-kernel": "^4.4.13|^5.1.5", "sensio/framework-extra-bundle": "^5.1", "friendsofphp/php-cs-fixer": "^2.10", - "phpunit/phpunit": "^7.0", + "phpunit/phpunit": "^9.5.16", "symfony/browser-kit": "^4.0", "symfony/yaml": "^4.0" } diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..e05e39d --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,5 @@ +parameters: + level: 6 + paths: + - src + - tests \ No newline at end of file diff --git a/tests/AnnotationProvider/AnnotationProviderTest.php b/tests/AnnotationProvider/AnnotationProviderTest.php index 64f6c26..ca37138 100644 --- a/tests/AnnotationProvider/AnnotationProviderTest.php +++ b/tests/AnnotationProvider/AnnotationProviderTest.php @@ -9,7 +9,7 @@ use Pgs\HashIdBundle\Exception\InvalidControllerException; use Pgs\HashIdBundle\Reflection\ReflectionProvider; use PHPUnit\Framework\TestCase; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; class AnnotationProviderTest extends TestCase { @@ -18,7 +18,7 @@ class AnnotationProviderTest extends TestCase */ protected $controllerAnnotationProvider; - protected function setUp() + protected function setUp(): void { $this->controllerAnnotationProvider = new AnnotationProvider( $this->getReaderMock(), @@ -90,7 +90,7 @@ protected function getReflectionProviderMock() protected function getControllerMock() { - $mock = $this->getMockBuilder(Controller::class)->setMethods(['demo'])->getMockForAbstractClass(); + $mock = $this->getMockBuilder(AbstractController::class)->setMethods(['demo'])->getMockForAbstractClass(); return $mock; } diff --git a/tests/Decorator/RouterDecoratorTest.php b/tests/Decorator/RouterDecoratorTest.php index 429fd5b..a5983c7 100644 --- a/tests/Decorator/RouterDecoratorTest.php +++ b/tests/Decorator/RouterDecoratorTest.php @@ -18,7 +18,7 @@ class RouterDecoratorTest extends WebTestCase */ protected static $container; - protected function setUp() + protected function setUp(): void { $this::$container = static::createClient()->getContainer(); $this->router = self::$container->get('router'); diff --git a/tests/DependencyInjection/Compiler/EventSubscriberCompilerPassTest.php b/tests/DependencyInjection/Compiler/EventSubscriberCompilerPassTest.php index 7c54407..c73cf53 100644 --- a/tests/DependencyInjection/Compiler/EventSubscriberCompilerPassTest.php +++ b/tests/DependencyInjection/Compiler/EventSubscriberCompilerPassTest.php @@ -30,7 +30,7 @@ class EventSubscriberCompilerPassTest extends TestCase */ private $decodeControllerParametersDefinition; - protected function setUp() + protected function setUp(): void { $this->pass = new EventSubscriberCompilerPass(); $this->container = new ContainerBuilder(); diff --git a/tests/DependencyInjection/Compiler/HashidsConverterCompilerPassTest.php b/tests/DependencyInjection/Compiler/HashidsConverterCompilerPassTest.php index bca6cff..82c683e 100644 --- a/tests/DependencyInjection/Compiler/HashidsConverterCompilerPassTest.php +++ b/tests/DependencyInjection/Compiler/HashidsConverterCompilerPassTest.php @@ -20,7 +20,7 @@ class HashidsConverterCompilerPassTest extends TestCase */ private $container; - protected function setUp() + protected function setUp(): void { $this->compilerPass = new HashidsConverterCompilerPass(); diff --git a/tests/EventSubscriber/AbstractEventSubscriberTest.php b/tests/EventSubscriber/AbstractEventSubscriberTest.php index 7251e37..5477cee 100644 --- a/tests/EventSubscriber/AbstractEventSubscriberTest.php +++ b/tests/EventSubscriber/AbstractEventSubscriberTest.php @@ -7,6 +7,7 @@ use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\ControllerEvent; +use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelEvents; abstract class AbstractEventSubscriberTest extends TestCase @@ -17,18 +18,15 @@ protected function subscribedEventsList(string $eventSubscriberClass): void } /** - * @return ControllerEvent|MockObject + * @return ControllerEvent */ - protected function getEventMock(): ControllerEvent + protected function getEvent(): ControllerEvent { - $mock = $this->getMockBuilder(ControllerEvent::class) - ->disableOriginalConstructor() - ->setMethods(['getRequest']) - ->getMock(); - - $mock->method('getRequest')->willReturn($this->getRequestMock()); + $kernel = $this->createMock(HttpKernelInterface::class); + $request = $this->getRequestMock(); + $event = new ControllerEvent($kernel, fn() => (null), $request, HttpKernelInterface::MAIN_REQUEST); - return $mock; + return $event; } /** diff --git a/tests/EventSubscriber/DecodeControllerParametersSubscriberTest.php b/tests/EventSubscriber/DecodeControllerParametersSubscriberTest.php index 07bd183..b0248e7 100644 --- a/tests/EventSubscriber/DecodeControllerParametersSubscriberTest.php +++ b/tests/EventSubscriber/DecodeControllerParametersSubscriberTest.php @@ -15,7 +15,7 @@ public function testSubscribedEvents(): void public function testOnKernelController(): void { $subscriber = new DecodeControllerParametersSubscriber($this->getDecodeControllerParametersMock()); - $event = $this->getEventMock(); + $event = $this->getEvent(); $encodedParameters = $event->getRequest()->attributes->all(); $subscriber->onKernelController($event); $this->assertNotSame($encodedParameters, $event->getRequest()->attributes->all()); diff --git a/tests/ParametersProcessor/Factory/ParametersProcessorFactoryTest.php b/tests/ParametersProcessor/Factory/ParametersProcessorFactoryTest.php index 8d23c4f..6e89273 100644 --- a/tests/ParametersProcessor/Factory/ParametersProcessorFactoryTest.php +++ b/tests/ParametersProcessor/Factory/ParametersProcessorFactoryTest.php @@ -18,7 +18,7 @@ abstract class ParametersProcessorFactoryTest extends TestCase protected $parametersProcessorMockProvider; - protected function setUp() + protected function setUp(): void { $this->controllerMockProvider = new ControllerMockProvider(); $this->controllerAnnotationMockProvider = new ControllerAnnotationProviderMockProvider(); diff --git a/tests/ParametersProcessor/NoOpTest.php b/tests/ParametersProcessor/NoOpTest.php index 8c77e80..329eec8 100644 --- a/tests/ParametersProcessor/NoOpTest.php +++ b/tests/ParametersProcessor/NoOpTest.php @@ -14,7 +14,7 @@ class NoOpTest extends TestCase */ protected $parametersProcessor; - protected function setUp() + protected function setUp(): void { $this->parametersProcessor = new NoOp($this->getHashidMock(), []); } diff --git a/tests/Service/DecodeControllerParametersTest.php b/tests/Service/DecodeControllerParametersTest.php index 66187d3..cc8cb98 100644 --- a/tests/Service/DecodeControllerParametersTest.php +++ b/tests/Service/DecodeControllerParametersTest.php @@ -13,6 +13,7 @@ use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\ControllerEvent; +use Symfony\Component\HttpKernel\HttpKernelInterface; class DecodeControllerParametersTest extends TestCase { @@ -20,7 +21,7 @@ class DecodeControllerParametersTest extends TestCase protected $parametersProcessorMockProvider; - protected function setUp() + protected function setUp(): void { $this->parametersProcessorMockProvider = new ParametersProcessorMockProvider(); } @@ -44,7 +45,7 @@ public function testDecodeControllerParameters($controller): void { $decodeParametersProcessorFactory = $this->getDecodeParametersProcessorFactoryMock(); $decodeControllerParameters = new DecodeControllerParameters($decodeParametersProcessorFactory); - $event = $this->getEventMock( + $event = $this->getEvent( [ [ 'id' => 'encoded', @@ -64,7 +65,7 @@ public function testDecodeControllerParameters($controller): void public function decodeControllerParametersDataProvider() { return [ - ['controller as array' => $this->getControllerMockProvider()->getTestControllerMock(), 'demo'], + ['controller as array' => fn() => null, 'demo'], ]; } @@ -78,7 +79,7 @@ public function testDecodeControllerParametersWithParamConverter($controller): v $decodeParametersProcessorFactory = $this->getDecodeParametersProcessorFactoryMock(); $decodeControllerParameters = new DecodeControllerParameters($decodeParametersProcessorFactory); $decodeControllerParameters->setParamConverterListener($this->getDoctrineParamConverterListenerMock()); - $event = $this->getEventMock( + $event = $this->getEvent( [ [ 'id' => 'encoded', @@ -122,20 +123,14 @@ protected function getDecodeParametersProcessorMock(): Decode /** * @return ControllerEvent|MockObject */ - protected function getEventMock(array $requestConsecutiveCalls, $controller): ControllerEvent + protected function getEvent(array $requestConsecutiveCalls, $controller): ControllerEvent { - $mock = $this->getMockBuilder(ControllerEvent::class) - ->disableOriginalConstructor() - ->setMethods(['getController', 'getRequest']) - ->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); + $request = $this->getRequestMock($requestConsecutiveCalls); - $mock->method('getController') - ->willReturn($controller); + $event = new ControllerEvent($kernel, $controller, $request, HttpKernelInterface::MAIN_REQUEST); - $mock->method('getRequest') - ->willReturn($this->getRequestMock($requestConsecutiveCalls)); - - return $mock; + return $event; } /** diff --git a/tests/Traits/DecoratorTraitTest.php b/tests/Traits/DecoratorTraitTest.php index 2e71b01..d3f9cf7 100644 --- a/tests/Traits/DecoratorTraitTest.php +++ b/tests/Traits/DecoratorTraitTest.php @@ -10,7 +10,7 @@ class DecoratorTraitTest extends TestCase { protected $decorateClass; - protected function setUp() + protected function setUp(): void { $baseClass = new BaseTestClass(); $this->decorateClass = new DecorateTestClass($baseClass); From a3e9f48a8dc659e8da161b797c980f3cc6d2730f Mon Sep 17 00:00:00 2001 From: Carlos Romero Date: Thu, 3 Mar 2022 11:23:46 +0100 Subject: [PATCH 5/6] : Fix errors callable controller, phpunit deprecated function, kernel.root_dir deprecatd --- tests/App/config.yml | 2 +- .../Controller/ParamsAnnotatedController.php | 28 +++++++++++++++++++ tests/Decorator/RouterDecoratorTest.php | 6 ++-- .../DecodeControllerParametersTest.php | 4 ++- 4 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 tests/Controller/ParamsAnnotatedController.php diff --git a/tests/App/config.yml b/tests/App/config.yml index e6863c9..f9ea92d 100644 --- a/tests/App/config.yml +++ b/tests/App/config.yml @@ -1,4 +1,4 @@ framework: secret: secret test: ~ - router: { resource: "%kernel.root_dir%/../../src/Resources/routes.yaml" } \ No newline at end of file + router: { resource: "%kernel.project_dir%/src/Resources/routes.yaml" } \ No newline at end of file diff --git a/tests/Controller/ParamsAnnotatedController.php b/tests/Controller/ParamsAnnotatedController.php new file mode 100644 index 0000000..190dd60 --- /dev/null +++ b/tests/Controller/ParamsAnnotatedController.php @@ -0,0 +1,28 @@ +router->generate(...$routeArgs); $this->assertNotSame(sprintf('/hash-id/demo/decode/%d/%d', $id, $other), $generatedPath); $pattern = sprintf('/\/hash-id\/demo\/decode\/[%s]{%d}\/\d+/', $alphabet, $hashLength); - $this->assertRegExp($pattern, $generatedPath); + $this->assertMatchesRegularExpression($pattern, $generatedPath); $routeArgs = ['pgs_hash_id_demo_encode_localized', ['id' => $id, '_locale' => 'pl']]; $generatedPath = $this->router->generate(...$routeArgs); $this->assertNotSame(sprintf('/hash-id/demo/encode-pl/%d', $id), $generatedPath); $pattern = sprintf('/\/hash-id\/demo\/encode-pl\/[%s]{%d}/', $alphabet, $hashLength); - $this->assertRegExp($pattern, $generatedPath); + $this->assertMatchesRegularExpression($pattern, $generatedPath); $routeArgs = ['pgs_hash_id_demo_decode_more', ['id' => $id, 'other' => $other]]; $generatedPath = $this->router->generate(...$routeArgs); @@ -52,6 +52,6 @@ public function testGenerateUrl(): void $alphabet, $hashLength ); - $this->assertRegExp($pattern, $generatedPath); + $this->assertMatchesRegularExpression($pattern, $generatedPath); } } diff --git a/tests/Service/DecodeControllerParametersTest.php b/tests/Service/DecodeControllerParametersTest.php index cc8cb98..d6017d5 100644 --- a/tests/Service/DecodeControllerParametersTest.php +++ b/tests/Service/DecodeControllerParametersTest.php @@ -6,6 +6,7 @@ use Pgs\HashIdBundle\ParametersProcessor\Factory\DecodeParametersProcessorFactory; use Pgs\HashIdBundle\Service\DecodeControllerParameters; use Pgs\HashIdBundle\Tests\Controller\ControllerMockProvider; +use Pgs\HashIdBundle\Tests\Controller\ParamsAnnotatedController; use Pgs\HashIdBundle\Tests\ParametersProcessor\ParametersProcessorMockProvider; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -64,8 +65,9 @@ public function testDecodeControllerParameters($controller): void public function decodeControllerParametersDataProvider() { + $controller = new ParamsAnnotatedController(); return [ - ['controller as array' => fn() => null, 'demo'], + ['controller' => $controller, 'demo'], ]; } From abd0580d856e2f2a1af85f36ddbdbf347d70aa0f Mon Sep 17 00:00:00 2001 From: Carlos Romero Date: Thu, 3 Mar 2022 11:49:48 +0100 Subject: [PATCH 6/6] : modify package name --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index dc4a75e..77b15c0 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "pgs-soft/hashid-bundle", + "name": "eductradesa/hashid-bundle", "type": "symfony-bundle", "description": "Symfony Hash Id", "keywords": [], @@ -11,7 +11,7 @@ } ], "require": { - "php": "^8.1.0", + "php": "^8.0.0", "symfony/dependency-injection": "^5.4|^6.0", "symfony/config": "~5.0|~6.0", "doctrine/annotations": "^1.11",