Skip to content

Commit 8179bb9

Browse files
authored
Merge pull request #1362 from zavitkov/zavitkov/feature/upgrade-to-symfony-7
add symfony 7 support for enqueue-bundle
2 parents 867d45f + 9570303 commit 8179bb9

32 files changed

+200
-285
lines changed

.github/workflows/ci.yml

+10-22
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
5959
- uses: shivammathur/setup-php@v2
6060
with:
61-
php-version: '7.4'
61+
php-version: '8.2'
6262
coverage: none
6363
extensions: mongodb, redis, :xdebug
6464
ini-values: memory_limit=2048M
@@ -77,18 +77,12 @@ jobs:
7777
strategy:
7878
fail-fast: false
7979
matrix:
80-
php: ['7.4', '8.0', '8.1', '8.2']
81-
symfony_version: ['5.4.*', '6.2.*', '6.3.*']
80+
php: ['8.1', '8.2']
81+
symfony_version: ['6.2.*', '6.3.*', '6.4.*', '7.0.*']
8282
dependencies: ['--prefer-lowest', '--prefer-dist']
8383
exclude:
84-
- php: '7.4'
85-
symfony_version: '6.2.*'
86-
- php: '7.4'
87-
symfony_version: '6.3.*'
88-
- php: '8.0'
89-
symfony_version: '6.2.*'
90-
- php: '8.0'
91-
symfony_version: '6.3.*'
84+
- php: '8.1'
85+
symfony_version: '7.0.*'
9286

9387
name: PHP ${{ matrix.php }} unit tests on Sf ${{ matrix.symfony_version }}, deps=${{ matrix.dependencies }}
9488

@@ -127,18 +121,12 @@ jobs:
127121
strategy:
128122
fail-fast: false
129123
matrix:
130-
php: ['7.4', '8.0', '8.1', '8.2'] # same as in the container
131-
symfony_version: ['5.4.*', '6.2.*', '6.3.*']
132-
dependencies: ['--prefer-lowest', '--prefer-dist']
124+
php: [ '8.1', '8.2' ]
125+
symfony_version: [ '6.2.*', '6.3.*', '6.4.*', '7.0.*' ]
126+
dependencies: [ '--prefer-lowest', '--prefer-dist' ]
133127
exclude:
134-
- php: '7.4'
135-
symfony_version: '6.2.*'
136-
- php: '7.4'
137-
symfony_version: '6.3.*'
138-
- php: '8.0'
139-
symfony_version: '6.2.*'
140-
- php: '8.0'
141-
symfony_version: '6.3.*'
128+
- php: '8.1'
129+
symfony_version: '7.0.*'
142130

143131
name: PHP ${{ matrix.php }} functional tests on Sf ${{ matrix.symfony_version }}, deps=${{ matrix.dependencies }}
144132

composer.json

+15-15
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"phpstan": "bin/phpstan analyse --memory-limit=512M -c phpstan.neon"
1010
},
1111
"require": {
12-
"php": "^7.4|^8.0",
12+
"php": "^8.1",
1313

1414
"ext-amqp": "^1.9.3|^2.0.0",
1515
"ext-gearman": "^2.0",
@@ -53,21 +53,21 @@
5353
"phpunit/phpunit": "^9.5",
5454
"phpstan/phpstan": "^0.12",
5555
"queue-interop/queue-spec": "^0.6.2",
56-
"symfony/browser-kit": "^5.4|^6.0",
57-
"symfony/config": "^5.4|^6.0",
58-
"symfony/process": "^5.4|^6.0",
59-
"symfony/console": "^5.4|^6.0",
60-
"symfony/dependency-injection": "^5.4|^6.0",
61-
"symfony/event-dispatcher": "^5.4|^6.0",
62-
"symfony/expression-language": "^5.4|^6.0",
63-
"symfony/http-kernel": "^5.4|^6.0",
64-
"symfony/filesystem": "^5.4|^6.0",
65-
"symfony/framework-bundle": "^5.4|^6.0",
66-
"symfony/validator": "^5.4|^6.0",
67-
"symfony/yaml": "^5.4|^6.0",
56+
"symfony/browser-kit": "^6.2|^7.0",
57+
"symfony/config": "^6.2|^7.0",
58+
"symfony/process": "^6.2|^7.0",
59+
"symfony/console": "^6.2|^7.0",
60+
"symfony/dependency-injection": "^6.2|^7.0",
61+
"symfony/event-dispatcher": "^6.2|^7.0",
62+
"symfony/expression-language": "^6.2|^7.0",
63+
"symfony/http-kernel": "^^6.2|^7.0",
64+
"symfony/filesystem": "^6.2|^7.0",
65+
"symfony/framework-bundle": "^^6.2|^7.0",
66+
"symfony/validator": "^6.2|^7.0",
67+
"symfony/yaml": "^6.2|^7.0",
6868
"empi89/php-amqp-stubs": "*@dev",
6969
"doctrine/doctrine-bundle": "^2.3.2",
70-
"doctrine/mongodb-odm-bundle": "^3.5|^4.3",
70+
"doctrine/mongodb-odm-bundle": "^3.5|^4.3|^5.0",
7171
"alcaeus/mongo-php-adapter": "^1.0",
7272
"kwn/php-rdkafka-stubs": "^2.0.3",
7373
"friendsofphp/php-cs-fixer": "^3.4",
@@ -125,7 +125,6 @@
125125
"ext-amqp": "1.9.3",
126126
"ext-gearman": "2.0.3",
127127
"ext-rdkafka": "4.0",
128-
"ext-mongodb": "1.5",
129128
"ext-bcmath": "1",
130129
"ext-mbstring": "1",
131130
"ext-mongo": "1.6.14",
@@ -137,3 +136,4 @@
137136
}
138137
}
139138
}
139+

pkg/async-event-dispatcher/ContainerAwareRegistry.php

+11-18
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
namespace Enqueue\AsyncEventDispatcher;
44

5-
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
6-
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
5+
use Psr\Container\ContainerInterface;
76

8-
class ContainerAwareRegistry implements Registry, ContainerAwareInterface
7+
class ContainerAwareRegistry implements Registry
98
{
10-
use ContainerAwareTrait;
9+
/**
10+
* @var ContainerInterface
11+
*/
12+
private $container;
1113

1214
/**
1315
* @var string[]
@@ -23,23 +25,21 @@ class ContainerAwareRegistry implements Registry, ContainerAwareInterface
2325
* @param string[] $eventsMap [eventName => transformerName]
2426
* @param string[] $transformersMap [transformerName => transformerServiceId]
2527
*/
26-
public function __construct(array $eventsMap, array $transformersMap)
28+
public function __construct(array $eventsMap, array $transformersMap, ContainerInterface $container)
2729
{
2830
$this->eventsMap = $eventsMap;
2931
$this->transformersMap = $transformersMap;
32+
$this->container = $container;
3033
}
3134

32-
/**
33-
* {@inheritdoc}
34-
*/
3535
public function getTransformerNameForEvent($eventName)
3636
{
3737
$transformerName = null;
3838
if (array_key_exists($eventName, $this->eventsMap)) {
3939
$transformerName = $this->eventsMap[$eventName];
4040
} else {
4141
foreach ($this->eventsMap as $eventNamePattern => $name) {
42-
if ('/' != $eventNamePattern[0]) {
42+
if ('/' !== $eventNamePattern[0]) {
4343
continue;
4444
}
4545

@@ -58,9 +58,6 @@ public function getTransformerNameForEvent($eventName)
5858
return $transformerName;
5959
}
6060

61-
/**
62-
* {@inheritdoc}
63-
*/
6461
public function getTransformer($name)
6562
{
6663
if (false == array_key_exists($name, $this->transformersMap)) {
@@ -69,12 +66,8 @@ public function getTransformer($name)
6966

7067
$transformer = $this->container->get($this->transformersMap[$name]);
7168

72-
if (false == $transformer instanceof EventTransformer) {
73-
throw new \LogicException(sprintf(
74-
'The container must return instance of %s but got %s',
75-
EventTransformer::class,
76-
is_object($transformer) ? get_class($transformer) : gettype($transformer)
77-
));
69+
if (false == $transformer instanceof EventTransformer) {
70+
throw new \LogicException(sprintf('The container must return instance of %s but got %s', EventTransformer::class, is_object($transformer) ? $transformer::class : gettype($transformer)));
7871
}
7972

8073
return $transformer;

pkg/async-event-dispatcher/DependencyInjection/Configuration.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77

88
class Configuration implements ConfigurationInterface
99
{
10-
/**
11-
* {@inheritdoc}
12-
*/
13-
public function getConfigTreeBuilder()
10+
public function getConfigTreeBuilder(): TreeBuilder
1411
{
1512
if (method_exists(TreeBuilder::class, 'getRootNode')) {
1613
$tb = new TreeBuilder('enqueue_async_event_dispatcher');

pkg/async-event-dispatcher/Resources/config/services.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ services:
88
enqueue.events.registry:
99
class: 'Enqueue\AsyncEventDispatcher\ContainerAwareRegistry'
1010
public: false
11-
arguments: [[], []]
12-
calls:
13-
- ['setContainer', ['@service_container']]
11+
arguments: [[], [], '@service_container']
1412

1513
enqueue.events.async_listener:
1614
class: 'Enqueue\AsyncEventDispatcher\AsyncListener'

pkg/async-event-dispatcher/Tests/ContainerAwareRegistryTest.php

+14-24
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,25 @@ public function testShouldImplementRegistryInterface()
2020
$this->assertClassImplements(Registry::class, ContainerAwareRegistry::class);
2121
}
2222

23-
public function testCouldBeConstructedWithEventsMapAndTransformersMapAsArguments()
24-
{
25-
new ContainerAwareRegistry([], []);
26-
}
27-
28-
public function testShouldSetContainerToContainerProperty()
23+
public function testShouldAllowGetTransportNameByEventName()
2924
{
3025
$container = new Container();
3126

32-
$registry = new ContainerAwareRegistry([], []);
33-
34-
$registry->setContainer($container);
35-
36-
$this->assertAttributeSame($container, 'container', $registry);
37-
}
38-
39-
public function testShouldAllowGetTransportNameByEventName()
40-
{
4127
$registry = new ContainerAwareRegistry([
42-
'fooEvent' => 'fooTrans',
43-
], []);
28+
'fooEvent' => 'fooTrans',
29+
], [], $container);
4430

4531
$this->assertEquals('fooTrans', $registry->getTransformerNameForEvent('fooEvent'));
4632
}
4733

4834
public function testShouldAllowDefineTransportNameAsRegExpPattern()
4935
{
36+
$container = new Container();
37+
5038
$registry = new ContainerAwareRegistry([
5139
'/.*/' => 'fooRegExpTrans',
5240
'fooEvent' => 'fooTrans',
53-
], []);
41+
], [], $container);
5442

5543
// guard
5644
$this->assertEquals('fooTrans', $registry->getTransformerNameForEvent('fooEvent'));
@@ -60,9 +48,11 @@ public function testShouldAllowDefineTransportNameAsRegExpPattern()
6048

6149
public function testThrowIfNotSupportedEventGiven()
6250
{
51+
$container = new Container();
52+
6353
$registry = new ContainerAwareRegistry([
6454
'fooEvent' => 'fooTrans',
65-
], []);
55+
], [], $container);
6656

6757
$this->expectException(\LogicException::class);
6858
$this->expectExceptionMessage('There is no transformer registered for the given event fooNotSupportedEvent');
@@ -71,9 +61,11 @@ public function testThrowIfNotSupportedEventGiven()
7161

7262
public function testThrowIfThereIsNoRegisteredTransformerWithSuchName()
7363
{
64+
$container = new Container();
65+
7466
$registry = new ContainerAwareRegistry([], [
7567
'fooTrans' => 'foo_trans_id',
76-
]);
68+
], $container);
7769

7870
$this->expectException(\LogicException::class);
7971
$this->expectExceptionMessage('There is no transformer named fooNotRegisteredName');
@@ -87,8 +79,7 @@ public function testThrowIfContainerReturnsServiceNotInstanceOfEventTransformer(
8779

8880
$registry = new ContainerAwareRegistry([], [
8981
'fooTrans' => 'foo_trans_id',
90-
]);
91-
$registry->setContainer($container);
82+
], $container);
9283

9384
$this->expectException(\LogicException::class);
9485
$this->expectExceptionMessage('The container must return instance of Enqueue\AsyncEventDispatcher\EventTransformer but got stdClass');
@@ -104,8 +95,7 @@ public function testShouldReturnEventTransformer()
10495

10596
$registry = new ContainerAwareRegistry([], [
10697
'fooTrans' => 'foo_trans_id',
107-
]);
108-
$registry->setContainer($container);
98+
], $container);
10999

110100
$this->assertSame($eventTransformerMock, $registry->getTransformer('fooTrans'));
111101
}

pkg/enqueue-bundle/Tests/Functional/App/CustomAppKernel.php

+3-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Symfony\Component\DependencyInjection\ContainerBuilder;
88
use Symfony\Component\Filesystem\Filesystem;
99
use Symfony\Component\HttpKernel\Kernel;
10-
use Symfony\Component\Routing\RouteCollectionBuilder;
10+
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
1111

1212
class CustomAppKernel extends Kernel
1313
{
@@ -27,7 +27,7 @@ class CustomAppKernel extends Kernel
2727
],
2828
];
2929

30-
public function setEnqueueConfig(array $config)
30+
public function setEnqueueConfig(array $config): void
3131
{
3232
$this->enqueueConfig = array_replace_recursive($this->enqueueConfig, $config);
3333
$this->enqueueConfig['default']['client']['app_name'] = str_replace('.', '', uniqid('app_name', true));
@@ -64,9 +64,6 @@ protected function getContainerClass(): string
6464
return parent::getContainerClass().'Custom'.$this->enqueueConfigId;
6565
}
6666

67-
/**
68-
* {@inheritdoc}
69-
*/
7067
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
7168
{
7269
if (self::VERSION_ID < 60000) {
@@ -78,10 +75,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
7875
$c->loadFromExtension('enqueue', $this->enqueueConfig);
7976
}
8077

81-
/**
82-
* {@inheritdoc}
83-
*/
84-
protected function configureRoutes(RouteCollectionBuilder $routes)
78+
protected function configureRoutes(RoutingConfigurator $routes)
8579
{
8680
}
8781
}

pkg/enqueue-bundle/Tests/Functional/LazyProducerTest.php

-12
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Enqueue\Bundle\Tests\Functional\App\CustomAppKernel;
66
use Enqueue\Symfony\Client\LazyProducer;
7-
use Symfony\Component\Filesystem\Filesystem;
87

98
/**
109
* @group functional
@@ -17,17 +16,6 @@ protected function setUp(): void
1716
// parent::setUp();
1817
}
1918

20-
protected function tearDown(): void
21-
{
22-
if (static::$kernel) {
23-
$fs = new Filesystem();
24-
$fs->remove(static::$kernel->getLogDir());
25-
$fs->remove(static::$kernel->getCacheDir());
26-
}
27-
28-
parent::tearDown();
29-
}
30-
3119
public function testShouldAllowGetLazyProducerWithoutError()
3220
{
3321
$this->customSetUp([

0 commit comments

Comments
 (0)