-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #291 from commercetools/gen-sdk-updates
Update generated SDKs
- Loading branch information
Showing
32 changed files
with
2,231 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
...commercetools-history-tests/test/unit/Client/Resource/ResourceByProjectKeyGraphqlTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file has been auto generated | ||
* Do not change it. | ||
*/ | ||
|
||
namespace Commercetools\History\Test\Client\Resource; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Commercetools\Exception\ApiClientException; | ||
use Commercetools\Exception\ApiServerException; | ||
use Commercetools\Client\ApiRequest; | ||
use Commercetools\Base\JsonObject; | ||
use Commercetools\History\Client\HistoryRequestBuilder; | ||
use Psr\Http\Message\RequestInterface; | ||
use GuzzleHttp\Exception\ClientException; | ||
use GuzzleHttp\Exception\ServerException; | ||
use GuzzleHttp\ClientInterface; | ||
use GuzzleHttp\Psr7\Response; | ||
|
||
/** | ||
* @covers \Commercetools\History\Client\Resource\ByProjectKeyGraphqlPost | ||
* @covers \Commercetools\History\Client\Resource\ResourceByProjectKeyGraphql | ||
*/ | ||
class ResourceByProjectKeyGraphqlTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider getRequests() | ||
*/ | ||
public function testBuilder(callable $builderFunction, string $method, string $relativeUri, string $body = null) | ||
{ | ||
$builder = new HistoryRequestBuilder(); | ||
$request = $builderFunction($builder); | ||
$this->assertSame(strtolower($method), strtolower($request->getMethod())); | ||
$this->assertSame($relativeUri, (string) $request->getUri()); | ||
if (!is_null($body)) { | ||
$this->assertJsonStringEqualsJsonString($body, (string) $request->getBody()); | ||
} else { | ||
$this->assertSame("", (string) $request->getBody()); | ||
} | ||
} | ||
|
||
|
||
|
||
/** | ||
* @dataProvider getRequestBuilderResponses() | ||
*/ | ||
public function testMapFromResponse(callable $builderFunction, $statusCode) | ||
{ | ||
$builder = new HistoryRequestBuilder(); | ||
$request = $builderFunction($builder); | ||
$this->assertInstanceOf(ApiRequest::class, $request); | ||
|
||
$response = new Response($statusCode, [], "{}"); | ||
$this->assertInstanceOf(JsonObject::class, $request->mapFromResponse($response)); | ||
} | ||
|
||
/** | ||
* @dataProvider getRequestBuilders() | ||
*/ | ||
public function testExecuteClientException(callable $builderFunction) | ||
{ | ||
$client = $this->createMock(ClientInterface::class); | ||
|
||
$builder = new HistoryRequestBuilder($client); | ||
$request = $builderFunction($builder); | ||
$client->method("send")->willThrowException(new ClientException("Oops!", $request, new Response(400))); | ||
|
||
$this->expectException(ApiClientException::class); | ||
$request->execute(); | ||
} | ||
|
||
/** | ||
* @dataProvider getRequestBuilders() | ||
*/ | ||
public function testExecuteServerException(callable $builderFunction) | ||
{ | ||
$client = $this->createMock(ClientInterface::class); | ||
|
||
$builder = new HistoryRequestBuilder($client); | ||
$request = $builderFunction($builder); | ||
$client->method("send")->willThrowException(new ServerException("Oops!", $request, new Response(500))); | ||
|
||
$this->expectException(ApiServerException::class); | ||
$request->execute(); | ||
} | ||
|
||
public function getRequests() | ||
{ | ||
return [ | ||
'ByProjectKeyGraphqlPost' => [ | ||
function (HistoryRequestBuilder $builder): RequestInterface { | ||
return $builder | ||
->withProjectKeyValue("test_projectKey") | ||
->graphql() | ||
->post(null); | ||
}, | ||
'post', | ||
'test_projectKey/graphql', | ||
] | ||
]; | ||
} | ||
|
||
public function getResources() | ||
{ | ||
return [ | ||
]; | ||
} | ||
|
||
public function getRequestBuilders() | ||
{ | ||
return [ | ||
'ByProjectKeyGraphqlPost' => [ | ||
function (HistoryRequestBuilder $builder): RequestInterface { | ||
return $builder | ||
->withProjectKeyValue("projectKey") | ||
->graphql() | ||
->post(null); | ||
} | ||
] | ||
]; | ||
} | ||
|
||
public function getRequestBuilderResponses() | ||
{ | ||
return [ | ||
'ByProjectKeyGraphqlPost_200' => [ | ||
function (HistoryRequestBuilder $builder): RequestInterface { | ||
return $builder | ||
->withProjectKeyValue("projectKey") | ||
->graphql() | ||
->post(null); | ||
}, | ||
200 | ||
], | ||
'ByProjectKeyGraphqlPost_599' => [ | ||
function (HistoryRequestBuilder $builder): RequestInterface { | ||
return $builder | ||
->withProjectKeyValue("projectKey") | ||
->graphql() | ||
->post(null); | ||
}, | ||
599 | ||
] | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
lib/commercetools-history/src/Client/Resource/ByProjectKeyGraphqlPost.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file has been auto generated | ||
* Do not change it. | ||
*/ | ||
|
||
namespace Commercetools\History\Client\Resource; | ||
|
||
use GuzzleHttp\ClientInterface; | ||
use GuzzleHttp\Exception\RequestException; | ||
use GuzzleHttp\Exception\ServerException; | ||
use GuzzleHttp\Exception\ClientException; | ||
use GuzzleHttp\Promise\PromiseInterface; | ||
use Commercetools\Exception\ExceptionFactory; | ||
use Commercetools\Exception\InvalidArgumentException; | ||
use Commercetools\Exception\ApiServerException; | ||
use Commercetools\Exception\ApiClientException; | ||
use Commercetools\Client\ApiRequest; | ||
use Commercetools\Base\JsonObject; | ||
use Commercetools\Base\JsonObjectModel; | ||
use Commercetools\History\Models\GraphQl\GraphQLResponse; | ||
use Commercetools\History\Models\GraphQl\GraphQLResponseModel; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
|
||
/** | ||
* @psalm-suppress PropertyNotSetInConstructor | ||
* | ||
*/ | ||
class ByProjectKeyGraphqlPost extends ApiRequest | ||
{ | ||
/** | ||
* @param ?object|array|string $body | ||
* @psalm-param array<string, scalar|scalar[]> $headers | ||
*/ | ||
public function __construct(string $projectKey, $body = null, array $headers = [], ClientInterface $client = null) | ||
{ | ||
$uri = str_replace(['{projectKey}'], [$projectKey], '{projectKey}/graphql'); | ||
parent::__construct($client, 'POST', $uri, $headers, is_object($body) || is_array($body) ? json_encode($body) : $body); | ||
} | ||
|
||
/** | ||
* @template T of JsonObject | ||
* @psalm-param ?class-string<T> $resultType | ||
* @return GraphQLResponse|JsonObject|T|null | ||
*/ | ||
public function mapFromResponse(?ResponseInterface $response, string $resultType = null) | ||
{ | ||
if (is_null($response)) { | ||
return null; | ||
} | ||
if (is_null($resultType)) { | ||
switch ($response->getStatusCode()) { | ||
case '200': | ||
$resultType = GraphQLResponseModel::class; | ||
|
||
break; | ||
default: | ||
$resultType = JsonObjectModel::class; | ||
|
||
break; | ||
} | ||
} | ||
|
||
return $resultType::of($this->responseData($response)); | ||
} | ||
|
||
/** | ||
* @template T of JsonObject | ||
* @psalm-param ?class-string<T> $resultType | ||
* | ||
* @return null|T|GraphQLResponse|JsonObject | ||
*/ | ||
public function execute(array $options = [], string $resultType = null) | ||
{ | ||
try { | ||
$response = $this->send($options); | ||
} catch (ServerException $e) { | ||
$response = $e->getResponse(); | ||
$e = ExceptionFactory::createServerException($e, $this, $response, $this->mapFromResponse($response, $resultType)); | ||
throw $e; | ||
} catch (ClientException $e) { | ||
$response = $e->getResponse(); | ||
$e = ExceptionFactory::createClientException($e, $this, $response, $this->mapFromResponse($response, $resultType)); | ||
throw $e; | ||
} | ||
|
||
return $this->mapFromResponse($response, $resultType); | ||
} | ||
|
||
/** | ||
* @template T of JsonObject | ||
* @psalm-param ?class-string<T> $resultType | ||
* | ||
* @return PromiseInterface | ||
*/ | ||
public function executeAsync(array $options = [], string $resultType = null) | ||
{ | ||
return $this->sendAsync($options)->then( | ||
function(ResponseInterface $response) use ($resultType) { | ||
return $this->mapFromResponse($response, $resultType); | ||
}, | ||
function (RequestException $e) use ($resultType) { | ||
$response = $e->getResponse(); | ||
if ($e instanceof ServerException) { | ||
$e = ExceptionFactory::createServerException($e, $this, $response, $this->mapFromResponse($response, $resultType)); | ||
} | ||
if ($e instanceof ClientException) { | ||
$e = ExceptionFactory::createClientException($e, $this, $response, $this->mapFromResponse($response, $resultType)); | ||
} | ||
throw $e; | ||
} | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
lib/commercetools-history/src/Client/Resource/ResourceByProjectKeyGraphql.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file has been auto generated | ||
* Do not change it. | ||
*/ | ||
|
||
namespace Commercetools\History\Client\Resource; | ||
|
||
use Commercetools\Client\ApiResource; | ||
use GuzzleHttp\ClientInterface; | ||
use Psr\Http\Message\UploadedFileInterface; | ||
use Commercetools\History\Models\GraphQl\GraphQLRequest; | ||
|
||
/** | ||
* @psalm-suppress PropertyNotSetInConstructor | ||
*/ | ||
class ResourceByProjectKeyGraphql extends ApiResource | ||
{ | ||
/** | ||
* @psalm-param array<string, string> $args | ||
*/ | ||
public function __construct(array $args = [], ClientInterface $client = null) { | ||
parent::__construct('/{projectKey}/graphql', $args, $client); | ||
} | ||
|
||
/** | ||
* @psalm-param ?GraphQLRequest $body | ||
* @psalm-param array<string, scalar|scalar[]> $headers | ||
*/ | ||
public function post(?GraphQLRequest $body = null, array $headers = []): ByProjectKeyGraphqlPost | ||
{ | ||
$args = $this->getArgs(); | ||
|
||
return new ByProjectKeyGraphqlPost($args['projectKey'], $body, $headers, $this->getClient()); | ||
} | ||
|
||
} |
Oops, something went wrong.