-
Notifications
You must be signed in to change notification settings - Fork 56
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 #174 from akeneo/MET-23
MET-23: add measurement families to the php client
- Loading branch information
Showing
7 changed files
with
156 additions
and
1 deletion.
There are no files selected for viewing
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
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,54 @@ | ||
<?php | ||
|
||
namespace spec\Akeneo\Pim\ApiClient\Api; | ||
|
||
use Akeneo\Pim\ApiClient\Api\MeasurementFamilyApi; | ||
use Akeneo\Pim\ApiClient\Api\MeasurementFamilyApiInterface; | ||
use Akeneo\Pim\ApiClient\Api\Operation\ListableResourceInterface; | ||
use Akeneo\Pim\ApiClient\Api\Operation\UpsertableResourceListInterface; | ||
use Akeneo\Pim\ApiClient\Client\ResourceClientInterface; | ||
use Akeneo\Pim\ApiClient\Pagination\PageFactoryInterface; | ||
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 MeasurementFamilyApiSpec extends ObjectBehavior | ||
{ | ||
function let(ResourceClientInterface $resourceClient) { | ||
$this->beConstructedWith($resourceClient); | ||
} | ||
|
||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType(MeasurementFamilyApi::class); | ||
$this->shouldImplement(MeasurementFamilyApiInterface::class); | ||
} | ||
|
||
function it_returns_all_measurement_families($resourceClient) { | ||
$resourceClient->getResource(MeasurementFamilyApi::MEASUREMENT_FAMILIES_URI)->willReturn([]); | ||
$this->all()->shouldReturn([]); | ||
} | ||
|
||
function it_upserts_a_list_of_measurement_families($resourceClient) | ||
{ | ||
$resourceClient->upsertJsonResourceList( | ||
MeasurementFamilyApi::MEASUREMENT_FAMILIES_URI, | ||
[], | ||
[ | ||
['code' => 'measurement_family_1'], | ||
['code' => 'measurement_family_2'], | ||
['code' => 'measurement_family_3'], | ||
] | ||
)->willReturn([]); | ||
|
||
$this->upsertList( | ||
[ | ||
['code' => 'measurement_family_1'], | ||
['code' => 'measurement_family_2'], | ||
['code' => 'measurement_family_3'], | ||
] | ||
)->shouldReturn([]); | ||
} | ||
} |
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
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
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
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,44 @@ | ||
<?php | ||
|
||
namespace Akeneo\Pim\ApiClient\Api; | ||
|
||
use Akeneo\Pim\ApiClient\Client\ResourceClientInterface; | ||
|
||
/** | ||
* API implementation to manage measurement families. | ||
* | ||
* @author Julien Sanchez <julien@akeneo.com> | ||
* @copyright 2020 Akeneo SAS (http://www.akeneo.com) | ||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) | ||
*/ | ||
class MeasurementFamilyApi implements MeasurementFamilyApiInterface | ||
{ | ||
const MEASUREMENT_FAMILIES_URI = 'api/rest/v1/measurement-families'; | ||
|
||
/** @var ResourceClientInterface */ | ||
protected $resourceClient; | ||
|
||
/** | ||
* @param ResourceClientInterface $resourceClient | ||
*/ | ||
public function __construct(ResourceClientInterface $resourceClient) | ||
{ | ||
$this->resourceClient = $resourceClient; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function all(): array | ||
{ | ||
return $this->resourceClient->getResource(static::MEASUREMENT_FAMILIES_URI); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function upsertList($measurementFamilies): array | ||
{ | ||
return $this->resourceClient->upsertJsonResourceList(static::MEASUREMENT_FAMILIES_URI, [], $measurementFamilies); | ||
} | ||
} |
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,35 @@ | ||
<?php | ||
|
||
namespace Akeneo\Pim\ApiClient\Api; | ||
|
||
use Akeneo\Pim\ApiClient\Exception\HttpException; | ||
|
||
/** | ||
* API to manage the measurement families. | ||
* | ||
* @author Julien Sanchez <julien@akeneo.com> | ||
* @copyright 2020 Akeneo SAS (http://www.akeneo.com) | ||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) | ||
*/ | ||
interface MeasurementFamilyApiInterface | ||
{ | ||
/** | ||
* Gets a cursor to iterate over all the measurement families | ||
* | ||
* @throws HttpException If the request failed. | ||
* | ||
* @return array | ||
*/ | ||
public function all(): array; | ||
|
||
/** | ||
* Updates or creates several resources. | ||
* | ||
* @param array $resources array object containing the measurement families to create or update | ||
* | ||
* @throws HttpException | ||
* | ||
* @return array returns an array, each entry corresponding to the response of the upserted measurement families | ||
*/ | ||
public function upsertList($resources): array; | ||
} |