Skip to content

Commit 9930140

Browse files
committed
Merge branch '7.4' into 8.0
* 7.4: do not use PHPUnit mock objects without configured expectations fix test do not use PHPUnit mock objects without configured expectations do not use PHPUnit mock objects without configured expectations do not use PHPUnit mock objects without configured expectations
2 parents 573f957 + dc2c0eb commit 9930140

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

Tests/Debug/WrappedListenerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\Attributes\DataProvider;
1515
use PHPUnit\Framework\TestCase;
1616
use Symfony\Component\EventDispatcher\Debug\WrappedListener;
17+
use Symfony\Component\EventDispatcher\EventDispatcher;
1718
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1819
use Symfony\Component\Stopwatch\Stopwatch;
1920
use Symfony\Component\Stopwatch\StopwatchEvent;
@@ -23,7 +24,7 @@ class WrappedListenerTest extends TestCase
2324
#[DataProvider('provideListenersToDescribe')]
2425
public function testListenerDescription($listener, $expected)
2526
{
26-
$wrappedListener = new WrappedListener($listener, null, $this->createMock(Stopwatch::class), $this->createMock(EventDispatcherInterface::class));
27+
$wrappedListener = new WrappedListener($listener, null, new Stopwatch(), new EventDispatcher());
2728

2829
$this->assertStringMatchesFormat($expected, $wrappedListener->getPretty());
2930
}

Tests/ImmutableEventDispatcherTest.php

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
namespace Symfony\Component\EventDispatcher\Tests;
1313

14-
use PHPUnit\Framework\MockObject\MockObject;
1514
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\EventDispatcher\EventDispatcher;
1616
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1717
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1818
use Symfony\Component\EventDispatcher\ImmutableEventDispatcher;
@@ -23,73 +23,81 @@
2323
*/
2424
class ImmutableEventDispatcherTest extends TestCase
2525
{
26-
private MockObject&EventDispatcherInterface $innerDispatcher;
27-
private ImmutableEventDispatcher $dispatcher;
28-
29-
protected function setUp(): void
30-
{
31-
$this->innerDispatcher = $this->createMock(EventDispatcherInterface::class);
32-
$this->dispatcher = new ImmutableEventDispatcher($this->innerDispatcher);
33-
}
34-
3526
public function testDispatchDelegates()
3627
{
28+
$innerDispatcher = $this->createMock(EventDispatcherInterface::class);
29+
$dispatcher = new ImmutableEventDispatcher($innerDispatcher);
30+
3731
$event = new Event();
3832
$resultEvent = new Event();
3933

40-
$this->innerDispatcher->expects($this->once())
34+
$innerDispatcher->expects($this->once())
4135
->method('dispatch')
4236
->with($event, 'event')
4337
->willReturn($resultEvent);
4438

45-
$this->assertSame($resultEvent, $this->dispatcher->dispatch($event, 'event'));
39+
$this->assertSame($resultEvent, $dispatcher->dispatch($event, 'event'));
4640
}
4741

4842
public function testGetListenersDelegates()
4943
{
50-
$this->innerDispatcher->expects($this->once())
44+
$innerDispatcher = $this->createMock(EventDispatcherInterface::class);
45+
$dispatcher = new ImmutableEventDispatcher($innerDispatcher);
46+
47+
$innerDispatcher->expects($this->once())
5148
->method('getListeners')
5249
->with('event')
5350
->willReturn(['result']);
5451

55-
$this->assertSame(['result'], $this->dispatcher->getListeners('event'));
52+
$this->assertSame(['result'], $dispatcher->getListeners('event'));
5653
}
5754

5855
public function testHasListenersDelegates()
5956
{
60-
$this->innerDispatcher->expects($this->once())
57+
$innerDispatcher = $this->createMock(EventDispatcherInterface::class);
58+
$dispatcher = new ImmutableEventDispatcher($innerDispatcher);
59+
60+
$innerDispatcher->expects($this->once())
6161
->method('hasListeners')
6262
->with('event')
6363
->willReturn(true);
6464

65-
$this->assertTrue($this->dispatcher->hasListeners('event'));
65+
$this->assertTrue($dispatcher->hasListeners('event'));
6666
}
6767

6868
public function testAddListenerDisallowed()
6969
{
70+
$dispatcher = new ImmutableEventDispatcher(new EventDispatcher());
71+
7072
$this->expectException(\BadMethodCallException::class);
71-
$this->dispatcher->addListener('event', fn () => 'foo');
73+
$dispatcher->addListener('event', fn () => 'foo');
7274
}
7375

7476
public function testAddSubscriberDisallowed()
7577
{
78+
$dispatcher = new ImmutableEventDispatcher(new EventDispatcher());
79+
7680
$this->expectException(\BadMethodCallException::class);
77-
$subscriber = $this->createMock(EventSubscriberInterface::class);
81+
$subscriber = $this->createStub(EventSubscriberInterface::class);
7882

79-
$this->dispatcher->addSubscriber($subscriber);
83+
$dispatcher->addSubscriber($subscriber);
8084
}
8185

8286
public function testRemoveListenerDisallowed()
8387
{
88+
$dispatcher = new ImmutableEventDispatcher(new EventDispatcher());
89+
8490
$this->expectException(\BadMethodCallException::class);
85-
$this->dispatcher->removeListener('event', fn () => 'foo');
91+
$dispatcher->removeListener('event', fn () => 'foo');
8692
}
8793

8894
public function testRemoveSubscriberDisallowed()
8995
{
96+
$dispatcher = new ImmutableEventDispatcher(new EventDispatcher());
97+
9098
$this->expectException(\BadMethodCallException::class);
91-
$subscriber = $this->createMock(EventSubscriberInterface::class);
99+
$subscriber = $this->createStub(EventSubscriberInterface::class);
92100

93-
$this->dispatcher->removeSubscriber($subscriber);
101+
$dispatcher->removeSubscriber($subscriber);
94102
}
95103
}

0 commit comments

Comments
 (0)