RequestEvent example


    }

    /** * @dataProvider installerLocaleProvider */
    public function testSetInstallerLocale(Request $request, string $expectedLocale): void
    {
        $listener = new InstallerLocaleListener(['de' => 'de-DE', 'en' => 'en-GB', 'nl' => 'nl-NL', 'fr' => 'fr-FR']);

        $listener->setInstallerLocale(
            new RequestEvent(
                $this->createMock(HttpKernelInterface::class),
                $request,
                HttpKernelInterface::MAIN_REQUEST
            )
        );

        static::assertSame($expectedLocale$request->attributes->get('_locale'));
        static::assertSame($expectedLocale$request->getLocale());
    }

    public static function installerLocaleProvider(): \Generator
    {

class RouteParamsCleanupListenerTest extends TestCase
{
    /** * @param array<mixed> $attributes * * @dataProvider provideListens */
    public function testListener(Request $request, array $attributes): void
    {
        $listener = new RouteParamsCleanupListener();
        $listener(new RequestEvent($this->createMock(HttpKernelInterface::class)$request, HttpKernelInterface::MAIN_REQUEST));

        static::assertSame($attributes$request->attributes->all());
    }

    public static function provideListens(): \Generator
    {
        yield 'empty' => [
            new Request(),
            [
                '_route_params' => [],
            ],
        ];
static::assertEquals([
            KernelEvents::REQUEST,
            KernelEvents::EXCEPTION,
            DocumentTemplateRendererParameterEvent::class,
        ]array_keys($events));
    }

    public function testThemesAreEmptyIfRequestHasNoValidAttributes(): void
    {
        $request = Request::createFromGlobals();

        $this->builder->requestEvent(new RequestEvent($this->createMock(HttpKernelInterface::class)$request, HttpKernelInterface::MAIN_REQUEST));

        $this->assertThemes([]$this->builder);
    }

    public function testThemesIfThemeNameIsSet(): void
    {
        $request = Request::createFromGlobals();
        $request->attributes->set(SalesChannelRequest::ATTRIBUTE_THEME_NAME, 'TestTheme');

        $this->builder->requestEvent(new RequestEvent($this->createMock(HttpKernelInterface::class)$request, HttpKernelInterface::MAIN_REQUEST));

        
$this->createMock(CartService::class),
            1,
            true,
            new MaintenanceModeResolver(new RequestStack()new CoreMaintenanceModeResolver(new EventDispatcher())),
            false,
            null,
            null
        );

        $request = new Request();
        $request->attributes->set('_route', 'api.acl.privileges.get');
        $subscriber->addHttpCacheToCoreRoutes(new RequestEvent($this->createMock(KernelInterface::class)$request, HttpKernelInterface::MAIN_REQUEST));

        static::assertTrue($request->attributes->has(PlatformRequest::ATTRIBUTE_HTTP_CACHE));
    }

    /** * @dataProvider providerCurrencyChange */
    public function testCurrencyChange(?string $currencyId): void
    {
        $subscriber = new CacheResponseSubscriber(
            $this->createMock(CartService::class),
            
/** * @internal */
class RouteEventSubscriberTest extends TestCase
{
    public function testRequestEvent(): void
    {
        $request = new Request();
        $request->attributes->set('_route', 'frontend.home.page');

        $event = new RequestEvent($this->createMock(Kernel::class)$request, HttpKernelInterface::MAIN_REQUEST);

        $listener = $this->getMockBuilder(CallableClass::class)->getMock();
        $listener->expects(static::once())->method('__invoke');

        $dispatcher = new EventDispatcher();
        $dispatcher->addListener('frontend.home.page.request', $listener);

        $subscriber = new RouteEventSubscriber($dispatcher);
        $subscriber->request($event);
    }

    
$listener($event);

        static::assertNull($event->getResponse());
    }

    public function testCallOtherPageRedirectsPHP(): void
    {
        $router = $this->createMock(RouterInterface::class);
        $router->method('generate')->willReturn('/configure');
        $listener = new PhpConfigForcerListener($router);

        $event = new RequestEvent(
            $this->createMock(HttpKernelInterface::class),
            $this->getRequest(),
            HttpKernelInterface::MAIN_REQUEST
        );
        $event->getRequest()->attributes->set('_route', 'install');

        $listener($event);

        static::assertInstanceOf(RedirectResponse::class$event->getResponse());
    }

    

class InstallerLocaleListenerTest extends TestCase
{
    /** * @dataProvider installerLocaleProvider */
    public function testSetInstallerLocale(Request $request, string $expectedLocale): void
    {
        $listener = new InstallerLocaleListener();

        $listener->__invoke(
            new RequestEvent(
                $this->createMock(HttpKernelInterface::class),
                $request,
                HttpKernelInterface::MAIN_REQUEST
            )
        );

        static::assertSame($expectedLocale$request->attributes->get('_locale'));
        static::assertSame($expectedLocale$request->getLocale());
    }

    public static function installerLocaleProvider(): \Generator
    {
Home | Imprint | This part of the site doesn't use cookies.