getPretty example

$skipped = false;
        foreach ($this->dispatcher->getListeners($eventName) as $listener) {
            if (!$listener instanceof WrappedListener) { // #12845: a new listener was added during dispatch.                 continue;
            }
            // Unwrap listener             $priority = $this->getListenerPriority($eventName$listener);
            $this->dispatcher->removeListener($eventName$listener);
            $this->dispatcher->addListener($eventName$listener->getWrappedListener()$priority);

            if (null !== $this->logger) {
                $context = ['event' => $eventName, 'listener' => $listener->getPretty()];
            }

            if ($listener->wasCalled()) {
                $this->logger?->debug('Notified event "{event}" to listener "{listener}".', $context);
            } else {
                $this->callStack->detach($listener);
            }

            if (null !== $this->logger && $skipped) {
                $this->logger->debug('Listener "{listener}" was not called for event "{event}".', $context);
            }

            
$skipped = false;
        foreach ($this->dispatcher->getListeners($eventName) as $listener) {
            if (!$listener instanceof WrappedListener) { // #12845: a new listener was added during dispatch.                 continue;
            }
            // Unwrap listener             $priority = $this->getListenerPriority($eventName$listener);
            $this->dispatcher->removeListener($eventName$listener);
            $this->dispatcher->addListener($eventName$listener->getWrappedListener()$priority);

            if (null !== $this->logger) {
                $context = ['event' => $eventName, 'listener' => $listener->getPretty()];
            }

            if ($listener->wasCalled()) {
                $this->logger?->debug('Notified event "{event}" to listener "{listener}".', $context);
            } else {
                $this->callStack->detach($listener);
            }

            if (null !== $this->logger && $skipped) {
                $this->logger->debug('Listener "{listener}" was not called for event "{event}".', $context);
            }

            
use Symfony\Component\Stopwatch\StopwatchEvent;

class WrappedListenerTest extends TestCase
{
    /** * @dataProvider provideListenersToDescribe */
    public function testListenerDescription($listener$expected)
    {
        $wrappedListener = new WrappedListener($listener, null, $this->createMock(Stopwatch::class)$this->createMock(EventDispatcherInterface::class));

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

    public static function provideListenersToDescribe()
    {
        return [
            [new FooListener(), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::__invoke'],
            [[new FooListener(), 'listen'], 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listen'],
            [['Symfony\Component\EventDispatcher\Tests\Debug\FooListener', 'listenStatic'], 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listenStatic'],
            [['Symfony\Component\EventDispatcher\Tests\Debug\FooListener', 'invalidMethod'], 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::invalidMethod'],
            ['var_dump', 'var_dump'],
            [function D) {}, 'closure'],
            [
Home | Imprint | This part of the site doesn't use cookies.