summaryrefslogtreecommitdiff
path: root/vendor/symfony/event-dispatcher/Tests/LegacyEventDispatcherProxyTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/symfony/event-dispatcher/Tests/LegacyEventDispatcherProxyTest.php')
-rw-r--r--vendor/symfony/event-dispatcher/Tests/LegacyEventDispatcherProxyTest.php63
1 files changed, 63 insertions, 0 deletions
diff --git a/vendor/symfony/event-dispatcher/Tests/LegacyEventDispatcherProxyTest.php b/vendor/symfony/event-dispatcher/Tests/LegacyEventDispatcherProxyTest.php
new file mode 100644
index 0000000000..09e5e927e1
--- /dev/null
+++ b/vendor/symfony/event-dispatcher/Tests/LegacyEventDispatcherProxyTest.php
@@ -0,0 +1,63 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\EventDispatcher\Tests;
+
+use Symfony\Component\EventDispatcher\Event;
+use Symfony\Component\EventDispatcher\EventDispatcher;
+use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
+use Symfony\Contracts\EventDispatcher\Event as ContractsEvent;
+
+/**
+ * @group legacy
+ */
+class LegacyEventDispatcherProxyTest extends EventDispatcherTest
+{
+ /**
+ * @group legacy
+ * @expectedDeprecation The signature of the "Symfony\Component\EventDispatcher\Tests\TestLegacyEventDispatcher::dispatch()" method should be updated to "dispatch($event, string $eventName = null)", not doing so is deprecated since Symfony 4.3.
+ * @expectedDeprecation Calling the "Symfony\Contracts\EventDispatcher\EventDispatcherInterface::dispatch()" method with the event name as the first argument is deprecated since Symfony 4.3, pass it as the second argument and provide the event object as the first argument instead.
+ */
+ public function testLegacySignatureWithoutEvent()
+ {
+ $this->createEventDispatcher()->dispatch('foo');
+ }
+
+ /**
+ * @group legacy
+ * @expectedDeprecation The signature of the "Symfony\Component\EventDispatcher\Tests\TestLegacyEventDispatcher::dispatch()" method should be updated to "dispatch($event, string $eventName = null)", not doing so is deprecated since Symfony 4.3.
+ * @expectedDeprecation Calling the "Symfony\Contracts\EventDispatcher\EventDispatcherInterface::dispatch()" method with the event name as the first argument is deprecated since Symfony 4.3, pass it as the second argument and provide the event object as the first argument instead.
+ */
+ public function testLegacySignatureWithEvent()
+ {
+ $this->createEventDispatcher()->dispatch('foo', new Event());
+ }
+
+ public function testLegacySignatureWithNewEventObject()
+ {
+ $this->expectException('TypeError');
+ $this->expectExceptionMessage('Argument 1 passed to "Symfony\Contracts\EventDispatcher\EventDispatcherInterface::dispatch()" must be an object, string given.');
+ $this->createEventDispatcher()->dispatch('foo', new ContractsEvent());
+ }
+
+ protected function createEventDispatcher()
+ {
+ return LegacyEventDispatcherProxy::decorate(new TestLegacyEventDispatcher());
+ }
+}
+
+class TestLegacyEventDispatcher extends EventDispatcher
+{
+ public function dispatch($eventName, Event $event = null)
+ {
+ return parent::dispatch($event, $eventName);
+ }
+}