Client example

static::assertEquals($this->captcha->supports($request$activeCaptchaConfig[$this->captcha->getName()])$isSupported);
    }

    /** * @dataProvider requestDataIsValidProvider */
    public function testIsValid(Request $request, MockHandler $mockHandler, bool $shouldBeValid, ?string $secretKey = null, ?string $configThreshold = null): void
    {
        $handlerStack = HandlerStack::create($mockHandler);

        $client = new Client(['handler' => $handlerStack]);

        $this->systemConfigService->set('core.basicInformation.activeCaptchasV2', [
            GoogleReCaptchaV3::CAPTCHA_NAME => [
                'name' => GoogleReCaptchaV3::CAPTCHA_NAME,
                'isActive' => true,
                'config' => [
                    'secretKey' => $secretKey,
                    'thresholdScore' => $configThreshold,
                ],
            ],
        ]);

        

        $store = StoreFactory::createStore($connection);

        $this->assertInstanceOf($expectedStoreClass$store);
    }

    public static function validConnections(): \Generator
    {
        if (class_exists(\Redis::class)) {
            yield [new \Redis(), RedisStore::class];
        }
        yield [new \Predis\Client(), RedisStore::class];
        if (class_exists(\Memcached::class)) {
            yield [new \Memcached(), MemcachedStore::class];
        }
        if (\extension_loaded('sysvsem')) {
            yield ['semaphore', SemaphoreStore::class];
        }
        if (class_exists(AbstractAdapter::class) && MemcachedAdapter::isSupported()) {
            yield ['memcached://server.com', MemcachedStore::class];
            yield ['memcached:?host[localhost]&host[localhost:12345]', MemcachedStore::class];
        }
        if (class_exists(\Redis::class) && class_exists(AbstractAdapter::class)) {
            


    public function testDeleteWhenManaged(): void
    {
        $pluginManagementService = new PluginManagementService(
            '',
            $this->createMock(PluginZipDetector::class),
            $this->createMock(PluginExtractor::class),
            $this->createMock(PluginService::class),
            $this->createMock(Filesystem::class),
            $this->createMock(CacheClearer::class),
            new Client(['handler' => new MockHandler()])
        );

        $plugin = new PluginEntity();
        $plugin->setManagedByComposer(true);
        $plugin->setName('Test');

        static::expectException(PluginException::class);
        $pluginManagementService->deletePlugin($plugin, Context::createDefaultContext());
    }

    /** * @param Response[] $responses */
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;

use Predis\Client;

/** * @group integration */
class PredisClusterSessionHandlerTest extends AbstractRedisSessionHandlerTestCase
{
    protected function createRedisClient(string $host): Client
    {
        return new Client(
            [array_combine(['host', 'port']explode(':', getenv('REDIS_HOST')) + [1 => 6379])],
            ['cluster' => 'redis']
        );
    }
}
private ContainerInterface $container;

    private HookableEventFactory&MockObject $eventFactory;

    private CollectingMessageBus $bus;

    protected function setUp(): void
    {
        $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
        $this->connection = $this->createMock(Connection::class);
        $this->clientMock = new MockHandler([new Response(200)]);
        $this->client = new Client(['handler' => HandlerStack::create($this->clientMock)]);
        $this->container = new Container();
        $this->eventFactory = $this->createMock(HookableEventFactory::class);
        $this->bus = new CollectingMessageBus();
    }

    public function testDispatchWithWebhooksSync(): void
    {
        $event = new AppFlowActionEvent('foobar', ['foo' => 'bar']['foo' => 'bar']);

        $webhookEntity = $this->getWebhookEntity($event->getName());
        $this->prepareContainer($webhookEntity);

        

    private function createAppRegistrationService(
        ?HandshakeFactory $handshakeFactory = null,
        ?Client $httpClient = null,
        ?EntityRepository $appRepository = null,
        ?ShopIdProvider $shopIdProvider = null,
    ): AppRegistrationService {
        return new AppRegistrationService(
            $handshakeFactory ?? $this->createMock(HandshakeFactory::class),
            $httpClient ?? new Client(),
            $appRepository ?? $this->createMock(EntityRepository::class),
            'https://shopware.swag',
            $shopIdProvider ?? $this->createMock(ShopIdProvider::class),
            '6.5.2.0'
        );
    }

    /** * @param array<Response|RequestException> $responses */
    private function createHttpClient(array $responses): Client
    {

class ExecutorTest extends TestCase
{
    public function testConnectionProblemsGotConverted(): void
    {
        $requestStack = $this->createMock(RequestStack::class);
        $requestStack
            ->method('getCurrentRequest')
            ->willReturn(new SfRequest());

        $guzzleClient = new Client([
            'handler' => function D): void {
                throw new ConnectException('Connection problems', new Request('POST', 'https://example.com'));
            },
        ]);

        $executor = new Executor(
            $guzzleClient,
            $this->createMock(LoggerInterface::class),
            $this->createMock(ActionButtonResponseFactory::class),
            $this->createMock(ShopIdProvider::class),
            $this->createMock(RouterInterface::class),
            
class FastlyReverseProxyGatewayTest extends TestCase
{
    private Client $client;

    private MockHandler $mockHandler;

    protected function setUp(): void
    {
        parent::setUp();

        $this->mockHandler = new MockHandler();
        $this->client = new Client(['handler' => HandlerStack::create($this->mockHandler)]);
    }

    public function testDecoration(): void
    {
        $gateway = new FastlyReverseProxyGateway($this->client, 'test', 'test', '0', 3, '', '', 'http://localhost');

        static::expectException(DecorationPatternException::class);
        $gateway->getDecorated();
    }

    public function testTagDeprecated(): void
    {
class VarnishReverseProxyGatewayTest extends TestCase
{
    private Client $client;

    private MockHandler $mockHandler;

    protected function setUp(): void
    {
        parent::setUp();

        $this->mockHandler = new MockHandler();
        $this->client = new Client(['handler' => HandlerStack::create($this->mockHandler)]);
    }

    public function testDecorated(): void
    {
        $gateway = new VarnishReverseProxyGateway([], 0, $this->client);

        static::expectException(DecorationPatternException::class);
        $gateway->getDecorated();
    }

    public function testTagggingMissingResponse(): void
    {
static::assertFalse($request->hasHeader('shopware-shop-signature'));
    }

    public function testNoRegisteredWebhook(): void
    {
        $event = new CustomerBeforeLoginEvent(
            $this->getContainer()->get(SalesChannelContextFactory::class)->create(Uuid::randomHex(), TestDefaults::SALES_CHANNEL),
            'test@example.com'
        );

        $client = new Client([
            'handler' => new MockHandler([]),
        ]);

        $webhookDispatcher = new WebhookDispatcher(
            $this->getContainer()->get('event_dispatcher'),
            $this->getContainer()->get(Connection::class),
            $client,
            $this->shopUrl,
            $this->getContainer(),
            $this->getContainer()->get(HookableEventFactory::class),
            Kernel::SHOPWARE_FALLBACK_VERSION,
            
parent::setUp();

        $this->redis = $this->createMock(\Redis::class);
        $this->mockHandler = new MockHandler();

        $this->gateway = new RedisReverseProxyGateway(
            ['http://localhost'],
            ['method' => 'BAN', 'headers' => []],
            ['method' => 'BAN', 'headers' => [], 'urls' => []],
            3,
            $this->redis,
            new Client(['handler' => HandlerStack::create($this->mockHandler)])
        );
    }

    public function testDecorated(): void
    {
        static::expectException(DecorationPatternException::class);
        $this->gateway->getDecorated();
    }

    public function testTagging(): void
    {
        
public function create(iterable $middlewares = []): ClientInterface
    {
        $stack = HandlerStack::create();

        foreach ($middlewares as $middleware) {
            $stack->push(Middleware::mapResponse($middleware));
        }

        $config = $this->getClientBaseConfig();
        $config['handler'] = $stack;

        return new Client($config);
    }

    /** * @return array{base_uri: string, headers: array<string, string>} */
    private function getClientBaseConfig(): array
    {
        return [
            'base_uri' => $this->configService->getString(self::CONFIG_KEY_STORE_API_URI),
            'headers' => [
                'Content-Type' => 'application/json',
                
$client = self::getMongoClient();
        try {
            $client->listDatabases();
        } catch (ConnectionTimeoutException $e) {
            throw new SkippedTestSuiteError('MongoDB server not found.');
        }
    }

    private static function getMongoClient(): Client
    {
        return new Client('mongodb://'.getenv('MONGODB_HOST'));
    }

    protected function getClockDelay(): int
    {
        return 250000;
    }

    public function getStore(): PersistingStoreInterface
    {
        return new MongoDbStore(self::getMongoClient()[
            'database' => 'test',
            

    /** * @return ClientInterface */
    public function createClient(array $guzzleConfig = [])
    {
        $certPath = __DIR__ . '/cacert.pem';
        if (is_file($certPath)) {
            $guzzleConfig['verify'] = $certPath;
        }

        return new Client($guzzleConfig);
    }
}
private MockHandler $mockHandler;

    private Client $client;

    private RedisReverseProxyGateway $gateway;

    protected function setUp(): void
    {
        parent::setUp();

        $this->mockHandler = new MockHandler();
        $this->client = new Client(['handler' => HandlerStack::create($this->mockHandler)]);
        $this->gateway = new RedisReverseProxyGateway(
            ['http://localhost'],
            ['method' => 'BAN', 'headers' => []],
            ['method' => 'PURGE', 'headers' => ['foo' => '1'], 'urls' => ['/']],
            3,
            $this->createMock(\Redis::class),
            $this->client
        );
    }

    public function testClear(): void
    {
Home | Imprint | This part of the site doesn't use cookies.