-
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 #69 from commercetools/gen-sdk-updates
- Loading branch information
Showing
392 changed files
with
26,296 additions
and
195 deletions.
There are no files selected for viewing
247 changes: 247 additions & 0 deletions
247
...it/Client/Resource/ResourceByProjectKeyInStoreKeyByStoreKeyProductProjectionsByIDTest.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,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 | ||
] | ||
]; | ||
} | ||
} |
Oops, something went wrong.