Skip to content

Commit

Permalink
Add compatability with symfony 6.4 and prepare for 7.0
Browse files Browse the repository at this point in the history
Add attributes to tenant entity
fix deprecations
  • Loading branch information
Matth-- committed Jan 5, 2024
1 parent 4bfebc2 commit 9772478
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 27 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ jobs:
- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer install --prefer-dist --no-progress --no-suggest
- name: Run php-cs-fixer
run: PHP_CS_FIXER_IGNORE_ENV=1 tools/php-cs-fixer fix --dry-run --diff --ansi
- name: Run psalm
run: tools/psalm
test:
runs-on: ubuntu-latest
strategy:
Expand All @@ -43,6 +47,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
Expand All @@ -65,10 +72,6 @@ jobs:
- run: |
sed -ri 's/"symfony\/(.+)": "(.+)"/"symfony\/\1": "'${{ matrix.symfony_version }}'"/' composer.json;
- run: composer update --no-interaction --no-progress --ansi ${{ matrix.composer_flags }}
- name: Run php-cs-fixer
run: tools/php-cs-fixer fix --dry-run --diff --ansi
- name: Run psalm
run: tools/psalm
- name: Run Tests
run: vendor/bin/phpunit --coverage-clover=coverage.xml
- name: Upload coverage to Codecov
Expand Down
3 changes: 1 addition & 2 deletions Tests/Functional/Repository/TenantRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace AtlassianConnectBundle\Tests\Functional\Repository;

use AtlassianConnectBundle\Entity\Tenant;
use AtlassianConnectBundle\Repository\TenantRepositoryInterface;
use AtlassianConnectBundle\Tests\Functional\KernelTestCase;
use Doctrine\ORM\EntityManagerInterface;
Expand Down Expand Up @@ -48,7 +47,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'));
}
Expand Down
1 change: 1 addition & 0 deletions Tests/Functional/app/config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ doctrine:
driver: pdo_sqlite
path: "%kernel.cache_dir%/test-database.sqlite"
orm:
report_fields_where_declared: true
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
12 changes: 9 additions & 3 deletions Tests/Functional/app/config/routes.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
controllers:
resource: ../src/Controller/
type: annotation
protected:
path: /protected/route
controller: AtlassianConnectBundle\Tests\Functional\App\Controller\ProtectedController::protectedRoute

license_protected:
path: /protected/license-route
defaults:
requires_license: true
controller: AtlassianConnectBundle\Tests\Functional\App\Controller\ProtectedController::licenseProtectedRoute

ac:
resource: "@AtlassianConnectBundle/Resources/config/routing.php"
7 changes: 0 additions & 7 deletions Tests/Functional/app/src/Controller/ProtectedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,14 @@

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

final class ProtectedController extends AbstractController
{
/**
* @Route("/protected/route")
*/
public function protectedRoute(): Response
{
return new Response('OK');
}

/**
* @Route("/protected/license-route", defaults={"requires_license": "true"})
*/
public function licenseProtectedRoute(): Response
{
return new Response('OK');
Expand Down
10 changes: 2 additions & 8 deletions Tests/Listener/LicenseListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use AtlassianConnectBundle\Listener\LicenseListener;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\RequestEvent;
Expand All @@ -33,13 +32,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,
Expand All @@ -48,6 +41,7 @@ public function testItSkipsOnASubRequest(): void
);

$this->getLicenseListener()->onKernelRequest($event);
$this->assertNull($event->getResponse());
}

public function testItSkipsWhenTheRouteIsNotNullAndRouteRequiresNoLicense(): void
Expand Down
4 changes: 2 additions & 2 deletions Tests/Service/AtlassianRestClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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())
Expand Down
4 changes: 4 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

class Configuration implements ConfigurationInterface
{
/**
* @psalm-suppress UndefinedInterfaceMethod
* @psalm-suppress UndefinedMethod
*/
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('atlassian_connect');
Expand Down
1 change: 1 addition & 0 deletions src/Entity/Tenant.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* @ORM\HasLifecycleCallbacks()
* @ORM\Entity()
*/
#[ORM\Entity, ORM\Table(name: 'tenant'), ORM\HasLifecycleCallbacks]
class Tenant implements TenantInterface
{
use TenantTrait;
Expand Down
19 changes: 19 additions & 0 deletions src/Entity/TenantTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace AtlassianConnectBundle\Entity;

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

trait TenantTrait
Expand All @@ -15,27 +16,31 @@ trait TenantTrait
* @ORM\Id()
* @ORM\GeneratedValue(strategy="AUTO")
*/
#[ORM\Column(name: 'id', type: Types::INTEGER), ORM\Id, ORM\GeneratedValue(strategy: 'AUTO')]
private $id;

/**
* @var string
*
* @ORM\Column(name="addon_key", type="string", length=255)
*/
#[ORM\Column(name: 'addon_key', type: Types::STRING, length: 255)]
private $addonKey;

/**
* @var string
*
* @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;

/**
* @var string|null
*
* @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;

/**
Expand All @@ -48,88 +53,101 @@ trait TenantTrait
*
* @ORM\Column(name="public_key", type="string", length=255)
*/
#[ORM\Column(name: 'public_key', type: Types::STRING, length: 255)]
private $publicKey;

/**
* @var string
*
* @ORM\Column(name="shared_secret", type="string", length=255)
*/
#[ORM\Column(name: 'shared_secret', type: Types::STRING, length: 255)]
private $sharedSecret;

/**
* @var string
*
* @ORM\Column(name="server_version", type="string", length=255)
*/
#[ORM\Column(name: 'server_version', type: Types::STRING, length: 255)]
private $serverVersion;

/**
* @var string
*
* @ORM\Column(name="plugins_version", type="string", length=255)
*/
#[ORM\Column(name: 'plugins_version', type: Types::STRING, length: 255)]
private $pluginsVersion;

/**
* @var string
*
* @ORM\Column(name="base_url", type="string", length=255)
*/
#[ORM\Column(name: 'base_url', type: Types::STRING, length: 255)]
private $baseUrl;

/**
* @var string
*
* @ORM\Column(name="product_type", type="string", length=255)
*/
#[ORM\Column(name: 'product_type', type: Types::STRING, length: 255)]
private $productType;

/**
* @var string
*
* @ORM\Column(name="description", type="string", length=255)
*/
#[ORM\Column(name: 'description', type: Types::STRING, length: 255)]
private $description;

/**
* @var string
*
* @ORM\Column(name="event_type", type="string", length=255)
*/
#[ORM\Column(name: 'event_type', type: Types::STRING, length: 255)]
private $eventType;

/**
* @var \DateTime
*
* @ORM\Column(name="created_at", type="datetime", nullable=false)
*/
#[ORM\Column(name: 'created_at', type: Types::DATETIME_MUTABLE, nullable: false)]
private $createdAt;

/**
* @var \DateTime
*
* @ORM\Column(name="updated_at", type="datetime", nullable=false)
*/
#[ORM\Column(name: 'updated_at', type: Types::DATETIME_MUTABLE, nullable: false)]
private $updatedAt;

/**
* @var bool
*
* @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;

/**
* @var \DateTime
*
* @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();
Expand All @@ -144,6 +162,7 @@ public function getCreatedAt(): \DateTime
/**
* @ORM\PreUpdate()
*/
#[ORM\PreUpdate]
public function setUpdatedAt(): void
{
$this->updatedAt = new \DateTime();
Expand Down
5 changes: 4 additions & 1 deletion src/Security/JWTUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
use Symfony\Component\Security\Core\User\UserInterface;

/**
* @template-implements JWTUserProviderInterface<TenantInterface>
*/
class JWTUserProvider implements JWTUserProviderInterface
{
public function __construct(private TenantRepositoryInterface $repository)
Expand All @@ -38,7 +41,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');
}
Expand Down
5 changes: 5 additions & 0 deletions src/Security/JWTUserProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@

namespace AtlassianConnectBundle\Security;

use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;

/**
* @template-covariant TUser of UserInterface
* @template-extends UserProviderInterface<TUser>
*/
interface JWTUserProviderInterface extends UserProviderInterface
{
public function getDecodedToken(string $jwt): object;
Expand Down
Binary file modified tools/psalm
Binary file not shown.

0 comments on commit 9772478

Please sign in to comment.