Skip to content

Commit

Permalink
extend test case with exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Sep 22, 2024
1 parent e5b9faa commit 7025b9c
Show file tree
Hide file tree
Showing 17 changed files with 438 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/Generator/Client/resource/php_test/BinaryException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* BinaryException automatically generated by SDKgen please do not edit this file manually
* @see https://sdkgen.app
*/

namespace Sdkgen\Client\Tests\Generated;

use Sdkgen\Client\Exception\KnownStatusCodeException;

class BinaryException extends KnownStatusCodeException
{
private \Psr\Http\Message\StreamInterface $payload;

public function __construct(\Psr\Http\Message\StreamInterface $payload)
{
parent::__construct('The server returned an error');

$this->payload = $payload;
}

/**
* @return \Psr\Http\Message\StreamInterface
*/
public function getPayload(): \Psr\Http\Message\StreamInterface
{
return $this->payload;
}
}
29 changes: 29 additions & 0 deletions tests/Generator/Client/resource/php_test/FormException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* FormException automatically generated by SDKgen please do not edit this file manually
* @see https://sdkgen.app
*/

namespace Sdkgen\Client\Tests\Generated;

use Sdkgen\Client\Exception\KnownStatusCodeException;

class FormException extends KnownStatusCodeException
{
private array $payload;

public function __construct(array $payload)
{
parent::__construct('The server returned an error');

$this->payload = $payload;
}

/**
* @return array
*/
public function getPayload(): array
{
return $this->payload;
}
}
29 changes: 29 additions & 0 deletions tests/Generator/Client/resource/php_test/JsonException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* JsonException automatically generated by SDKgen please do not edit this file manually
* @see https://sdkgen.app
*/

namespace Sdkgen\Client\Tests\Generated;

use Sdkgen\Client\Exception\KnownStatusCodeException;

class JsonException extends KnownStatusCodeException
{
private \stdClass $payload;

public function __construct(\stdClass $payload)
{
parent::__construct('The server returned an error');

$this->payload = $payload;
}

/**
* @return \stdClass
*/
public function getPayload(): \stdClass
{
return $this->payload;
}
}
29 changes: 29 additions & 0 deletions tests/Generator/Client/resource/php_test/MultipartException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* MultipartException automatically generated by SDKgen please do not edit this file manually
* @see https://sdkgen.app
*/

namespace Sdkgen\Client\Tests\Generated;

use Sdkgen\Client\Exception\KnownStatusCodeException;

class MultipartException extends KnownStatusCodeException
{
private array $payload;

public function __construct(array $payload)
{
parent::__construct('The server returned an error');

$this->payload = $payload;
}

/**
* @return array
*/
public function getPayload(): array
{
return $this->payload;
}
}
51 changes: 51 additions & 0 deletions tests/Generator/Client/resource/php_test/ProductTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function getAll(?int $startIndex = null, ?int $count = null, ?string $sea
*
* @param TestRequest $payload
* @return TestResponse
* @throws TestResponseException
* @throws ClientException
*/
public function create(TestRequest $payload): TestResponse
Expand Down Expand Up @@ -93,6 +94,12 @@ public function create(TestRequest $payload): TestResponse
$body = $e->getResponse()->getBody();
$statusCode = $e->getResponse()->getStatusCode();

if ($statusCode === 500) {
$data = $this->parser->parse((string) $body, TestResponse::class);

throw new TestResponseException($data);
}

throw new UnknownStatusCodeException('The server returned an unknown status code: ' . $statusCode);
} catch (\Throwable $e) {
throw new ClientException('An unknown error occurred: ' . $e->getMessage());
Expand Down Expand Up @@ -230,6 +237,7 @@ public function delete(int $id): TestResponse
*
* @param \Psr\Http\Message\StreamInterface $payload
* @return TestResponse
* @throws BinaryException
* @throws ClientException
*/
public function binary(\Psr\Http\Message\StreamInterface $payload): TestResponse
Expand Down Expand Up @@ -260,6 +268,12 @@ public function binary(\Psr\Http\Message\StreamInterface $payload): TestResponse
$body = $e->getResponse()->getBody();
$statusCode = $e->getResponse()->getStatusCode();

if ($statusCode === 500) {
$data = $body;

throw new BinaryException($data);
}

throw new UnknownStatusCodeException('The server returned an unknown status code: ' . $statusCode);
} catch (\Throwable $e) {
throw new ClientException('An unknown error occurred: ' . $e->getMessage());
Expand All @@ -271,6 +285,7 @@ public function binary(\Psr\Http\Message\StreamInterface $payload): TestResponse
*
* @param array $payload
* @return TestResponse
* @throws FormException
* @throws ClientException
*/
public function form(array $payload): TestResponse
Expand Down Expand Up @@ -301,6 +316,13 @@ public function form(array $payload): TestResponse
$body = $e->getResponse()->getBody();
$statusCode = $e->getResponse()->getStatusCode();

if ($statusCode === 500) {
$data = [];
parse_str((string) $body, $data);

throw new FormException($data);
}

throw new UnknownStatusCodeException('The server returned an unknown status code: ' . $statusCode);
} catch (\Throwable $e) {
throw new ClientException('An unknown error occurred: ' . $e->getMessage());
Expand All @@ -312,6 +334,7 @@ public function form(array $payload): TestResponse
*
* @param \stdClass $payload
* @return TestResponse
* @throws JsonException
* @throws ClientException
*/
public function json(\stdClass $payload): TestResponse
Expand Down Expand Up @@ -342,6 +365,12 @@ public function json(\stdClass $payload): TestResponse
$body = $e->getResponse()->getBody();
$statusCode = $e->getResponse()->getStatusCode();

if ($statusCode === 500) {
$data = \json_decode((string) $body);

throw new JsonException($data);
}

throw new UnknownStatusCodeException('The server returned an unknown status code: ' . $statusCode);
} catch (\Throwable $e) {
throw new ClientException('An unknown error occurred: ' . $e->getMessage());
Expand All @@ -353,6 +382,7 @@ public function json(\stdClass $payload): TestResponse
*
* @param array $payload
* @return TestResponse
* @throws MultipartException
* @throws ClientException
*/
public function multipart(array $payload): TestResponse
Expand Down Expand Up @@ -382,6 +412,13 @@ public function multipart(array $payload): TestResponse
$body = $e->getResponse()->getBody();
$statusCode = $e->getResponse()->getStatusCode();

if ($statusCode === 500) {
// @TODO currently not possible, please create an issue at https://github.com/apioo/psx-api if needed
$data = [];

throw new MultipartException($data);
}

throw new UnknownStatusCodeException('The server returned an unknown status code: ' . $statusCode);
} catch (\Throwable $e) {
throw new ClientException('An unknown error occurred: ' . $e->getMessage());
Expand All @@ -393,6 +430,7 @@ public function multipart(array $payload): TestResponse
*
* @param string $payload
* @return TestResponse
* @throws TextException
* @throws ClientException
*/
public function text(string $payload): TestResponse
Expand Down Expand Up @@ -423,6 +461,12 @@ public function text(string $payload): TestResponse
$body = $e->getResponse()->getBody();
$statusCode = $e->getResponse()->getStatusCode();

if ($statusCode === 500) {
$data = (string) $body;

throw new TextException($data);
}

throw new UnknownStatusCodeException('The server returned an unknown status code: ' . $statusCode);
} catch (\Throwable $e) {
throw new ClientException('An unknown error occurred: ' . $e->getMessage());
Expand All @@ -434,6 +478,7 @@ public function text(string $payload): TestResponse
*
* @param string $payload
* @return TestResponse
* @throws XmlException
* @throws ClientException
*/
public function xml(string $payload): TestResponse
Expand Down Expand Up @@ -464,6 +509,12 @@ public function xml(string $payload): TestResponse
$body = $e->getResponse()->getBody();
$statusCode = $e->getResponse()->getStatusCode();

if ($statusCode === 500) {
$data = (string) $body;

throw new XmlException($data);
}

throw new UnknownStatusCodeException('The server returned an unknown status code: ' . $statusCode);
} catch (\Throwable $e) {
throw new ClientException('An unknown error occurred: ' . $e->getMessage());
Expand Down
29 changes: 29 additions & 0 deletions tests/Generator/Client/resource/php_test/TestResponseException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* TestResponseException automatically generated by SDKgen please do not edit this file manually
* @see https://sdkgen.app
*/

namespace Sdkgen\Client\Tests\Generated;

use Sdkgen\Client\Exception\KnownStatusCodeException;

class TestResponseException extends KnownStatusCodeException
{
private TestResponse $payload;

public function __construct(TestResponse $payload)
{
parent::__construct('The server returned an error');

$this->payload = $payload;
}

/**
* @return TestResponse
*/
public function getPayload(): TestResponse
{
return $this->payload;
}
}
29 changes: 29 additions & 0 deletions tests/Generator/Client/resource/php_test/TextException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* TextException automatically generated by SDKgen please do not edit this file manually
* @see https://sdkgen.app
*/

namespace Sdkgen\Client\Tests\Generated;

use Sdkgen\Client\Exception\KnownStatusCodeException;

class TextException extends KnownStatusCodeException
{
private string $payload;

public function __construct(string $payload)
{
parent::__construct('The server returned an error');

$this->payload = $payload;
}

/**
* @return string
*/
public function getPayload(): string
{
return $this->payload;
}
}
29 changes: 29 additions & 0 deletions tests/Generator/Client/resource/php_test/XmlException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* XmlException automatically generated by SDKgen please do not edit this file manually
* @see https://sdkgen.app
*/

namespace Sdkgen\Client\Tests\Generated;

use Sdkgen\Client\Exception\KnownStatusCodeException;

class XmlException extends KnownStatusCodeException
{
private string $payload;

public function __construct(string $payload)
{
parent::__construct('The server returned an error');

$this->payload = $payload;
}

/**
* @return string
*/
public function getPayload(): string
{
return $this->payload;
}
}
19 changes: 19 additions & 0 deletions tests/Generator/Client/resource/typescript_test/BinaryException.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* BinaryException automatically generated by SDKgen please do not edit this file manually
* {@link https://sdkgen.app}
*/

import {KnownStatusCodeException} from "sdkgen-client"


export class BinaryException extends KnownStatusCodeException {

public constructor(private payload: ArrayBuffer) {
super('The server returned an error');
}

public getPayload(): ArrayBuffer {
return this.payload;
}

}
19 changes: 19 additions & 0 deletions tests/Generator/Client/resource/typescript_test/FormException.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* FormException automatically generated by SDKgen please do not edit this file manually
* {@link https://sdkgen.app}
*/

import {KnownStatusCodeException} from "sdkgen-client"


export class FormException extends KnownStatusCodeException {

public constructor(private payload: URLSearchParams) {
super('The server returned an error');
}

public getPayload(): URLSearchParams {
return this.payload;
}

}
Loading

0 comments on commit 7025b9c

Please sign in to comment.