|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Akeneo\Pim\ApiClient\tests\Api; |
| 4 | + |
| 5 | +use Akeneo\Pim\ApiClient\Api\ProductDraftUuidApi; |
| 6 | +use Akeneo\Pim\ApiClient\Client\HttpClient; |
| 7 | +use donatj\MockWebServer\RequestInfo; |
| 8 | +use donatj\MockWebServer\Response; |
| 9 | +use donatj\MockWebServer\ResponseStack; |
| 10 | +use PHPUnit\Framework\Assert; |
| 11 | + |
| 12 | +/** |
| 13 | + * @copyright 2022 Akeneo SAS (https://www.akeneo.com) |
| 14 | + * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
| 15 | + */ |
| 16 | +class GetProductDraftUuidIntegration extends ApiTestCase |
| 17 | +{ |
| 18 | + public function test_get_product() |
| 19 | + { |
| 20 | + $this->server->setResponseOfPath( |
| 21 | + '/'.sprintf(ProductDraftUuidApi::PRODUCT_DRAFT_UUID_URI, '12951d98-210e-4bRC-ab18-7fdgf1bd14f3'), |
| 22 | + new ResponseStack( |
| 23 | + new Response($this->getProductDraft(), [], HttpClient::HTTP_OK) |
| 24 | + ) |
| 25 | + ); |
| 26 | + |
| 27 | + $api = $this->createClientByPassword()->getProductDraftUuidApi(); |
| 28 | + $product = $api->get('12951d98-210e-4bRC-ab18-7fdgf1bd14f3'); |
| 29 | + |
| 30 | + Assert::assertSame('GET', $this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_METHOD]); |
| 31 | + Assert::assertEquals($product, json_decode($this->getProductDraft(), true)); |
| 32 | + } |
| 33 | + |
| 34 | + public function test_get_unknown_product() |
| 35 | + { |
| 36 | + $this->server->setResponseOfPath( |
| 37 | + '/'.sprintf(ProductDraftUuidApi::PRODUCT_DRAFT_UUID_URI, '12951d98-210e-4bRC-ab18-7fdgf1bd14f3'), |
| 38 | + new ResponseStack( |
| 39 | + new Response('{"code": 404, "message":"Resource `12951d98-210e-4bRC-ab18-7fdgf1bd14f3` does not exist."}', [], 404) |
| 40 | + ) |
| 41 | + ); |
| 42 | + |
| 43 | + $this->expectException(\Akeneo\Pim\ApiClient\Exception\NotFoundHttpException::class); |
| 44 | + $this->expectExceptionMessage('Resource `12951d98-210e-4bRC-ab18-7fdgf1bd14f3` does not exist.'); |
| 45 | + |
| 46 | + $api = $this->createClientByPassword()->getProductDraftUuidApi(); |
| 47 | + $api->get('12951d98-210e-4bRC-ab18-7fdgf1bd14f3'); |
| 48 | + } |
| 49 | + |
| 50 | + private function getProductDraft(): string |
| 51 | + { |
| 52 | + return <<<JSON |
| 53 | + [ |
| 54 | + { |
| 55 | + "uuid" : "12951d98-210e-4bRC-ab18-7fdgf1bd14f3", |
| 56 | + "identifier" : "black_sneakers", |
| 57 | + "family" : "sneakers", |
| 58 | + "groups": [], |
| 59 | + "categories": ["summer_collection"], |
| 60 | + "values": [{ |
| 61 | + "color": {"locale": null, "scope": null, "data": "black"} |
| 62 | + }] |
| 63 | + } |
| 64 | + ] |
| 65 | +JSON; |
| 66 | + } |
| 67 | +} |
0 commit comments