From b8921bf1792af079418e6358bb0d658c60f1a01b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Marseille?= Date: Tue, 25 Oct 2022 17:39:54 +0200 Subject: [PATCH] chore(deps): support only sonata-project/admin-bundle ^4.0 and sonata-project/twig-extensions ^2.0 and drop support for Symfony 3 --- Admin/LogsAdmin.php | 4 +- CHANGELOG.md | 2 + .../EnvVarEncryptedProcessor.php | 2 +- Tests/Admin/LogsAdminTest.php | 4 +- Tests/BypassFinalHook.php | 25 ++++++++++++ Tests/Command/EncryptCommandTest.php | 10 ++--- Tests/Controller/LogsAdminControllerTest.php | 7 +--- .../EkinoDataProtectionExtensionTest.php | 2 +- composer.json | 21 +++++----- phpstan.neon.dist | 3 +- phpunit.xml.dist | 39 ++++++++++++------- 11 files changed, 76 insertions(+), 43 deletions(-) create mode 100644 Tests/BypassFinalHook.php diff --git a/Admin/LogsAdmin.php b/Admin/LogsAdmin.php index 36e784a..c925cd9 100644 --- a/Admin/LogsAdmin.php +++ b/Admin/LogsAdmin.php @@ -14,7 +14,7 @@ namespace Ekino\DataProtectionBundle\Admin; use Sonata\AdminBundle\Admin\AbstractAdmin; -use Sonata\AdminBundle\Route\RouteCollection; +use Sonata\AdminBundle\Route\RouteCollectionInterface; /** * Class LogsAdmin. @@ -36,7 +36,7 @@ class LogsAdmin extends AbstractAdmin /** * {@inheritdoc} */ - protected function configureRoutes(RouteCollection $collection): void + protected function configureRoutes(RouteCollectionInterface $collection): void { $collection->add('decrypt_encrypt', 'decrypt-encrypt', [], [], [], '', [], ['GET', 'POST']); } diff --git a/CHANGELOG.md b/CHANGELOG.md index b8e0732..ed7bd5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ master * Drop support for PHP 7 * Bump PHPStan from ^0.12 to ^1.0 * Allow Symfony 6 +* Drop support for Symfony 3 +* Support only sonata-project/admin-bundle ^4.0 and sonata-project/twig-extensions ^2.0 v1.3.1 ------ diff --git a/DependencyInjection/EnvVarEncryptedProcessor.php b/DependencyInjection/EnvVarEncryptedProcessor.php index d9e3a7c..634ba31 100644 --- a/DependencyInjection/EnvVarEncryptedProcessor.php +++ b/DependencyInjection/EnvVarEncryptedProcessor.php @@ -40,7 +40,7 @@ public function __construct(EncryptorInterface $encryptor) /** * {@inheritdoc} */ - public function getEnv($prefix, $name, \Closure $getEnv) + public function getEnv(string $prefix, string $name, \Closure $getEnv): string { if ('ekino_encrypted' === $prefix) { return $this->encryptor->decrypt($getEnv($name)); diff --git a/Tests/Admin/LogsAdminTest.php b/Tests/Admin/LogsAdminTest.php index d0ea435..e0a802c 100644 --- a/Tests/Admin/LogsAdminTest.php +++ b/Tests/Admin/LogsAdminTest.php @@ -17,7 +17,7 @@ use Ekino\DataProtectionBundle\Controller\LogsAdminController; use PHPUnit\Framework\TestCase; use ReflectionMethod; -use Sonata\AdminBundle\Route\RouteCollection; +use Sonata\AdminBundle\Route\RouteCollectionInterface; /** * Class LogsAdminTest. @@ -46,7 +46,7 @@ protected function setUp(): void */ public function testConfigureRoutes(): void { - $routeCollection = $this->createMock(RouteCollection::class); + $routeCollection = $this->createMock(RouteCollectionInterface::class); $routeCollection->expects($this->once()) ->method('add') ->with('decrypt_encrypt', 'decrypt-encrypt', [], [], [], '', [], ['GET', 'POST']); diff --git a/Tests/BypassFinalHook.php b/Tests/BypassFinalHook.php new file mode 100644 index 0000000..d671065 --- /dev/null +++ b/Tests/BypassFinalHook.php @@ -0,0 +1,25 @@ +input->expects($this->at(0))->method('getArgument')->with('text')->willReturn('SomeText'); - $this->input->expects($this->at(1))->method('getOption')->with('secret')->willReturn('theApplicationSecret'); - $this->input->expects($this->at(2))->method('getOption')->with('method')->willReturn(self::CIPHER); + $this->input->expects($this->once())->method('getArgument')->with('text')->willReturn('SomeText'); + $this->input->expects($this->exactly(2))->method('getOption')->withConsecutive(['secret'], ['method'])->willReturnOnConsecutiveCalls('theApplicationSecret', self::CIPHER); $this->output->expects($this->exactly(2))->method('writeln'); @@ -66,9 +65,8 @@ public function testExcecute(): void public function testExcecuteWithBadCipher(): void { - $this->input->expects($this->at(0))->method('getArgument')->with('text')->willReturn('SomeText'); - $this->input->expects($this->at(1))->method('getOption')->with('secret')->willReturn('theApplicationSecret'); - $this->input->expects($this->at(2))->method('getOption')->with('method')->willReturn('NotACipher'); + $this->input->expects($this->once())->method('getArgument')->with('text')->willReturn('SomeText'); + $this->input->expects($this->exactly(2))->method('getOption')->withConsecutive(['secret'], ['method'])->willReturnOnConsecutiveCalls('theApplicationSecret', 'NotACipher'); $this->output->expects($this->never())->method('writeln'); diff --git a/Tests/Controller/LogsAdminControllerTest.php b/Tests/Controller/LogsAdminControllerTest.php index d70012b..8e54be9 100644 --- a/Tests/Controller/LogsAdminControllerTest.php +++ b/Tests/Controller/LogsAdminControllerTest.php @@ -22,7 +22,6 @@ use Symfony\Component\Form\Form; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Translation\TranslatorInterface; /** * Class LogsAdminControllerTest. @@ -52,7 +51,7 @@ protected function setUp(): void ->disableOriginalClone() ->disableArgumentCloning() ->disallowMockingUnknownTypes() - ->setMethods(['addFlash', 'createForm', 'get', 'renderWithExtraParams']) + ->onlyMethods(['addFlash', 'createForm', 'renderWithExtraParams', 'trans']) ->getMock(); } @@ -106,9 +105,7 @@ public function testDecryptEncryptActionNok(): void $request = $this->createMock(Request::class); - $translator = $this->createMock(TranslatorInterface::class); - $translator->expects($this->once())->method('trans')->willReturn('admin.logs.encrypt.error'); - $this->controller->expects($this->once())->method('get')->with($this->equalTo('translator'))->willReturn($translator); + $this->controller->expects($this->once())->method('trans')->with('admin.logs.encrypt.error', [], 'EkinoDataProtectionBundle'); $this->controller->decryptEncryptAction($request); } diff --git a/Tests/DependencyInjection/EkinoDataProtectionExtensionTest.php b/Tests/DependencyInjection/EkinoDataProtectionExtensionTest.php index ed3a654..36eb399 100644 --- a/Tests/DependencyInjection/EkinoDataProtectionExtensionTest.php +++ b/Tests/DependencyInjection/EkinoDataProtectionExtensionTest.php @@ -59,7 +59,7 @@ public function testLoadWithInvalidConfigs(array $configs, string $exceptionMess $this->fail(sprintf('Expecting %s with message \'%s\'', InvalidConfigurationException::class, $exceptionMessage)); } catch (InvalidConfigurationException $e) { - $this->assertRegExp($exceptionMessage, $e->getMessage()); + $this->assertMatchesRegularExpression($exceptionMessage, $e->getMessage()); } } diff --git a/composer.json b/composer.json index 7e15807..6540444 100644 --- a/composer.json +++ b/composer.json @@ -17,22 +17,23 @@ "ext-json": "*", "ext-openssl": "*", "monolog/monolog": "^1.24 || ~2.0", - "symfony/config": "^3.4 || ^4.4 || ^5.3 || ^6.0", - "symfony/console": "^3.4 || ^4.4 || ^5.3 || ^6.0", - "symfony/dependency-injection": "^3.4 || ^4.4 || ^5.3 || ^6.0", - "symfony/form": "^3.4 || ^4.4 || ^5.3 || ^6.0", - "symfony/http-kernel": "^3.4 || ^4.4 || ^5.3 || ^6.0", - "symfony/options-resolver": "^3.4 || ^4.4 || ^5.3 || ^6.0", - "symfony/translation": "^3.4 || ^4.4 || ^5.3 || ^6.0", - "symfony/validator": "^3.4 || ^4.4 || ^5.3 || ^6.0" + "symfony/config": "^4.4 || ^5.3 || ^6.0", + "symfony/console": "^4.4 || ^5.3 || ^6.0", + "symfony/dependency-injection": "^4.4 || ^5.3 || ^6.0", + "symfony/form": "^4.4 || ^5.3 || ^6.0", + "symfony/http-kernel": "^4.4 || ^5.3 || ^6.0", + "symfony/options-resolver": "^4.4 || ^5.3 || ^6.0", + "symfony/translation": "^4.4 || ^5.3 || ^6.0", + "symfony/validator": "^4.4 || ^5.3 || ^6.0" }, "require-dev": { + "dg/bypass-finals": "^1.4", "ekino/phpstan-banned-code": "^1.0", "friendsofphp/php-cs-fixer": "^3.0", "phpstan/phpstan-phpunit": "^1.0", "phpunit/phpunit": "^9.5", - "sonata-project/admin-bundle": "3.*", - "sonata-project/twig-extensions": "1.*" + "sonata-project/admin-bundle": "^4.0", + "sonata-project/twig-extensions": "^2.0" }, "autoload": { "psr-4": { "Ekino\\DataProtectionBundle\\": "" }, diff --git a/phpstan.neon.dist b/phpstan.neon.dist index a74868d..e17bb2e 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -9,7 +9,8 @@ parameters: - %rootDir%/../../.. checkGenericClassInNonGenericObjectType: false checkMissingIterableValueType: false - excludes_analyse: + + excludePaths: - %rootDir%/../../../vendor/* - %rootDir%/../../../DependencyInjection/Configuration.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index d159da0..053270e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,30 +1,39 @@ + + + + ./ + + + + ./Resources + ./Tests + ./vendor + + + + + + + + Tests - - - ./ - - ./Resources - ./Tests - ./vendor - - - - - - - + + + + +