From 5b22804c7eb7ef77939133920773487b907bbf6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Cr=C3=A9mier?= Date: Mon, 1 Sep 2025 17:42:12 +0200 Subject: [PATCH] update to symfony ^7.0 --- .github/workflows/unit-tests.yml | 45 +++++++++++----- .../DeamonLoggerExtraExtension.php | 2 +- README.md | 8 +-- .../DeamonLoggerExtraExtensionTest.php | 13 ++--- .../DeamonLoggerExtraWebProcessorTest.php | 30 +++++------ .../Services/DeamonLoggerExtraContextTest.php | 8 +-- composer.json | 18 +++---- phpunit.xml.dist | 53 ++++++++++--------- 8 files changed, 98 insertions(+), 79 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 53950a6..85eaf1d 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -13,32 +13,49 @@ jobs: strategy: matrix: include: - - php: '8.0' + - php: '8.2' mode: low-deps - - php: '8.1' - mode: high-deps - php: '8.2' - #mode: experimental + - php: '8.3' + - php: '8.4' + mode: high-deps fail-fast: false - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - - name: Cache Composer packages + - name: Get Composer cache dir id: composer-cache - uses: actions/cache@v3 + run: echo "dir=$(composer config cache-dir)" >> $GITHUB_OUTPUT + + - name: Cache Composer + uses: actions/cache@v4 with: - path: vendor - key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ matrix.mode }}-${{ hashFiles('**/composer.json') }} restore-keys: | - ${{ runner.os }}-php- + ${{ runner.os }}-composer-${{ matrix.php }}-${{ matrix.mode }}- + ${{ runner.os }}-composer-${{ matrix.php }}- + ${{ runner.os }}-composer- + - name: Install Dependencies run: | - if [[ "${{ matrix.mode }}" = low-deps ]]; then - COMPOSER_OPTIONS="--prefer-lowest" + if [[ "${{ matrix.mode }}" == "low-deps" ]]; then + # Force LTS of Bridge to avoid the bootstrapping big in prefer-lowest + composer require --no-update --dev symfony/phpunit-bridge:^6.4 + COMPOSER_OPTIONS="--prefer-lowest --prefer-stable" + # in case of previously cache vendor folder + rm -rf vendor fi composer update --ansi --no-interaction --no-scripts --prefer-dist $COMPOSER_OPTIONS + - name: Audit Security + run: composer audit + - name: Execute tests (Unit and Feature tests) via PHPUnit - run: ./vendor/bin/simple-phpunit + env: + SYMFONY_PHPUNIT_VERSION: ${{ matrix.mode == 'low-deps' && '9.5' || '' }} + run: | + composer config --global use-parent-dir false + ./vendor/bin/simple-phpunit diff --git a/DependencyInjection/DeamonLoggerExtraExtension.php b/DependencyInjection/DeamonLoggerExtraExtension.php index d740a92..c82b51f 100644 --- a/DependencyInjection/DeamonLoggerExtraExtension.php +++ b/DependencyInjection/DeamonLoggerExtraExtension.php @@ -4,8 +4,8 @@ use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Extension\Extension; use Symfony\Component\DependencyInjection\Loader; -use Symfony\Component\HttpKernel\DependencyInjection\Extension; /** * This is the class that loads and manages your bundle configuration. diff --git a/README.md b/README.md index d7450ec..c95f92b 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ DeamonLoggerExtra Bundle ![Build status](https://github.com/FrDeamon/logger-extra-bundle/actions/workflows/unit-tests.yml/badge.svg?branch=master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/FrDeamon/logger-extra-bundle/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/FrDeamon/logger-extra-bundle/?branch=master) [![Code Coverage](https://scrutinizer-ci.com/g/FrDeamon/logger-extra-bundle/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/FrDeamon/logger-extra-bundle/?branch=master) -![symfony version](https://img.shields.io/badge/symfony->=6.0-blue.svg) -![php version](https://img.shields.io/badge/php->=8.0-blue.svg) +![symfony version](https://img.shields.io/badge/symfony->=7.0-blue.svg) +![php version](https://img.shields.io/badge/php->=8.2-blue.svg) This project is used to add extra context information in your logs. @@ -13,7 +13,7 @@ If you need compatibility with previous Symfony versions, have a look at previou Requirements ---------------- -php >=8.0.2 +php >=8.2 symfony/security-core symfony/dependency-injection @@ -31,7 +31,7 @@ Installation You need to add a package to your dependency list : ``` // composer.json - "deamon/logger-extra-bundle": "^6.0" + "deamon/logger-extra-bundle": "^7.0" ``` Then enable the bundle into your kernel diff --git a/Tests/DependencyInjection/DeamonLoggerExtraExtensionTest.php b/Tests/DependencyInjection/DeamonLoggerExtraExtensionTest.php index f8d9485..277d9ad 100755 --- a/Tests/DependencyInjection/DeamonLoggerExtraExtensionTest.php +++ b/Tests/DependencyInjection/DeamonLoggerExtraExtensionTest.php @@ -32,7 +32,7 @@ public function setUp(): void $this->container = new ContainerBuilder(); } - public function testLoad() + public function testLoad(): void { $configs = [ $this->getValidConfigFull(), @@ -57,7 +57,7 @@ public function testLoad() $this->assertEquals('bar', $tag[0]['handler']); } - public function testDefaultValue() + public function testDefaultValue(): void { $configs = [ $this->getValidConfigMin(), @@ -98,7 +98,7 @@ public function testDefaultValue() $this->assertEquals($defaultConfigValues, $definition2->getArgument(0)); } - public function testConvertStringHandlerToArray() + public function testConvertStringHandlerToArray(): void { $configs = [ [ @@ -123,7 +123,7 @@ public function testConvertStringHandlerToArray() /** * @return array */ - private function getValidConfigFull() + private function getValidConfigFull(): array { return [ 'application' => [ @@ -155,10 +155,7 @@ private function getValidConfigFull() ]; } - /** - * @return array - */ - private function getValidConfigMin() + private function getValidConfigMin(): array { return [ 'application' => null, diff --git a/Tests/Processors/Monolog/DeamonLoggerExtraWebProcessorTest.php b/Tests/Processors/Monolog/DeamonLoggerExtraWebProcessorTest.php index e8411b6..551ab89 100755 --- a/Tests/Processors/Monolog/DeamonLoggerExtraWebProcessorTest.php +++ b/Tests/Processors/Monolog/DeamonLoggerExtraWebProcessorTest.php @@ -14,7 +14,7 @@ class DeamonLoggerExtraWebProcessorTest extends TestCase { - public function testProcessorWithNullContainer() + public function testProcessorWithNullContainer(): void { $processor = new DeamonLoggerExtraWebProcessor(); $originalRecord = $this->getRecord(); @@ -26,7 +26,7 @@ public function testProcessorWithNullContainer() /** * @runInSeparateProcess */ - public function testAddContextInfo() + public function testAddContextInfo(): void { $config = $this->getDisplayConfig([ 'env' => true, @@ -49,7 +49,7 @@ public function testAddContextInfo() /** * @runInSeparateProcess */ - public function testAddContextInfoWithoutLocaleAndVersion() + public function testAddContextInfoWithoutLocaleAndVersion(): void { $config = $this->getDisplayConfig([ 'env' => true, @@ -69,7 +69,7 @@ public function testAddContextInfoWithoutLocaleAndVersion() $this->assertArrayHasKeyAndEquals('application', $record->extra, 'foo_app'); } - public function testAddRequestInfo() + public function testAddRequestInfo(): void { $config = $this->getDisplayConfig( [ @@ -92,7 +92,7 @@ public function testAddRequestInfo() $this->assertArrayHasKeyAndEquals('client_ip', $record->extra, '123.456.789.123'); } - public function testAddOnlyUserInfoOnDefinedClass() + public function testAddOnlyUserInfoOnDefinedClass(): void { $config = $this->getDisplayConfig([ 'user' => true, @@ -109,7 +109,7 @@ public function testAddOnlyUserInfoOnDefinedClass() $this->assertArrayNotHasKey('user_name', $record->extra); } - public function testAddUserInfoWithNotExistingClass() + public function testAddUserInfoWithNotExistingClass(): void { $config = $this->getDisplayConfig([ 'user' => true, @@ -121,7 +121,7 @@ public function testAddUserInfoWithNotExistingClass() $this->assertArrayNotHasKey('user_name', $record->extra); } - public function testAddUserInfoWithNullClass() + public function testAddUserInfoWithNullClass(): void { $config = $this->getDisplayConfig([ 'user' => true, @@ -133,7 +133,7 @@ public function testAddUserInfoWithNullClass() $this->assertArrayNotHasKey('user_name', $record->extra); } - public function testAddUserinfoWithNoTokenStorage() + public function testAddUserinfoWithNoTokenStorage(): void { $config = $this->getDisplayConfig([ 'user' => true, @@ -145,7 +145,7 @@ public function testAddUserinfoWithNoTokenStorage() $this->assertArrayNotHasKey('user_name', $record->extra); } - public function testAddUserInfo() + public function testAddUserInfo(): void { $config = $this->getDisplayConfig([ 'user' => true, @@ -164,7 +164,7 @@ public function testAddUserInfo() $this->assertArrayHasKeyAndEquals('user_name', $record->extra, 'foo'); } - protected function getDisplayConfig($trueValues, $channelPrefix = null, $user_class = '\Symfony\Component\Security\Core\User\UserInterface', $user_methods = null) + protected function getDisplayConfig($trueValues, $channelPrefix = null, $user_class = '\Symfony\Component\Security\Core\User\UserInterface', $user_methods = null): array { if (!is_array($user_methods)) { $user_methods = [ @@ -195,13 +195,13 @@ protected function getDisplayConfig($trueValues, $channelPrefix = null, $user_cl ]; } - protected function assertArrayHasKeyAndEquals($key, $array, $value, $message = '') + protected function assertArrayHasKeyAndEquals($key, $array, $value, $message = ''): void { $this->assertArrayHasKey($key, $array); $this->assertEquals($value, $array[$key], $message); } - private function getRequestStack() + private function getRequestStack(): RequestStack { $request = new Request([], [], [ '_route' => 'requested_route', @@ -217,12 +217,12 @@ private function getRequestStack() return $stack; } - private function getLoggerExtraContext($locale = 'fr', $version = null) + private function getLoggerExtraContext($locale = 'fr', $version = null): DeamonLoggerExtraContext { return new DeamonLoggerExtraContext('foo_app', $locale, $version); } - private function getTokenStorage(UserInterface $user = null) + private function getTokenStorage(?UserInterface $user = null): TokenStorage { $storage = new TokenStorage(); $storage->setToken(new MyToken($user)); @@ -265,7 +265,7 @@ public function getSalt(): ?string //not needed in tests } - public function eraseCredentials() + public function eraseCredentials(): void { //not needed in tests } diff --git a/Tests/Services/DeamonLoggerExtraContextTest.php b/Tests/Services/DeamonLoggerExtraContextTest.php index 66b6f5b..675fd08 100644 --- a/Tests/Services/DeamonLoggerExtraContextTest.php +++ b/Tests/Services/DeamonLoggerExtraContextTest.php @@ -12,13 +12,13 @@ class DeamonLoggerExtraContextTest extends TestCase * * @param string $locale */ - public function testGetLocale($locale) + public function testGetLocale($locale): void { $context = new DeamonLoggerExtraContext('', $locale); $this->assertEquals($locale, $context->getLocale(), sprintf('locale should be %s, %s returned.', $locale, $context->getLocale())); } - public function getLocaleDataset() + public function getLocaleDataset(): array { return [ ['fr', 'locale should be fr'], @@ -31,13 +31,13 @@ public function getLocaleDataset() * * @param $applicationName */ - public function testGetApplicationName($applicationName) + public function testGetApplicationName($applicationName): void { $context = new DeamonLoggerExtraContext($applicationName, 'fr'); $this->assertEquals($applicationName, $context->getApplicationName(), sprintf('application_name should be %s, %s returned.', $applicationName, $context->getApplicationName())); } - public function getApplicationNameDataset() + public function getApplicationNameDataset(): array { return [ ['github.com/deamon'], diff --git a/composer.json b/composer.json index 411a471..aae4692 100644 --- a/composer.json +++ b/composer.json @@ -17,17 +17,17 @@ "Log" ], "require": { - "php": ">=8.0.2", - "symfony/security-core": "^6.0", - "symfony/dependency-injection": "^6.0", - "symfony/monolog-bridge": "^6.0", + "php": ">=8.2", + "symfony/security-core": "^7.0", + "symfony/dependency-injection": "^7.0", + "symfony/monolog-bridge": "^7.0", "monolog/monolog": "^3.0", - "symfony/http-kernel": "^6.0", - "symfony/http-foundation": "^6.0", - "symfony/config": "^6.0" + "symfony/http-kernel": "^7.0", + "symfony/http-foundation": "^7.2", + "symfony/config": "^7.0" }, "require-dev": { - "symfony/phpunit-bridge": "^6.0" + "symfony/phpunit-bridge": "^7.0" }, "autoload": { "psr-4": { @@ -36,7 +36,7 @@ }, "extra": { "branch-alias": { - "dev-master": "6.0.x-dev" + "dev-master": "7.0.x-dev" } }, "suggest": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 7a86d8b..63325f0 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,26 +1,31 @@ - - - - - - - - . - - - ./Resources - ./Tests - ./vendor - - - - - ./Tests - - - - - - + + + + . + + + ./Resources + ./Tests + ./vendor + + + + + ./Tests + + + + + + + + + + +