ControllerEvent example

->willReturn($isValid);

        $captcha->expects($supports ? static::once() : static::never())
            ->method('shouldBreak')
            ->willReturn(true);

        return [$captcha];
    }

    private function getControllerEventMock(): ControllerEvent
    {
        return new ControllerEvent(
            $this->createMock(HttpKernelInterface::class),
            function D): void {
            },
            self::getRequest($this->getRequestAttributes(true)),
            HttpKernelInterface::MAIN_REQUEST
        );
    }

    private static function getRequest(ParameterBag $attributes): Request
    {
        return new Request([][]$attributes->all()[][][]);
    }
'dev_requirement' => false,
                ],
            ],
        ]);
    }

    public function testExpectFailsOutdatedShopwareVersion(): void
    {
        $request = $this->makeRequest();
        $request->headers->set(PlatformRequest::HEADER_EXPECT_PACKAGES, 'shopware/core:~6.4');

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

        static::expectException(ExpectationFailedException::class);

        $this->expectationSubscriber->checkExpectations($event);
    }

    
$stack->push($requestSub);

        $event = $this->createEvent($requestSub);

        $listener->checkScope($event);
    }

    private function createEvent(Request $request): ControllerEvent
    {
        $controller = $this->getContainer()->get(ApiController::class);

        return new ControllerEvent(
            $this->getContainer()->get('kernel'),
            $controller->clone(...),
            $request,
            HttpKernelInterface::SUB_REQUEST
        );
    }

    private function createRequest(string $route, string $scopeName, ContextSource $source): Request
    {
        $request = Request::create($route);

        
$request = new Request();
        $request->attributes->set(PlatformRequest::ATTRIBUTE_ACL, $acl);
        $request->attributes->set(PlatformRequest::ATTRIBUTE_CONTEXT_OBJECT, $context);

        $kernel = $this->createMock(Kernel::class);

        $exception = null;

        $controller = new AclTestController();

        try {
            $this->validator->validate(new ControllerEvent($kernel$controller->testRoute(...)$request, 1));
        } catch (\Exception $e) {
            $exception = $e;
        }

        if ($pass) {
            static::assertNull($exception, 'Exception: ' . ($exception !== null ? \print_r($exception->getMessage(), true) : 'No Exception'));
        } else {
            static::assertInstanceOf(MissingPrivilegeException::class$exception, 'Exception: ' . ($exception !== null ? \print_r($exception->getMessage(), true) : 'No Exception'));
        }
    }

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