assertIsString example

public function testDownloadNoDocuments(): void
    {
        $this->getBrowser()->request(
            'POST',
            '/api/_action/order/document/download',
            [],
            [],
            [],
            json_encode([]) ?: ''
        );

        static::assertIsString($this->getBrowser()->getResponse()->getContent());
        $response = json_decode($this->getBrowser()->getResponse()->getContent() ?: '', true, 512, \JSON_THROW_ON_ERROR);

        static::assertEquals(400, $this->getBrowser()->getResponse()->getStatusCode());
        static::assertArrayHasKey('errors', $response);
        static::assertEquals('FRAMEWORK__INVALID_REQUEST_PARAMETER', $response['errors'][0]['code']);

        $this->getBrowser()->request(
            'POST',
            '/api/_action/order/document/download',
            [],
            [],
            [],
public function testRequestNotLoggedIn(): void
    {
        $this->browser
            ->request(
                'GET',
                '/store-api/handle-payment',
                [
                ]
            );

        static::assertIsString($this->browser->getResponse()->getContent());
        $response = json_decode($this->browser->getResponse()->getContent(), true, 512, \JSON_THROW_ON_ERROR);

        static::assertArrayHasKey('errors', $response);
        static::assertSame('VIOLATION::IS_BLANK_ERROR', $response['errors'][0]['code']);
    }

    public function testRequestRandomOrderId(): void
    {
        $this->browser
            ->request(
                'GET',
                
$this->assertSame('bar', $attributeName);
                        $this->assertSame('any', $format);
                        $this->assertIsArray($context);
                    },
                ],
                'baz',
                new CallbacksObject(null),
            ],
            'Format a date' => [
                [
                    'bar' => function D$bar) {
                        $this->assertIsString($bar);

                        return \DateTimeImmutable::createFromFormat('d-m-Y H:i:s', $bar);
                    },
                ],
                '10-09-2011 06:30:00',
                new CallbacksObject(new \DateTimeImmutable('2011-09-10 06:30:00')),
            ],
            'Collect a property' => [
                [
                    'bar' => function Darray $bars) {
                        $result = '';
                        
public function testCanReadWithPermission(): void
    {
        $this->loadAppsFromDir(self::$fixturesPath . '/test');

        $browser = $this->createClient();
        $this->authorizeBrowserWithIntegrationByAppName($this->getBrowser(), 'test');

        $browser->request('GET', '/api/product');
        $response = $browser->getResponse();

        static::assertIsString($response->getContent());
        static::assertEquals(200, $response->getStatusCode()$response->getContent());
    }

    public function testCantReadWithoutPermission(): void
    {
        $this->loadAppsFromDir(self::$fixturesPath . '/test');

        $browser = $this->createClient();
        $this->authorizeBrowserWithIntegrationByAppName($browser, 'test');

        $browser->request('GET', '/api/media');

        
return [
            'token' => $token,
            'transactionId' => $transactionId,
            'paymentMethodId' => $paymentMethodId,
        ];
    }

    private function getToken(string $returnUrl): string
    {
        $query = \parse_url($returnUrl, \PHP_URL_QUERY);
        static::assertIsString($query);

        \parse_str($query$params);

        $token = $params['_sw_payment_token'];

        static::assertIsString($token);

        return $token;
    }
}
public function testConstructorWithSimpleTypes()
    {
        $response = new JsonResponse('foo');
        $this->assertSame('"foo"', $response->getContent());

        $response = new JsonResponse(0);
        $this->assertSame('0', $response->getContent());

        $response = new JsonResponse(0.1);
        $this->assertEquals(0.1, $response->getContent());
        $this->assertIsString($response->getContent());

        $response = new JsonResponse(true);
        $this->assertSame('true', $response->getContent());
    }

    public function testConstructorWithCustomStatus()
    {
        $response = new JsonResponse([], 202);
        $this->assertSame(202, $response->getStatusCode());
    }

    
public function testDownloadWithoutDocuments(): void
    {
        $this->getBrowser()->request(
            'POST',
            '/api/_action/order/document/download',
            [],
            [],
            [],
            (string) json_encode([])
        );

        static::assertIsString($this->getBrowser()->getResponse()->getContent());
        $response = json_decode((string) $this->getBrowser()->getResponse()->getContent(), true, 512, \JSON_THROW_ON_ERROR);

        static::assertEquals(400, $this->getBrowser()->getResponse()->getStatusCode());
        static::assertArrayHasKey('errors', $response);
        static::assertEquals('FRAMEWORK__INVALID_REQUEST_PARAMETER', $response['errors'][0]['code']);

        $this->getBrowser()->request(
            'POST',
            '/api/_action/order/document/download',
            [],
            [],
            [],
'b4b45f58088d41289490db956ca19af7',
        ];

        foreach ($expectedResult as $id) {
            static::assertContains($idarray_keys($result->getData())print_r(array_keys($result->getData()), true));
        }
    }

    private function installTestData(): void
    {
        $salutationSql = file_get_contents(__DIR__ . '/../fixtures/salutation.sql');
        static::assertIsString($salutationSql);
        $this->getContainer()->get(Connection::class)->executeStatement($salutationSql);

        $recipientSql = file_get_contents(__DIR__ . '/../fixtures/recipient.sql');
        static::assertIsString($recipientSql);
        $recipientSql = str_replace(':createdAt', (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT)$recipientSql);
        $this->getContainer()->get(Connection::class)->executeStatement($recipientSql);
    }

    private function getTaskHandler(): NewsletterRecipientTaskHandler
    {
        return new NewsletterRecipientTaskHandler(
            
/** @var ExtensionStruct $extension */
        $extension = $extensions->get('TestAppTheme');
        static::assertTrue($extension->isTheme());
        $this->removeApp(__DIR__ . '/../_fixtures/TestAppTheme');
    }

    public function testLocalUpdateShouldSetLatestVersion(): void
    {
        $appManifestPath = $this->getContainer()->getParameter('kernel.app_dir') . '/TestApp/manifest.xml';
        $appManifestXml = file_get_contents($appManifestPath);
        static::assertIsString($appManifestXml, 'Could not read manifest.xml file');
        file_put_contents($appManifestPathstr_replace('1.0.0', '1.0.1', $appManifestXml));

        $extensions = $this->extensionLoader->loadFromAppCollection(
            Context::createDefaultContext(),
            new AppCollection([$this->getInstalledApp()])
        );

        /** @var ExtensionStruct $extension */
        $extension = $extensions->get('TestApp');
        static::assertSame('1.0.0', $extension->getVersion());
        static::assertSame('1.0.1', $extension->getLatestVersion());
    }

        );

        $exception = new StoreApiException($clientException);

        foreach ($exception->getErrors(true) as $error) {
            static::assertSame('FRAMEWORK__STORE_ERROR', $error['code']);
            static::assertSame((string) Response::HTTP_INTERNAL_SERVER_ERROR, $error['status']);
            static::assertSame('title', $error['title']);
            static::assertSame('description', $error['detail']);
            static::assertSame('https://shopware.docs', $error['meta']['documentationLink']);
            static::assertIsString($error['trace']);
        }
    }
}
private function getPrePaymentMethodId(): string
    {
        /** @var EntityRepository $repository */
        $repository = $this->getContainer()->get('payment_method.repository');

        $criteria = (new Criteria())
            ->setLimit(1)
            ->addFilter(new EqualsFilter('active', true))
            ->addFilter(new EqualsFilter('handlerIdentifier', PrePayment::class));

        $id = $repository->searchIds($criteria, Context::createDefaultContext())->getIds()[0];
        static::assertIsString($id);

        return $id;
    }

    private function getStateId(string $state, string $machine): ?string
    {
        return $this->getContainer()->get(Connection::class)
            ->fetchOne(' SELECT LOWER(HEX(state_machine_state.id)) FROM state_machine_state INNER JOIN state_machine ON state_machine.id = state_machine_state.state_machine_id AND state_machine.technical_name = :machine WHERE state_machine_state.technical_name = :state ',
$node = $this->createNode('input', '', ['type' => 'file']);
        $field = new FileFormField($node);

        $field->$method(null);
        $this->assertEquals(['name' => '', 'type' => '', 'tmp_name' => '', 'error' => \UPLOAD_ERR_NO_FILE, 'size' => 0]$field->getValue(), "->$method() clears the uploaded file if the value is null");

        $field->$method(__FILE__);
        $value = $field->getValue();

        $this->assertEquals(basename(__FILE__)$value['name'], "->$method() sets the name of the file field");
        $this->assertEquals('', $value['type'], "->$method() sets the type of the file field");
        $this->assertIsString($value['tmp_name'], "->$method() sets the tmp_name of the file field");
        $this->assertFileExists($value['tmp_name'], "->$method() creates a copy of the file at the tmp_name path");
        $this->assertEquals(0, $value['error'], "->$method() sets the error of the file field");
        $this->assertEquals(filesize(__FILE__)$value['size'], "->$method() sets the size of the file field");

        $origInfo = pathinfo(__FILE__);
        $tmpInfo = pathinfo($value['tmp_name']);
        $this->assertEquals(
            $origInfo['extension'],
            $tmpInfo['extension'],
            "->$method() keeps the same file extension in the tmp_name copy"
        );

        
private function isRegistrationConfirmation(RequestInterface $request): bool
    {
        return ((string) $request->getUri()) === self::CONFIRMATION_URL;
    }

    private function getQueryParameter(RequestInterface $request, string $param): string
    {
        $query = [];
        \parse_str($request->getUri()->getQuery()$query);

        TestCase::assertIsString($query[$param]);

        return $query[$param];
    }

    private function getAppname(RequestInterface $request): string
    {
        $path = $request->getUri()->getPath();
        $pathElems = \explode('/', $path);

        return $pathElems[1] ?? '';
    }
}
$reflProp = $reflObject->getProperty('config');

        $reflProp->setAccessible(true);

        return $reflProp->getValue($client);
    }

    private function getApiUrlFromSystemConfig(): string
    {
        $apiUrl = $this->getSystemConfigService()->get(self::STORE_URI_CONFIG_KEY);

        static::assertIsString($apiUrl);

        return $apiUrl;
    }
}
static::assertEquals($shopId['value']$query['shop-id']);
        static::assertArrayHasKey('sw-version', $query);
        static::assertEquals($this->getContainer()->getParameter('kernel.shopware_version')$query['sw-version']);
        static::assertArrayHasKey('sw-context-language', $query);
        static::assertEquals(Context::createDefaultContext()->getLanguageId()$query['sw-context-language']);
        static::assertArrayHasKey('sw-user-language', $query);
        static::assertEquals('en-GB', $query['sw-user-language']);
        static::assertArrayHasKey('shopware-shop-signature', $query);

        $signature = $query['shopware-shop-signature'];

        static::assertIsString($signature);

        $signedQuery = str_replace('&shopware-shop-signature=' . $signature, '', $queryString);

        static::assertEquals(hash_hmac('sha256', $signedQuery$secret)$signature);
    }
}
Home | Imprint | This part of the site doesn't use cookies.