Skip to content

Commit 04046f3

Browse files
Merge branch '5.4' into 6.2
* 5.4: re-allow phpdocumentor/type-resolver 1.7 skip test using attributes on PHP 7 [HttpClient] Encode and decode curly brackets {} fix: GetSetMethodNormalizer::supportss should not check ignored methods Stop stopwatch events in case of exception add translations for the filename max length validator option [Validator] Update BIC validator IBAN mappings [String] Correct inflection of 'codes' and 'names'
2 parents 0b7e351 + 1df20e4 commit 04046f3

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

Debug/WrappedListener.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,12 @@ public function __invoke(object $event, string $eventName, EventDispatcherInterf
112112

113113
$e = $this->stopwatch->start($this->name, 'event_listener');
114114

115-
($this->optimizedListener ?? $this->listener)($event, $eventName, $dispatcher);
116-
117-
if ($e->isStarted()) {
118-
$e->stop();
115+
try {
116+
($this->optimizedListener ?? $this->listener)($event, $eventName, $dispatcher);
117+
} finally {
118+
if ($e->isStarted()) {
119+
$e->stop();
120+
}
119121
}
120122

121123
if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) {

Tests/Debug/WrappedListenerTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\EventDispatcher\Debug\WrappedListener;
1616
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1717
use Symfony\Component\Stopwatch\Stopwatch;
18+
use Symfony\Component\Stopwatch\StopwatchEvent;
1819

1920
class WrappedListenerTest extends TestCase
2021
{
@@ -43,6 +44,25 @@ public static function provideListenersToDescribe()
4344
[[#[\Closure(name: FooListener::class)] static fn () => new FooListener(), 'listen'], 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listen'],
4445
];
4546
}
47+
48+
public function testStopwatchEventIsStoppedWhenListenerThrows()
49+
{
50+
$stopwatchEvent = $this->createMock(StopwatchEvent::class);
51+
$stopwatchEvent->expects(self::once())->method('isStarted')->willReturn(true);
52+
$stopwatchEvent->expects(self::once())->method('stop');
53+
54+
$stopwatch = $this->createStub(Stopwatch::class);
55+
$stopwatch->method('start')->willReturn($stopwatchEvent);
56+
57+
$dispatcher = $this->createStub(EventDispatcherInterface::class);
58+
59+
$wrappedListener = new WrappedListener(function () { throw new \Exception(); }, null, $stopwatch, $dispatcher);
60+
61+
try {
62+
$wrappedListener(new \stdClass(), 'foo', $dispatcher);
63+
} catch (\Exception $ex) {
64+
}
65+
}
4666
}
4767

4868
class FooListener

0 commit comments

Comments
 (0)