From d5ea5677d68cb5f6a65a7aa774142ef4eb63bd74 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Sat, 29 Nov 2025 18:18:39 +0100 Subject: [PATCH 1/2] Update test matrix, bump minimium requirements --- .github/workflows/lock-symfony-version.sh | 3 --- .github/workflows/tests.yml | 23 +++++++++----------- composer.json | 15 ++++++------- phpunit.xml.dist | 26 +++++++++++------------ 4 files changed, 30 insertions(+), 37 deletions(-) delete mode 100755 .github/workflows/lock-symfony-version.sh diff --git a/.github/workflows/lock-symfony-version.sh b/.github/workflows/lock-symfony-version.sh deleted file mode 100755 index 64bf1c2..0000000 --- a/.github/workflows/lock-symfony-version.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -cat <<< $(jq --arg version $VERSION '.require |= with_entries(if ((.key|test("^symfony/deprecation-contracts")|not) and (.key|test("^symfony/"))) then .value=$version else . end)' < composer.json) > composer.json diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 53f8aba..1cf8946 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -6,9 +6,6 @@ on: - master pull_request: -env: - SYMFONY_DEPRECATIONS_HELPER: weak - jobs: PHPUnit: runs-on: ubuntu-22.04 @@ -16,25 +13,25 @@ jobs: fail-fast: false matrix: include: - - { php-version: 8.1, symfony-locked-version: none, dependency-version: prefer-lowest } - - { php-version: 8.2, symfony-locked-version: 6.4.*, dependency-version: prefer-stable } - - { php-version: 8.3, symfony-locked-version: none, dependency-version: prefer-stable } - name: PHPUnit (PHP ${{matrix.php-version}}, Symfony Version Lock ${{ matrix.symfony-locked-version }}, ${{ matrix.dependency-version }}) + - { php-version: 8.1, symfony-version: '', dependency-version: prefer-lowest } + - { php-version: 8.3, symfony-version: 6.4.*, dependency-version: prefer-stable } + - { php-version: 8.4, symfony-version: 7.*, dependency-version: prefer-stable } + name: PHPUnit (PHP ${{matrix.php-version}}, Symfony version lock ${{ matrix.symfony-version || 'none' }}, ${{ matrix.dependency-version }}) steps: - uses: actions/checkout@v4 - uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-version }} coverage: none - tools: composer:v2 + tools: composer:v2, flex - uses: actions/cache@v4 with: path: vendor - key: composer-${{ runner.os }}-${{ matrix.php-version }}-${{ matrix.symfony-locked-version }}-${{ matrix.dependency-version }}-${{ hashFiles('composer.json') }} + key: composer-${{ runner.os }}-${{ matrix.php-version }}-${{ matrix.symfony-version }}-${{ matrix.dependency-version }}-${{ hashFiles('composer.json') }} restore-keys: | - composer-${{ runner.os }}-${{ matrix.php-version }}-${{ matrix.symfony-locked-version }}-${{ matrix.dependency-version }}- - - run: VERSION=${{ matrix.symfony-locked-version }} .github/workflows/lock-symfony-version.sh - if: matrix.symfony-locked-version != 'none' + composer-${{ runner.os }}-${{ matrix.php-version }}-${{ matrix.symfony-version }}-${{ matrix.dependency-version }}- - run: composer update --${{ matrix.dependency-version }} --no-interaction --no-scripts --no-progress --ansi + env: + SYMFONY_REQUIRE: ${{ matrix.symfony-version }} - run: composer show - - run: vendor/bin/phpunit + - run: vendor/bin/phpunit --display-warnings --display-deprecations diff --git a/composer.json b/composer.json index 3a3652a..ed908c7 100644 --- a/composer.json +++ b/composer.json @@ -19,17 +19,16 @@ ], "require": { - "php": "^8.1", - "symfony/config": "^5.0 | ^6.0 | ^7.0", - "symfony/dependency-injection": "^5.0 | ^6.0 | ^7.0", - "symfony/deprecation-contracts": "^2.0|^3.0", - "symfony/http-foundation": "^5.0 | ^6.0 | ^7.0", - "symfony/http-kernel": "^6.4 | ^7.0" + "php": ">= 8.1", + "symfony/config": "^6.4|^7.0", + "symfony/dependency-injection": "^6.4|^7.0", + "symfony/deprecation-contracts": "^3.0", + "symfony/http-foundation": "^6.4|^7.0", + "symfony/http-kernel": "^6.4|^7.0" }, "require-dev": { - "phpunit/phpunit": "^9.6", - "symfony/phpunit-bridge": "^6.0 | ^7.0" + "phpunit/phpunit": "^10.5.58" }, "suggest": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index fcfc7c0..366a2bf 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,21 +1,21 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd" + bootstrap="vendor/autoload.php" + colors="true" + displayDetailsOnTestsThatTriggerDeprecations="true" + displayDetailsOnTestsThatTriggerNotices="true" + displayDetailsOnTestsThatTriggerWarnings="true" +> + + + src + + tests - - - - - src/ - - - - - - From 4c0b9ef8cc35342315e8498cefc5b6a0464927ac Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Sat, 29 Nov 2025 18:27:22 +0100 Subject: [PATCH 2/2] Convert PHPUnit annotations to attributes --- .../ReplaceWithNotModifiedResponseTest.php | 40 ++++++------------- tests/NotModified/EventListenerTest.php | 33 ++++++++------- 2 files changed, 29 insertions(+), 44 deletions(-) diff --git a/tests/NotModified/Attribute/ReplaceWithNotModifiedResponseTest.php b/tests/NotModified/Attribute/ReplaceWithNotModifiedResponseTest.php index 99df1a4..ec55cf0 100644 --- a/tests/NotModified/Attribute/ReplaceWithNotModifiedResponseTest.php +++ b/tests/NotModified/Attribute/ReplaceWithNotModifiedResponseTest.php @@ -10,6 +10,9 @@ namespace Webfactory\HttpCacheBundle\Tests\NotModified\Attribute; use DateTime; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; +use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use RuntimeException; @@ -23,9 +26,7 @@ */ final class ReplaceWithNotModifiedResponseTest extends TestCase { - /** - * @test - */ + #[Test] public function lastModifiedDescriptionsCannotBeEmpty() { $this->expectException(RuntimeException::class); @@ -33,20 +34,15 @@ public function lastModifiedDescriptionsCannotBeEmpty() $attribute->determineLastModified(new Request()); } - /** - * @test - * - * @doesNotPerformAssertions - */ + #[Test] + #[DoesNotPerformAssertions] public function stringAsSimpleLastModifiedDescription() { $attribute = new ReplaceWithNotModifiedResponse([MyLastModifedDeterminator::class]); $attribute->determineLastModified(new Request()); } - /** - * @test - */ + #[Test] public function serviceNameAsLastModifiedDescription() { /** @var ContainerInterface|MockObject $container */ @@ -62,20 +58,15 @@ public function serviceNameAsLastModifiedDescription() $attribute->determineLastModified(new Request()); } - /** - * @test - * - * @doesNotPerformAssertions - */ + #[Test] + #[DoesNotPerformAssertions] public function arrayAslastModifiedDeterminatorDescriptionWithConstructorArguments() { $attribute = new ReplaceWithNotModifiedResponse([[MyLastModifedDeterminator::class => new DateTime('2000-01-01')]]); $attribute->determineLastModified(new Request()); } - /** - * @test - */ + #[Test] public function lastModifiedDeterminatorsHaveToImplementInterface() { $this->expectException(RuntimeException::class); @@ -83,11 +74,8 @@ public function lastModifiedDeterminatorsHaveToImplementInterface() $attribute->determineLastModified(new Request()); } - /** - * @test - * - * @group time-sensitive - */ + #[Group('time-sensitive')] + #[Test] public function determineLastModifiedDeterminesLastModifiedOfOneDeterminator() { $attribute = new ReplaceWithNotModifiedResponse([MyLastModifedDeterminator::class]); @@ -97,9 +85,7 @@ public function determineLastModifiedDeterminesLastModifiedOfOneDeterminator() self::assertEquals(DateTime::createFromFormat('U', time()), $lastModified); } - /** - * @test - */ + #[Test] public function determineLastModifiedDeterminesLastModifiedOfMultipleDeterminators() { $attribute = new ReplaceWithNotModifiedResponse([ diff --git a/tests/NotModified/EventListenerTest.php b/tests/NotModified/EventListenerTest.php index c79715c..35ca559 100644 --- a/tests/NotModified/EventListenerTest.php +++ b/tests/NotModified/EventListenerTest.php @@ -12,6 +12,8 @@ use Closure; use DateTime; use Error; +use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -27,9 +29,8 @@ /** * Tests for the EventListener. - * - * @group time-sensitive */ +#[Group('time-sensitive')] final class EventListenerTest extends TestCase { /** @@ -53,7 +54,7 @@ protected function setUp(): void $this->eventListener = new EventListener($this->container); } - /** @test */ + #[Test] public function onKernelControllerDoesNoHarmForMissingAnnotation(): void { $this->exerciseOnKernelController([DummyController::class, 'plainAction']); @@ -61,7 +62,7 @@ public function onKernelControllerDoesNoHarmForMissingAnnotation(): void $this->assertRegularControllerResponse(); } - /** @test */ + #[Test] public function onKernelControllerDoesNoHarmForNoDeterminedLastModified(): void { $this->exerciseOnKernelController([DummyController::class, 'abstainingLastModifiedAction']); @@ -69,7 +70,7 @@ public function onKernelControllerDoesNoHarmForNoDeterminedLastModified(): void $this->assertRegularControllerResponse(); } - /** @test */ + #[Test] public function onKernelControllerDoesNoHarmIfNotModifiedSinceHeaderIsNotInRequest(): void { $this->exerciseOnKernelController([DummyController::class, 'oneDayAgoModifiedLastModifiedAction']); @@ -77,7 +78,7 @@ public function onKernelControllerDoesNoHarmIfNotModifiedSinceHeaderIsNotInReque $this->assertRegularControllerResponse(); } - /** @test */ + #[Test] public function onKernelControllerSkipsToModifiedResponseIfLastModifiedIsSmallerThanIfNotModifiedSinceHeader(): void { $this->request->headers->set('If-Modified-Since', '-1 hour'); @@ -87,7 +88,7 @@ public function onKernelControllerSkipsToModifiedResponseIfLastModifiedIsSmaller $this->assertNotModifiedResponse(); } - /** @test */ + #[Test] public function onKernelControllerAlwaysRunsControllerInKernelDebugMode(): void { $this->eventListener = new EventListener($this->container, true); @@ -98,7 +99,7 @@ public function onKernelControllerAlwaysRunsControllerInKernelDebugMode(): void $this->assertRegularControllerResponse(); } - /** @test */ + #[Test] public function onKernelControllerSkipsToNotModifiedResponseIfLastModifiedIsEqualToIfNotModifiedSinceHeader(): void { $this->request->headers->set('If-Modified-Since', '2000-01-01'); @@ -108,7 +109,7 @@ public function onKernelControllerSkipsToNotModifiedResponseIfLastModifiedIsEqua $this->assertNotModifiedResponse(); } - /** @test */ + #[Test] public function onKernelControllerDoesNotReplaceDeterminedControllerIfLastModifiedIsGreaterThanIfNotModifiedSinceHeader(): void { $this->request->headers->set('If-Modified-Since', '-2 day'); @@ -118,9 +119,7 @@ public function onKernelControllerDoesNotReplaceDeterminedControllerIfLastModifi $this->assertRegularControllerResponse(); } - /** - * @test - */ + #[Test] public function onKernelResponseSetsLastModifiedHeaderToResponseIfAvailable(): void { $this->exerciseOnKernelController([DummyController::class, 'oneDayAgoModifiedLastModifiedAction']); @@ -131,7 +130,7 @@ public function onKernelResponseSetsLastModifiedHeaderToResponseIfAvailable(): v self::assertEquals(DateTime::createFromFormat('U', time() - 86400), $this->response->getLastModified()); } - /** @test */ + #[Test] public function onKernelResponseDoesNotSetLastModifiedHeaderToResponseIfNotAvailable(): void { $this->exerciseOnKernelController([DummyController::class, 'abstainingLastModifiedAction']); @@ -142,7 +141,7 @@ public function onKernelResponseDoesNotSetLastModifiedHeaderToResponseIfNotAvail self::assertNull($this->response->getLastModified()); } - /** @test */ + #[Test] public function eventListenerDifferentiatesBetweenMultipleRequests(): void { $this->exerciseOnKernelController([DummyController::class, 'oneDayAgoModifiedLastModifiedAction']); @@ -160,7 +159,7 @@ public function eventListenerDifferentiatesBetweenMultipleRequests(): void self::assertNull($anotherResponse->getLastModified()); } - /** @test */ + #[Test] public function onKernelControllerSearchesEventInsteadOfControllerForAttribute(): void { // setup an event that should lead to a NotModified response @@ -186,7 +185,7 @@ function () { self::assertNotModifiedResponse(); } - /** @test */ + #[Test] public function onKernelControllerSavesOriginalControllerAttributesWhenReplacingTheController(): void { $this->request->headers->set('If-Modified-Since', '-1 hour'); @@ -196,7 +195,7 @@ public function onKernelControllerSavesOriginalControllerAttributesWhenReplacing self::assertNotEmpty($this->filterControllerEvent->getAttributes()); } - /** @test */ + #[Test] public function onKernelControllerThrowsExceptionIfAttributeIsFoundMoreThanOnce(): void { self::expectException(Error::class);