Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add symfony 7 support for enqueue-bundle #1362

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 10 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:

- uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.2'
coverage: none
extensions: mongodb, redis, :xdebug
ini-values: memory_limit=2048M
Expand All @@ -77,18 +77,12 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['7.4', '8.0', '8.1', '8.2']
symfony_version: ['5.4.*', '6.2.*', '6.3.*']
php: ['8.1', '8.2']
symfony_version: ['6.2.*', '6.3.*', '6.4.*', '7.0.*']
dependencies: ['--prefer-lowest', '--prefer-dist']
exclude:
- php: '7.4'
symfony_version: '6.2.*'
- php: '7.4'
symfony_version: '6.3.*'
- php: '8.0'
symfony_version: '6.2.*'
- php: '8.0'
symfony_version: '6.3.*'
- php: '8.1'
symfony_version: '7.0.*'

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

Expand Down Expand Up @@ -127,18 +121,12 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['7.4', '8.0', '8.1', '8.2'] # same as in the container
symfony_version: ['5.4.*', '6.2.*', '6.3.*']
dependencies: ['--prefer-lowest', '--prefer-dist']
php: [ '8.1', '8.2' ]
symfony_version: [ '6.2.*', '6.3.*', '6.4.*', '7.0.*' ]
dependencies: [ '--prefer-lowest', '--prefer-dist' ]
exclude:
- php: '7.4'
symfony_version: '6.2.*'
- php: '7.4'
symfony_version: '6.3.*'
- php: '8.0'
symfony_version: '6.2.*'
- php: '8.0'
symfony_version: '6.3.*'
- php: '8.1'
symfony_version: '7.0.*'

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

Expand Down
30 changes: 15 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"phpstan": "bin/phpstan analyse --memory-limit=512M -c phpstan.neon"
},
"require": {
"php": "^7.4|^8.0",
"php": "^8.1",

"ext-amqp": "^1.9.3|^2.0.0",
"ext-gearman": "^2.0",
Expand Down Expand Up @@ -53,21 +53,21 @@
"phpunit/phpunit": "^9.5",
"phpstan/phpstan": "^0.12",
"queue-interop/queue-spec": "^0.6.2",
"symfony/browser-kit": "^5.4|^6.0",
"symfony/config": "^5.4|^6.0",
"symfony/process": "^5.4|^6.0",
"symfony/console": "^5.4|^6.0",
"symfony/dependency-injection": "^5.4|^6.0",
"symfony/event-dispatcher": "^5.4|^6.0",
"symfony/expression-language": "^5.4|^6.0",
"symfony/http-kernel": "^5.4|^6.0",
"symfony/filesystem": "^5.4|^6.0",
"symfony/framework-bundle": "^5.4|^6.0",
"symfony/validator": "^5.4|^6.0",
"symfony/yaml": "^5.4|^6.0",
"symfony/browser-kit": "^6.2|^7.0",
"symfony/config": "^6.2|^7.0",
"symfony/process": "^6.2|^7.0",
"symfony/console": "^6.2|^7.0",
"symfony/dependency-injection": "^6.2|^7.0",
"symfony/event-dispatcher": "^6.2|^7.0",
"symfony/expression-language": "^6.2|^7.0",
"symfony/http-kernel": "^^6.2|^7.0",
"symfony/filesystem": "^6.2|^7.0",
"symfony/framework-bundle": "^^6.2|^7.0",
"symfony/validator": "^6.2|^7.0",
"symfony/yaml": "^6.2|^7.0",
"empi89/php-amqp-stubs": "*@dev",
"doctrine/doctrine-bundle": "^2.3.2",
"doctrine/mongodb-odm-bundle": "^3.5|^4.3",
"doctrine/mongodb-odm-bundle": "^3.5|^4.3|^5.0",
"alcaeus/mongo-php-adapter": "^1.0",
"kwn/php-rdkafka-stubs": "^2.0.3",
"friendsofphp/php-cs-fixer": "^3.4",
Expand Down Expand Up @@ -125,7 +125,6 @@
"ext-amqp": "1.9.3",
"ext-gearman": "2.0.3",
"ext-rdkafka": "4.0",
"ext-mongodb": "1.5",
"ext-bcmath": "1",
"ext-mbstring": "1",
"ext-mongo": "1.6.14",
Expand All @@ -137,3 +136,4 @@
}
}
}

29 changes: 11 additions & 18 deletions pkg/async-event-dispatcher/ContainerAwareRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

namespace Enqueue\AsyncEventDispatcher;

use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Psr\Container\ContainerInterface;

class ContainerAwareRegistry implements Registry, ContainerAwareInterface
class ContainerAwareRegistry implements Registry
{
use ContainerAwareTrait;
/**
* @var ContainerInterface
*/
private $container;

/**
* @var string[]
Expand All @@ -23,23 +25,21 @@ class ContainerAwareRegistry implements Registry, ContainerAwareInterface
* @param string[] $eventsMap [eventName => transformerName]
* @param string[] $transformersMap [transformerName => transformerServiceId]
*/
public function __construct(array $eventsMap, array $transformersMap)
public function __construct(array $eventsMap, array $transformersMap, ContainerInterface $container)
{
$this->eventsMap = $eventsMap;
$this->transformersMap = $transformersMap;
$this->container = $container;
}

/**
* {@inheritdoc}
*/
public function getTransformerNameForEvent($eventName)
{
$transformerName = null;
if (array_key_exists($eventName, $this->eventsMap)) {
$transformerName = $this->eventsMap[$eventName];
} else {
foreach ($this->eventsMap as $eventNamePattern => $name) {
if ('/' != $eventNamePattern[0]) {
if ('/' !== $eventNamePattern[0]) {
continue;
}

Expand All @@ -58,9 +58,6 @@ public function getTransformerNameForEvent($eventName)
return $transformerName;
}

/**
* {@inheritdoc}
*/
public function getTransformer($name)
{
if (false == array_key_exists($name, $this->transformersMap)) {
Expand All @@ -69,12 +66,8 @@ public function getTransformer($name)

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

if (false == $transformer instanceof EventTransformer) {
throw new \LogicException(sprintf(
'The container must return instance of %s but got %s',
EventTransformer::class,
is_object($transformer) ? get_class($transformer) : gettype($transformer)
));
if (false == $transformer instanceof EventTransformer) {
throw new \LogicException(sprintf('The container must return instance of %s but got %s', EventTransformer::class, is_object($transformer) ? $transformer::class : gettype($transformer)));
}

return $transformer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@

class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
if (method_exists(TreeBuilder::class, 'getRootNode')) {
$tb = new TreeBuilder('enqueue_async_event_dispatcher');
Expand Down
4 changes: 1 addition & 3 deletions pkg/async-event-dispatcher/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ services:
enqueue.events.registry:
class: 'Enqueue\AsyncEventDispatcher\ContainerAwareRegistry'
public: false
arguments: [[], []]
calls:
- ['setContainer', ['@service_container']]
arguments: [[], [], '@service_container']

enqueue.events.async_listener:
class: 'Enqueue\AsyncEventDispatcher\AsyncListener'
Expand Down
38 changes: 14 additions & 24 deletions pkg/async-event-dispatcher/Tests/ContainerAwareRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,25 @@ public function testShouldImplementRegistryInterface()
$this->assertClassImplements(Registry::class, ContainerAwareRegistry::class);
}

public function testCouldBeConstructedWithEventsMapAndTransformersMapAsArguments()
{
new ContainerAwareRegistry([], []);
}

public function testShouldSetContainerToContainerProperty()
public function testShouldAllowGetTransportNameByEventName()
{
$container = new Container();

$registry = new ContainerAwareRegistry([], []);

$registry->setContainer($container);

$this->assertAttributeSame($container, 'container', $registry);
}

public function testShouldAllowGetTransportNameByEventName()
{
$registry = new ContainerAwareRegistry([
'fooEvent' => 'fooTrans',
], []);
'fooEvent' => 'fooTrans',
], [], $container);

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

public function testShouldAllowDefineTransportNameAsRegExpPattern()
{
$container = new Container();

$registry = new ContainerAwareRegistry([
'/.*/' => 'fooRegExpTrans',
'fooEvent' => 'fooTrans',
], []);
], [], $container);

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

public function testThrowIfNotSupportedEventGiven()
{
$container = new Container();

$registry = new ContainerAwareRegistry([
'fooEvent' => 'fooTrans',
], []);
], [], $container);

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

public function testThrowIfThereIsNoRegisteredTransformerWithSuchName()
{
$container = new Container();

$registry = new ContainerAwareRegistry([], [
'fooTrans' => 'foo_trans_id',
]);
], $container);

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

$registry = new ContainerAwareRegistry([], [
'fooTrans' => 'foo_trans_id',
]);
$registry->setContainer($container);
], $container);

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

$registry = new ContainerAwareRegistry([], [
'fooTrans' => 'foo_trans_id',
]);
$registry->setContainer($container);
], $container);

$this->assertSame($eventTransformerMock, $registry->getTransformer('fooTrans'));
}
Expand Down
12 changes: 3 additions & 9 deletions pkg/enqueue-bundle/Tests/Functional/App/CustomAppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\RouteCollectionBuilder;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;

class CustomAppKernel extends Kernel
{
Expand All @@ -27,7 +27,7 @@ class CustomAppKernel extends Kernel
],
];

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

/**
* {@inheritdoc}
*/
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
{
if (self::VERSION_ID < 60000) {
Expand All @@ -78,10 +75,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
$c->loadFromExtension('enqueue', $this->enqueueConfig);
}

/**
* {@inheritdoc}
*/
protected function configureRoutes(RouteCollectionBuilder $routes)
protected function configureRoutes(RoutingConfigurator $routes)
{
}
}
12 changes: 0 additions & 12 deletions pkg/enqueue-bundle/Tests/Functional/LazyProducerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Enqueue\Bundle\Tests\Functional\App\CustomAppKernel;
use Enqueue\Symfony\Client\LazyProducer;
use Symfony\Component\Filesystem\Filesystem;

/**
* @group functional
Expand All @@ -17,17 +16,6 @@ protected function setUp(): void
// parent::setUp();
}

protected function tearDown(): void
{
if (static::$kernel) {
$fs = new Filesystem();
$fs->remove(static::$kernel->getLogDir());
$fs->remove(static::$kernel->getCacheDir());
}

parent::tearDown();
}

public function testShouldAllowGetLazyProducerWithoutError()
{
$this->customSetUp([
Expand Down
Loading