Skip to content

Commit 2e0ba29

Browse files
authored
Merge branch 'master' into correct-getNextPage-method-description
2 parents 45fb623 + 0930cc2 commit 2e0ba29

File tree

11 files changed

+193
-42
lines changed

11 files changed

+193
-42
lines changed

.circleci/config.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
version: 2.1
2+
3+
jobs:
4+
build:
5+
docker:
6+
- image: akeneo/php:7.2
7+
steps:
8+
- checkout
9+
- run: composer install
10+
- persist_to_workspace:
11+
root: ~/
12+
paths:
13+
- project
14+
15+
test_php:
16+
docker:
17+
- image: akeneo/php:7.2
18+
steps:
19+
- attach_workspace:
20+
at: ~/
21+
- run: bin/phpunit -c phpunit.xml.dist
22+
- run: bin/phpspec run
23+
24+
test_php_code_style:
25+
docker:
26+
- image: akeneo/php:7.2
27+
steps:
28+
- attach_workspace:
29+
at: ~/
30+
- run: bin/php-cs-fixer fix --diff --dry-run --config=.php_cs.php -vvv
31+
32+
workflow_success:
33+
docker:
34+
- image: akeneo/php:7.2
35+
steps:
36+
- run:
37+
name: Success
38+
command: echo "The build has run with success! Let's merge :)"
39+
40+
workflows:
41+
pull_request:
42+
jobs:
43+
- wait_for_user_approval:
44+
type: approval
45+
filters:
46+
branches:
47+
ignore:
48+
- master
49+
- build:
50+
requires:
51+
- wait_for_user_approval
52+
- test_php:
53+
requires:
54+
- build
55+
- test_php_code_style:
56+
requires:
57+
- build
58+
- workflow_success:
59+
requires:
60+
- test_php
61+
- test_php_code_style
62+
63+
after_merge:
64+
jobs:
65+
- build:
66+
filters:
67+
branches:
68+
only:
69+
- master
70+
- test_php:
71+
requires:
72+
- build
73+
- test_php_code_style:
74+
requires:
75+
- build
76+
77+
nightly:
78+
when:
79+
and:
80+
- equal: [ scheduled_pipeline, << pipeline.trigger_source >> ]
81+
- equal: [ "nightly_master", << pipeline.schedule.name >> ]
82+
jobs:
83+
- build
84+
- test_php:
85+
requires:
86+
- build

.travis.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Contributing
2+
3+
Want to do your bit for our PHP client? All contributions are warmly welcomed!
4+
5+
## Contribution process
6+
7+
First and foremost, please accept and sign our [Contributor License Agreement](https://www.akeneo.com/contributor-license-agreement/).
8+
9+
And then, do your magic :
10+
* Fork our repository
11+
* Create a branch (choose a descriptive name)
12+
* Work on your own code (don't forget to add necessessaries tests)
13+
* Commit your branch and submit a pull request to our projet
14+
15+
At this moment, the ball is in our court: we will check your PR and add comments or suggestions if needed.
16+
17+
When everything is ok, we merge your work.
18+
19+
Congratulations, you are officially a contributor to our dear PHP client!

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Matrix compatibility:
1010
| v2.1 - v2.2 | v2.0 | March 2019 | [![Build Status](https://travis-ci.org/akeneo/api-php-client.svg?branch=2.0)](https://travis-ci.org/akeneo/api-php-client) |
1111
| v2.3 | v3.0 | December 2019 | [![Build Status](https://travis-ci.org/akeneo/api-php-client.svg?branch=3.0)](https://travis-ci.org/akeneo/api-php-client) |
1212
| v3.0 | v4.0 | August 2020 | [![Build Status](https://travis-ci.org/akeneo/api-php-client.svg?branch=4.0)](https://travis-ci.org/akeneo/api-php-client) |
13-
| - | master | - | [![Build Status](https://travis-ci.org/akeneo/api-php-client.svg?branch=master)](https://travis-ci.org/akeneo/api-php-client)|
13+
| - | master | - | [![CircleCI](https://circleci.com/gh/akeneo/api-php-client/tree/master.svg?style=svg)](https://circleci.com/gh/akeneo/api-php-client/tree/master)|
1414

1515
Note that our PHP client is backward compatible.
1616
For example, if your PIM is currently a v2.3, you can still use a 1.0 version of the PHP client. The new endpoints available in v2.3 will not be available in the v1.0 of the PHP client.
@@ -161,3 +161,9 @@ The support of this client is made in best effort by our Akeneo team.
161161

162162
If you find a bug or want to submit an improvement, don't hesitate to raise an issue on Github.
163163
Also, you can ask questions and discuss about the PHP client with the community in the [Slack User Group](https://akeneopim-ug.slack.com/messages/web-api/).
164+
165+
## Contributing
166+
167+
As this PHP client is an open-source project, all contributions are very welcome!
168+
169+
For more information, please consult [the contributing section](CONTRIBUTING.md)

spec/Api/ProductMediaFileApiSpec.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,11 @@ function it_creates_a_media_file_from_a_path($resourceClient, $fileSystem, Respo
129129
]
130130
];
131131

132-
$response->getHeaders()->willReturn(['Location' => [
132+
$response->hasHeader('location')->willReturn(true);
133+
134+
$response->getHeader('location')->willReturn([
133135
'http://localhost/api/rest/v1/media-files/1/e/e/d/1eed10f108bde68b279d6f903f17b4b053e9d89d_akeneo.png'
134-
]]);
136+
]);
135137

136138
$resourceClient
137139
->createMultipartResource(ProductMediaFileApi::MEDIA_FILES_URI, [], $requestParts)
@@ -164,9 +166,10 @@ function it_creates_a_media_file_from_a_resource($resourceClient, $fileSystem, R
164166
]
165167
];
166168

167-
$response->getHeaders()->willReturn(['Location' => [
169+
$response->hasHeader('location')->willReturn(true);
170+
$response->getHeader('location')->willReturn([
168171
'http://localhost/api/rest/v1/media-files/1/e/e/d/1eed10f108bde68b279d6f903f17b4b053e9d89d_akeneo.png'
169-
]]);
172+
]);
170173

171174
$resourceClient
172175
->createMultipartResource(ProductMediaFileApi::MEDIA_FILES_URI, [], $requestParts)
@@ -202,9 +205,10 @@ function it_creates_a_media_file_for_a_product_model($resourceClient, $fileSyste
202205
]
203206
];
204207

205-
$response->getHeaders()->willReturn(['Location' => [
208+
$response->hasHeader('location')->willReturn(true);
209+
$response->getHeader('location')->willReturn([
206210
'http://localhost/api/rest/v1/media-files/1/e/e/d/1eed10f108bde68b279d6f903f17b4b053e9d89d_akeneo.png'
207-
]]);
211+
]);
208212

209213
$resourceClient
210214
->createMultipartResource(ProductMediaFileApi::MEDIA_FILES_URI, [], $requestParts)
@@ -236,7 +240,7 @@ function it_throws_an_exception_if_the_response_does_not_contain_the_uri_of_the_
236240
]
237241
];
238242

239-
$response->getHeaders()->willReturn(['Location' => '']);
243+
$response->hasHeader('location')->willReturn(false);
240244

241245
$resourceClient
242246
->createMultipartResource(ProductMediaFileApi::MEDIA_FILES_URI, [], $requestParts)
@@ -268,7 +272,8 @@ function it_throws_an_exception_if_the_uri_of_the_created_media_file_is_invalid(
268272
]
269273
];
270274

271-
$response->getHeaders()->willReturn(['Location' => ['http://localhost/api/rest/v1/products/foo']]);
275+
$response->hasHeader('location')->willReturn(true);
276+
$response->getHeader('location')->willReturn(['http://localhost/api/rest/v1/products/foo']);
272277

273278
$resourceClient
274279
->createMultipartResource(ProductMediaFileApi::MEDIA_FILES_URI, [], $requestParts)

src/Api/ProductMediaFileApi.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,13 @@ public function download(string $code): ResponseInterface
130130
*/
131131
protected function extractCodeFromCreationResponse(ResponseInterface $response)
132132
{
133-
$headers = $response->getHeaders();
134-
135-
if (!isset($headers['Location'][0])) {
133+
if (!$response->hasHeader('location')) {
136134
throw new RuntimeException('The response does not contain the URI of the created media-file.');
137135
}
136+
$locationHeader = $response->getHeader('location')[0];
138137

139138
$matches = [];
140-
if (1 !== preg_match(static::MEDIA_FILE_URI_CODE_REGEX, $headers['Location'][0], $matches)) {
139+
if (1 !== preg_match(static::MEDIA_FILE_URI_CODE_REGEX, $locationHeader, $matches)) {
141140
throw new RuntimeException('Unable to find the code in the URI of the created media-file.');
142141
}
143142

src/Api/ProductModelApi.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,12 @@ public function upsertList($productModels): \Traversable
122122
{
123123
return $this->resourceClient->upsertStreamResourceList(static::PRODUCT_MODELS_URI, [], $productModels);
124124
}
125+
126+
/**
127+
* {@inheritdoc}
128+
*/
129+
public function delete(string $code): int
130+
{
131+
return $this->resourceClient->deleteResource(static::PRODUCT_MODEL_URI, [$code]);
132+
}
125133
}

src/Api/ProductModelApiInterface.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Akeneo\Pim\ApiClient\Api;
44

55
use Akeneo\Pim\ApiClient\Api\Operation\CreatableResourceInterface;
6+
use Akeneo\Pim\ApiClient\Api\Operation\DeletableResourceInterface;
67
use Akeneo\Pim\ApiClient\Api\Operation\GettableResourceInterface;
78
use Akeneo\Pim\ApiClient\Api\Operation\ListableResourceInterface;
89
use Akeneo\Pim\ApiClient\Api\Operation\UpsertableResourceInterface;
@@ -20,6 +21,7 @@ interface ProductModelApiInterface extends
2021
CreatableResourceInterface,
2122
UpsertableResourceInterface,
2223
UpsertableResourceListInterface,
23-
ListableResourceInterface
24+
ListableResourceInterface,
25+
DeletableResourceInterface
2426
{
2527
}

tests/Api/CreateProductMediaFileTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,29 @@ public function test_create_media_file()
4141

4242
Assert::assertSame('f/b/0/6/fb068ccc9e3c5609d73c28d852812ba5faeeab28_akeneo.png', $response);
4343
}
44+
45+
public function test_get_created_media_file_location_regardless_of_the_header_case()
46+
{
47+
$mediaFileURI = $this->server->getServerRoot(
48+
) . '/' . ProductMediaFileApi::MEDIA_FILES_URI . '/f/b/0/6/fb068ccc9e3c5609d73c28d852812ba5faeeab28_akeneo.png';
49+
$this->server->setResponseOfPath(
50+
'/' . ProductMediaFileApi::MEDIA_FILES_URI,
51+
new ResponseStack(
52+
new Response('', ['LOcaTiON' => $mediaFileURI], 201)
53+
)
54+
);
55+
56+
$api = $this->createClient()->getProductMediaFileApi();
57+
$mediaFile = realpath(__DIR__ . '/../fixtures/akeneo.png');
58+
59+
$productInfos = [
60+
'identifier' => 'medium_boot',
61+
'attribute' => 'side_view',
62+
'scope' => null,
63+
'locale' => null,
64+
];
65+
66+
$response = $api->create($mediaFile, $productInfos);
67+
Assert::assertSame('f/b/0/6/fb068ccc9e3c5609d73c28d852812ba5faeeab28_akeneo.png', $response);
68+
}
4469
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Akeneo\Pim\ApiClient\tests\Api;
4+
5+
use Akeneo\Pim\ApiClient\Api\ProductModelApi;
6+
use donatj\MockWebServer\RequestInfo;
7+
use donatj\MockWebServer\Response;
8+
use donatj\MockWebServer\ResponseStack;
9+
use PHPUnit\Framework\Assert;
10+
11+
class DeleteProductModelTest extends ApiTestCase
12+
{
13+
public function test_delete_product_model()
14+
{
15+
$this->server->setResponseOfPath(
16+
'/'. sprintf(ProductModelApi::PRODUCT_MODEL_URI, 'docks_white'),
17+
new ResponseStack(
18+
new Response('', [], 204)
19+
)
20+
);
21+
22+
$api = $this->createClient()->getProductModelApi();
23+
24+
$response = $api->delete('docks_white');
25+
26+
Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_METHOD], 'DELETE');
27+
Assert::assertSame(204, $response);
28+
}
29+
}

0 commit comments

Comments
 (0)