From 59b4bffc0b18f8858b5a742fb83bf22d2b56d9d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20DECOOL?= Date: Tue, 30 Nov 2021 20:51:46 +0100 Subject: [PATCH 1/4] feat: allow Symfony 6 installation --- .github/workflows/ci.yml | 3 ++- composer.json | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eb3eea6..3b2a55e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,8 +18,9 @@ jobs: runs-on: ubuntu-18.04 strategy: matrix: - version: ['7.1', 7.2', '7.3', '7.4', '8.0'] + version: ['7.1', '7.2', '7.3', '7.4', '8.0'] flags: ['', '--prefer-lowest'] + fail-fast: false steps: - uses: actions/checkout@master - uses: shivammathur/setup-php@v2 diff --git a/composer.json b/composer.json index ffddaa6..b15963d 100644 --- a/composer.json +++ b/composer.json @@ -9,18 +9,18 @@ "prefer-stable": true, "require": { "php": ">=7.1.3", - "symfony/config": "^4.4|^5.0", - "symfony/yaml": "^4.4|^5.0", - "symfony/routing": "^4.4|^5.0", - "symfony/expression-language": "^4.4|^5.0", - "symfony/security-core": "^4.4|^5.0" + "symfony/config": "^4.4|^5.0|^6.0", + "symfony/yaml": "^4.4|^5.0|^6.0", + "symfony/routing": "^4.4|^5.0|^6.0", + "symfony/expression-language": "^4.4|^5.0|^6.0", + "symfony/security-core": "^4.4|^5.0|^6.0" }, "require-dev": { "atoum/atoum": "^3.4|^4.0", "friendsofphp/php-cs-fixer": "^2.19", "m6web/symfony2-coding-standard": "~1.2", "m6web/php-cs-fixer-config": "^1.0", - "symfony/http-foundation": "^4.4|^5.0" + "symfony/http-foundation": "^4.4|^5.0|^6.0" }, "extra": { "branch-alias": { From 6fce984f0555e47e98a8e43f5e9310bf148910a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20DECOOL?= Date: Tue, 30 Nov 2021 22:03:48 +0100 Subject: [PATCH 2/4] feat: add Symfony 6 compatibilit --- .../Formatter/DefaultFormatter.php | 11 ++++-- .../LogBridgeBundle/Tests/Units/BaseTest.php | 3 +- .../Units/Formatter/DefaultFormatter.php | 34 +++++++++++-------- .../Units/Formatter/ExceptionFormatter.php | 28 ++++++++++----- 4 files changed, 49 insertions(+), 27 deletions(-) diff --git a/src/M6Web/Bundle/LogBridgeBundle/Formatter/DefaultFormatter.php b/src/M6Web/Bundle/LogBridgeBundle/Formatter/DefaultFormatter.php index 87296cb..2d82eae 100644 --- a/src/M6Web/Bundle/LogBridgeBundle/Formatter/DefaultFormatter.php +++ b/src/M6Web/Bundle/LogBridgeBundle/Formatter/DefaultFormatter.php @@ -149,11 +149,16 @@ public function getLogContext(Request $request, Response $response, array $optio */ protected function getUsername() { - if ($this->tokenStorage && $this->tokenStorage->getToken()) { - return $this->tokenStorage->getToken()->getUsername(); + if (!$this->tokenStorage || !$token = $this->tokenStorage->getToken()) { + return ''; } - return ''; + // compatibility Symfony < 6 + if (method_exists('Symfony\Component\Security\Core\Authentication\Token\TokenInterface', 'getUsername')) { + return $token->getUsername(); + } + + return $token->getUserIdentifier(); } /** diff --git a/src/M6Web/Bundle/LogBridgeBundle/Tests/Units/BaseTest.php b/src/M6Web/Bundle/LogBridgeBundle/Tests/Units/BaseTest.php index d40e57f..11d4b41 100644 --- a/src/M6Web/Bundle/LogBridgeBundle/Tests/Units/BaseTest.php +++ b/src/M6Web/Bundle/LogBridgeBundle/Tests/Units/BaseTest.php @@ -4,6 +4,7 @@ use atoum; use Symfony\Component\Routing\RequestContext; +use Symfony\Component\Routing\Route; /** * Base Class Unit test @@ -14,7 +15,7 @@ protected function getMockedRouterCollection() { $collection = new \mock\Symfony\Component\Routing\RouteCollection(); $collection->getMockController()->get = function($name) { - return $name != 'invalid_route' ? true : false; + return $name != 'invalid_route' ? new Route('/path') : null; }; return $collection; diff --git a/src/M6Web/Bundle/LogBridgeBundle/Tests/Units/Formatter/DefaultFormatter.php b/src/M6Web/Bundle/LogBridgeBundle/Tests/Units/Formatter/DefaultFormatter.php index dfa4852..4b9f9bf 100644 --- a/src/M6Web/Bundle/LogBridgeBundle/Tests/Units/Formatter/DefaultFormatter.php +++ b/src/M6Web/Bundle/LogBridgeBundle/Tests/Units/Formatter/DefaultFormatter.php @@ -3,6 +3,7 @@ namespace M6Web\Bundle\LogBridgeBundle\Tests\Units\Formatter; use atoum; +use Symfony\Component\Security\Core\User\InMemoryUser; use Symfony\Component\Security\Core\User\User; use M6Web\Bundle\LogBridgeBundle\Formatter; use Symfony\Component\HttpFoundation\Request; @@ -14,21 +15,30 @@ class DefaultFormatter extends atoum { const ENVIRONMENT = 'test'; + const USERNAME = 'test-username'; + const PASSWORD = 'test-password'; private function getUser() { - return new User('test', 'password'); + if (class_exists(User::class)) { + return new User(self::USERNAME, self::PASSWORD); + } + + return new InMemoryUser(self::USERNAME, self::PASSWORD); } - private function getMockedToken(User $user = null) + private function getMockedToken() { - $user = $user ?: $this->getUser(); - $token = new \mock\Symfony\Component\Security\Core\Authentication\TokenInterface(); + $usernameMethod = 'getUserIdentifier'; + if (method_exists('Symfony\Component\Security\Core\Authentication\Token\TokenInterface', 'getUsername')) { + // compatibility Symfony < 6 + $usernameMethod = 'getUsername'; + } - $token->getMockController()->getUsername = $user->getUsername(); - $token->getMockController()->getUser = $user; - $token->getMockController()->__toString = $user->getUsername(); - $token->getMockController()->getCredentials = 'test'; + $token = new \mock\Symfony\Component\Security\Core\Authentication\Token\TokenInterface(); + $token->getMockController()->$usernameMethod = self::USERNAME; + $token->getMockController()->getUser = $this->getUser(); + $token->getMockController()->__toString = self::USERNAME; return $token; } @@ -85,7 +95,7 @@ public function testProvider() ->integer($logContext['status']) ->isEqualTo($status) ->string($logContext['user']) - ->isEqualTo($tokenstorage->getToken()->getUsername()) + ->isEqualTo(self::USERNAME) ->string($logContext['key']) ->isEqualTo(sprintf('%s.%s.%s.%s', self::ENVIRONMENT, $route, $method, $status)) ; @@ -104,14 +114,10 @@ public function testPostProvider() ]; - $request = new \mock\Symfony\Component\HttpFoundation\Request([], $post); - $request->getMockController()->getMethod = 'POST'; + $request = new Request([], $post, [], [], [], ['REQUEST_METHOD' => 'POST']); $response = new Response('Body content response'); $tokenstorage = $this->getMockedTokenStorage(); - $route = $request->get('_route'); - $method = $request->getMethod(); - $status = $response->getStatusCode(); $this ->if($provider = $this->createProvider()) diff --git a/src/M6Web/Bundle/LogBridgeBundle/Tests/Units/Formatter/ExceptionFormatter.php b/src/M6Web/Bundle/LogBridgeBundle/Tests/Units/Formatter/ExceptionFormatter.php index c14032e..3a548c9 100644 --- a/src/M6Web/Bundle/LogBridgeBundle/Tests/Units/Formatter/ExceptionFormatter.php +++ b/src/M6Web/Bundle/LogBridgeBundle/Tests/Units/Formatter/ExceptionFormatter.php @@ -3,6 +3,7 @@ namespace M6Web\Bundle\LogBridgeBundle\Tests\Units\Formatter; use atoum; +use Symfony\Component\Security\Core\User\InMemoryUser; use Symfony\Component\Security\Core\User\User; use M6Web\Bundle\LogBridgeBundle\Formatter; use Symfony\Component\HttpFoundation\Request; @@ -14,6 +15,8 @@ class ExceptionFormatter extends atoum { const ENVIRONMENT = 'test'; + const USERNAME = 'test-username'; + const PASSWORD = 'test-password'; /** * @var string @@ -30,18 +33,25 @@ public function beforeTestMethod($method) private function getUser() { - return new User('test', 'password'); + if (class_exists(User::class)) { + return new User(self::USERNAME, self::PASSWORD); + } + + return new InMemoryUser(self::USERNAME, self::PASSWORD); } - private function getMockedToken(User $user = null) + private function getMockedToken() { - $user = $user ?: $this->getUser(); - $token = new \mock\Symfony\Component\Security\Core\Authentication\TokenInterface(); + $usernameMethod = 'getUserIdentifier'; + if (method_exists('Symfony\Component\Security\Core\Authentication\Token\TokenInterface', 'getUsername')) { + // compatibility Symfony < 6 + $usernameMethod = 'getUsername'; + } - $token->getMockController()->getUsername = $user->getUsername(); - $token->getMockController()->getUser = $user; - $token->getMockController()->__toString = $user->getUsername(); - $token->getMockController()->getCredentials = 'test'; + $token = new \mock\Symfony\Component\Security\Core\Authentication\Token\TokenInterface(); + $token->getMockController()->$usernameMethod = self::USERNAME; + $token->getMockController()->getUser = $this->getUser(); + $token->getMockController()->__toString = self::USERNAME; return $token; } @@ -111,7 +121,7 @@ public function testProvider() ->integer($logContext['status']) ->isEqualTo($status) ->string($logContext['user']) - ->isEqualTo($tokenstorage->getToken()->getUsername()) + ->isEqualTo(self::USERNAME) ->string($logContext['key']) ->isEqualTo(sprintf('%s.%s.%s.%s', self::ENVIRONMENT, $route, $method, $status)) ; From 18f879655e38c9ba5df50cb12f21e2dace56a0dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20DECOOL?= Date: Wed, 1 Dec 2021 21:10:18 +0100 Subject: [PATCH 3/4] fix: fix build status badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d921013..bf5f89b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# LogBridgeBundle [![Build Status](https://travis-ci.org/M6Web/LogBridgeBundle.svg?branch=master)](https://travis-ci.org/M6Web/LogBridgeBundle) +# LogBridgeBundle [![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2FBedrockStreaming%2FLogBridgeBundle%2Fbadge%3Fref%3Dmaster&style=flat)](https://actions-badge.atrox.dev/BedrockStreaming/LogBridgeBundle/goto?ref=master) Symfony Bundle to log Request/Response with Monolog. From 0ebd893deb1461c6a2d36d64d51f7ad5f7dbbb13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Je=CC=81re=CC=81my=20DECOOL?= Date: Thu, 2 Dec 2021 16:10:37 +0100 Subject: [PATCH 4/4] feat: add PHP 8.1 in test matrix --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3b2a55e..2db2211 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: runs-on: ubuntu-18.04 strategy: matrix: - version: ['7.1', '7.2', '7.3', '7.4', '8.0'] + version: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] flags: ['', '--prefer-lowest'] fail-fast: false steps: