minor #33299 [EventDispatcher] Fix mocks for ImmutableEventDispatcher (derrabus)

This PR was merged into the 3.4 branch.

Discussion
----------

[EventDispatcher] Fix mocks for ImmutableEventDispatcher

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #33228
| License       | MIT
| Doc PR        | N/A

Backport from #33248. This PR fixes mocks that return values that are incompatible with the annotated return type.

Commits
-------

874aaea75f Fix mocks for ImmutableEventDispatcher.
This commit is contained in:
Nicolas Grekas 2019-08-23 12:00:53 +02:00
commit 1f7250139f

View File

@ -40,13 +40,14 @@ class ImmutableEventDispatcherTest extends TestCase
public function testDispatchDelegates() public function testDispatchDelegates()
{ {
$event = new Event(); $event = new Event();
$resultEvent = new Event();
$this->innerDispatcher->expects($this->once()) $this->innerDispatcher->expects($this->once())
->method('dispatch') ->method('dispatch')
->with('event', $event) ->with('event', $event)
->willReturn('result'); ->willReturn($resultEvent);
$this->assertSame('result', $this->dispatcher->dispatch('event', $event)); $this->assertSame($resultEvent, $this->dispatcher->dispatch('event', $event));
} }
public function testGetListenersDelegates() public function testGetListenersDelegates()
@ -54,9 +55,9 @@ class ImmutableEventDispatcherTest extends TestCase
$this->innerDispatcher->expects($this->once()) $this->innerDispatcher->expects($this->once())
->method('getListeners') ->method('getListeners')
->with('event') ->with('event')
->willReturn('result'); ->willReturn(['result']);
$this->assertSame('result', $this->dispatcher->getListeners('event')); $this->assertSame(['result'], $this->dispatcher->getListeners('event'));
} }
public function testHasListenersDelegates() public function testHasListenersDelegates()
@ -64,9 +65,9 @@ class ImmutableEventDispatcherTest extends TestCase
$this->innerDispatcher->expects($this->once()) $this->innerDispatcher->expects($this->once())
->method('hasListeners') ->method('hasListeners')
->with('event') ->with('event')
->willReturn('result'); ->willReturn(true);
$this->assertSame('result', $this->dispatcher->hasListeners('event')); $this->assertTrue($this->dispatcher->hasListeners('event'));
} }
public function testAddListenerDisallowed() public function testAddListenerDisallowed()