Skip to content

Commit

Permalink
Merge branch '5.4' into 6.2
Browse files Browse the repository at this point in the history
* 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'
  • Loading branch information
nicolas-grekas committed Mar 20, 2023
2 parents 0b7e351 + 1df20e4 commit 04046f3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Debug/WrappedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,12 @@ public function __invoke(object $event, string $eventName, EventDispatcherInterf

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

($this->optimizedListener ?? $this->listener)($event, $eventName, $dispatcher);

if ($e->isStarted()) {
$e->stop();
try {
($this->optimizedListener ?? $this->listener)($event, $eventName, $dispatcher);
} finally {
if ($e->isStarted()) {
$e->stop();
}
}

if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
Expand Down
20 changes: 20 additions & 0 deletions Tests/Debug/WrappedListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\EventDispatcher\Debug\WrappedListener;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Component\Stopwatch\StopwatchEvent;

class WrappedListenerTest extends TestCase
{
Expand Down Expand Up @@ -43,6 +44,25 @@ public static function provideListenersToDescribe()
[[#[\Closure(name: FooListener::class)] static fn () => new FooListener(), 'listen'], 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listen'],
];
}

public function testStopwatchEventIsStoppedWhenListenerThrows()
{
$stopwatchEvent = $this->createMock(StopwatchEvent::class);
$stopwatchEvent->expects(self::once())->method('isStarted')->willReturn(true);
$stopwatchEvent->expects(self::once())->method('stop');

$stopwatch = $this->createStub(Stopwatch::class);
$stopwatch->method('start')->willReturn($stopwatchEvent);

$dispatcher = $this->createStub(EventDispatcherInterface::class);

$wrappedListener = new WrappedListener(function () { throw new \Exception(); }, null, $stopwatch, $dispatcher);

try {
$wrappedListener(new \stdClass(), 'foo', $dispatcher);
} catch (\Exception $ex) {
}
}
}

class FooListener
Expand Down

0 comments on commit 04046f3

Please sign in to comment.