Skip to content

Commit

Permalink
Merge pull request #69 from commercetools/gen-sdk-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jenschude authored Jan 25, 2022
2 parents b762f21 + a002164 commit b05baed
Show file tree
Hide file tree
Showing 392 changed files with 26,296 additions and 195 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
<?php

declare(strict_types=1);
/**
* This file has been auto generated
* Do not change it.
*/

namespace Commercetools\Api\Test\Client\Resource;

use Commercetools\Api\Client\ApiRequestBuilder;
use Commercetools\Base\JsonObject;
use Commercetools\Client\ApiRequest;
use Commercetools\Exception\ApiClientException;
use Commercetools\Exception\ApiServerException;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\ServerException;
use GuzzleHttp\Psr7\Response;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\RequestInterface;

/**
* @covers \Commercetools\Api\Client\Resource\ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDGet
* @covers \Commercetools\Api\Client\Resource\ResourceByProjectKeyInStoreKeyByStoreKeyProductProjectionsByID
*/
class ResourceByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDTest extends TestCase
{
/**
* @dataProvider getRequests()
*/
public function testBuilder(callable $builderFunction, string $method, string $relativeUri, string $body = null)
{
$builder = new ApiRequestBuilder();
$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 ApiRequestBuilder();
$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 ApiRequestBuilder($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 ApiRequestBuilder($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 [
'ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDGet_withExpand' => [
function (ApiRequestBuilder $builder): RequestInterface {
return $builder
->withProjectKey('test_projectKey')
->inStoreKeyWithStoreKeyValue('test_storeKey')
->productProjections()
->withId('test_ID')
->get()
->withExpand('expand');
},
'get',
'test_projectKey/in-store/key=test_storeKey/product-projections/test_ID?expand=expand',
],
'ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDGet' => [
function (ApiRequestBuilder $builder): RequestInterface {
return $builder
->withProjectKey("test_projectKey")
->inStoreKeyWithStoreKeyValue("test_storeKey")
->productProjections()
->withId("test_ID")
->get();
},
'get',
'test_projectKey/in-store/key=test_storeKey/product-projections/test_ID',
]
];
}

public function getResources()
{
return [
];
}

public function getRequestBuilders()
{
return [
'ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDGet' => [
function (ApiRequestBuilder $builder): RequestInterface {
return $builder
->withProjectKey("projectKey")
->inStoreKeyWithStoreKeyValue("storeKey")
->productProjections()
->withId("ID")
->get();
}
]
];
}

public function getRequestBuilderResponses()
{
return [
'ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDGet_200' => [
function (ApiRequestBuilder $builder): RequestInterface {
return $builder
->withProjectKey("projectKey")
->inStoreKeyWithStoreKeyValue("storeKey")
->productProjections()
->withId("ID")
->get();
},
200
],
'ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDGet_400' => [
function (ApiRequestBuilder $builder): RequestInterface {
return $builder
->withProjectKey("projectKey")
->inStoreKeyWithStoreKeyValue("storeKey")
->productProjections()
->withId("ID")
->get();
},
400
],
'ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDGet_401' => [
function (ApiRequestBuilder $builder): RequestInterface {
return $builder
->withProjectKey("projectKey")
->inStoreKeyWithStoreKeyValue("storeKey")
->productProjections()
->withId("ID")
->get();
},
401
],
'ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDGet_403' => [
function (ApiRequestBuilder $builder): RequestInterface {
return $builder
->withProjectKey("projectKey")
->inStoreKeyWithStoreKeyValue("storeKey")
->productProjections()
->withId("ID")
->get();
},
403
],
'ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDGet_404' => [
function (ApiRequestBuilder $builder): RequestInterface {
return $builder
->withProjectKey("projectKey")
->inStoreKeyWithStoreKeyValue("storeKey")
->productProjections()
->withId("ID")
->get();
},
404
],
'ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDGet_500' => [
function (ApiRequestBuilder $builder): RequestInterface {
return $builder
->withProjectKey("projectKey")
->inStoreKeyWithStoreKeyValue("storeKey")
->productProjections()
->withId("ID")
->get();
},
500
],
'ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDGet_502' => [
function (ApiRequestBuilder $builder): RequestInterface {
return $builder
->withProjectKey("projectKey")
->inStoreKeyWithStoreKeyValue("storeKey")
->productProjections()
->withId("ID")
->get();
},
502
],
'ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDGet_503' => [
function (ApiRequestBuilder $builder): RequestInterface {
return $builder
->withProjectKey("projectKey")
->inStoreKeyWithStoreKeyValue("storeKey")
->productProjections()
->withId("ID")
->get();
},
503
],
'ByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDGet_599' => [
function (ApiRequestBuilder $builder): RequestInterface {
return $builder
->withProjectKey("projectKey")
->inStoreKeyWithStoreKeyValue("storeKey")
->productProjections()
->withId("ID")
->get();
},
599
]
];
}
}
Loading

0 comments on commit b05baed

Please sign in to comment.