Skip to content

Commit 5992aaa

Browse files
alamiraultnicolas-grekas
authored andcommitted
[DoctrineBridge] Improve subscriber deprecation message
1 parent ae613a8 commit 5992aaa

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

ContainerAwareEventManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ private function initializeSubscribers(): void
189189
$listener = $this->container->get($listener);
190190
}
191191
// throw new \InvalidArgumentException(sprintf('Using Doctrine subscriber "%s" is not allowed, declare it as a listener instead.', \is_object($listener) ? $listener::class : $listener));
192-
trigger_deprecation('symfony/doctrine-bridge', '6.3', 'Using Doctrine subscribers as services is deprecated, declare listeners instead');
192+
trigger_deprecation('symfony/doctrine-bridge', '6.3', 'Registering "%s" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[AsDoctrineListener] attribute.', \is_object($listener) ? get_debug_type($listener) : $listener);
193193
parent::addEventSubscriber($listener);
194194
}
195195
}

DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private function addTaggedServices(ContainerBuilder $container): array
106106
$refs = $managerDef->getArguments()[1] ?? [];
107107
$listenerRefs[$con][$id] = new Reference($id);
108108
if ($subscriberTag === $tagName) {
109-
trigger_deprecation('symfony/doctrine-bridge', '6.3', 'Using Doctrine subscribers as services is deprecated, declare listeners instead');
109+
trigger_deprecation('symfony/doctrine-bridge', '6.3', 'Registering "%s" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[AsDoctrineListener] attribute.', $id);
110110
$refs[] = $id;
111111
} else {
112112
$refs[] = [[$tag['event']], $id];

Tests/ContainerAwareEventManagerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function testDispatchEventRespectOrderWithSubscribers()
5050
$this->container->set('sub1', $subscriber1 = new MySubscriber(['foo']));
5151
$this->container->set('sub2', $subscriber2 = new MySubscriber(['foo']));
5252

53-
$this->expectDeprecation('Since symfony/doctrine-bridge 6.3: Using Doctrine subscribers as services is deprecated, declare listeners instead');
53+
$this->expectDeprecation('Since symfony/doctrine-bridge 6.3: Registering "Symfony\Bridge\Doctrine\Tests\MySubscriber" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[AsDoctrineListener] attribute.');
5454
$this->assertSame([$subscriber1, $subscriber2], array_values($this->evm->getListeners('foo')));
5555
}
5656

@@ -92,7 +92,7 @@ public function testDispatchEventWithSubscribers()
9292
$this->assertSame(0, $subscriber1->calledSubscribedEventsCount);
9393

9494
$this->container->set('lazy1', $listener1 = new MyListener());
95-
$this->expectDeprecation('Since symfony/doctrine-bridge 6.3: Using Doctrine subscribers as services is deprecated, declare listeners instead');
95+
$this->expectDeprecation('Since symfony/doctrine-bridge 6.3: Registering "Symfony\Bridge\Doctrine\Tests\MySubscriber" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[AsDoctrineListener] attribute.');
9696
$this->evm->addEventListener('foo', 'lazy1');
9797
$this->evm->addEventListener('foo', $listener2 = new MyListener());
9898
$this->evm->addEventSubscriber($subscriber2 = new MySubscriber(['bar']));
@@ -177,7 +177,7 @@ public function testAddEventListenerAndSubscriberAfterDispatchEvent()
177177
$this->assertSame(0, $subscriber1->calledSubscribedEventsCount);
178178

179179
$this->container->set('lazy1', $listener1 = new MyListener());
180-
$this->expectDeprecation('Since symfony/doctrine-bridge 6.3: Using Doctrine subscribers as services is deprecated, declare listeners instead');
180+
$this->expectDeprecation('Since symfony/doctrine-bridge 6.3: Registering "Symfony\Bridge\Doctrine\Tests\MySubscriber" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[AsDoctrineListener] attribute.');
181181
$this->evm->addEventListener('foo', 'lazy1');
182182
$this->assertSame(1, $subscriber1->calledSubscribedEventsCount);
183183

@@ -238,7 +238,7 @@ public function testGetListenersForEventWhenSubscribersArePresent()
238238

239239
$this->container->set('lazy', $listener1 = new MyListener());
240240
$this->container->set('lazy2', $subscriber1 = new MySubscriber(['foo']));
241-
$this->expectDeprecation('Since symfony/doctrine-bridge 6.3: Using Doctrine subscribers as services is deprecated, declare listeners instead');
241+
$this->expectDeprecation('Since symfony/doctrine-bridge 6.3: Registering "Symfony\Bridge\Doctrine\Tests\MySubscriber" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[AsDoctrineListener] attribute.');
242242
$this->evm->addEventListener('foo', 'lazy');
243243
$this->evm->addEventListener('foo', $listener2 = new MyListener());
244244

Tests/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPassTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public function testProcessEventSubscribersWithMultipleConnections()
238238
])
239239
;
240240

241-
$this->expectDeprecation('Since symfony/doctrine-bridge 6.3: Using Doctrine subscribers as services is deprecated, declare listeners instead');
241+
$this->expectDeprecation('Since symfony/doctrine-bridge 6.3: Registering "d" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[AsDoctrineListener] attribute.');
242242
$this->process($container);
243243

244244
$eventManagerDef = $container->getDefinition('doctrine.dbal.default_connection.event_manager');
@@ -322,7 +322,7 @@ public function testProcessEventSubscribersWithPriorities()
322322
])
323323
;
324324

325-
$this->expectDeprecation('Since symfony/doctrine-bridge 6.3: Using Doctrine subscribers as services is deprecated, declare listeners instead');
325+
$this->expectDeprecation('Since symfony/doctrine-bridge 6.3: Registering "d" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[AsDoctrineListener] attribute.');
326326
$this->process($container);
327327

328328
$eventManagerDef = $container->getDefinition('doctrine.dbal.default_connection.event_manager');
@@ -416,7 +416,7 @@ public function testProcessEventSubscribersAndListenersWithPriorities()
416416
])
417417
;
418418

419-
$this->expectDeprecation('Since symfony/doctrine-bridge 6.3: Using Doctrine subscribers as services is deprecated, declare listeners instead');
419+
$this->expectDeprecation('Since symfony/doctrine-bridge 6.3: Registering "d" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[AsDoctrineListener] attribute.');
420420
$this->process($container);
421421

422422
$eventManagerDef = $container->getDefinition('doctrine.dbal.default_connection.event_manager');

0 commit comments

Comments
 (0)