Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .ci/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,9 @@ def runPim2IntegrationTest(String phpVersion, String client, String psrImplem, S
def files = []

// Find and store PHP test integration files to launch them in parallels
if ("2.1" == pimVersion) {
files += sh (returnStdout: true, script: 'find /home/jenkins/php-api-client/tests/v2_1/Api -name "*Integration.php"').tokenize('\n')
}
files += sh (returnStdout: true, script: 'find /home/jenkins/php-api-client/tests/v2_0/Api -name "*Integration.php"').tokenize('\n')
files += sh (returnStdout: true, script: 'find /home/jenkins/php-api-client/tests/Common/Api -name "*Integration.php"').tokenize('\n')
for (file in files) {
Expand Down
6 changes: 6 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@
<directory suffix="Integration.php">tests/v2_0/Api/*</directory>
</testsuite>

<testsuite name="PHP_Client_Test_2_1">
<directory suffix="Integration.php">tests/Common/Api/*</directory>
<directory suffix="Integration.php">tests/v2_0/Api/*</directory>
<directory suffix="Integration.php">tests/v2_1/Api/*</directory>
</testsuite>

</phpunit>
14 changes: 14 additions & 0 deletions spec/Api/AttributeOptionApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Akeneo\Pim\ApiClient\Pagination\PageInterface;
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface;
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface;
use Akeneo\Pim\ApiClient\Stream\UpsertResourceListResponse;
use PhpSpec\ObjectBehavior;

class AttributeOptionApiSpec extends ObjectBehavior
Expand Down Expand Up @@ -149,4 +150,17 @@ function it_upserts_an_attribute_option($resourceClient)
->upsert('foo', 'bar', ['code' => 'bar', 'attribute' => 'foo', 'sort_order' => 42])
->shouldReturn(204);
}

function it_upserts_a_list_of_attribute_options($resourceClient, UpsertResourceListResponse $response)
{
$resourceClient->upsertResourceList(AttributeOptionApi::ATTRIBUTE_OPTIONS_URI, ['foo'], [
['code' => 'bar', 'attribute' => 'foo', 'sort_order' => 42],
['code' => 'fighters', 'attribute' => 'foo', 'sort_order' => 43]
])->willReturn($response);

$this->upsertList('foo', [
['code' => 'bar', 'attribute' => 'foo', 'sort_order' => 42],
['code' => 'fighters', 'attribute' => 'foo', 'sort_order' => 43]
])->shouldReturn($response);
}
}
8 changes: 8 additions & 0 deletions src/Api/AttributeOptionApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,12 @@ public function upsert($attributeCode, $attributeOptionCode, array $data = [])
{
return $this->resourceClient->upsertResource(static::ATTRIBUTE_OPTION_URI, [$attributeCode, $attributeOptionCode], $data);
}

/**
* {@inheritdoc}
*/
public function upsertList($attributeCode, $attributeOptions)
{
return $this->resourceClient->upsertResourceList(static::ATTRIBUTE_OPTIONS_URI, [$attributeCode], $attributeOptions);
}
}
12 changes: 12 additions & 0 deletions src/Api/AttributeOptionApiInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,16 @@ public function create($attributeCode, $attributeOptionCode, array $data = []);
* @return int returns either http code 201 if the attribute option has been created or 204 if it has been updated
*/
public function upsert($attributeCode, $attributeOptionCode, array $data = []);

/**
* Updates or creates several attribute options at once.
*
* @param string $attributeCode code of the attribute
* @param array|StreamInterface $attributeOptions array or StreamInterface object containing data of the attribute options to create or update
*
* @throws HttpException
*
* @return \Traversable returns an iterable object, each entry corresponding to the response of the upserted attribute options
*/
public function upsertList($attributeCode, $attributeOptions);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

namespace Akeneo\Pim\ApiClient\tests\v2_1\Api\AttributeOption;

use Akeneo\Pim\ApiClient\tests\Common\Api\ApiTestCase;

class UpsertListAttributeOptionIntegration extends ApiTestCase
{
public function testUpsertListSuccessful()
{
$api = $this->createClient()->getAttributeOptionApi();
$response = $api->upsertList('weather_conditions', [
[
'code' => 'hot',
'attribute' => 'weather_conditions',
'sort_order' => 34,
'labels' => [
'en_US' => 'Hot!',
],
],
[
'code' => 'cloudy',
'attribute' => 'weather_conditions',
'sort_order' => 35,
'labels' => [
'en_US' => 'Cloudy',
],

],
]);

$this->assertInstanceOf('\Iterator', $response);

$responseLines = iterator_to_array($response);
$this->assertCount(2, $responseLines);

$this->assertSame([
'line' => 1,
'code' => 'hot',
'status_code' => 204,
], $responseLines[1]);

$this->assertSame([
'line' => 2,
'code' => 'cloudy',
'status_code' => 201,
], $responseLines[2]);
}

public function testUpsertListFailed()
{
$api = $this->createClient()->getAttributeOptionApi();
$response = $api->upsertList('weather_conditions', [
[
'attribute' => 'weather_conditions',
'sort_order' => 34,
'labels' => [
'en_US' => 'Hot!',
],
],
[
'code' => 'cloudy!',
'attribute' => 'weather_conditions',
'sort_order' => 35,
'labels' => [
'en_US' => 'Cloudy',
],

],
]);

$this->assertInstanceOf('\Iterator', $response);

$responseLines = iterator_to_array($response);
$this->assertCount(2, $responseLines);

$this->assertSame([
'line' => 1,
'status_code' => 422,
'message' => 'Code is missing.',
], $responseLines[1]);

$this->assertSame([
'line' => 2,
'code' => 'cloudy!',
'status_code' => 422,
'message' => 'Validation failed.',
'errors' => [[
'property' => 'code',
'message' => 'Option code may contain only letters, numbers and underscores'
]]
], $responseLines[2]);
}
}