10000 minor #38233 [EventDispatcher] drop logger mock in favor of using the… · symfony/symfony@da644e6 · GitHub
[go: up one dir, main page]

Skip to content

Commit da644e6

Browse files
committed
minor #38233 [EventDispatcher] drop logger mock in favor of using the BufferingLogger (xabbuh)
This PR was merged into the 3.4 branch. Discussion ---------- [EventDispatcher] drop logger mock in favor of using the BufferingLogger | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | Fix #37808 (comment) | License | MIT | Doc PR | Commits ------- 86a7e32 drop logger mock in favor of using the BufferingLogger
2 parents 2eeb75d + 86a7e32 commit da644e6

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

src/Symfony/Component/EventDispatcher/Tests/Debug/TraceableEventDispatcherTest.php

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\EventDispatcher\Tests\Debug;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Debug\BufferingLogger;
1516
use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher;
1617
use Symfony\Component\EventDispatcher\Event;
1718
use Symfony\Component\EventDispatcher\EventDispatcher;
@@ -167,41 +168,57 @@ public function testGetCalledListenersNested()
167168

168169
public function testLogger()
169170
{
170-
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
171+
$logger = new BufferingLogger();
171172

172173
$dispatcher = new EventDispatcher();
173174
$tdispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch(), $logger);
174175
$tdispatcher->addListener('foo', $listener1 = function () {});
175176
$tdispatcher->addListener('foo', $listener2 = function () {});
176177

177-
$logger->expects($this->exactly(2))
178-
->method('debug')
179-
->withConsecutive(
180-
['Notified event "{event}" to listener "{listener}".', ['event' => 'foo', 'listener' => 'closure']],
181-
['Notified event "{event}" to listener "{listener}".', ['event' => 'foo', 'listener' => 'closure']]
182-
);
183-
184178
$tdispatcher->dispatch('foo');
179+
180+
$this->assertSame([
181+
[
182+
'debug',
183+
'Notified event "{event}" to listener "{listener}".',
184+
['event' => 'foo', 'listener' => 'closure'],
185+
],
186+
[
187+
'debug',
188+
'Notified event "{event}" to listener "{listener}".',
189+
['event' => 'foo', 'listener' => 'closure'],
190+
],
191+
], $logger->cleanLogs());
185192
}
186193

187194
public function testLoggerWithStoppedEvent()
188195
{
189-
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
196+
$logger = new BufferingLogger();
190197

191198
$dispatcher = new EventDispatcher();
192199
$tdispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch(), $logger);
193200
$tdispatcher->addListener('foo', $listener1 = function (Event $event) { $event->stopPropagation(); });
194201
$tdispatcher->addListener('foo', $listener2 = function () {});
195202

196-
$logger->expects($this->exactly(3))
197-
->method('debug')
198-
->withConsecutive(
199-
['Notified event "{event}" to listener "{listener}".', ['event' => 'foo', 'listener' => 'closure']],
200-
['Listener "{listener}" stopped propagation of the event "{event}".', ['event' => 'foo', 'listener' => 'closure']],
201-
['Listener "{listener}" was not called for event "{event}".', ['event' => 'foo', 'listener' => 'closure']]
202-
);
203-
204203
$tdispatcher->dispatch('foo');
204+
205+
$this->assertSame([
206+
[
207+
'debug',
208+
'Notified event "{event}" to listener "{listener}".',
209+
['event' => 'foo', 'listener' => 'closure'],
210+
],
211+
[
212+
'debug',
213+
'Listener "{listener}" stopped propagation of the event "{event}".',
214+
['event' => 'foo', 'listener' => 'closure'],
215+
],
216+
[
217+
'debug',
218+
'Listener "{listener}" was not called for event "{event}".',
219+
['event' => 'foo', 'listener' => 'closure'],
220+
],
221+
], $logger->cleanLogs());
205222
}
206223

207224
public function testDispatchCallListeners()

src/Symfony/Component/EventDispatcher/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"symfony/dependency-injection": "~3.3|~4.0",
2323
"symfony/expression-language": "~2.8|~3.0|~4.0",
2424
"symfony/config": "~2.8|~3.0|~4.0",
25+
"symfony/debug": "~3.4|~4.4",
2526
"symfony/stopwatch": "~2.8|~3.0|~4.0",
2627
"psr/log": "~1.0"
2728
},

0 commit comments

Comments
 (0)
0