Skip to content

Commit

Permalink
feat(42): Prepare for the next Symfony version
Browse files Browse the repository at this point in the history
Fixing command deprecation requires AsCommand, which breaks support for SF < 5.3
  • Loading branch information
121593 committed Dec 9, 2023
1 parent 8a2e1fe commit 10403e1
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 61 deletions.
22 changes: 11 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -149,4 +149,4 @@
"chrome",
"firefox"
]
}
}
47 changes: 19 additions & 28 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
cacheResult ="false"
>
<php>
<ini name="error_reporting" value="-1" />
<env name="KERNEL_CLASS" value="BenTools\WebPushBundle\Tests\Classes\TestKernel" />
<env name="APP_ENV" value="test" />
<env name="APP_DEBUG" value="1" />
<env name="APP_SECRET" value="s$cretf0rt3st" />
<env name="SHELL_VERBOSITY" value="-1" />
</php>

<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="vendor/autoload.php" cacheResult="false">
<coverage>
<include>
<directory>src</directory>
</include>
</coverage>
<php>
<ini name="error_reporting" value="-1"/>
<env name="KERNEL_CLASS" value="BenTools\WebPushBundle\Tests\Classes\TestKernel"/>
<env name="APP_ENV" value="test"/>
<env name="APP_DEBUG" value="1"/>
<env name="APP_SECRET" value="s$cretf0rt3st"/>
<env name="SHELL_VERBOSITY" value="-1"/>
</php>
<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
16 changes: 3 additions & 13 deletions src/Command/WebPushGenerateKeysCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,7 +26,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$io->writeln(sprintf('Your private key is: <info>%s</info>', $keys['privateKey']));
$io->newLine(2);

if (-1 === version_compare(Kernel::VERSION, 4)) {
if (-1 === version_compare(Kernel::VERSION, '4')) {
$io->writeln('Update <info>app/config/config.yml</info>:');
$io->newLine(1);
$io->writeln('<info># app/config/config.yml</info>');
Expand Down
2 changes: 1 addition & 1 deletion src/Sender/PushMessageSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class PushMessageSender implements PushMessagerSenderInterface
{
/**
* @var Client
* @var ClientInterface
*/
private $client;

Expand Down
6 changes: 3 additions & 3 deletions src/Sender/RequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/Classes/TestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ 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(),
new WebPushBundle(),
];
}

protected function configureRoutes(RouteCollectionBuilder $routes)
protected function configureRoutes(): void
{
}

Expand All @@ -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;
}
Expand Down
8 changes: 7 additions & 1 deletion tests/Classes/TestUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ public function getUsername()
return $this->userName;
}

public function getRoles()
public function getRoles(): array
{
return [];
}

public function getPassword()
Expand All @@ -36,4 +37,9 @@ public function getSalt()
public function eraseCredentials()
{
}

public function getUserIdentifier(): string
{
return $this->userName;
}
}

0 comments on commit 10403e1

Please sign in to comment.