-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
822 additions
and
193 deletions.
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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Webgriffe\SyliusAkeneoPlugin\InMemory\Client\Api; | ||
|
||
use Akeneo\Pim\ApiClient\Api\FamilyApiInterface; | ||
use Tests\Webgriffe\SyliusAkeneoPlugin\InMemory\Client\Api\Model\Family; | ||
|
||
final class InMemoryFamilyApi extends InMemoryApi implements FamilyApiInterface | ||
{ | ||
protected function getResourceClass(): string | ||
{ | ||
return Family::class; | ||
} | ||
} |
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,81 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Webgriffe\SyliusAkeneoPlugin\InMemory\Client\Api; | ||
|
||
use Akeneo\Pim\ApiClient\Api\FamilyVariantApiInterface; | ||
use Akeneo\Pim\ApiClient\Exception\NotFoundHttpException; | ||
use Akeneo\Pim\ApiClient\Pagination\PageInterface; | ||
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface; | ||
use GuzzleHttp\Promise\PromiseInterface; | ||
use GuzzleHttp\Psr7\Request; | ||
use GuzzleHttp\Psr7\Response; | ||
use Http\Promise\Promise; | ||
use Tests\Webgriffe\SyliusAkeneoPlugin\InMemory\Client\Api\Model\FamilyVariant; | ||
|
||
final class InMemoryFamilyVariantApi implements FamilyVariantApiInterface | ||
{ | ||
/** | ||
* @var array<string, <string, FamilyVariant>> | ||
*/ | ||
public static array $familyVariants = []; | ||
|
||
public static function addResource(string $familyCode, FamilyVariant $familyVariant): void | ||
{ | ||
self::$familyVariants[$familyCode][$familyVariant->code] = $familyVariant; | ||
} | ||
|
||
public function get($familyCode, $familyVariantCode): array | ||
{ | ||
if (!array_key_exists($familyCode, self::$familyVariants)) { | ||
throw $this->createNotFoundException(); | ||
} | ||
$familyVariants = self::$familyVariants[$familyCode]; | ||
if (!array_key_exists($familyVariantCode, $familyVariants)) { | ||
throw $this->createNotFoundException(); | ||
} | ||
|
||
return $familyVariants[$familyVariantCode]->__serialize(); | ||
} | ||
|
||
public function create($familyCode, $familyVariantCode, array $data = []): int | ||
{ | ||
// TODO: Implement create() method. | ||
} | ||
|
||
public function upsert($familyCode, $familyVariantCode, array $data = []): int | ||
{ | ||
// TODO: Implement upsert() method. | ||
} | ||
|
||
public function upsertAsync($familyCode, $familyVariantCode, array $data = []): PromiseInterface|Promise | ||
{ | ||
// TODO: Implement upsertAsync() method. | ||
} | ||
|
||
public function listPerPage($familyCode, $limit = 100, $withCount = false, array $queryParameters = []): PageInterface | ||
{ | ||
// TODO: Implement listPerPage() method. | ||
} | ||
|
||
public function all($familyCode, $pageSize = 10, array $queryParameters = []): ResourceCursorInterface | ||
{ | ||
// TODO: Implement all() method. | ||
} | ||
|
||
public function upsertList($familyCode, $familyVariants): \Traversable | ||
{ | ||
// TODO: Implement upsertList() method. | ||
} | ||
|
||
public function upsertAsyncList($familyCode, $familyVariants): PromiseInterface|Promise | ||
{ | ||
// TODO: Implement upsertAsyncList() method. | ||
} | ||
|
||
private function createNotFoundException(): NotFoundHttpException | ||
{ | ||
return new NotFoundHttpException('Attribute option not found', new Request('GET', '/'), new Response(404)); | ||
} | ||
} |
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,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Webgriffe\SyliusAkeneoPlugin\InMemory\Client\Api; | ||
|
||
use Akeneo\Pim\ApiClient\Api\MediaFileApiInterface; | ||
use Akeneo\Pim\ApiClient\Exception\HttpException; | ||
use Akeneo\Pim\ApiClient\Pagination\PageInterface; | ||
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface; | ||
use GuzzleHttp\Psr7\Request; | ||
use GuzzleHttp\Psr7\Response; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Tests\Webgriffe\SyliusAkeneoPlugin\Integration\DataFixtures\DataFixture; | ||
|
||
final class InMemoryProductMediaFileApi implements MediaFileApiInterface | ||
{ | ||
public function download(string $code): ResponseInterface | ||
{ | ||
$path = DataFixture::path . '/Media/' . $code; | ||
if (!file_exists($path)) { | ||
throw new HttpException("File '$path' does not exists.", new Request('GET', '/'), new Response(404)); | ||
} | ||
|
||
return new Response(200, [], file_get_contents($path)); | ||
} | ||
|
||
public function get(string $code): array | ||
{ | ||
// TODO: Implement get() method. | ||
} | ||
|
||
public function listPerPage(int $limit = 100, bool $withCount = false, array $queryParameters = []): PageInterface | ||
{ | ||
// TODO: Implement listPerPage() method. | ||
} | ||
|
||
public function all(int $pageSize = 100, array $queryParameters = []): ResourceCursorInterface | ||
{ | ||
// TODO: Implement all() method. | ||
} | ||
|
||
public function create($mediaFile, array $data): string | ||
{ | ||
// TODO: Implement create() method. | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Webgriffe\SyliusAkeneoPlugin\InMemory\Client\Api; | ||
|
||
use Akeneo\Pim\ApiClient\Api\ProductModelApiInterface; | ||
use Tests\Webgriffe\SyliusAkeneoPlugin\InMemory\Client\Api\Model\ProductModel; | ||
|
||
final class InMemoryProductModelApi extends InMemoryApi implements ProductModelApiInterface | ||
{ | ||
protected function getResourceClass(): string | ||
{ | ||
return ProductModel::class; | ||
} | ||
} |
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,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Webgriffe\SyliusAkeneoPlugin\InMemory\Client\Api\Model; | ||
|
||
final class Family implements ResourceInterface | ||
{ | ||
public function __construct( | ||
public string $code, | ||
public array $attributes = [], | ||
public string $attributeAsLabel = '', | ||
public string $attributeAsImage = '', | ||
public array $attributeRequirements = [], | ||
public array $labels = [], | ||
) { | ||
} | ||
|
||
public static function create(string $code, array $data = []): ResourceInterface | ||
{ | ||
return new self( | ||
$code, | ||
$data['attributes'] ?? [], | ||
$data['attribute_as_label'] ?? '', | ||
$data['attribute_as_image'] ?? '', | ||
$data['attribute_requirements'] ?? [], | ||
$data['labels'] ?? [], | ||
); | ||
} | ||
|
||
public function __serialize(): array | ||
{ | ||
return [ | ||
'code' => $this->code, | ||
'attributes' => $this->attributes, | ||
'attribute_as_label' => $this->attributeAsLabel, | ||
'attribute_as_image' => $this->attributeAsImage, | ||
'attribute_requirements' => $this->attributeRequirements, | ||
'labels' => $this->labels, | ||
]; | ||
} | ||
|
||
public function getIdentifier(): string | ||
{ | ||
return $this->code; | ||
} | ||
} |
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,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Webgriffe\SyliusAkeneoPlugin\InMemory\Client\Api\Model; | ||
|
||
final class FamilyVariant implements ResourceInterface | ||
{ | ||
public function __construct( | ||
public string $code, | ||
public array $labels = [], | ||
public array $variantAttributeSets = [], | ||
) { | ||
} | ||
|
||
public static function create(string $code, array $data = []): ResourceInterface | ||
{ | ||
return new self( | ||
$code, | ||
$data['labels'] ?? [], | ||
$data['variant_attribute_sets'] ?? [], | ||
); | ||
} | ||
|
||
public function __serialize(): array | ||
{ | ||
return [ | ||
'code' => $this->code, | ||
'labels' => $this->labels, | ||
'variant_attribute_sets' => $this->variantAttributeSets, | ||
]; | ||
} | ||
|
||
public function getIdentifier(): string | ||
{ | ||
return $this->code; | ||
} | ||
} |
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,76 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Webgriffe\SyliusAkeneoPlugin\InMemory\Client\Api\Model; | ||
|
||
use DateTimeImmutable; | ||
use DateTimeInterface; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class ProductModel implements ResourceInterface | ||
{ | ||
public DateTimeInterface $created; | ||
public DateTimeInterface $updated; | ||
|
||
/** | ||
* @param string[] $categories | ||
* @param array<string, array{'locale': ?string, 'scope': ?string, 'data': mixed}> $values | ||
* @param array<string, array{'products': string[], 'product_models': string[], 'groups': string[]}> $associations | ||
* @param array $quantifiedAssociations | ||
*/ | ||
private function __construct( | ||
public string $code, | ||
public ?string $family = null, | ||
public ?string $familyVariant = null, | ||
public ?string $parent = null, | ||
public array $categories = [], | ||
public array $values = [], | ||
public array $associations = [], | ||
public array $quantifiedAssociations = [], | ||
) { | ||
$now = new DateTimeImmutable(); | ||
$this->created = $now; | ||
$this->updated = $now; | ||
} | ||
|
||
public static function create(string $code, array $data = []): self | ||
{ | ||
Assert::keyExists($data, 'family'); | ||
Assert::keyExists($data, 'family_variant'); | ||
$family = $data['family']; | ||
$familyVariant = $data['family_variant']; | ||
|
||
return new self( | ||
$code, | ||
$family, | ||
$familyVariant, | ||
$data['parent'] ?? null, | ||
$data['categories'] ?? [], | ||
$data['values'] ?? [], | ||
$data['associations'] ?? [], | ||
$data['quantifiedAssociations'] ?? [], | ||
); | ||
} | ||
|
||
public function getIdentifier(): string | ||
{ | ||
return $this->code; | ||
} | ||
|
||
public function __serialize(): array | ||
{ | ||
return [ | ||
'code' => $this->code, | ||
'family' => $this->family, | ||
'family_variant' => $this->familyVariant, | ||
'parent' => $this->parent, | ||
'categories' => $this->categories, | ||
'values' => $this->values, | ||
'created' => $this->created->format('c'), | ||
'updated' => $this->updated->format('c'), | ||
'associations' => $this->associations, | ||
'quantified_associations' => $this->quantifiedAssociations, | ||
]; | ||
} | ||
} |
Oops, something went wrong.