Skip to content

Commit 0b09cfb

Browse files
committed
chore: add Symfony 7 support
1 parent ccd82a7 commit 0b09cfb

13 files changed

+103
-150
lines changed

README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,12 @@ This bundle is just the back-end part of the subscription process. For the front
3939

4040
### Composer is your friend:
4141

42-
PHP7.1+ is required.
42+
PHP8.1+ is required.
4343

4444
```bash
4545
composer require bentools/webpush-bundle
4646
```
4747

48-
If you're using Symfony 3, add the bundle to your kernel. With Symfony Flex, this should be done automatically.
49-
5048
⚠️ _We aren't on stable version yet - expect some changes._
5149

5250

composer.json

+15-20
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,23 @@
1515
"ext-json": "*",
1616
"ext-mbstring": "*",
1717
"ext-openssl": "*",
18-
"guzzlehttp/guzzle": "^6.5.8|^7.4",
19-
"minishlink/web-push": "~6.0|~7.0|~8.0",
20-
"symfony/http-kernel": "^4.4.50|^5.4.20|^6.0"
18+
"guzzlehttp/guzzle": "^6.5.8 || ^7.4",
19+
"minishlink/web-push": "^6.0.7 || ^7.0 || ^8.0",
20+
"symfony/http-kernel": "^5.4.20 || ^6.0 || ^7.0"
2121
},
2222
"require-dev": {
2323
"bentools/doctrine-static": "1.0.x-dev",
24-
"doctrine/dbal": "~2.5 <=2.9",
25-
"nyholm/symfony-bundle-test": "~1.8",
26-
"phpunit/phpunit": "^8.5.38|~9.0",
27-
"symfony/config": "~4.0|~5.0|~6.0",
28-
"symfony/dependency-injection": "~3.0|~4.0|~5.0|~6.0",
29-
"symfony/framework-bundle": "~3.0|~4.0|~5.0|~6.0",
30-
"symfony/http-foundation": "~3.0|~4.0|~5.0|~6.0",
31-
"symfony/routing": "~3.0|~4.0|~5.0|~6.0",
32-
"symfony/security": "~3.0|~4.0|~5.0|~6.0",
33-
"symfony/var-dumper": "~3.0|~4.0|~5.0|~6.0",
34-
"symfony/yaml": "~3.0|~4.0|~5.0|~6.0",
35-
"twig/twig": "~1.0|~2.0",
36-
"web-token/jwt-util-ecc": ">=2.1"
24+
"doctrine/dbal": "^2.9 || ^3.0",
25+
"phpunit/phpunit": "^9.0",
26+
"symfony/config": "^5.4 || ^6.0 || ^7.0",
27+
"symfony/dependency-injection": "^5.4 || ^6.0 || ^7.0",
28+
"symfony/framework-bundle": "^5.4 || ^6.0 || ^7.0",
29+
"symfony/http-foundation": "^5.4 || ^6.0 || ^7.0",
30+
"symfony/routing": "^5.4 || ^6.0 || ^7.0",
31+
"symfony/security-core": "^5.4 || ^6.0 || ^7.0",
32+
"symfony/var-dumper": "^5.4 || ^6.0 || ^7.0",
33+
"symfony/yaml": "^5.4 || ^6.0 || ^7.0",
34+
"twig/twig": "^2.0 || ^3.0"
3735
},
3836
"autoload": {
3937
"psr-4": {
@@ -43,10 +41,7 @@
4341
"autoload-dev": {
4442
"psr-4": {
4543
"BenTools\\WebPushBundle\\Tests\\": "tests"
46-
},
47-
"files": [
48-
"vendor/symfony/var-dumper/Resources/functions/dump.php"
49-
]
44+
}
5045
},
5146
"config": {
5247
"sort-packages": true

doc/02 - The UserSubscription Manager.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace App\Services;
1515
use App\Entity\UserSubscription;
1616
use BenTools\WebPushBundle\Model\Subscription\UserSubscriptionInterface;
1717
use BenTools\WebPushBundle\Model\Subscription\UserSubscriptionManagerInterface;
18-
use Doctrine\Common\Persistence\ManagerRegistry;
18+
use Doctrine\Persistence\ManagerRegistry;
1919
use Symfony\Component\Security\Core\User\UserInterface;
2020

2121
class UserSubscriptionManager implements UserSubscriptionManagerInterface
@@ -120,4 +120,4 @@ services:
120120
121121
Previous: [The UserSubscription Class](01%20-%20The%20UserSubscription%20Class.md)
122122
123-
Next: [Configuration](03%20-%20Configuration.md)
123+
Next: [Configuration](03%20-%20Configuration.md)

phpunit.xml.dist

+14-17
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
32
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
43
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/phpunit.xsd"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
65
backupGlobals="false"
76
colors="true"
8-
bootstrap="vendor/autoload.php"
9-
cacheResult ="false"
7+
bootstrap="tests/bootstrap.php"
8+
cacheResult="false"
109
>
10+
<coverage>
11+
<include>
12+
<directory>src</directory>
13+
</include>
14+
</coverage>
1115
<php>
12-
<ini name="error_reporting" value="-1" />
13-
<env name="KERNEL_CLASS" value="BenTools\WebPushBundle\Tests\Classes\TestKernel" />
14-
<env name="APP_ENV" value="test" />
15-
<env name="APP_DEBUG" value="1" />
16-
<env name="APP_SECRET" value="s$cretf0rt3st" />
17-
<env name="SHELL_VERBOSITY" value="-1" />
16+
<ini name="error_reporting" value="-1"/>
17+
<env name="KERNEL_CLASS" value="BenTools\WebPushBundle\Tests\Classes\TestKernel"/>
18+
<env name="APP_ENV" value="test"/>
19+
<env name="APP_DEBUG" value="1"/>
20+
<env name="APP_SECRET" value="s$cretf0rt3st"/>
21+
<env name="SHELL_VERBOSITY" value="-1"/>
1822
</php>
19-
2023
<testsuites>
2124
<testsuite name="Project Test Suite">
2225
<directory>tests</directory>
2326
</testsuite>
2427
</testsuites>
25-
26-
<filter>
27-
<whitelist>
28-
<directory>src</directory>
29-
</whitelist>
30-
</filter>
3128
</phpunit>

src/DependencyInjection/Configuration.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,13 @@
44

55
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
66
use Symfony\Component\Config\Definition\ConfigurationInterface;
7-
use Symfony\Component\HttpKernel\Kernel;
87

98
class Configuration implements ConfigurationInterface
109
{
1110
public function getConfigTreeBuilder(): TreeBuilder
1211
{
13-
if (Kernel::MAJOR_VERSION < 4) {
14-
$treeBuilder = new TreeBuilder();
15-
$rootNode = $treeBuilder->root('bentools_webpush');
16-
} else {
17-
$treeBuilder = new TreeBuilder('bentools_webpush');
18-
$rootNode = $treeBuilder->getRootNode();
19-
}
12+
$treeBuilder = new TreeBuilder('bentools_webpush');
13+
$rootNode = $treeBuilder->getRootNode();
2014

2115
$rootNode
2216
->children()

tests/BundleTest.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,31 @@ protected function setUp(): void
1717
/**
1818
* @test
1919
*/
20-
public function parameters_are_set()
20+
public function parameters_are_set(): void
2121
{
22-
$this->assertEquals('this_is_a_private_key', self::$kernel->getContainer()->getParameter('bentools_webpush.vapid_private_key'));
23-
$this->assertEquals('this_is_a_public_key', self::$kernel->getContainer()->getParameter('bentools_webpush.vapid_public_key'));
24-
$this->assertTrue(self::$kernel->getContainer()->has(UserSubscriptionManagerRegistry::class));
22+
$this->assertEquals('this_is_a_private_key', self::getContainer()->getParameter('bentools_webpush.vapid_private_key'));
23+
$this->assertEquals('this_is_a_public_key', self::getContainer()->getParameter('bentools_webpush.vapid_public_key'));
24+
$this->assertTrue(self::getContainer()->has(UserSubscriptionManagerRegistry::class));
2525
}
2626

2727
/**
2828
* @test
2929
*/
30-
public function manager_is_found()
30+
public function manager_is_found(): void
3131
{
3232
// Find by class name
33-
$this->assertInstanceOf(TestUserSubscriptionManager::class, self::$kernel->getContainer()->get(UserSubscriptionManagerRegistry::class)->getManager(TestUser::class));
33+
$this->assertInstanceOf(TestUserSubscriptionManager::class, self::getContainer()->get(UserSubscriptionManagerRegistry::class)->getManager(TestUser::class));
3434

3535
// Find by object
36-
$this->assertInstanceOf(TestUserSubscriptionManager::class, self::$kernel->getContainer()->get(UserSubscriptionManagerRegistry::class)->getManager(new TestUser('foo')));
36+
$this->assertInstanceOf(TestUserSubscriptionManager::class, self::getContainer()->get(UserSubscriptionManagerRegistry::class)->getManager(new TestUser('foo')));
3737
}
3838

3939
/**
4040
* @test
4141
*/
42-
public function unknown_manager_raises_exception()
42+
public function unknown_manager_raises_exception(): void
4343
{
4444
$this->expectException(\InvalidArgumentException::class);
45-
self::$kernel->getContainer()->get(UserSubscriptionManagerRegistry::class)->getManager(Foo::class);
45+
self::getContainer()->get(UserSubscriptionManagerRegistry::class)->getManager(Foo::class);
4646
}
4747
}

tests/Classes/TestKernel.php

+9-20
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@
33
namespace BenTools\WebPushBundle\Tests\Classes;
44

55
use BenTools\WebPushBundle\WebPushBundle;
6-
use Nyholm\BundleTest\CompilerPass\PublicServicePass;
76
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
87
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
98
use Symfony\Component\Config\Loader\LoaderInterface;
109
use Symfony\Component\DependencyInjection\ContainerBuilder;
1110
use Symfony\Component\HttpKernel\Kernel;
12-
use Symfony\Component\Routing\RouteCollectionBuilder;
1311

1412
final class TestKernel extends Kernel
1513
{
1614
use MicroKernelTrait;
1715

18-
protected $cacheDir;
19-
protected $logDir;
16+
protected string $cacheDir;
17+
protected string $logDir;
2018

2119
public function __construct(string $environment, bool $debug)
2220
{
@@ -26,44 +24,35 @@ public function __construct(string $environment, bool $debug)
2624
$this->logDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $uniqid . DIRECTORY_SEPARATOR . 'logs';
2725
}
2826

29-
public function registerBundles()
27+
public function registerBundles(): iterable
3028
{
3129
return [
3230
new FrameworkBundle(),
3331
new WebPushBundle(),
3432
];
3533
}
3634

37-
protected function configureRoutes(RouteCollectionBuilder $routes)
35+
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
3836
{
39-
}
40-
41-
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
42-
{
43-
$c->loadFromExtension('framework', [
37+
$container->loadFromExtension('framework', [
4438
'secret' => getenv('APP_SECRET'),
4539
]);
46-
$c->loadFromExtension('bentools_webpush', [
40+
$container->loadFromExtension('bentools_webpush', [
4741
'settings' => [
4842
'private_key' => 'this_is_a_private_key',
4943
'public_key' => 'this_is_a_public_key',
5044
]
5145
]);
5246
$loader->load(dirname(__DIR__) . '/Resources/services.yaml');
53-
54-
if (1 === version_compare(self::VERSION, '4.0')) {
55-
$loader->load(dirname(__DIR__) . '/Resources/framework.yaml');
56-
}
57-
58-
$c->addCompilerPass(new PublicServicePass());
47+
$loader->load(dirname(__DIR__) . '/Resources/framework.yaml');
5948
}
6049

61-
public function getCacheDir()
50+
public function getCacheDir(): string
6251
{
6352
return $this->cacheDir;
6453
}
6554

66-
public function getLogDir()
55+
public function getLogDir(): string
6756
{
6857
return $this->logDir;
6958
}

tests/Classes/TestUser.php

+5-18
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,21 @@
66

77
final class TestUser implements UserInterface
88
{
9-
/**
10-
* @var string
11-
*/
12-
private $userName;
13-
14-
public function __construct(string $userName)
9+
public function __construct(private string $userName)
1510
{
16-
$this->userName = $userName;
1711
}
1812

19-
public function getUsername()
13+
public function getUserIdentifier(): string
2014
{
2115
return $this->userName;
2216
}
2317

24-
public function getRoles()
25-
{
26-
}
27-
28-
public function getPassword()
29-
{
30-
}
31-
32-
public function getSalt()
18+
public function getRoles(): array
3319
{
20+
return [];
3421
}
3522

36-
public function eraseCredentials()
23+
public function eraseCredentials(): void
3724
{
3825
}
3926
}

tests/Classes/TestUserSubscription.php

+7-38
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,16 @@
77

88
final class TestUserSubscription implements UserSubscriptionInterface
99
{
10-
11-
private $id;
12-
13-
/**
14-
* @var UserInterface
15-
*/
16-
private $user;
17-
18-
/**
19-
* @var string
20-
*/
21-
private $endpoint;
22-
23-
/**
24-
* @var string
25-
*/
26-
private $publicKey;
27-
28-
/**
29-
* @var string
30-
*/
31-
private $authtoken;
32-
33-
/**
34-
* @var string
35-
*/
36-
private $subscriptionHash;
10+
private string $id;
3711

3812
public function __construct(
39-
UserInterface $user,
40-
string $endpoint,
41-
string $publicKey,
42-
string $authtoken,
43-
string $subscriptionHash
13+
private UserInterface $user,
14+
private string $endpoint,
15+
private string $publicKey,
16+
private string $authtoken,
17+
private string $subscriptionHash
4418
) {
45-
$this->id = $user->getUsername();
46-
$this->user = $user;
47-
$this->endpoint = $endpoint;
48-
$this->publicKey = $publicKey;
49-
$this->authtoken = $authtoken;
50-
$this->subscriptionHash = $subscriptionHash;
19+
$this->id = $user->getUserIdentifier();
5120
}
5221

5322
public function getUser(): UserInterface

tests/Classes/TestUserSubscriptionManager.php

+2-12
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,13 @@
44

55
use BenTools\WebPushBundle\Model\Subscription\UserSubscriptionInterface;
66
use BenTools\WebPushBundle\Model\Subscription\UserSubscriptionManagerInterface;
7-
use Doctrine\Common\Persistence\ManagerRegistry;
7+
use Doctrine\Persistence\ManagerRegistry;
88
use Symfony\Component\Security\Core\User\UserInterface;
99

1010
final class TestUserSubscriptionManager implements UserSubscriptionManagerInterface
1111
{
12-
/**
13-
* @var ManagerRegistry
14-
*/
15-
private $doctrine;
16-
17-
/**
18-
* UserSubscriptionManager constructor.
19-
* @param ManagerRegistry $doctrine
20-
*/
21-
public function __construct(ManagerRegistry $doctrine)
12+
public function __construct(private readonly ManagerRegistry $doctrine)
2213
{
23-
$this->doctrine = $doctrine;
2414
}
2515

2616
/**

0 commit comments

Comments
 (0)