8000 bug #43202 Fix framework configuration when messenger uses without co… · symfony/symfony@7244d83 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7244d83

Browse files
committed
bug #43202 Fix framework configuration when messenger uses without console (upyx)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- Fix framework configuration when messenger uses without console | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | yes | Tickets | Fix #43133 (review) | License | MIT | Doc PR | later We hurried, an addition to #43133 It fixes #43133 (review) It adds the forgotten CHANGELOG & UPGRADE I'm not sure about the CHANGELOG format. I've done as people do but... [it says](https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry) "New entries must be added on top of the list." However, nobody does it 🤷 ~I don't know how to test the fix, because of `class_exists()` call that cannot be easily mocked.~ `src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php:245`: ```php if (class_exists(Application::class)) { $loader->load('console.php'); /* ... */ } ``` Commits ------- d098ef8 Fix framework configuration when messenger uses without console
2 parents 6e4bbd3 + d098ef8 commit 7244d83

File tree

6 files changed

+33
-5
lines changed

6 files changed

+33
-5
lines changed

UPGRADE-5.4.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Messenger
4545

4646
* Deprecate not setting the `delete_after_ack` config option (or DSN parameter) using the Redis transport,
4747
its default value will change to `true` in 6.0
48+
* Deprecate not setting the `reset_on_message` config option, its default value will change to `true` in 6.0
4849

4950
SecurityBundle
5051
--------------

UPGRADE-6.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ Messenger
157157
* Removed the `prefetch_count` parameter in the AMQP bridge.
158158
* Removed the use of TLS option for Redis Bridge, use `rediss://127.0.0.1` instead of `redis://127.0.0.1?tls=1`
159159
* The `delete_after_ack` config option of the Redis transport now defaults to `true`
160+
* The `reset_on_message` config option now defaults to `true`
160161

161162
Mime
162163
----

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public function load(array $configs, ContainerBuilder $container)
242242

243243
$container->registerAliasForArgument('parameter_bag', PsrContainerInterface::class);
244244

245-
if (class_exists(Application::class)) {
245+
if ($this->hasConsole()) {
246246
$loader->load('console.php');
247247

248248
if (!class_exists(BaseXliffLintCommand::class)) {
@@ -599,6 +599,11 @@ public function getConfiguration(array $config, ContainerBuilder $container)
599599
return new Configuration($container->getParameter('kernel.debug'));
600600
}
601601

602+
protected function hasConsole(): bool
603+
{
604+
return class_exists(Application::class);
605+
}
606+
602607
private function registerFormConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader)
603608
{
604609
$loader->load('form.php');
@@ -2081,7 +2086,9 @@ private function registerMessengerConfiguration(array $config, ContainerBuilder
20812086
throw new LogicException('The "framework.messenger.reset_on_message" configuration option can be set to "true" only. To prevent services resetting after each message you can set the "--no-reset" option in "messenger:consume" command.');
20822087
}
20832088

2084-
if (null === $config['reset_on_message']) {
2089+
if (!$container->hasDefinition('console.command.messenger_consume_messages')) {
2090+
$container->removeDefinition('messenger.listener.reset_services');
2091+
} elseif (null === $config['reset_on_message']) {
20852092
trigger_deprecation('symfony/framework-bundle', '5.4', 'Not setting the "framework.messenger.reset_on_message" configuration option is deprecated, it will default to "true" in version 6.0.');
20862093

20872094
$container->getDefinition('console.command.messenger_consume_messages')->replaceArgument(5, null);

src/Symfony/Bundle/FrameworkBundle/Resources/config/messenger.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@
201201
->set('messenger.listener.reset_services', ResetServicesListener::class)
202202
->args([
203203
service('services_resetter'),
204-
abstract_arg('receivers names'),
205204
])
206205

207206
->set('messenger.routable_message_bus', RoutableMessageBus::class)

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,25 @@ public function testMessenger()
746746
$this->assertSame('messenger.listener.reset_services', (string) $container->getDefinition('console.command.messenger_consume_messages')->getArgument(5));
747747
}
748748

749+
public function testMessengerWithoutConsole()
750+
{
751+
$extension = $this->createPartialMock(FrameworkExtension::class, ['hasConsole', 'getAlias']);
752+
$extension->method('hasConsole')->willReturn(false);
753+
$extension->method('getAlias')->willReturn((new FrameworkExtension())->getAlias());
754+
755+
$container = $this->createContainerFromFile('messenger', [], true, false, $extension);
756+
$container->compile();
757+
758+
$this->assertFalse($container->hasDefinition('console.command.messenger_consume_messages'));
759+
$this->assertTrue($container->hasAlias('messenger.default_bus'));
760+
$this->assertTrue($container->getAlias('messenger.default_bus')->isPublic());
761+
$this->assertTrue($container->hasDefinition('messenger.transport.amqp.factory'));
762+
$this->assertTrue($container->hasDefinition('messenger.transport.redis.factory'));
763+
$this->assertTrue($container->hasDefinition('messenger.transport_factory'));
764+
$this->assertSame(TransportFactory::class, $container->getDefinition('messenger.transport_factory')->getClass());
765+
$this->assertFalse($container->hasDefinition('messenger.listener.reset_services'));
766+
}
767+
749768
public function testMessengerMultipleFailureTransports()
750769
{
751770
$container = $this->createContainerFromFile('messenger_multiple_failure_transports');
@@ -1960,14 +1979,14 @@ protected function createContainer(array $data = [])
19601979
], $data)));
19611980
}
19621981

1963-
protected function createContainerFromFile($file, $data = [], $resetCompilerPasses = true, $compile = true)
1982+
protected function createContainerFromFile($file, $data = [], $resetCompilerPasses = true, $compile = true, FrameworkExtension $extension = null)
19641983
{
19651984
$cacheKey = md5(static::class.$file.serialize($data));
19661985
if ($compile && isset(self::$containerCache[$cacheKey])) {
19671986
return self::$containerCache[$cacheKey];
19681987
}
19691988
$container = $this->createContainer($data);
1970-
$container->registerExtension(new FrameworkExtension());
1989+
$container->registerExtension($extension ?: new FrameworkExtension());
19711990
$this->loadFromFile($container, $file);
19721991

19731992
if ($resetCompilerPasses) {

src/Symfony/Component/Messenger/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CHANGELOG
88
* Add support for resetting container services after each messenger message.
99
* Added `WorkerMetadata` class which allows you to access the configuration details of a worker, like `queueNames` and `transportNames` it consumes from.
1010
* New method `getMetadata()` was added to `Worker` class which returns the `WorkerMetadata` object.
11+
* Deprecate not setting the `reset_on_message` config option, its default value will change to `true` in 6.0
1112

1213
5.3
1314
---

0 commit comments

Comments
 (0)
0