ClientException example

return json_decode($responseContent, true, flags: \JSON_THROW_ON_ERROR);
    }

    private function createContext(): Context
    {
        return Context::createDefaultContext();
    }

    private function createClientException(string $message): ClientException
    {
        return new ClientException($message$this->createMock(GuzzleRequest::class)new Response(400));
    }

    /** * @param array<string, mixed>[] $data */
    private function createPluginCollection(array $data): PluginCollection
    {
        $collection = new PluginCollection();
        $counter = \count($data);
        for ($i = 0; $i < $counter; ++$i) {
            if (!\array_key_exists('id', $data[$i])) {
                
'deliveryStatus' => WebhookEventLogDefinition::STATUS_QUEUED,
            'webhookName' => 'hook1',
            'eventName' => 'order',
            'appVersion' => '0.0.1',
            'url' => 'https://test.com',
            'serializedWebhookMessage' => serialize($webhookEventMessage),
        ]]$this->context);

        $event = new WorkerMessageFailedEvent(
            new Envelope($webhookEventMessage),
            'async',
            new ClientException('test', new Request('GET', 'https://test.com')new Response(500))
        );

        $this->getContainer()->get(RetryWebhookMessageFailedSubscriber::class)
            ->failed($event);

        $webhookEventLog = $webhookEventLogRepository->search(new Criteria([$webhookEventId])$this->context)->first();
        static::assertEquals($webhookEventLog->getDeliveryStatus(), WebhookEventLogDefinition::STATUS_FAILED);
    }
}
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);
    }

    public function testExternalAreAdded(): void
    {
        
__DIR__ . './../_fixtures/responses/extension-red.json',
            'notCompatible',
            null,
        ];
    }

    public function testGetExtensionWhenInvalidVersion(): void
    {
        $storeClient = $this->createMock(StoreClient::class);
        $storeClient
            ->method('getExtensionCompatibilities')
            ->willThrowException(new ClientException('test', new Request('GET', '/')new Response(400)));

        $pluginCompatibility = new ExtensionCompatibility(
            $storeClient,
            $this->getExtensionDataProvider()
        );

        $version = new Version();
        $version->assign([
            'version' => '6.6.0.0',
        ]);

        
static::assertEquals('1234', $handshake->fetchAppProof());
    }

    public function testThrowsIfSbpRespondsWithUnauthorized(): void
    {
        $storeClient = $this->createMock(StoreClient::class);
        $json = \json_encode(['code' => 'ShopwarePlatformException-1']);

        static::assertNotFalse($json);

        $storeClient->method('signPayloadWithAppSecret')
            ->willThrowException(new ClientException(
                '',
                new Request('POST', 'app_generate_signature'),
                new Response(401, []$json)
            ));

        $handshake = new StoreHandshake(
            'http://shop.url',
            'http://app.url',
            'TestApp',
            'my-shop-id',
            $storeClient,
            
/** * @package merchant-services * * @internal * * @covers \Shopware\Core\Framework\Store\Exception\StoreApiException */
class StoreApiExceptionTest extends TestCase
{
    public function testGetErrorCode(): void
    {
        $clientException = new ClientException(
            'message',
            new Request('GET', 'https://example.com'),
            new \GuzzleHttp\Psr7\Response()
        );

        static::assertSame(
            'FRAMEWORK__STORE_ERROR',
            (new StoreApiException($clientException))->getErrorCode()
        );
    }

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