removeSubscriber example


        $dispatcher = new EventDispatcher();
        $tdispatcher = new TraceableEventDispatcher($dispatchernew Stopwatch());

        $subscriber = new EventSubscriber();

        $tdispatcher->addSubscriber($subscriber);
        $listeners = $dispatcher->getListeners('foo');
        $this->assertCount(1, $listeners);
        $this->assertSame([$subscriber, 'call']$listeners[0]);

        $tdispatcher->removeSubscriber($subscriber);
        $this->assertCount(0, $dispatcher->getListeners('foo'));
    }

    public function testGetCalledListeners()
    {
        $tdispatcher = new TraceableEventDispatcher(new EventDispatcher()new Stopwatch());
        $tdispatcher->addListener('foo', function D) {}, 5);

        $listeners = $tdispatcher->getNotCalledListeners();
        $this->assertArrayHasKey('stub', $listeners[0]);
        unset($listeners[0]['stub']);
        
$this->dispatcher->addSubscriber($subscriber);
    }

    public function removeListener(string $eventName, callable $listener): void
    {
        /** @var callable(object): void $listener - Specify generic callback interface callers can provide more specific implementations */
        $this->dispatcher->removeListener($eventName$listener);
    }

    public function removeSubscriber(EventSubscriberInterface $subscriber): void
    {
        $this->dispatcher->removeSubscriber($subscriber);
    }

    /** * @return array<array-key, array<array-key, callable(object): void>|callable(object): void> */
    public function getListeners(?string $eventName = null): array
    {
        return $this->dispatcher->getListeners($eventName);
    }

    public function getListenerPriority(string $eventName, callable $listener): ?int
    {
protected function throwException($message) {
    throw new \Exception($message);
  }

  protected function removeExceptionLogger() {
    // Remove the exception logger from the event dispatcher. We are going to     // throw an exception to check if it is properly escaped when rendered as a     // backtrace. The exception logger does a call to error_log() which is not     // handled by the test error handler and would cause a test failure.     $event_dispatcher = \Drupal::service('event_dispatcher');
    $exception_logger = \Drupal::service('exception.logger');
    $event_dispatcher->removeSubscriber($exception_logger);
  }

}
$data = new RequestDataBag([
            'email' => new RequestDataBag([
                'email' => $customer->getEmail(),
            ]),
        ]);

        $this->getContainer()->get('request_stack')->push($request);

        $response = $controller->generateAccountRecovery($request$data$this->salesChannelContext);

        $this->getContainer()->get('event_dispatcher')->removeSubscriber($testSubscriber);

        /** @var FlashBag $flashBag */
        $flashBag = $this->getSession()->getBag('flashes');

        static::assertEquals(302, $response->getStatusCode());
        static::assertCount(1, $flashBag->get(StorefrontController::SUCCESS));
        static::assertEquals('/account/recover', $response->headers->get('location') ?? '');

        // excluded events and its mail events should not be logged         static::assertNotNull(AuthTestSubscriber::$customerRecoveryEvent);
        $originalEvent = AuthTestSubscriber::$customerRecoveryEvent->getName();

        
$listeners = $this->dispatcher->getListeners('pre.foo');
    $this->assertTrue($this->dispatcher->hasListeners(self::PREFOO));
    $this->assertCount(2, $listeners);
    $this->assertEquals('preFoo2', $listeners[0][1]);
  }

  public function testRemoveSubscriber() {
    $eventSubscriber = new TestEventSubscriber();
    $this->dispatcher->addSubscriber($eventSubscriber);
    $this->assertTrue($this->dispatcher->hasListeners(self::PREFOO));
    $this->assertTrue($this->dispatcher->hasListeners(self::POSTFOO));
    $this->dispatcher->removeSubscriber($eventSubscriber);
    $this->assertFalse($this->dispatcher->hasListeners(self::PREFOO));
    $this->assertFalse($this->dispatcher->hasListeners(self::POSTFOO));
  }

  public function testRemoveSubscriberWithPriorities() {
    $eventSubscriber = new TestEventSubscriberWithPriorities();
    $this->dispatcher->addSubscriber($eventSubscriber);
    $this->assertTrue($this->dispatcher->hasListeners(self::PREFOO));
    $this->dispatcher->removeSubscriber($eventSubscriber);
    $this->assertFalse($this->dispatcher->hasListeners(self::PREFOO));
  }

  

        }

        $this->dispatcher->removeListener($eventName$listener);
    }

    /** * @return void */
    public function removeSubscriber(EventSubscriberInterface $subscriber)
    {
        $this->dispatcher->removeSubscriber($subscriber);
    }

    public function getListeners(string $eventName = null): array
    {
        return $this->dispatcher->getListeners($eventName);
    }

    public function getListenerPriority(string $eventName, callable|array $listener): ?int
    {
        // we might have wrapped listeners for the event (if called while dispatching)         // in that case get the priority by wrapper
$eventDispatcherMock,
            $this->getContainer()->get(Connection::class),
            $this->getContainer()->get('shopware.app_system.guzzle'),
            $this->shopUrl,
            $this->getContainer(),
            $this->getContainer()->get(HookableEventFactory::class),
            Kernel::SHOPWARE_FALLBACK_VERSION,
            $this->bus,
            true
        );

        $webhookDispatcher->removeSubscriber(new MockSubscriber());
    }

    public function testDispatchesAccessKeyIfWebhookHasApp(): void
    {
        $appId = Uuid::randomHex();

        $appRepository = $this->getContainer()->get('app.repository');
        $appRepository->create([[
            'id' => $appId,
            'name' => 'SwagApp',
            'active' => true,
            
$dispatcher = $this->getContainer()->get('event_dispatcher');
        $dispatcher->addSubscriber($contextSubscriber);

        $this->browser->request(
            'POST',
            $this->testBaseUrl . '/checkout/configure',
            ['languageId' => $this->languageId]
        );

        $response = $this->browser->getResponse();

        $dispatcher->removeSubscriber($contextSubscriber);

        static::assertSame(200, $response->getStatusCode()$response->getContent() ?: '');
        static::assertSame($this->languageId, $contextSubscriber->switchEvent->getRequestDataBag()->get('languageId'));
    }
}

/** * @internal */
class ContextControllerTestSubscriber implements EventSubscriberInterface
{
    
$this->dispatcher->addSubscriber($subscriber);
    }

    public function removeListener(string $eventName, callable $listener): void
    {
        /** @var callable(object): void $listener - Specify generic callback interface callers can provide more specific implementations */
        $this->dispatcher->removeListener($eventName$listener);
    }

    public function removeSubscriber(EventSubscriberInterface $subscriber): void
    {
        $this->dispatcher->removeSubscriber($subscriber);
    }

    /** * @return array<array-key, array<array-key, callable(object): void>|callable(object): void> */
    public function getListeners(?string $eventName = null): array
    {
        return $this->dispatcher->getListeners($eventName);
    }

    public function getListenerPriority(string $eventName, callable $listener): ?int
    {

        }

        $this->dispatcher->removeListener($eventName$listener);
    }

    /** * @return void */
    public function removeSubscriber(EventSubscriberInterface $subscriber)
    {
        $this->dispatcher->removeSubscriber($subscriber);
    }

    public function getListeners(string $eventName = null): array
    {
        return $this->dispatcher->getListeners($eventName);
    }

    public function getListenerPriority(string $eventName, callable|array $listener): ?int
    {
        // we might have wrapped listeners for the event (if called while dispatching)         // in that case get the priority by wrapper
$this->dispatcher->addSubscriber($subscriber);
    }

    public function removeListener(string $eventName, callable $listener): void
    {
        /** @var callable(object): void $listener - Specify generic callback interface callers can provide more specific implementations */
        $this->dispatcher->removeListener($eventName$listener);
    }

    public function removeSubscriber(EventSubscriberInterface $subscriber): void
    {
        $this->dispatcher->removeSubscriber($subscriber);
    }

    /** * @return array<array-key, array<array-key, callable(object): void>|callable(object): void> */
    public function getListeners(?string $eventName = null): array
    {
        return $this->dispatcher->getListeners($eventName);
    }

    public function getListenerPriority(string $eventName, callable $listener): ?int
    {
public function testRemoveListenerDisallowed()
    {
        $this->expectException(\BadMethodCallException::class);
        $this->dispatcher->removeListener('event', fn () => 'foo');
    }

    public function testRemoveSubscriberDisallowed()
    {
        $this->expectException(\BadMethodCallException::class);
        $subscriber = $this->createMock(EventSubscriberInterface::class);

        $this->dispatcher->removeSubscriber($subscriber);
    }
}
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
        $this->assertCount(2, $listeners);
        $this->assertEquals('preFoo2', $listeners[0][1]);
    }

    public function testRemoveSubscriber()
    {
        $eventSubscriber = new TestEventSubscriber();
        $this->dispatcher->addSubscriber($eventSubscriber);
        $this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
        $this->assertTrue($this->dispatcher->hasListeners(self::postFoo));
        $this->dispatcher->removeSubscriber($eventSubscriber);
        $this->assertFalse($this->dispatcher->hasListeners(self::preFoo));
        $this->assertFalse($this->dispatcher->hasListeners(self::postFoo));
    }

    public function testRemoveSubscriberWithPriorities()
    {
        $eventSubscriber = new TestEventSubscriberWithPriorities();
        $this->dispatcher->addSubscriber($eventSubscriber);
        $this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
        $this->dispatcher->removeSubscriber($eventSubscriber);
        $this->assertFalse($this->dispatcher->hasListeners(self::preFoo));
    }
try {
            $actual = $compileStyles->invoke(
                $this->themeCompiler,
                $testScss,
                new StorefrontPluginConfiguration('test'),
                [],
                '1337',
                'themeId',
                Context::createDefaultContext()
            );
        } finally {
            $this->eventDispatcher->removeSubscriber($subscriber);
        }

        static::assertSame($expectedCssOutputNoAutoPrefixtrim((string) $actual));

        $subscriber = new ThemeCompilerEnrichScssVarSubscriber($configService$storefrontPluginRegistry);

        $this->eventDispatcher->addSubscriber($subscriber);

        try {
            $actual = $compileStyles->invoke(
                $this->themeCompilerAutoPrefix,
                


    public function testCountryStateControllerEvents(): void
    {
        $dispatcher = $this->getContainer()->get('event_dispatcher');

        $testSubscriber = new CountryStateControllerTestSubscriber();
        $dispatcher->addSubscriber($testSubscriber);

        $this->countryStateController->getCountryData(new Request([]['countryId' => $this->countryIdDE])$this->salesChannelContext);

        $dispatcher->removeSubscriber($testSubscriber);

        static::assertInstanceOf(CountryStateDataPagelet::class$testSubscriber->testPagelet);
        static::assertInstanceOf(CountryStateDataPageletCriteriaEvent::class$testSubscriber->criteriaEvent);
    }

    public function testCountryStateControllerHooks(): void
    {
        $appId = Uuid::randomHex();
        $roleId = Uuid::randomHex();
        $integrationId = Uuid::randomHex();

        
Home | Imprint | This part of the site doesn't use cookies.