MockHandler example

/** * @package merchant-services * * @internal * * @covers \Shopware\Core\Framework\Store\Services\TrackingEventClient */
class TrackingEventClientTest extends TestCase
{
    public function testEventRequestNotMadeIfInstanceIdIsUnknown(): void
    {
        $mockHandler = new MockHandler();
        $mockHandler->append(new Response(200));

        $instanceService = $this->createMock(InstanceService::class);
        $instanceService->method('getShopwareVersion')->willReturn('6.5.0.0-test');
        $instanceService->method('getInstanceId')->willReturn(null);

        $trackingEventClient = new TrackingEventClient(
            new Client(['handler' => HandlerStack::create($mockHandler)]),
            $instanceService
        );

        
'https://shopware.swag',
            $shopIdProvider ?? $this->createMock(ShopIdProvider::class),
            '6.5.2.0'
        );
    }

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

        return new Client(['handler' => $mockHandler]);
    }
}

    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
        );
    }

    

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();
    }

    
$activeCaptchaConfig = $this->systemConfigService->get('core.basicInformation.activeCaptchasV2');
        $captcha = new GoogleReCaptchaV2($client);

        static::assertEquals($captcha->isValid($request$activeCaptchaConfig[$captcha->getName()])$shouldBeValid);
    }

    public static function requestDataIsValidProvider(): array
    {
        return [
            'request with no captcha input' => [
                self::getRequest(),
                new MockHandler(),
                self::IS_INVALID,
                'secret123',
            ],
            'request with null captcha input' => [
                self::getRequest([
                    GoogleReCaptchaV2::CAPTCHA_REQUEST_PARAMETER => null,
                ]),
                new MockHandler(),
                self::IS_INVALID,
                'secret123',
            ],
            
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,
            $this->bus,
            
private RedisReverseProxyGateway $gateway;

    private \Redis&MockObject $redis;

    private MockHandler $mockHandler;

    protected function setUp(): void
    {
        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)])
        );
    }

    
$this->createCustomer($customerId);

        $customer = $this->getContainer()->get('customer.repository')->search(new Criteria([$customerId]), Context::createDefaultContext())->get($customerId);
        static::assertInstanceOf(CustomerEntity::class$customer);
        $event = new CustomerLoginEvent(
            $this->getContainer()->get(SalesChannelContextFactory::class)->create(Uuid::randomHex(), TestDefaults::SALES_CHANNEL),
            $customer,
            'testToken'
        );

        $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,
            $this->bus,
            
$activeCaptchaConfig = $this->systemConfigService->get('core.basicInformation.activeCaptchasV2');
        $captcha = new GoogleReCaptchaV3($client);

        static::assertEquals($captcha->isValid($request$activeCaptchaConfig[$captcha->getName()])$shouldBeValid);
    }

    public static function requestDataIsValidProvider(): array
    {
        return [
            'request with no captcha input' => [
                self::getRequest(),
                new MockHandler(),
                self::IS_INVALID,
                'secret123',
            ],
            'request with null captcha input' => [
                self::getRequest([
                    GoogleReCaptchaV3::CAPTCHA_REQUEST_PARAMETER => null,
                ]),
                new MockHandler(),
                self::IS_INVALID,
                'secret123',
            ],
            
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());
        


    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 */

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();
    }

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