summaryrefslogtreecommitdiff
path: root/vendor/symfony/event-dispatcher/Tests/LegacyEventDispatcherTest.php
blob: 30bd0c33463bd85f9d3cdbd00e7cde157005e506 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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 LegacyEventDispatcherTest 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);
    }
}