StoreClientFactory example

/** * @internal * * @covers \Shopware\Core\Framework\Store\Services\StoreClientFactory */
#[Package('merchant-services')] class StoreClientFactoryTest extends TestCase
{
    public function testCreatesClientWithoutMiddlewares(): void
    {
        $factory = new StoreClientFactory($this->createSystemConfigService());

        $client = $factory->create();
        $config = $this->getConfigFromClient($client);
        $handler = $this->getHandlerFromConfig($config);

        static::assertTrue($handler->hasHandler());
    }

    public function testCreatesClientWithMiddlewares(): void
    {
        $factory = new StoreClientFactory($this->createSystemConfigService());

        
/** * @after */
    public function restoreStoreUri(): void
    {
        $this->getSystemConfigService()->set(self::STORE_URI_CONFIG_KEY, $this->originalStoreUri);
    }

    public function testItCreatesAnClientWithBaseConfig(): void
    {
        $storeClientFactory = new StoreClientFactory($this->getSystemConfigService());

        $client = $storeClientFactory->create([$this->createMock(VerifyResponseSignatureMiddleware::class)]);
        $config = $this->getConfigFromClient($client);

        static::assertEquals(self::TEST_STORE_URI, $config['base_uri']);

        static::assertArrayHasKey('Content-Type', $config['headers']);
        static::assertEquals('application/json', $config['headers']['Content-Type']);

        static::assertArrayHasKey('Accept', $config['headers']);
        static::assertEquals('application/vnd.api+json,application/json', $config['headers']['Accept']);

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