From 10403e183af5b4dcada30e430358b6dcc3aa9447 Mon Sep 17 00:00:00 2001 From: 121593 <5079173-121593@users.noreply.gitlab.com> Date: Wed, 15 Nov 2023 14:25:48 +0100 Subject: [PATCH] feat(42): Prepare for the next Symfony version Fixing command deprecation requires AsCommand, which breaks support for SF < 5.3 --- composer.json | 22 +++++----- phpunit.xml.dist | 47 +++++++++------------- src/Command/WebPushGenerateKeysCommand.php | 16 ++------ src/Sender/PushMessageSender.php | 2 +- src/Sender/RequestBuilder.php | 6 +-- tests/Classes/TestKernel.php | 8 ++-- tests/Classes/TestUser.php | 8 +++- 7 files changed, 48 insertions(+), 61 deletions(-) diff --git a/composer.json b/composer.json index 0741c8a..d0d7354 100644 --- a/composer.json +++ b/composer.json @@ -17,21 +17,21 @@ "ext-openssl": "*", "guzzlehttp/guzzle": "~6.0|~7.0", "minishlink/web-push": "~4.0|~5.0|~6.0|~7.0", - "symfony/http-kernel": "~3.0|~4.0|~5.0|~6.0" + "symfony/http-kernel": "~5.3|~6.0" }, "require-dev": { "bentools/doctrine-static": "1.0.x-dev", - "doctrine/dbal": "~2.5 <=2.9", + "doctrine/dbal": ">=2.5|~3", "nyholm/symfony-bundle-test": "~1.8", "phpunit/phpunit": "~5.0|~6.0|~7.0|~8.0|~9.0", - "symfony/config": "~4.0|~5.0|~6.0", - "symfony/dependency-injection": "~3.0|~4.0|~5.0|~6.0", - "symfony/framework-bundle": "~3.0|~4.0|~5.0|~6.0", - "symfony/http-foundation": "~3.0|~4.0|~5.0|~6.0", - "symfony/routing": "~3.0|~4.0|~5.0|~6.0", - "symfony/security": "~3.0|~4.0|~5.0|~6.0", - "symfony/var-dumper": "~3.0|~4.0|~5.0|~6.0", - "symfony/yaml": "~3.0|~4.0|~5.0|~6.0", + "symfony/config": "~5.3|~6.0", + "symfony/dependency-injection": "~5.3|~6.0", + "symfony/framework-bundle": "~5.3|~6.0", + "symfony/http-foundation": "~5.3|~6.0", + "symfony/routing": "~5.3|~6.0", + "symfony/security-bundle": "~5.3|~6.0", + "symfony/var-dumper": "~5.3|~6.0", + "symfony/yaml": "~5.3|~6.0", "twig/twig": "~1.0|~2.0" }, "autoload": { @@ -149,4 +149,4 @@ "chrome", "firefox" ] -} \ No newline at end of file +} diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 4bd0fd2..47c8b5e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,31 +1,22 @@ - - - - - - - - - - - - - - tests - - - - - - src - - + + + + src + + + + + + + + + + + + + tests + + diff --git a/src/Command/WebPushGenerateKeysCommand.php b/src/Command/WebPushGenerateKeysCommand.php index aea5ac1..eb049aa 100644 --- a/src/Command/WebPushGenerateKeysCommand.php +++ b/src/Command/WebPushGenerateKeysCommand.php @@ -4,25 +4,15 @@ use Minishlink\WebPush\VAPID; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\HttpKernel\Kernel; +#[AsCommand(name:"webpush:generate:keys", description:"Generate your VAPID keys for bentools/webpush.")] final class WebPushGenerateKeysCommand extends Command { - protected static $defaultName = 'webpush:generate:keys'; - - /** - * {@inheritdoc} - */ - protected function configure() - { - $this - ->setName('webpush:generate:keys') - ->setDescription('Generate your VAPID keys for bentools/webpush.'); - } - /** * {@inheritdoc} * @throws \ErrorException @@ -36,7 +26,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $io->writeln(sprintf('Your private key is: %s', $keys['privateKey'])); $io->newLine(2); - if (-1 === version_compare(Kernel::VERSION, 4)) { + if (-1 === version_compare(Kernel::VERSION, '4')) { $io->writeln('Update app/config/config.yml:'); $io->newLine(1); $io->writeln('# app/config/config.yml'); diff --git a/src/Sender/PushMessageSender.php b/src/Sender/PushMessageSender.php index d64feff..1670a23 100644 --- a/src/Sender/PushMessageSender.php +++ b/src/Sender/PushMessageSender.php @@ -16,7 +16,7 @@ class PushMessageSender implements PushMessagerSenderInterface { /** - * @var Client + * @var ClientInterface */ private $client; diff --git a/src/Sender/RequestBuilder.php b/src/Sender/RequestBuilder.php index 6ee13e8..e003dc2 100644 --- a/src/Sender/RequestBuilder.php +++ b/src/Sender/RequestBuilder.php @@ -31,7 +31,7 @@ public function createRequest( ): RequestInterface { $request = new Request('POST', $subscription->getEndpoint()); $request = $this->withOptionalHeaders($request, $message); - $request = $request->withHeader('TTL', $ttl); + $request = $request->withHeader('TTL', (string) $ttl); if (null !== $message->getPayload() && null !== $subscription->getPublicKey() && null !== $subscription->getAuthToken()) { $request = $request @@ -57,11 +57,11 @@ public function createRequest( return $request ->withBody(GuzzleUtils::streamFor($content)) - ->withHeader('Content-Length', Utils::safeStrlen($content)); + ->withHeader('Content-Length', (string) Utils::safeStrlen($content)); } return $request - ->withHeader('Content-Length', 0); + ->withHeader('Content-Length', '0'); } /** diff --git a/tests/Classes/TestKernel.php b/tests/Classes/TestKernel.php index 7f59d78..76d86d4 100644 --- a/tests/Classes/TestKernel.php +++ b/tests/Classes/TestKernel.php @@ -26,7 +26,7 @@ public function __construct(string $environment, bool $debug) $this->logDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $uniqid . DIRECTORY_SEPARATOR . 'logs'; } - public function registerBundles() + public function registerBundles(): \Traversable|array { return [ new FrameworkBundle(), @@ -34,7 +34,7 @@ public function registerBundles() ]; } - protected function configureRoutes(RouteCollectionBuilder $routes) + protected function configureRoutes(): void { } @@ -58,12 +58,12 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load $c->addCompilerPass(new PublicServicePass()); } - public function getCacheDir() + public function getCacheDir(): string { return $this->cacheDir; } - public function getLogDir() + public function getLogDir(): string { return $this->logDir; } diff --git a/tests/Classes/TestUser.php b/tests/Classes/TestUser.php index 8419013..bd58f65 100644 --- a/tests/Classes/TestUser.php +++ b/tests/Classes/TestUser.php @@ -21,8 +21,9 @@ public function getUsername() return $this->userName; } - public function getRoles() + public function getRoles(): array { + return []; } public function getPassword() @@ -36,4 +37,9 @@ public function getSalt() public function eraseCredentials() { } + + public function getUserIdentifier(): string + { + return $this->userName; + } }