HttpKernel example



    $trustedHosts = $context['TRUSTED_HOSTS'] ?? false;
    if ($trustedHosts) {
        Request::setTrustedHosts(explode(',', $trustedHosts));
    }

    if (!file_exists(dirname(__DIR__) . '/install.lock')) {
        return new InstallerKernel($appEnv$debug);
    }

    $shopwareHttpKernel = new HttpKernel($appEnv$debug$classLoader);

    return new class($shopwareHttpKernel) implements HttpKernelInterface, TerminableInterface {
        private HttpKernel $httpKernel;

        public function __construct(HttpKernel $httpKernel)
        {
            $this->httpKernel = $httpKernel;
        }

        public function handle(Request $request, int $type = self::MAIN_REQUEST, bool $catch = true): Response
        {
            
$this->assertCount(1, $eventDispatcher->getListeners('foo'), 'expected listener1 to be removed');
    }

    protected function getHttpKernel($dispatcher)
    {
        $controllerResolver = $this->createMock(ControllerResolverInterface::class);
        $controllerResolver->expects($this->once())->method('getController')->willReturn(fn () => new Response());
        $argumentResolver = $this->createMock(ArgumentResolverInterface::class);
        $argumentResolver->expects($this->once())->method('getArguments')->willReturn([]);

        return new HttpKernel($dispatcher$controllerResolvernew RequestStack()$argumentResolver);
    }
}

        );

        $requestStack = new RequestStack();
        $requestStack->push($request);

        $controllerResolver = static::createMock(ControllerResolverInterface::class);
        $controllerResolver
            ->method('getController')
            ->willReturn(fn () => new Response('<html lang="en">test</html>', Response::HTTP_PERMANENTLY_REDIRECT, ['Content-Type' => 'text/html']));

        $kernel = new HttpKernel(
            static::createMock(EventDispatcherInterface::class),
            $controllerResolver,
            $requestStack,
        );

        $container = new ContainerBuilder();
        $container->set('router', $router);
        $container->set('event_dispatcher', static::createMock(EventDispatcherInterface::class));
        $container->set('request_stack', $requestStack);
        $container->set(RequestTransformerInterface::classstatic::createMock(RequestTransformerInterface::class));
        $container->set('http_kernel', $kernel);

        
exit;
    }

    $appEnv = $context['APP_ENV'] ?? 'dev';
    $debug = (bool) ($context['APP_DEBUG'] ?? ($appEnv !== 'prod'));

    if (!file_exists(dirname(__DIR__) . '/install.lock')) {
        return new InstallerKernel($appEnv$debug);
    }

    $shopwareHttpKernel = new HttpKernel($appEnv$debug$classLoader);

    if (EnvironmentHelper::getVariable('COMPOSER_PLUGIN_LOADER', false)) {
        $shopwareHttpKernel->setPluginLoader(
            new ComposerPluginLoader($classLoader, null)
        );
    }

    return new class($shopwareHttpKernel) implements HttpKernelInterface, TerminableInterface {
        private HttpKernel $httpKernel;

        public function __construct(HttpKernel $httpKernel)
        {
$response->headers->setCookie(new Cookie('bazz', 'foo', '2000-12-12', '/', null, false, true, false, null));

        return $response;
    }

    /** * Inject the given controller callable into the data collector. */
    protected function injectController($collector$controller$request)
    {
        $resolver = $this->createMock(ControllerResolverInterface::class);
        $httpKernel = new HttpKernel(new EventDispatcher()$resolver, null, $this->createMock(ArgumentResolverInterface::class));
        $event = new ControllerEvent($httpKernel$controller$request, HttpKernelInterface::MAIN_REQUEST);
        $collector->onKernelController($event);
    }

    private function getCookieByName(Response $response$name)
    {
        foreach ($response->headers->getCookies() as $cookie) {
            if ($cookie->getName() == $name) {
                return $cookie;
            }
        }

        
$controllerResolver
            ->expects($this->any())
            ->method('getController')
            ->willReturn(static fn () => throw new \TypeError('foo'));

        $argumentResolver = $this->createMock(ArgumentResolverInterface::class);
        $argumentResolver
            ->expects($this->any())
            ->method('getArguments')
            ->willReturn([]);

        $kernel = new HttpKernel($dispatcher$controllerResolver, null, $argumentResolver);

        $this->expectException(\TypeError::class);
        $kernel->handle(new Request(), HttpKernelInterface::MAIN_REQUEST, true);
    }

    /** * Catch exceptions: true * Throwable type: RuntimeException * Listener: true. */
    public function testHandleWhenControllerThrowsAnExceptionAndCatchIsTrueWithANonHandlingListener()
    {

        $requestStack = new RequestStack();

        $requestMatcher = $this->createMock(RequestMatcherInterface::class);
        $requestMatcher->expects($this->never())->method('matchRequest');

        $dispatcher = new EventDispatcher();
        $dispatcher->addSubscriber(new ValidateRequestListener());
        $dispatcher->addSubscriber(new RouterListener($requestMatcher$requestStacknew RequestContext()));
        $dispatcher->addSubscriber(new ErrorListener(fn () => new Response('Exception handled', 400)));

        $kernel = new HttpKernel($dispatchernew ControllerResolver()$requestStacknew ArgumentResolver());

        $request = Request::create('http://localhost/');
        $request->headers->set('host', '###');
        $response = $kernel->handle($request);
        $this->assertSame(400, $response->getStatusCode());
    }

    public function testNoRoutingConfigurationResponse()
    {
        $requestStack = new RequestStack();

        
throw new \RuntimeException();
            })
        ;

        $argumentResolver = $this->createMock(ArgumentResolverInterface::class);
        $argumentResolver
            ->expects($this->once())
            ->method('getArguments')
            ->willReturn([])
        ;

        $kernel = new HttpKernel(new EventDispatcher()$controllerResolvernew RequestStack()$argumentResolver);
        $renderer = new InlineFragmentRenderer($kernel);

        // simulate a main request with output buffering         ob_start();
        echo 'Foo';

        // simulate a sub-request with output buffering and an exception         $renderer->render('/', Request::create('/')['ignore_errors' => true]);

        $this->assertEquals('Foo', ob_get_clean());
    }

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