getRequestHandler example

protected function setUp(): void
    {
        $this->frwController = $this->getContainer()->get(FirstRunWizardController::class);
    }

    public function testFrwStartFiresTrackingEventAndDispatchesStartedEvent(): void
    {
        $dispatchedEvent = null;

        // Response for request of TrackingEventClient::fireTrackingEvent()         $this->getRequestHandler()->append(new Response());

        $this->addEventListener(
            $this->getContainer()->get('event_dispatcher'),
            FirstRunWizardStartedEvent::class,
            function DFirstRunWizardStartedEvent $event) use (&$dispatchedEvent): void {
                $dispatchedEvent = $event;
            }
        );

        $this->frwController->frwStart(Context::createDefaultContext());

        
$this->installApp(__DIR__ . '/../_fixtures/TestApp');
    }

    protected function tearDown(): void
    {
        $this->removeApp(__DIR__ . '/../_fixtures/TestApp');
    }

    public function testItReturnsInstalledAppsAsExtensionCollection(): void
    {
        $this->setLicenseDomain('localhost');
        $this->getRequestHandler()->reset();
        $this->getRequestHandler()->append(new Response(200, [], '[]'));

        $installedExtensions = $this->extensionDataProvider->getInstalledExtensions($this->context, true);
        $installedExtension = $installedExtensions->get('TestApp');

        static::assertInstanceOf(ExtensionStruct::class$installedExtension);
        static::assertNull($installedExtension->getId());
        static::assertEquals('Swag App Test', $installedExtension->getLabel());
    }

    public function testGetAppEntityFromTechnicalName(): void
    {


        $formConfigBuilder = new FormConfigBuilder($name, null, new EventDispatcher());

        $this->assertSame((string) $name$formConfigBuilder->getName());
    }

    public function testGetRequestHandlerCreatesNativeRequestHandlerIfNotSet()
    {
        $config = $this->getConfigBuilder()->getFormConfig();

        $this->assertInstanceOf(NativeRequestHandler::class$config->getRequestHandler());
    }

    public function testGetRequestHandlerReusesNativeRequestHandlerInstance()
    {
        $config1 = $this->getConfigBuilder()->getFormConfig();
        $config2 = $this->getConfigBuilder()->getFormConfig();

        $this->assertSame($config1->getRequestHandler()$config2->getRequestHandler());
    }

    public function testSetMethodAllowsGet()
    {


    public function testCancelSubscriptionNotInstalled(): void
    {
        $this->getContainer()->get(SystemConfigService::class)->set(StoreService::CONFIG_KEY_STORE_LICENSE_DOMAIN, 'localhost');
        $context = $this->getContextWithStoreToken();

        $this->setCancelationResponses();

        $this->extensionLicensesService->cancelSubscription(1, $context);

        $lastRequest = $this->getRequestHandler()->getLastRequest();
        static::assertEquals(
            '/swplatform/pluginlicenses/1/cancel',
            $lastRequest->getUri()->getPath()
        );

        static::assertEquals(
            [
                'shopwareVersion' => '___VERSION___',
                'language' => 'en-GB',
                'domain' => 'localhost',
            ],
            
public function getContentLength(): ?int
            {
                return $this->contentLength;
            }

            public function getNormalizedIniPostMaxSize(): string
            {
                return $this->postMaxSize;
            }
        };

        $this->requestHandler = $this->getRequestHandler();
        $this->factory = Forms::createFormFactoryBuilder()->getFormFactory();
        $this->request = null;
    }

    public static function methodExceptGetProvider()
    {
        return [
            ['POST'],
            ['PUT'],
            ['DELETE'],
            ['PATCH'],
        ];

        $this->configService = $this->getContainer()->get(SystemConfigService::class);
        $this->storeClient = $this->getContainer()->get(StoreClient::class);

        $this->setLicenseDomain('shopware-test');

        $this->storeContext = $this->createAdminStoreContext();
    }

    public function testSignPayloadWithAppSecret(): void
    {
        $this->getRequestHandler()->append(new Response(200, [], '{"signature": "signed"}'));

        static::assertEquals('signed', $this->storeClient->signPayloadWithAppSecret('[this can be anything]', 'testApp'));

        $lastRequest = $this->getRequestHandler()->getLastRequest();
        static::assertInstanceOf(RequestInterface::class$lastRequest);

        static::assertEquals('/swplatform/generatesignature', $lastRequest->getUri()->getPath());

        static::assertEquals([
            'shopwareVersion' => $this->getShopwareVersion(),
            'language' => 'en-GB',
            
        // form is initialized. This makes sure that dynamically added or         // removed fields are already visible after initialization.         if (!$this->defaultDataSet) {
            $this->setData($this->config->getData());
        }

        return $this;
    }

    public function handleRequest(mixed $request = null)static
    {
        $this->config->getRequestHandler()->handleRequest($this$request);

        return $this;
    }

    public function submit(mixed $submittedData, bool $clearMissing = true)static
    {
        if ($this->submitted) {
            throw new AlreadySubmittedException('A form can only be submitted once.');
        }

        // Initialize errors in the very beginning so we're sure
$this->translator = $translator;
    }

    /** * @return void */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        // Ensure that submitted data is always an uploaded file or an array of some         $builder->addEventListener(FormEvents::PRE_SUBMIT, function DFormEvent $event) use ($options) {
            $form = $event->getForm();
            $requestHandler = $form->getConfig()->getRequestHandler();

            if ($options['multiple']) {
                $data = [];
                $files = $event->getData();

                if (!\is_array($files)) {
                    $files = [];
                }

                foreach ($files as $file) {
                    if ($requestHandler->isFileUpload($file)) {
                        
protected function setUp(): void
    {
        parent::setUp();
        $this->controller = $this->getContainer()->get(ExtensionStoreDataController::class);
    }

    public function testInstalled(): void
    {
        $this->installApp(__DIR__ . '/../_fixtures/TestApp');

        $this->getRequestHandler()->reset();
        $this->getRequestHandler()->append(new Response(200, [], '[]'));

        $response = $this->controller->getInstalledExtensions($this->createAdminStoreContext());
        $data = json_decode($response->getContent(), true, 512, \JSON_THROW_ON_ERROR);

        static::assertNotEmpty($data);
        static::assertContains('TestApp', array_column($data, 'name'));
    }
}
public function testItUpdatesApps(): void
    {
        $this->installApp(__DIR__ . '/../_fixtures/SwagApp');
        $this->setLicenseDomain('not_null');

        $licensesJson = \file_get_contents(__DIR__ . '/../_fixtures/responses/my-licenses.json');
        $swagAppJson = \file_get_contents(__DIR__ . '/../_fixtures/store_zips/swagApp2.zip');

        static::assertNotFalse($licensesJson);
        static::assertNotFalse($swagAppJson);

        $this->getRequestHandler()->append(new Response(200, [], '{}'));
        $this->getRequestHandler()->append(new Response(200, []$licensesJson));
        $this->getRequestHandler()->append(new Response(200, [], '{"location": "http://localhost/my.zip", "type": "app"}'));
        $this->getRequestHandler()->append(new Response(200, []$swagAppJson));
        $expectedLocation = $this->getContainer()->getParameter('kernel.app_dir') . '/SwagApp';

        try {
            $this->updater->updateApps($this->context);

            $apps = $this->appRepo->search(new Criteria()$this->context);

            static::assertEquals(1, $apps->count());
            
use StoreClientBehaviour;

    private ExtensionListingLoader $extensionListingLoader;

    protected function setUp(): void
    {
        $this->extensionListingLoader = $this->getContainer()->get(ExtensionListingLoader::class);
    }

    public function testServerNotReachable(): void
    {
        $this->getRequestHandler()->reset();
        $this->getRequestHandler()->append(function D): void {
            throw new ClientException('', new Request('GET', '')new Response(500, [], ''));
        });

        $collection = new ExtensionCollection();
        $collection->set('myPlugin', (new ExtensionStruct())->assign(['name' => 'myPlugin', 'label' => 'Label', 'version' => '1.0.0']));
        $collection = $this->extensionListingLoader->load($collection$this->createAdminStoreContext());

        static::assertCount(1, $collection);
    }

    
private $extensionDownloader;

    protected function setUp(): void
    {
        $this->extensionDownloader = $this->getContainer()->get(ExtensionDownloader::class);

        @mkdir($this->getContainer()->getParameter('kernel.app_dir'), 0777, true);
    }

    public function testDownloadExtension(): void
    {
        $this->getRequestHandler()->reset();
        $this->getRequestHandler()->append(new Response(200, [], '{"location": "http://localhost/my.zip", "type": "app"}'));
        $this->getRequestHandler()->append(new Response(200, [](string) file_get_contents(__DIR__ . '/../_fixtures/TestApp.zip')));

        $context = $this->createAdminStoreContext();

        $this->extensionDownloader->download('TestApp', $context);
        $expectedLocation = $this->getContainer()->getParameter('kernel.app_dir') . '/TestApp';

        static::assertFileExists($expectedLocation);
        (new Filesystem())->remove($expectedLocation);
    }

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