From 31d61cf61d21233a54754e0a7002f7bf757af904 Mon Sep 17 00:00:00 2001 From: Matthieu Calie Date: Fri, 5 Jan 2024 13:38:44 +0100 Subject: [PATCH] Add compatability with symfony 6.4 and prepare for 7.0 Add attributes to tenant entity fix deprecations --- .github/workflows/php.yml | 3 +++ .../Repository/TenantRepositoryTest.php | 2 +- .../app/config/packages/doctrine.yaml | 2 ++ Tests/Functional/app/config/routes.yaml | 2 +- .../src/Controller/ProtectedController.php | 2 ++ Tests/Listener/LicenseListenerTest.php | 9 ++------- Tests/Service/AtlassianRestClientTest.php | 4 ++-- src/Entity/Tenant.php | 1 + src/Entity/TenantTrait.php | 19 +++++++++++++++++++ src/Security/JWTUserProvider.php | 2 +- 10 files changed, 34 insertions(+), 12 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 22c413c..760e79f 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -43,6 +43,9 @@ jobs: - description: 'PHP 8.1 - SF 6.0.*' php: '8.1' symfony_version: '6.0.*' + - description: 'PHP 8.3 - SF 6.4.*' + php: '8.3' + symfony_version: '6.4.*' name: Tests ${{ matrix.description }} steps: - name: Checkout diff --git a/Tests/Functional/Repository/TenantRepositoryTest.php b/Tests/Functional/Repository/TenantRepositoryTest.php index 5b35798..5efa555 100644 --- a/Tests/Functional/Repository/TenantRepositoryTest.php +++ b/Tests/Functional/Repository/TenantRepositoryTest.php @@ -48,7 +48,7 @@ public function testSaveTenant(): void $tenant->setEventType('event'); $repository->save($tenant); - self::getContainer()->get(EntityManagerInterface::class)->clear(Tenant::class); + self::getContainer()->get(EntityManagerInterface::class)->clear(); $this->assertNotNull($repository->findByClientKey('new_client_key')); } diff --git a/Tests/Functional/app/config/packages/doctrine.yaml b/Tests/Functional/app/config/packages/doctrine.yaml index 6e965c2..bc1db7d 100644 --- a/Tests/Functional/app/config/packages/doctrine.yaml +++ b/Tests/Functional/app/config/packages/doctrine.yaml @@ -3,6 +3,8 @@ doctrine: driver: pdo_sqlite path: "%kernel.cache_dir%/test-database.sqlite" orm: + enable_lazy_ghost_objects: true + report_fields_where_declared: true auto_generate_proxy_classes: true naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware auto_mapping: true diff --git a/Tests/Functional/app/config/routes.yaml b/Tests/Functional/app/config/routes.yaml index 5595381..eca6df3 100644 --- a/Tests/Functional/app/config/routes.yaml +++ b/Tests/Functional/app/config/routes.yaml @@ -1,6 +1,6 @@ controllers: resource: ../src/Controller/ - type: annotation + type: attribute ac: resource: "@AtlassianConnectBundle/Resources/config/routing.php" diff --git a/Tests/Functional/app/src/Controller/ProtectedController.php b/Tests/Functional/app/src/Controller/ProtectedController.php index c37ea40..35ab56e 100644 --- a/Tests/Functional/app/src/Controller/ProtectedController.php +++ b/Tests/Functional/app/src/Controller/ProtectedController.php @@ -13,6 +13,7 @@ final class ProtectedController extends AbstractController /** * @Route("/protected/route") */ + #[Route('/protected/route')] public function protectedRoute(): Response { return new Response('OK'); @@ -21,6 +22,7 @@ public function protectedRoute(): Response /** * @Route("/protected/license-route", defaults={"requires_license": "true"}) */ + #[Route('/protected/license-route', defaults: ['requires_license' => true])] public function licenseProtectedRoute(): Response { return new Response('OK'); diff --git a/Tests/Listener/LicenseListenerTest.php b/Tests/Listener/LicenseListenerTest.php index c03134e..d6ebc06 100644 --- a/Tests/Listener/LicenseListenerTest.php +++ b/Tests/Listener/LicenseListenerTest.php @@ -33,13 +33,7 @@ protected function setUp(): void public function testItSkipsOnASubRequest(): void { - $attributeParameterBag = $this->createMock(ParameterBagInterface::class); - $attributeParameterBag - ->expects($this->never()) - ->method('get'); - - $request = new Request(); - $request->attributes = $attributeParameterBag; + $request = new Request([], [], []); $event = $this->getEvent( $this->kernel, @@ -48,6 +42,7 @@ public function testItSkipsOnASubRequest(): void ); $this->getLicenseListener()->onKernelRequest($event); + $this->assertNull($event->getResponse()); } public function testItSkipsWhenTheRouteIsNotNullAndRouteRequiresNoLicense(): void diff --git a/Tests/Service/AtlassianRestClientTest.php b/Tests/Service/AtlassianRestClientTest.php index a8751b8..17c0d4b 100644 --- a/Tests/Service/AtlassianRestClientTest.php +++ b/Tests/Service/AtlassianRestClientTest.php @@ -151,7 +151,7 @@ public function testGetTenantFromTokenStorage(): void public function testNoTenantInToken(): void { $this->expectException(\RuntimeException::class); - $this->expectDeprecationMessage('Could not get tenant from token'); + $this->expectExceptionMessage('Could not get tenant from token'); $this->tokenStorage ->expects($this->once()) @@ -164,7 +164,7 @@ public function testNoTenantInToken(): void public function testNotInTenantContext(): void { $this->expectException(\RuntimeException::class); - $this->expectDeprecationMessage('Current user is not a Tenant'); + $this->expectExceptionMessage('Current user is not a Tenant'); $this->tokenStorage ->expects($this->once()) diff --git a/src/Entity/Tenant.php b/src/Entity/Tenant.php index 82d46da..af86142 100644 --- a/src/Entity/Tenant.php +++ b/src/Entity/Tenant.php @@ -11,6 +11,7 @@ * @ORM\HasLifecycleCallbacks() * @ORM\Entity() */ +#[ORM\Entity, ORM\Table(name: 'tenant'), ORM\HasLifecycleCallbacks] class Tenant implements TenantInterface { use TenantTrait; diff --git a/src/Entity/TenantTrait.php b/src/Entity/TenantTrait.php index 14abebd..714cd0b 100644 --- a/src/Entity/TenantTrait.php +++ b/src/Entity/TenantTrait.php @@ -4,6 +4,7 @@ namespace AtlassianConnectBundle\Entity; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; trait TenantTrait @@ -15,6 +16,7 @@ trait TenantTrait * @ORM\Id() * @ORM\GeneratedValue(strategy="AUTO") */ + #[ORM\Column(name: 'id', type: Types::INTEGER), ORM\Id, ORM\GeneratedValue(strategy: 'AUTO')] private $id; /** @@ -22,6 +24,7 @@ trait TenantTrait * * @ORM\Column(name="addon_key", type="string", length=255) */ + #[ORM\Column(name: 'addon_key', type: Types::STRING, length: 255)] private $addonKey; /** @@ -29,6 +32,7 @@ trait TenantTrait * * @ORM\Column(name="client_key", type="string", length=255, unique=true) */ + #[ORM\Column(name: 'client_key', type: Types::STRING, length: 255, unique: true)] private $clientKey; /** @@ -36,6 +40,7 @@ trait TenantTrait * * @ORM\Column(name="oauth_client_id", type="string", length=255, nullable=true) */ + #[ORM\Column(name: 'oauth_client_id', type: Types::STRING, length: 255, nullable: true)] private $oauthClientId; /** @@ -48,6 +53,7 @@ trait TenantTrait * * @ORM\Column(name="public_key", type="string", length=255) */ + #[ORM\Column(name: 'public_key', type: Types::STRING, length: 255)] private $publicKey; /** @@ -55,6 +61,7 @@ trait TenantTrait * * @ORM\Column(name="shared_secret", type="string", length=255) */ + #[ORM\Column(name: 'shared_secret', type: Types::STRING, length: 255)] private $sharedSecret; /** @@ -62,6 +69,7 @@ trait TenantTrait * * @ORM\Column(name="server_version", type="string", length=255) */ + #[ORM\Column(name: 'server_version', type: Types::STRING, length: 255)] private $serverVersion; /** @@ -69,6 +77,7 @@ trait TenantTrait * * @ORM\Column(name="plugins_version", type="string", length=255) */ + #[ORM\Column(name: 'plugins_version', type: Types::STRING, length: 255)] private $pluginsVersion; /** @@ -76,6 +85,7 @@ trait TenantTrait * * @ORM\Column(name="base_url", type="string", length=255) */ + #[ORM\Column(name: 'base_url', type: Types::STRING, length: 255)] private $baseUrl; /** @@ -83,6 +93,7 @@ trait TenantTrait * * @ORM\Column(name="product_type", type="string", length=255) */ + #[ORM\Column(name: 'product_type', type: Types::STRING, length: 255)] private $productType; /** @@ -90,6 +101,7 @@ trait TenantTrait * * @ORM\Column(name="description", type="string", length=255) */ + #[ORM\Column(name: 'description', type: Types::STRING, length: 255)] private $description; /** @@ -97,6 +109,7 @@ trait TenantTrait * * @ORM\Column(name="event_type", type="string", length=255) */ + #[ORM\Column(name: 'event_type', type: Types::STRING, length: 255)] private $eventType; /** @@ -104,6 +117,7 @@ trait TenantTrait * * @ORM\Column(name="created_at", type="datetime", nullable=false) */ + #[ORM\Column(name: 'created_at', type: Types::DATETIME_MUTABLE, nullable: false)] private $createdAt; /** @@ -111,6 +125,7 @@ trait TenantTrait * * @ORM\Column(name="updated_at", type="datetime", nullable=false) */ + #[ORM\Column(name: 'updated_at', type: Types::DATETIME_MUTABLE, nullable: false)] private $updatedAt; /** @@ -118,6 +133,7 @@ trait TenantTrait * * @ORM\Column(name="is_white_listed", type="boolean", options={"default":0}) */ + #[ORM\Column(name: 'is_white_listed', type: Types::BOOLEAN, options: ['default' => 0])] private $isWhiteListed = false; /** @@ -125,11 +141,13 @@ trait TenantTrait * * @ORM\Column(name="white_listed_until", type="datetime", nullable=true) */ + #[ORM\Column(name: 'white_listed_until', type: Types::DATETIME_MUTABLE, nullable: true)] private $whiteListedUntil; /** * @ORM\PrePersist() */ + #[ORM\PrePersist] public function setCreatedAt(): void { $this->createdAt = new \DateTime(); @@ -144,6 +162,7 @@ public function getCreatedAt(): \DateTime /** * @ORM\PreUpdate() */ + #[ORM\PreUpdate] public function setUpdatedAt(): void { $this->updatedAt = new \DateTime(); diff --git a/src/Security/JWTUserProvider.php b/src/Security/JWTUserProvider.php index 79ec5d7..cbddca4 100644 --- a/src/Security/JWTUserProvider.php +++ b/src/Security/JWTUserProvider.php @@ -38,7 +38,7 @@ public function loadUserByUsername(string $username): UserInterface return $this->loadUserByIdentifier($username); } - public function refreshUser(UserInterface $user): void + public function refreshUser(UserInterface $user): UserInterface { throw new UnsupportedUserException('Refresh prohibited'); }