From 2271797a6062731a928019105d85db3e498ab0ee Mon Sep 17 00:00:00 2001 From: core23 Date: Sat, 4 Dec 2021 13:00:17 +0100 Subject: [PATCH] Bump symfony 5.4 --- .github/settings.yml | 12 ++--- .github/workflows/continuous-integration.yml | 3 +- composer.json | 40 ++++++++-------- phpstan-baseline.neon | 33 +++++++------ psalm-baseline.xml | 7 ++- .../Transformer/RestoreRolesTransformer.php | 27 ++++++----- tests/Action/IntegrationTestCase.php | 2 +- tests/Action/LoginActionTest.php | 3 ++ tests/App/AppKernel.php | 2 +- tests/App/Entity/User.php | 46 +++++++++++++++++++ tests/App/config/config.php | 2 +- .../RestoreRolesTransformerTest.php | 2 + 12 files changed, 119 insertions(+), 60 deletions(-) diff --git a/.github/settings.yml b/.github/settings.yml index d8c21a73..5cf21376 100644 --- a/.github/settings.yml +++ b/.github/settings.yml @@ -16,14 +16,10 @@ branches: contexts: - "Coding Standards (8)" - "Static Code Analysis (8.1)" - - "Test (PHP 8, symfony 4.4, lowest)" - - "Test (PHP 8, symfony 4.4, highest)" - - "Test (PHP 8, symfony 5.3, lowest)" - - "Test (PHP 8, symfony 5.3, highest)" - - "Test (PHP 8.1, symfony 4.4, lowest)" - - "Test (PHP 8.1, symfony 4.4, highest)" - - "Test (PHP 8.1, symfony 5.3, lowest)" - - "Test (PHP 8.1, symfony 5.3, highest)" + - "Test (PHP 8, symfony 5.4, lowest)" + - "Test (PHP 8, symfony 5.4, highest)" + - "Test (PHP 8.1, symfony 5.4, lowest)" + - "Test (PHP 8.1, symfony 5.4, highest)" - "Code Coverage (8.1)" - "Mutation Tests (8.1)" strict: true diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index a06b1c68..4e22f01c 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -118,8 +118,7 @@ jobs: - highest symfony: - - 4.4 - - 5.3 + - 5.4 steps: - name: "Checkout" diff --git a/composer.json b/composer.json index 9d371f80..703f4019 100644 --- a/composer.json +++ b/composer.json @@ -24,32 +24,32 @@ "psr/log": "^1.0 || ^2.0 || ^3.0", "sonata-project/admin-bundle": "^3.90 || ^4.0", "sonata-project/doctrine-extensions": "^1.5.1", - "symfony/asset": "^4.4 || ^5.3", - "symfony/config": "^4.4 || ^5.3", - "symfony/dependency-injection": "^4.4 || ^5.3", - "symfony/event-dispatcher": "^4.4 || ^5.3", + "symfony/asset": "^5.4", + "symfony/config": "^5.4", + "symfony/dependency-injection": "^5.4", + "symfony/event-dispatcher": "^5.4", "symfony/event-dispatcher-contracts": "^1.0 || ^2.0", - "symfony/form": "^4.4 || ^5.3", - "symfony/framework-bundle": "^4.4 || ^5.3", - "symfony/http-foundation": "^4.4 || ^5.3", - "symfony/http-kernel": "^4.4 || ^5.3", - "symfony/options-resolver": "^4.4 || ^5.3", - "symfony/routing": "^4.4 || ^5.3", + "symfony/form": "^5.4", + "symfony/framework-bundle": "^5.4", + "symfony/http-foundation": "^5.4", + "symfony/http-kernel": "^5.4", + "symfony/options-resolver": "^5.4", + "symfony/routing": "^5.4", "symfony/security-acl": "^3.0", - "symfony/security-core": "^4.4 || ^5.3", - "symfony/security-csrf": "^4.4 || ^5.3", - "symfony/security-http": "^4.4 || ^5.3", - "symfony/translation": "^4.4 || ^5.3", + "symfony/security-core": "^5.4", + "symfony/security-csrf": "^5.4", + "symfony/security-http": "^5.4", + "symfony/translation": "^5.4", "symfony/translation-contracts": "^1.0 || ^2.0", - "symfony/twig-bridge": "^4.4 || ^5.3", - "symfony/twig-bundle": "^4.4 || ^5.3", + "symfony/twig-bridge": "^5.4", + "symfony/twig-bundle": "^5.4", "twig/extra-bundle": "^3.0", "twig/twig": "^2.14 || ^3.1" }, "conflict": { "doctrine/doctrine-bundle": "<1.12", "doctrine/orm": "<2.7", - "symfony/doctrine-bridge": "<4.4" + "symfony/doctrine-bridge": "<5.4" }, "require-dev": { "bamarni/composer-bin-plugin": "^1.3", @@ -58,9 +58,9 @@ "ergebnis/composer-normalize": "^2.0.1", "knplabs/knp-menu": "^2.3 || ^3.0", "sonata-project/doctrine-orm-admin-bundle": "^3.13 || ^4.0", - "symfony/browser-kit": "^4.4 || ^5.3", - "symfony/doctrine-bridge": "^4.4 || ^5.3", - "symfony/intl": "^4.4 || ^5.3" + "symfony/browser-kit": "^5.4", + "symfony/doctrine-bridge": "^5.4", + "symfony/intl": "^5.3" }, "config": { "sort-packages": true diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 7e61a699..5838af54 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -50,16 +50,6 @@ parameters: count: 1 path: src/DependencyInjection/NucleosUserAdminExtension.php - - - message: "#^Method Nucleos\\\\UserAdminBundle\\\\Form\\\\Transformer\\\\RestoreRolesTransformer\\:\\:setOriginalRoles\\(\\) has parameter \\$originalRoles with no value type specified in iterable type array\\.$#" - count: 1 - path: src/Form/Transformer/RestoreRolesTransformer.php - - - - message: "#^Property Nucleos\\\\UserAdminBundle\\\\Form\\\\Transformer\\\\RestoreRolesTransformer\\:\\:\\$originalRoles type has no value type specified in iterable type array\\.$#" - count: 1 - path: src/Form/Transformer/RestoreRolesTransformer.php - - message: "#^Strict comparison using \\=\\=\\= between false and array\\<\\(int\\|string\\)\\> will always evaluate to false\\.$#" count: 1 @@ -81,7 +71,7 @@ parameters: path: src/Security/EditableRolesBuilder.php - - message: "#^Call to function is_array\\(\\) with array\\ string, 'label' \\=\\> string, 'roles' \\=\\> array\\, 'route' \\=\\> string, 'route_absolute' \\=\\> bool, 'route_params' \\=\\> array\\\\)\\> will always evaluate to true\\.$#" + message: "#^Call to function is_array\\(\\) with array\\, route\\: string, route_absolute\\: bool, route_params\\: array\\\\}\\> will always evaluate to true\\.$#" count: 1 path: src/Security/RolesBuilder/AdminRolesBuilder.php @@ -141,17 +131,32 @@ parameters: path: tests/Resources/XliffTest.php - - message: "#^Parameter \\#3 \\$options of class Sonata\\\\AdminBundle\\\\SonataConfiguration constructor expects array\\('confirm_exit' \\=\\> bool, 'default_group' \\=\\> string, 'default_icon' \\=\\> string, 'default_label_catalogue' \\=\\> string, 'dropdown_number_groups_per_colums' \\=\\> int, 'form_type' \\=\\> string, 'html5_validate' \\=\\> bool, 'javascripts' \\=\\> array\\, \\.\\.\\.\\), array\\(\\) given\\.$#" + message: "#^Parameter \\#3 \\$options of class Sonata\\\\AdminBundle\\\\SonataConfiguration constructor expects array\\{confirm_exit\\: bool, default_group\\: string, default_icon\\: string, default_label_catalogue\\: string, dropdown_number_groups_per_colums\\: int, form_type\\: string, html5_validate\\: bool, javascripts\\: array\\, \\.\\.\\.\\}, array\\{\\} given\\.$#" count: 3 path: tests/Security/Authorization/Voter/EditableRolesBuilderTest.php - - message: "#^Parameter \\#3 \\$options of class Sonata\\\\AdminBundle\\\\SonataConfiguration constructor expects array\\('confirm_exit' \\=\\> bool, 'default_group' \\=\\> string, 'default_icon' \\=\\> string, 'default_label_catalogue' \\=\\> string, 'dropdown_number_groups_per_colums' \\=\\> int, 'form_type' \\=\\> string, 'html5_validate' \\=\\> bool, 'javascripts' \\=\\> array\\, \\.\\.\\.\\), array\\(\\) given\\.$#" + message: "#^Parameter \\#3 \\$options of class Sonata\\\\AdminBundle\\\\SonataConfiguration constructor expects array\\{confirm_exit\\: bool, default_group\\: string, default_icon\\: string, default_label_catalogue\\: string, dropdown_number_groups_per_colums\\: int, form_type\\: string, html5_validate\\: bool, javascripts\\: array\\, \\.\\.\\.\\}, array\\{\\} given\\.$#" + count: 1 + path: tests/Security/RolesBuilder/AdminRolesBuilderTest.php + + - + message: "#^Property Nucleos\\\\UserAdminBundle\\\\Tests\\\\Security\\\\RolesBuilder\\\\AdminRolesBuilderTest\\:\\:\\$token is never read, only written\\.$#" + count: 1 + path: tests/Security/RolesBuilder/AdminRolesBuilderTest.php + + - + message: "#^Property Nucleos\\\\UserAdminBundle\\\\Tests\\\\Security\\\\RolesBuilder\\\\AdminRolesBuilderTest\\:\\:\\$tokenStorage is never read, only written\\.$#" count: 1 path: tests/Security/RolesBuilder/AdminRolesBuilderTest.php - - message: "#^Parameter \\#3 \\$options of class Sonata\\\\AdminBundle\\\\SonataConfiguration constructor expects array\\('confirm_exit' \\=\\> bool, 'default_group' \\=\\> string, 'default_icon' \\=\\> string, 'default_label_catalogue' \\=\\> string, 'dropdown_number_groups_per_colums' \\=\\> int, 'form_type' \\=\\> string, 'html5_validate' \\=\\> bool, 'javascripts' \\=\\> array\\, \\.\\.\\.\\), array\\('role_super_admin' \\=\\> 'ROLE_SUPER_ADMIN', 'role_admin' \\=\\> 'ROLE_SONATA_ADMIN'\\) given\\.$#" + message: "#^Parameter \\#3 \\$options of class Sonata\\\\AdminBundle\\\\SonataConfiguration constructor expects array\\{confirm_exit\\: bool, default_group\\: string, default_icon\\: string, default_label_catalogue\\: string, dropdown_number_groups_per_colums\\: int, form_type\\: string, html5_validate\\: bool, javascripts\\: array\\, \\.\\.\\.\\}, array\\{role_super_admin\\: 'ROLE_SUPER_ADMIN', role_admin\\: 'ROLE_SONATA_ADMIN'\\} given\\.$#" + count: 1 + path: tests/Security/RolesBuilder/SecurityRolesBuilderTest.php + + - + message: "#^Property Nucleos\\\\UserAdminBundle\\\\Tests\\\\Security\\\\RolesBuilder\\\\SecurityRolesBuilderTest\\:\\:\\$admin is never read, only written\\.$#" count: 1 path: tests/Security/RolesBuilder/SecurityRolesBuilderTest.php diff --git a/psalm-baseline.xml b/psalm-baseline.xml index c1346e49..53eb247e 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + $username @@ -13,6 +13,11 @@ children + + + DataTransformerInterface + + array diff --git a/src/Form/Transformer/RestoreRolesTransformer.php b/src/Form/Transformer/RestoreRolesTransformer.php index 15a08496..9f2bb62e 100644 --- a/src/Form/Transformer/RestoreRolesTransformer.php +++ b/src/Form/Transformer/RestoreRolesTransformer.php @@ -17,8 +17,14 @@ use RuntimeException; use Symfony\Component\Form\DataTransformerInterface; +/** + * @phpstan-implements DataTransformerInterface + */ final class RestoreRolesTransformer implements DataTransformerInterface { + /** + * @var string[]|null + */ private ?array $originalRoles = null; private EditableRolesBuilderInterface $rolesBuilder; @@ -28,6 +34,9 @@ public function __construct(EditableRolesBuilderInterface $rolesBuilder) $this->rolesBuilder = $rolesBuilder; } + /** + * @param string[]|null $originalRoles + */ public function setOriginalRoles(?array $originalRoles = []): void { if (null === $originalRoles) { @@ -37,12 +46,7 @@ public function setOriginalRoles(?array $originalRoles = []): void $this->originalRoles = $originalRoles; } - /** - * @param mixed $value - * - * @return mixed|null - */ - public function transform($value) + public function transform($value): mixed { if (null === $value) { return null; @@ -55,13 +59,12 @@ public function transform($value) return $value; } - /** - * @param mixed $value - * - * @return mixed[] - */ - public function reverseTransform($value): array + public function reverseTransform($value): mixed { + if (null === $value) { + $value = []; + } + if (null === $this->originalRoles) { throw new RuntimeException('Invalid state, originalRoles array is not set'); } diff --git a/tests/Action/IntegrationTestCase.php b/tests/Action/IntegrationTestCase.php index bbe95143..3fb5df35 100644 --- a/tests/Action/IntegrationTestCase.php +++ b/tests/Action/IntegrationTestCase.php @@ -56,7 +56,7 @@ protected function tearDown(): void protected function getEntityManager(): EntityManagerInterface { - $manager = self::$container->get('doctrine.orm.entity_manager'); + $manager = self::getContainer()->get('doctrine.orm.entity_manager'); \assert($manager instanceof EntityManagerInterface); diff --git a/tests/Action/LoginActionTest.php b/tests/Action/LoginActionTest.php index 4bcd01f1..33ce8e54 100644 --- a/tests/Action/LoginActionTest.php +++ b/tests/Action/LoginActionTest.php @@ -92,6 +92,9 @@ protected function setUp(): void $this->formFactory = $this->createMock(FormFactoryInterface::class); } + /** + * @runInSeparateProcess + */ public function testAlreadyAuthenticated(): void { $user = $this->createMock(UserInterface::class); diff --git a/tests/App/AppKernel.php b/tests/App/AppKernel.php index de74dfec..8370be9e 100644 --- a/tests/App/AppKernel.php +++ b/tests/App/AppKernel.php @@ -41,7 +41,7 @@ public function __construct() parent::__construct('test', false); } - public function registerBundles() + public function registerBundles(): iterable { yield new FrameworkBundle(); yield new TwigBundle(); diff --git a/tests/App/Entity/User.php b/tests/App/Entity/User.php index f67f4413..59c2d405 100644 --- a/tests/App/Entity/User.php +++ b/tests/App/Entity/User.php @@ -49,6 +49,52 @@ public function __construct() $this->groups = new ArrayCollection(); } + /** + * @return array + */ + public function __serialize(): array + { + return [ + $this->password, + $this->salt, + $this->usernameCanonical, + $this->username, + $this->enabled, + $this->id, + $this->email, + $this->emailCanonical, + ]; + } + + /** + * @param mixed $serialized + */ + public function __unserialize($serialized): void + { + $data = unserialize($serialized); + + if (13 === \count($data)) { + // Unserializing a User object from 1.3.x + unset($data[4], $data[5], $data[6], $data[9], $data[10]); + $data = array_values($data); + } elseif (11 === \count($data)) { + // Unserializing a User from a dev version somewhere between 2.0-alpha3 and 2.0-beta1 + unset($data[4], $data[7], $data[8]); + $data = array_values($data); + } + + [ + $this->password, + $this->salt, + $this->usernameCanonical, + $this->username, + $this->enabled, + $this->id, + $this->email, + $this->emailCanonical + ] = $data; + } + public function toString(): string { return $this->getUsername(); diff --git a/tests/App/config/config.php b/tests/App/config/config.php index 7b626be3..29f73c63 100644 --- a/tests/App/config/config.php +++ b/tests/App/config/config.php @@ -23,7 +23,7 @@ $containerConfigurator->extension('framework', ['test' => true]); - $containerConfigurator->extension('framework', ['session' => ['storage_id' => 'session.storage.mock_file']]); + $containerConfigurator->extension('framework', ['session' => ['storage_factory_id' => 'session.storage.factory.mock_file']]); $containerConfigurator->extension('framework', ['cache' => ['pools' => ['avatar.preview.cache' => ['adapter' => 'cache.app', 'default_lifetime' => 60]]]]); diff --git a/tests/Form/Transformer/RestoreRolesTransformerTest.php b/tests/Form/Transformer/RestoreRolesTransformerTest.php index 68377903..ef7d67b7 100644 --- a/tests/Form/Transformer/RestoreRolesTransformerTest.php +++ b/tests/Form/Transformer/RestoreRolesTransformerTest.php @@ -114,6 +114,7 @@ public function testReverseTransformRevokedHierarchicalRole(): void $revokedRole = array_shift($userRoles); $processedRoles = $transformer->reverseTransform($userRoles); + static::assertNotNull($processedRoles); static::assertNotContains($revokedRole, $processedRoles); } @@ -138,6 +139,7 @@ public function testReverseTransformHiddenRole(): void unset($userRoles[array_search('ROLE_SUPER_ADMIN', $userRoles, true)]); $processedRoles = $transformer->reverseTransform($userRoles); + static::assertNotNull($processedRoles); static::assertContains('ROLE_SUPER_ADMIN', $processedRoles); } }