From 5e8f9f74ad9a090a7f47f33a7d3c03df5fa8ad78 Mon Sep 17 00:00:00 2001 From: Andrew MacRobert Date: Mon, 8 Sep 2025 12:38:38 -0400 Subject: [PATCH] Symfony 7 support --- .github/workflows/ci.yml | 11 +++++-- EventListener/RateLimitAnnotationListener.php | 2 +- .../RateLimitAnnotationListenerTest.php | 10 +++---- Tests/Service/Storage/PsrCacheTest.php | 29 ++++++++++++++----- composer.json | 4 +-- 5 files changed, 39 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c82e609..6c86daf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,10 +12,17 @@ jobs: matrix: php: [ "8.0", "8.1", "8.2", "8.3", "8.4" ] composer_flags: [ "", "--prefer-lowest" ] - symfony_version: [ "^5.4", "^6.4" ] + symfony_version: [ "^5.4", "^6.4", "^7.3" ] exclude: + # Symfony 6 requires PHP 8.1+ - php: "8.0" symfony_version: "^6.4" + # Symfony 7 requires PHP 8.2+ + - php: "8.0" + symfony_version: "^7.3" + - php: "8.1" + symfony_version: "^7.3" + name: PHP ${{ matrix.php }} SF ${{ matrix.symfony_version }} ${{ matrix.composer_flags}} env: PHP: ${{ matrix.os }} @@ -38,7 +45,7 @@ jobs: run: | composer self-update if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --no-update; fi; - if [ "$SYMFONY_VERSION" = "^6.4" ]; then composer remove --dev "friendsofsymfony/oauth-server-bundle" --no-update; fi; + if [ "$SYMFONY_VERSION" != "^5.4" ]; then composer remove --dev "friendsofsymfony/oauth-server-bundle" --no-update; fi; COMPOSER_MEMORY_LIMIT=-1 composer update --prefer-dist --no-interaction $COMPOSER_FLAGS - name: Static analysis run: | diff --git a/EventListener/RateLimitAnnotationListener.php b/EventListener/RateLimitAnnotationListener.php index 662f295..7ea8440 100644 --- a/EventListener/RateLimitAnnotationListener.php +++ b/EventListener/RateLimitAnnotationListener.php @@ -41,7 +41,7 @@ public function onKernelController(ControllerEvent $event): void } // Skip if we aren't the main request - if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) { + if ($event->getRequestType() !== HttpKernelInterface::MAIN_REQUEST) { return; } diff --git a/Tests/EventListener/RateLimitAnnotationListenerTest.php b/Tests/EventListener/RateLimitAnnotationListenerTest.php index d3b0662..c4585a6 100644 --- a/Tests/EventListener/RateLimitAnnotationListenerTest.php +++ b/Tests/EventListener/RateLimitAnnotationListenerTest.php @@ -64,7 +64,7 @@ public function testReturnedWhenNoControllerFound(): void $kernel = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\HttpKernelInterface')->getMock(); $request = new Request(); - $event = new ControllerEvent($kernel, static function() {}, $request, HttpKernelInterface::MASTER_REQUEST); + $event = new ControllerEvent($kernel, static function() {}, $request, HttpKernelInterface::MAIN_REQUEST); $listener->onKernelController($event); } @@ -81,7 +81,7 @@ public function testReturnedWhenNoAttributesFound(): void public function testDelegatesToPathLimitProcessorWhenNoAttributesFound(): void { $request = new Request(); - $event = $this->createEvent(HttpKernelInterface::MASTER_REQUEST, $request); + $event = $this->createEvent(HttpKernelInterface::MAIN_REQUEST, $request); $listener = $this->createListener($this->once()); @@ -109,7 +109,7 @@ public function testDispatchIsCalledWithAttributes(): void $listener = $this->createListener($this->exactly(2)); $event = $this->createEvent( - HttpKernelInterface::MASTER_REQUEST, + HttpKernelInterface::MAIN_REQUEST, null, new MockControllerWithAttributes() ); @@ -119,7 +119,7 @@ public function testDispatchIsCalledWithAttributes(): void public function testDispatchIsCalledIfThePathLimitProcessorReturnsARateLimit(): void { - $event = $this->createEvent(HttpKernelInterface::MASTER_REQUEST); + $event = $this->createEvent(HttpKernelInterface::MAIN_REQUEST); $listener = $this->createListener($this->exactly(2)); $rateLimit = new RateLimit( @@ -315,7 +315,7 @@ public function testFindBestMethodMatchMatchingMultipleAnnotations(): void } protected function createEvent( - int $requestType = HttpKernelInterface::MASTER_REQUEST, + int $requestType = HttpKernelInterface::MAIN_REQUEST, ?Request $request = null, ?MockController $controller = null, ): ControllerEvent diff --git a/Tests/Service/Storage/PsrCacheTest.php b/Tests/Service/Storage/PsrCacheTest.php index 6948ffb..b97d33b 100644 --- a/Tests/Service/Storage/PsrCacheTest.php +++ b/Tests/Service/Storage/PsrCacheTest.php @@ -37,12 +37,27 @@ public function testCreateRate() { $item = $this->getMockBuilder('Psr\\Cache\\CacheItemInterface') ->getMock(); - $item->expects($this->once()) - ->method('set') - ->willReturn(true); - $item->expects($this->once()) - ->method('expiresAfter') - ->willReturn(true); + + /** + * psr/cache 3.0 changed the return type of set() and expiresAfter() to return self. + * @TODO NEXT_MAJOR: Remove this check and the first conditional block when psr/cache <3 support is dropped. + */ + $psrCacheVersion = \Composer\InstalledVersions::getVersion('psr/cache'); + if (version_compare($psrCacheVersion, '3.0', '<')) { + $item->expects($this->once()) + ->method('set') + ->willReturn(true); + $item->expects($this->once()) + ->method('expiresAfter') + ->willReturn(true); + } else { + $item->expects($this->once()) + ->method('set') + ->willReturnSelf(); + $item->expects($this->once()) + ->method('expiresAfter') + ->willReturnSelf(); + } $client = $this->getMockBuilder('Psr\\Cache\\CacheItemPoolInterface') ->getMock(); @@ -121,4 +136,4 @@ public function testResetRate() $storage = new PsrCache($client); $this->assertTrue($storage->resetRate('foo')); } -} +} diff --git a/composer.json b/composer.json index 3a6156e..848fef1 100644 --- a/composer.json +++ b/composer.json @@ -12,13 +12,13 @@ ], "require": { "php": "^8.0", - "symfony/framework-bundle": "^5.4.2|^6.4" + "symfony/framework-bundle": "^5.4.2|^6.4|^7.3" }, "require-dev": { "symfony/phpunit-bridge": ">=5.4", "psr/simple-cache": "^1.0|^2.0", "doctrine/cache": "^1.5", - "psr/cache": "^1.0|^2.0", + "psr/cache": "^1.0|^2.0|^3.0", "predis/predis": "^1.1|^2.0", "friendsofsymfony/oauth-server-bundle": "^1.5|^2.0@dev", "phpstan/phpstan": "^2.1"