diff --git a/.gitignore b/.gitignore index db2b67b..9ba184f 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,8 @@ ###> docker ### docker-compose.override.yml ###< docker ### + +###> friendsofphp/php-cs-fixer ### +/.php_cs +/.php_cs.cache +###< friendsofphp/php-cs-fixer ### diff --git a/.phpspec.yml b/.phpspec.yml new file mode 100644 index 0000000..b0471b1 --- /dev/null +++ b/.phpspec.yml @@ -0,0 +1,7 @@ +suites: + dam-connector: + namespace: AkeneoDAMConnector + psr4_prefix: AkeneoDAMConnector + spec_path: tests/ + spec_prefix: Specification + src_path: src/ diff --git a/composer.json b/composer.json index 18383cb..7d2a40f 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,8 @@ "symfony/yaml": "4.3.*" }, "require-dev": { - "akeneo/php-coupling-detector": "0.3.*" + "akeneo/php-coupling-detector": "0.3.*", + "phpspec/phpspec": "^4.0" }, "repositories": [ { @@ -38,7 +39,8 @@ "preferred-install": { "*": "dist" }, - "sort-packages": true + "sort-packages": true, + "bin-dir": "vendor/bin" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index e5c2682..da588d5 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "110670ab8ee294cdc320eb76f5755b63", + "content-hash": "ecfac2df9355ba0acf4ccd8e82ba27bd", "packages": [ { "name": "akeneo/api-php-client", @@ -3031,16 +3031,16 @@ }, { "name": "doctrine/annotations", - "version": "v1.7.0", + "version": "v1.8.0", "source": { "type": "git", "url": "https://github.com/doctrine/annotations.git", - "reference": "fa4c4e861e809d6a1103bd620cce63ed91aedfeb" + "reference": "904dca4eb10715b92569fbcd79e201d5c349b6bc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/annotations/zipball/fa4c4e861e809d6a1103bd620cce63ed91aedfeb", - "reference": "fa4c4e861e809d6a1103bd620cce63ed91aedfeb", + "url": "https://api.github.com/repos/doctrine/annotations/zipball/904dca4eb10715b92569fbcd79e201d5c349b6bc", + "reference": "904dca4eb10715b92569fbcd79e201d5c349b6bc", "shasum": "" }, "require": { @@ -3049,7 +3049,7 @@ }, "require-dev": { "doctrine/cache": "1.*", - "phpunit/phpunit": "^7.5@dev" + "phpunit/phpunit": "^7.5" }, "type": "library", "extra": { @@ -3095,7 +3095,63 @@ "docblock", "parser" ], - "time": "2019-08-08T18:11:40+00:00" + "time": "2019-10-01T18:55:10+00:00" + }, + { + "name": "doctrine/instantiator", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "a2c590166b2133a4633738648b6b064edae0814a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/a2c590166b2133a4633738648b6b064edae0814a", + "reference": "a2c590166b2133a4633738648b6b064edae0814a", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "require-dev": { + "doctrine/coding-standard": "^6.0", + "ext-pdo": "*", + "ext-phar": "*", + "phpbench/phpbench": "^0.13", + "phpstan/phpstan-phpunit": "^0.11", + "phpstan/phpstan-shim": "^0.11", + "phpunit/phpunit": "^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://www.doctrine-project.org/projects/instantiator.html", + "keywords": [ + "constructor", + "instantiate" + ], + "time": "2019-03-17T17:37:11+00:00" }, { "name": "doctrine/lexer", @@ -3299,6 +3355,578 @@ ], "time": "2018-02-15T16:58:55+00:00" }, + { + "name": "phpdocumentor/reflection-common", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionCommon.git", + "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/63a995caa1ca9e5590304cd845c15ad6d482a62a", + "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "require-dev": { + "phpunit/phpunit": "~6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jaap van Otterdijk", + "email": "opensource@ijaap.nl" + } + ], + "description": "Common reflection classes used by phpdocumentor to reflect the code structure", + "homepage": "http://www.phpdoc.org", + "keywords": [ + "FQSEN", + "phpDocumentor", + "phpdoc", + "reflection", + "static analysis" + ], + "time": "2018-08-07T13:53:10+00:00" + }, + { + "name": "phpdocumentor/reflection-docblock", + "version": "4.3.2", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", + "reference": "b83ff7cfcfee7827e1e78b637a5904fe6a96698e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/b83ff7cfcfee7827e1e78b637a5904fe6a96698e", + "reference": "b83ff7cfcfee7827e1e78b637a5904fe6a96698e", + "shasum": "" + }, + "require": { + "php": "^7.0", + "phpdocumentor/reflection-common": "^1.0.0 || ^2.0.0", + "phpdocumentor/type-resolver": "~0.4 || ^1.0.0", + "webmozart/assert": "^1.0" + }, + "require-dev": { + "doctrine/instantiator": "^1.0.5", + "mockery/mockery": "^1.0", + "phpunit/phpunit": "^6.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", + "time": "2019-09-12T14:27:41+00:00" + }, + { + "name": "phpdocumentor/type-resolver", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/TypeResolver.git", + "reference": "2e32a6d48972b2c1976ed5d8967145b6cec4a4a9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/2e32a6d48972b2c1976ed5d8967145b6cec4a4a9", + "reference": "2e32a6d48972b2c1976ed5d8967145b6cec4a4a9", + "shasum": "" + }, + "require": { + "php": "^7.1", + "phpdocumentor/reflection-common": "^2.0" + }, + "require-dev": { + "ext-tokenizer": "^7.1", + "mockery/mockery": "~1", + "phpunit/phpunit": "^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", + "time": "2019-08-22T18:11:29+00:00" + }, + { + "name": "phpspec/php-diff", + "version": "v1.1.0", + "source": { + "type": "git", + "url": "https://github.com/phpspec/php-diff.git", + "reference": "0464787bfa7cd13576c5a1e318709768798bec6a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpspec/php-diff/zipball/0464787bfa7cd13576c5a1e318709768798bec6a", + "reference": "0464787bfa7cd13576c5a1e318709768798bec6a", + "shasum": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Diff": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Chris Boulton", + "homepage": "http://github.com/chrisboulton" + } + ], + "description": "A comprehensive library for generating differences between two hashable objects (strings or arrays).", + "time": "2016-04-07T12:29:16+00:00" + }, + { + "name": "phpspec/phpspec", + "version": "4.3.4", + "source": { + "type": "git", + "url": "https://github.com/phpspec/phpspec.git", + "reference": "a601fa68ccb42dbcff4a55e462e780700c4811ee" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpspec/phpspec/zipball/a601fa68ccb42dbcff4a55e462e780700c4811ee", + "reference": "a601fa68ccb42dbcff4a55e462e780700c4811ee", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.5", + "ext-tokenizer": "*", + "php": "^7.0,<7.3", + "phpspec/php-diff": "^1.0.0", + "phpspec/prophecy": "^1.6", + "sebastian/exporter": "^1.0 || ^2.0 || ^3.0", + "symfony/console": "^3.2 || ^4.0", + "symfony/event-dispatcher": "^3.2 || ^4.0", + "symfony/finder": "^3.2 || ^4.0", + "symfony/process": "^3.2 || ^4.0", + "symfony/yaml": "^3.2 || ^4.0" + }, + "require-dev": { + "behat/behat": "^3.3", + "phpunit/phpunit": "^5.7|^6.0", + "symfony/filesystem": "^3.2 || ^4.0" + }, + "suggest": { + "phpspec/nyan-formatters": "Adds Nyan formatters" + }, + "bin": [ + "bin/phpspec" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.3.x-dev" + } + }, + "autoload": { + "psr-0": { + "PhpSpec": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + }, + { + "name": "Marcello Duarte", + "homepage": "http://marcelloduarte.net/" + }, + { + "name": "Ciaran McNulty", + "homepage": "https://ciaranmcnulty.com/" + } + ], + "description": "Specification-oriented BDD framework for PHP 5.6+", + "homepage": "http://phpspec.net/", + "keywords": [ + "BDD", + "SpecBDD", + "TDD", + "spec", + "specification", + "testing", + "tests" + ], + "time": "2019-08-05T09:27:18+00:00" + }, + { + "name": "phpspec/prophecy", + "version": "1.9.0", + "source": { + "type": "git", + "url": "https://github.com/phpspec/prophecy.git", + "reference": "f6811d96d97bdf400077a0cc100ae56aa32b9203" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/f6811d96d97bdf400077a0cc100ae56aa32b9203", + "reference": "f6811d96d97bdf400077a0cc100ae56aa32b9203", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "php": "^5.3|^7.0", + "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0|^5.0", + "sebastian/comparator": "^1.1|^2.0|^3.0", + "sebastian/recursion-context": "^1.0|^2.0|^3.0" + }, + "require-dev": { + "phpspec/phpspec": "^2.5|^3.2", + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5 || ^7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.8.x-dev" + } + }, + "autoload": { + "psr-4": { + "Prophecy\\": "src/Prophecy" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + }, + { + "name": "Marcello Duarte", + "email": "marcello.duarte@gmail.com" + } + ], + "description": "Highly opinionated mocking framework for PHP 5.3+", + "homepage": "https://github.com/phpspec/prophecy", + "keywords": [ + "Double", + "Dummy", + "fake", + "mock", + "spy", + "stub" + ], + "time": "2019-10-03T11:07:50+00:00" + }, + { + "name": "sebastian/comparator", + "version": "3.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "5de4fc177adf9bce8df98d8d141a7559d7ccf6da" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/5de4fc177adf9bce8df98d8d141a7559d7ccf6da", + "reference": "5de4fc177adf9bce8df98d8d141a7559d7ccf6da", + "shasum": "" + }, + "require": { + "php": "^7.1", + "sebastian/diff": "^3.0", + "sebastian/exporter": "^3.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "https://github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "time": "2018-07-12T15:12:46+00:00" + }, + { + "name": "sebastian/diff", + "version": "3.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "720fcc7e9b5cf384ea68d9d930d480907a0c1a29" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/720fcc7e9b5cf384ea68d9d930d480907a0c1a29", + "reference": "720fcc7e9b5cf384ea68d9d930d480907a0c1a29", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.5 || ^8.0", + "symfony/process": "^2 || ^3.3 || ^4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Diff implementation", + "homepage": "https://github.com/sebastianbergmann/diff", + "keywords": [ + "diff", + "udiff", + "unidiff", + "unified diff" + ], + "time": "2019-02-04T06:01:07+00:00" + }, + { + "name": "sebastian/exporter", + "version": "3.1.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/68609e1261d215ea5b21b7987539cbfbe156ec3e", + "reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e", + "shasum": "" + }, + "require": { + "php": "^7.0", + "sebastian/recursion-context": "^3.0" + }, + "require-dev": { + "ext-mbstring": "*", + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "http://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "time": "2019-09-14T09:02:43+00:00" + }, + { + "name": "sebastian/recursion-context", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", + "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", + "shasum": "" + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "time": "2017-03-03T06:23:57+00:00" + }, { "name": "symfony/options-resolver", "version": "v4.3.4", @@ -3451,6 +4079,56 @@ "description": "Symfony Stopwatch Component", "homepage": "https://symfony.com", "time": "2019-08-07T11:52:19+00:00" + }, + { + "name": "webmozart/assert", + "version": "1.5.0", + "source": { + "type": "git", + "url": "https://github.com/webmozart/assert.git", + "reference": "88e6d84706d09a236046d686bbea96f07b3a34f4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webmozart/assert/zipball/88e6d84706d09a236046d686bbea96f07b3a34f4", + "reference": "88e6d84706d09a236046d686bbea96f07b3a34f4", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0", + "symfony/polyfill-ctype": "^1.8" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.36 || ^7.5.13" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "psr-4": { + "Webmozart\\Assert\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Assertions to validate method input/output with nice error messages.", + "keywords": [ + "assert", + "check", + "validate" + ], + "time": "2019-08-24T08:43:50+00:00" } ], "aliases": [], diff --git a/src/Application/DamAdapter/FetchAssets.php b/src/Application/DamAdapter/FetchAssets.php index 03f1c36..e5ab5d7 100644 --- a/src/Application/DamAdapter/FetchAssets.php +++ b/src/Application/DamAdapter/FetchAssets.php @@ -4,12 +4,12 @@ namespace AkeneoDAMConnector\Application\DamAdapter; -use AkeneoDAMConnector\Domain\AssetFamilyCode; +use AkeneoDAMConnector\Domain\Model\FamilyCode; interface FetchAssets { /** * Fetches assets on DAM third party system depending on the last fetch date. */ - public function fetch(AssetFamilyCode $assetFamilyCode, ?\DateTimeInterface $lastFetchDate): \Iterator; + public function fetch(FamilyCode $assetFamilyCode, ?\DateTimeInterface $lastFetchDate): \Iterator; } diff --git a/src/Application/Mapping/AssetAttributeBuilder.php b/src/Application/Mapping/AssetAttributeBuilder.php index 40ebbd2..37d50a4 100644 --- a/src/Application/Mapping/AssetAttributeBuilder.php +++ b/src/Application/Mapping/AssetAttributeBuilder.php @@ -6,9 +6,9 @@ namespace AkeneoDAMConnector\Application\Mapping; use AkeneoDAMConnector\Application\ConfigLoader; -use AkeneoDAMConnector\Domain\AssetAttribute; -use AkeneoDAMConnector\Domain\AssetAttributeCode; -use AkeneoDAMConnector\Domain\AssetFamilyCode; +use AkeneoDAMConnector\Domain\Model\Pim\Attribute; +use AkeneoDAMConnector\Domain\Model\Pim\AttributeCode; +use AkeneoDAMConnector\Domain\Model\FamilyCode; class AssetAttributeBuilder { @@ -20,11 +20,11 @@ public function __construct(ConfigLoader $structureConfigLoader) $this->structureConfigLoader = $structureConfigLoader; } - public function build(AssetFamilyCode $familyCode, AssetAttributeCode $attributeCode): AssetAttribute + public function build(FamilyCode $familyCode, AttributeCode $attributeCode): Attribute { $attributeType = $this->getAttributeType($familyCode, $attributeCode); - return new AssetAttribute($attributeCode, $attributeType, false); + return new Attribute($attributeCode, $attributeType, false); } private function getStructureConfig(): array @@ -36,7 +36,7 @@ private function getStructureConfig(): array return $this->structureConfig; } - private function getAttributeType(AssetFamilyCode $familyCode, AssetAttributeCode $attributeCode): string + private function getAttributeType(FamilyCode $familyCode, AttributeCode $attributeCode): string { foreach ($this->getStructureConfig()[(string)$familyCode]['attributes'] as $attribute) { if ($attribute['code'] === (string)$attributeCode) { diff --git a/src/Application/Mapping/AssetConverter.php b/src/Application/Mapping/AssetConverter.php index 840aec7..9198ce8 100644 --- a/src/Application/Mapping/AssetConverter.php +++ b/src/Application/Mapping/AssetConverter.php @@ -4,10 +4,10 @@ namespace AkeneoDAMConnector\Application\Mapping; -use AkeneoDAMConnector\Domain\Asset\DamAsset; -use AkeneoDAMConnector\Domain\Asset\DamAssetValue; -use AkeneoDAMConnector\Domain\Asset\PimAssetValue; -use AkeneoDAMConnector\Domain\AssetAttribute; +use AkeneoDAMConnector\Domain\Model\Dam\DamAsset; +use AkeneoDAMConnector\Domain\Model\Dam\DamAssetValue; +use AkeneoDAMConnector\Domain\Model\Pim\PimAssetValue; +use AkeneoDAMConnector\Domain\Model\Pim\Attribute; class AssetConverter { @@ -18,7 +18,7 @@ public function __construct(AssetValueConverterRegistry $registry) $this->registry = $registry; } - public function convert(DamAsset $damAsset, DamAssetValue $damAssetValue, AssetAttribute $attribute): PimAssetValue + public function convert(DamAsset $damAsset, DamAssetValue $damAssetValue, Attribute $attribute): PimAssetValue { return $this->registry->getConverter($attribute->getType())->convert( $damAsset, diff --git a/src/Application/Mapping/AssetMapper.php b/src/Application/Mapping/AssetMapper.php index 733f6b0..5446334 100644 --- a/src/Application/Mapping/AssetMapper.php +++ b/src/Application/Mapping/AssetMapper.php @@ -5,9 +5,9 @@ namespace AkeneoDAMConnector\Application\Mapping; use AkeneoDAMConnector\Application\ConfigLoader; -use AkeneoDAMConnector\Domain\AssetAttribute; -use AkeneoDAMConnector\Domain\AssetAttributeCode; -use AkeneoDAMConnector\Domain\AssetFamilyCode; +use AkeneoDAMConnector\Domain\Model\Pim\Attribute; +use AkeneoDAMConnector\Domain\Model\Pim\AttributeCode; +use AkeneoDAMConnector\Domain\Model\FamilyCode; use AkeneoDAMConnector\Domain\Exception\AttributeMappingNotFound; use AkeneoDAMConnector\Domain\Exception\FamilyMappingNotFound; @@ -24,15 +24,15 @@ public function __construct(ConfigLoader $mappingConfigLoader, AssetAttributeBui $this->assetAttributeBuilder = $assetAttributeBuilder; } - public function getMappedProperties(AssetFamilyCode $familyCode): array + public function getMappedProperties(FamilyCode $familyCode): array { return array_keys($this->getFamilyMapping($familyCode)); } public function mapAttribute( - AssetFamilyCode $familyCode, + FamilyCode $familyCode, string $damAttributeProperty - ): AssetAttribute { + ): Attribute { $attributeCode = $this->getAttributeCodeFromFamilyMapping( $this->getFamilyMapping($familyCode), $damAttributeProperty @@ -50,7 +50,7 @@ private function getMappingConfig(): array return $this->mappingConfig; } - private function getFamilyMapping(AssetFamilyCode $familyCode): array + private function getFamilyMapping(FamilyCode $familyCode): array { $mapping = $this->getMappingConfig(); @@ -64,11 +64,11 @@ private function getFamilyMapping(AssetFamilyCode $familyCode): array private function getAttributeCodeFromFamilyMapping( array $familyMapping, string $damAttributeProperty - ): AssetAttributeCode { + ): AttributeCode { if (!isset($familyMapping[$damAttributeProperty])) { throw new AttributeMappingNotFound(); } - return new AssetAttributeCode($familyMapping[$damAttributeProperty]); + return new AttributeCode($familyMapping[$damAttributeProperty]); } } diff --git a/src/Application/Mapping/AssetTransformer.php b/src/Application/Mapping/AssetTransformer.php index 166502b..0957080 100644 --- a/src/Application/Mapping/AssetTransformer.php +++ b/src/Application/Mapping/AssetTransformer.php @@ -4,9 +4,9 @@ namespace AkeneoDAMConnector\Application\Mapping; -use AkeneoDAMConnector\Domain\Asset\DamAsset; -use AkeneoDAMConnector\Domain\Asset\PimAsset; -use AkeneoDAMConnector\Domain\Asset\PimAssetValue; +use AkeneoDAMConnector\Domain\Model\Dam\DamAsset; +use AkeneoDAMConnector\Domain\Model\Pim\PimAsset; +use AkeneoDAMConnector\Domain\Model\Pim\PimAssetValue; class AssetTransformer { diff --git a/src/Application/Mapping/AssetValueConverter.php b/src/Application/Mapping/AssetValueConverter.php index 2ebe877..fd432a9 100644 --- a/src/Application/Mapping/AssetValueConverter.php +++ b/src/Application/Mapping/AssetValueConverter.php @@ -4,14 +4,14 @@ namespace AkeneoDAMConnector\Application\Mapping; -use AkeneoDAMConnector\Domain\Asset\DamAsset; -use AkeneoDAMConnector\Domain\Asset\DamAssetValue; -use AkeneoDAMConnector\Domain\Asset\PimAssetValue; -use AkeneoDAMConnector\Domain\AssetAttribute; +use AkeneoDAMConnector\Domain\Model\Dam\DamAsset; +use AkeneoDAMConnector\Domain\Model\Dam\DamAssetValue; +use AkeneoDAMConnector\Domain\Model\Pim\PimAssetValue; +use AkeneoDAMConnector\Domain\Model\Pim\Attribute; interface AssetValueConverter { public function getSupportedType(): string; - public function convert(DamAsset $damAsset, DamAssetValue $asset, AssetAttribute $attribute): PimAssetValue; + public function convert(DamAsset $damAsset, DamAssetValue $asset, Attribute $attribute): PimAssetValue; } diff --git a/src/Application/Mapping/AssetValueConverter/MediaLinkConverter.php b/src/Application/Mapping/AssetValueConverter/MediaLinkConverter.php index 2c644ba..c1ac962 100644 --- a/src/Application/Mapping/AssetValueConverter/MediaLinkConverter.php +++ b/src/Application/Mapping/AssetValueConverter/MediaLinkConverter.php @@ -5,10 +5,10 @@ namespace AkeneoDAMConnector\Application\Mapping\AssetValueConverter; use AkeneoDAMConnector\Application\Mapping\AssetValueConverter; -use AkeneoDAMConnector\Domain\Asset\DamAsset; -use AkeneoDAMConnector\Domain\Asset\DamAssetValue; -use AkeneoDAMConnector\Domain\Asset\PimAssetValue; -use AkeneoDAMConnector\Domain\AssetAttribute; +use AkeneoDAMConnector\Domain\Model\Dam\DamAsset; +use AkeneoDAMConnector\Domain\Model\Dam\DamAssetValue; +use AkeneoDAMConnector\Domain\Model\Pim\PimAssetValue; +use AkeneoDAMConnector\Domain\Model\Pim\Attribute; class MediaLinkConverter implements AssetValueConverter { @@ -17,7 +17,7 @@ public function getSupportedType(): string return 'media_link'; } - public function convert(DamAsset $damAsset, DamAssetValue $damAssetValue, AssetAttribute $attribute): PimAssetValue + public function convert(DamAsset $damAsset, DamAssetValue $damAssetValue, Attribute $attribute): PimAssetValue { $locale = $attribute->isLocalizable() ? (string)$damAsset->locale() : null; diff --git a/src/Application/Mapping/AssetValueConverter/MultiOptionConverter.php b/src/Application/Mapping/AssetValueConverter/MultiOptionConverter.php index 26e8182..603b880 100644 --- a/src/Application/Mapping/AssetValueConverter/MultiOptionConverter.php +++ b/src/Application/Mapping/AssetValueConverter/MultiOptionConverter.php @@ -5,11 +5,10 @@ namespace AkeneoDAMConnector\Application\Mapping\AssetValueConverter; use AkeneoDAMConnector\Application\Mapping\AssetValueConverter; -use AkeneoDAMConnector\Domain\Asset\DamAsset; -use AkeneoDAMConnector\Domain\Asset\DamAssetValue; -use AkeneoDAMConnector\Domain\Asset\PimAssetValue; -use AkeneoDAMConnector\Domain\AssetAttribute; -use AkeneoDAMConnector\Domain\AssetAttributeCode; +use AkeneoDAMConnector\Domain\Model\Dam\DamAsset; +use AkeneoDAMConnector\Domain\Model\Dam\DamAssetValue; +use AkeneoDAMConnector\Domain\Model\Pim\PimAssetValue; +use AkeneoDAMConnector\Domain\Model\Pim\Attribute; class MultiOptionConverter implements AssetValueConverter { @@ -21,7 +20,7 @@ public function getSupportedType(): string public function convert( DamAsset $damAsset, DamAssetValue $damAssetValue, - AssetAttribute $attribute + Attribute $attribute ): PimAssetValue { $options = array_map( function ($option) { diff --git a/src/Application/Mapping/AssetValueConverter/SingleOptionConverter.php b/src/Application/Mapping/AssetValueConverter/SingleOptionConverter.php index d09ac89..6e2dd0c 100644 --- a/src/Application/Mapping/AssetValueConverter/SingleOptionConverter.php +++ b/src/Application/Mapping/AssetValueConverter/SingleOptionConverter.php @@ -5,10 +5,10 @@ namespace AkeneoDAMConnector\Application\Mapping\AssetValueConverter; use AkeneoDAMConnector\Application\Mapping\AssetValueConverter; -use AkeneoDAMConnector\Domain\Asset\DamAsset; -use AkeneoDAMConnector\Domain\Asset\DamAssetValue; -use AkeneoDAMConnector\Domain\Asset\PimAssetValue; -use AkeneoDAMConnector\Domain\AssetAttribute; +use AkeneoDAMConnector\Domain\Model\Dam\DamAsset; +use AkeneoDAMConnector\Domain\Model\Dam\DamAssetValue; +use AkeneoDAMConnector\Domain\Model\Pim\PimAssetValue; +use AkeneoDAMConnector\Domain\Model\Pim\Attribute; class SingleOptionConverter implements AssetValueConverter { @@ -17,7 +17,7 @@ public function getSupportedType(): string return 'single_option'; } - public function convert(DamAsset $damAsset, DamAssetValue $damAssetValue, AssetAttribute $attribute): PimAssetValue + public function convert(DamAsset $damAsset, DamAssetValue $damAssetValue, Attribute $attribute): PimAssetValue { $locale = $attribute->isLocalizable() ? (string)$damAsset->locale() : null; diff --git a/src/Application/Mapping/AssetValueConverter/TextConverter.php b/src/Application/Mapping/AssetValueConverter/TextConverter.php index f98faa9..8877b9d 100644 --- a/src/Application/Mapping/AssetValueConverter/TextConverter.php +++ b/src/Application/Mapping/AssetValueConverter/TextConverter.php @@ -5,10 +5,10 @@ namespace AkeneoDAMConnector\Application\Mapping\AssetValueConverter; use AkeneoDAMConnector\Application\Mapping\AssetValueConverter; -use AkeneoDAMConnector\Domain\Asset\DamAsset; -use AkeneoDAMConnector\Domain\Asset\DamAssetValue; -use AkeneoDAMConnector\Domain\Asset\PimAssetValue; -use AkeneoDAMConnector\Domain\AssetAttribute; +use AkeneoDAMConnector\Domain\Model\Dam\DamAsset; +use AkeneoDAMConnector\Domain\Model\Dam\DamAssetValue; +use AkeneoDAMConnector\Domain\Model\Pim\PimAssetValue; +use AkeneoDAMConnector\Domain\Model\Pim\Attribute; class TextConverter implements AssetValueConverter { @@ -17,7 +17,7 @@ public function getSupportedType(): string return 'text'; } - public function convert(DamAsset $damAsset, DamAssetValue $damAssetValue, AssetAttribute $attribute): PimAssetValue + public function convert(DamAsset $damAsset, DamAssetValue $damAssetValue, Attribute $attribute): PimAssetValue { $locale = $attribute->isLocalizable() ? (string)$damAsset->locale() : null; diff --git a/src/Application/PimAdapter/UpdateAsset.php b/src/Application/PimAdapter/UpdateAsset.php index f63582b..7d71959 100644 --- a/src/Application/PimAdapter/UpdateAsset.php +++ b/src/Application/PimAdapter/UpdateAsset.php @@ -4,12 +4,12 @@ namespace AkeneoDAMConnector\Application\PimAdapter; -use AkeneoDAMConnector\Domain\Asset\PimAsset; -use AkeneoDAMConnector\Domain\AssetFamilyCode; +use AkeneoDAMConnector\Domain\Model\Pim\PimAsset; +use AkeneoDAMConnector\Domain\Model\FamilyCode; interface UpdateAsset { - public function upsert(AssetFamilyCode $assetFamilyCode, PimAsset $asset): void; + public function upsert(FamilyCode $assetFamilyCode, PimAsset $asset): void; - public function flush(AssetFamilyCode $assetFamilyCode): void; + public function flush(FamilyCode $assetFamilyCode): void; } diff --git a/src/Application/Service/SynchronizeAssets.php b/src/Application/Service/SynchronizeAssets.php index 3f0dcdc..a24ec02 100644 --- a/src/Application/Service/SynchronizeAssets.php +++ b/src/Application/Service/SynchronizeAssets.php @@ -7,7 +7,7 @@ use AkeneoDAMConnector\Application\DamAdapter\FetchAssets; use AkeneoDAMConnector\Application\Mapping\AssetTransformer; use AkeneoDAMConnector\Application\PimAdapter\UpdateAsset; -use AkeneoDAMConnector\Domain\AssetFamilyCode; +use AkeneoDAMConnector\Domain\Model\FamilyCode; class SynchronizeAssets { @@ -30,7 +30,7 @@ public function __construct( $this->assetApi = $assetApi; } - public function execute(AssetFamilyCode $assetFamilyCode, ?\DateTimeInterface $lastFetchDate): void + public function execute(FamilyCode $assetFamilyCode, ?\DateTimeInterface $lastFetchDate): void { $damAssets = $this->fetchAssets->fetch($assetFamilyCode, $lastFetchDate); diff --git a/src/Application/Service/SynchronizeAssetsStructure.php b/src/Application/Service/SynchronizeAssetsStructure.php index 128caa5..829d057 100644 --- a/src/Application/Service/SynchronizeAssetsStructure.php +++ b/src/Application/Service/SynchronizeAssetsStructure.php @@ -34,7 +34,6 @@ public function execute() { $structureConfig = $this->structureConfigLoader->load(); foreach ($structureConfig as $assetFamilyCode => $assetFamilyConfig) { - echo "Creating family: ". $assetFamilyCode ."\n"; $assetFamilyData = [ 'code' => $assetFamilyCode, ]; diff --git a/src/Domain/Asset/DamAsset.php b/src/Domain/Model/Dam/DamAsset.php similarity index 80% rename from src/Domain/Asset/DamAsset.php rename to src/Domain/Model/Dam/DamAsset.php index c7b62c2..2d235c5 100644 --- a/src/Domain/Asset/DamAsset.php +++ b/src/Domain/Model/Dam/DamAsset.php @@ -2,17 +2,17 @@ declare(strict_types=1); -namespace AkeneoDAMConnector\Domain\Asset; +namespace AkeneoDAMConnector\Domain\Model\Dam; -use AkeneoDAMConnector\Domain\AssetFamilyCode; -use AkeneoDAMConnector\Domain\Locale; +use AkeneoDAMConnector\Domain\Model\FamilyCode; +use AkeneoDAMConnector\Domain\Model\Locale; class DamAsset { /** @var DamAssetIdentifier */ private $damAssetIdentifier; - /** @var AssetFamilyCode */ + /** @var FamilyCode */ private $assetFamilyCode; /** @var Locale|null */ @@ -23,7 +23,7 @@ class DamAsset public function __construct( DamAssetIdentifier $damAssetIdentifier, - AssetFamilyCode $assetFamilyCode, + FamilyCode $assetFamilyCode, ?Locale $locale ) { $this->damAssetIdentifier = $damAssetIdentifier; @@ -42,7 +42,7 @@ public function damAssetIdentifier(): DamAssetIdentifier return $this->damAssetIdentifier; } - public function assetFamilyCode(): AssetFamilyCode + public function assetFamilyCode(): FamilyCode { return $this->assetFamilyCode; } diff --git a/src/Domain/Asset/DamAssetCollection.php b/src/Domain/Model/Dam/DamAssetCollection.php similarity index 95% rename from src/Domain/Asset/DamAssetCollection.php rename to src/Domain/Model/Dam/DamAssetCollection.php index f92d796..24d087a 100644 --- a/src/Domain/Asset/DamAssetCollection.php +++ b/src/Domain/Model/Dam/DamAssetCollection.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace AkeneoDAMConnector\Domain\Asset; +namespace AkeneoDAMConnector\Domain\Model\Dam; /** * @author Willy Mesnage diff --git a/src/Domain/Asset/DamAssetIdentifier.php b/src/Domain/Model/Dam/DamAssetIdentifier.php similarity index 53% rename from src/Domain/Asset/DamAssetIdentifier.php rename to src/Domain/Model/Dam/DamAssetIdentifier.php index 66b1554..36bbd36 100644 --- a/src/Domain/Asset/DamAssetIdentifier.php +++ b/src/Domain/Model/Dam/DamAssetIdentifier.php @@ -2,16 +2,7 @@ declare(strict_types=1); -/* - * This file is part of the Akeneo PIM Enterprise Edition. - * - * (c) 2019 Akeneo SAS (http://www.akeneo.com) - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace AkeneoDAMConnector\Domain\Asset; +namespace AkeneoDAMConnector\Domain\Model\Dam; /** * @author Romain Monceau diff --git a/src/Domain/Asset/DamAssetValue.php b/src/Domain/Model/Dam/DamAssetValue.php similarity index 61% rename from src/Domain/Asset/DamAssetValue.php rename to src/Domain/Model/Dam/DamAssetValue.php index 80e6067..1915e6d 100644 --- a/src/Domain/Asset/DamAssetValue.php +++ b/src/Domain/Model/Dam/DamAssetValue.php @@ -2,16 +2,7 @@ declare(strict_types=1); -/* - * This file is part of the Akeneo PIM Enterprise Edition. - * - * (c) 2019 Akeneo SAS (http://www.akeneo.com) - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace AkeneoDAMConnector\Domain\Asset; +namespace AkeneoDAMConnector\Domain\Model\Dam; /** * @author Romain Monceau diff --git a/src/Domain/AssetFamilyCode.php b/src/Domain/Model/FamilyCode.php similarity index 79% rename from src/Domain/AssetFamilyCode.php rename to src/Domain/Model/FamilyCode.php index d641838..cf8ed7a 100644 --- a/src/Domain/AssetFamilyCode.php +++ b/src/Domain/Model/FamilyCode.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace AkeneoDAMConnector\Domain; +namespace AkeneoDAMConnector\Domain\Model; -class AssetFamilyCode +class FamilyCode { private $code; diff --git a/src/Domain/Locale.php b/src/Domain/Model/Locale.php similarity index 91% rename from src/Domain/Locale.php rename to src/Domain/Model/Locale.php index 28ab13f..0bc0cb5 100644 --- a/src/Domain/Locale.php +++ b/src/Domain/Model/Locale.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace AkeneoDAMConnector\Domain; +namespace AkeneoDAMConnector\Domain\Model; /** * @author Willy Mesnage diff --git a/src/Domain/AssetAttribute.php b/src/Domain/Model/Pim/Attribute.php similarity index 68% rename from src/Domain/AssetAttribute.php rename to src/Domain/Model/Pim/Attribute.php index 26a3ea3..678f9ff 100644 --- a/src/Domain/AssetAttribute.php +++ b/src/Domain/Model/Pim/Attribute.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace AkeneoDAMConnector\Domain; +namespace AkeneoDAMConnector\Domain\Model\Pim; -class AssetAttribute +class Attribute { private $code; @@ -12,14 +12,14 @@ class AssetAttribute private $localizable; - public function __construct(AssetAttributeCode $code, string $type, bool $localizable) + public function __construct(AttributeCode $code, string $type, bool $localizable) { $this->code = $code; $this->type = $type; $this->localizable = $localizable; } - public function getCode(): AssetAttributeCode + public function getCode(): AttributeCode { return $this->code; } diff --git a/src/Domain/AssetAttributeCode.php b/src/Domain/Model/Pim/AttributeCode.php similarity index 77% rename from src/Domain/AssetAttributeCode.php rename to src/Domain/Model/Pim/AttributeCode.php index 6dfee9f..eb58fa0 100644 --- a/src/Domain/AssetAttributeCode.php +++ b/src/Domain/Model/Pim/AttributeCode.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace AkeneoDAMConnector\Domain; +namespace AkeneoDAMConnector\Domain\Model\Pim; -class AssetAttributeCode +class AttributeCode { private $code; diff --git a/src/Domain/Asset/PimAsset.php b/src/Domain/Model/Pim/PimAsset.php similarity index 83% rename from src/Domain/Asset/PimAsset.php rename to src/Domain/Model/Pim/PimAsset.php index 9c169e1..5c9688d 100644 --- a/src/Domain/Asset/PimAsset.php +++ b/src/Domain/Model/Pim/PimAsset.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace AkeneoDAMConnector\Domain\Asset; +namespace AkeneoDAMConnector\Domain\Model\Pim; -use AkeneoDAMConnector\Domain\AssetFamilyCode; +use AkeneoDAMConnector\Domain\Model\FamilyCode; class PimAsset { @@ -13,10 +13,10 @@ class PimAsset /** @var PimAssetValue[] */ private $values; - /** @var AssetFamilyCode */ + /** @var FamilyCode */ private $familyCode; - public function __construct(string $code, AssetFamilyCode $familyCode, array $values = []) + public function __construct(string $code, FamilyCode $familyCode, array $values = []) { $this->code = $code; $this->values = $values; diff --git a/src/Domain/Asset/PimAssetCollection.php b/src/Domain/Model/Pim/PimAssetCollection.php similarity index 94% rename from src/Domain/Asset/PimAssetCollection.php rename to src/Domain/Model/Pim/PimAssetCollection.php index 25592e1..30fa124 100644 --- a/src/Domain/Asset/PimAssetCollection.php +++ b/src/Domain/Model/Pim/PimAssetCollection.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace AkeneoDAMConnector\Domain\Asset; +namespace AkeneoDAMConnector\Domain\Model\Pim; class PimAssetCollection implements \Iterator { diff --git a/src/Domain/Asset/PimAssetValue.php b/src/Domain/Model/Pim/PimAssetValue.php similarity index 64% rename from src/Domain/Asset/PimAssetValue.php rename to src/Domain/Model/Pim/PimAssetValue.php index 788b73a..d2ae608 100644 --- a/src/Domain/Asset/PimAssetValue.php +++ b/src/Domain/Model/Pim/PimAssetValue.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace AkeneoDAMConnector\Domain\Asset; +namespace AkeneoDAMConnector\Domain\Model\Pim; -use AkeneoDAMConnector\Domain\AssetAttribute; -use AkeneoDAMConnector\Domain\AssetAttributeCode; +use AkeneoDAMConnector\Domain\Model\Pim\Attribute; +use AkeneoDAMConnector\Domain\Model\Pim\AttributeCode; class PimAssetValue { @@ -17,7 +17,7 @@ class PimAssetValue private $channel; - public function __construct(AssetAttribute $attribute, $data, string $locale = null, string $channel = null) + public function __construct(Attribute $attribute, $data, ?string $locale = null, ?string $channel = null) { $this->attribute = $attribute; $this->data = $data; @@ -25,12 +25,12 @@ public function __construct(AssetAttribute $attribute, $data, string $locale = n $this->channel = $channel; } - public function getAttribute(): AssetAttribute + public function getAttribute(): Attribute { return $this->attribute; } - public function getAttributeCode(): AssetAttributeCode + public function getAttributeCode(): AttributeCode { return $this->attribute->getCode(); } @@ -43,12 +43,12 @@ public function getData() return $this->data; } - public function getLocale(): string + public function getLocale(): ?string { return $this->locale; } - public function getChannel(): string + public function getChannel(): ?string { return $this->channel; } diff --git a/src/Domain/ResourceType.php b/src/Domain/ResourceType.php deleted file mode 100644 index 71dc4d5..0000000 --- a/src/Domain/ResourceType.php +++ /dev/null @@ -1,27 +0,0 @@ - - */ -class ResourceType -{ - /** @var string */ - private $resourceType; - - public function __construct(string $resourceType) - { - if (!in_array($resourceType, ['image', 'other'])) { - $resourceType = 'other'; - } - $this->resourceType = $resourceType; - } - - public function __toString(): string - { - return $this->resourceType; - } -} diff --git a/src/Infrastructure/Command/SynchronizeAssetsCommand.php b/src/Infrastructure/Command/SynchronizeAssetsCommand.php index 3d498f7..f974d75 100644 --- a/src/Infrastructure/Command/SynchronizeAssetsCommand.php +++ b/src/Infrastructure/Command/SynchronizeAssetsCommand.php @@ -6,7 +6,7 @@ use AkeneoDAMConnector\Application\ConfigLoader; use AkeneoDAMConnector\Application\Service\SynchronizeAssets; -use AkeneoDAMConnector\Domain\AssetFamilyCode; +use AkeneoDAMConnector\Domain\Model\FamilyCode; use AkeneoDAMConnector\Infrastructure\Persistence\Execution; use AkeneoDAMConnector\Infrastructure\Persistence\SynchronizeAssetsExecutionRepository; use Symfony\Component\Console\Command\Command; @@ -56,7 +56,7 @@ protected function execute(InputInterface $input, OutputInterface $output) private function synchronizeFamily(string $familyCode, ?\DateTimeInterface $sinceLastSucceededExecutionTime): void { - $assetFamilyCode = new AssetFamilyCode($familyCode); + $assetFamilyCode = new FamilyCode($familyCode); $currentExecution = Execution::create($familyCode)->run(); $this->synchronizeAssetsExecutionRepository->save($currentExecution); diff --git a/src/Infrastructure/DAM/DamExample/FetchAssets.php b/src/Infrastructure/DAM/DamExample/FetchAssets.php index c63607e..b0df9e6 100644 --- a/src/Infrastructure/DAM/DamExample/FetchAssets.php +++ b/src/Infrastructure/DAM/DamExample/FetchAssets.php @@ -5,13 +5,13 @@ namespace AkeneoDAMConnector\Infrastructure\DAM\DamExample; use AkeneoDAMConnector\Application\DamAdapter\FetchAssets as FetchAssetsInterface; -use AkeneoDAMConnector\Domain\Asset\DamAsset; -use AkeneoDAMConnector\Domain\Asset\DamAssetIdentifier; -use AkeneoDAMConnector\Domain\AssetFamilyCode; +use AkeneoDAMConnector\Domain\Model\Dam\DamAsset; +use AkeneoDAMConnector\Domain\Model\Dam\DamAssetIdentifier; +use AkeneoDAMConnector\Domain\Model\FamilyCode; class FetchAssets implements FetchAssetsInterface { - public function fetch(AssetFamilyCode $assetFamilyCode, ?\DateTimeInterface $lastFetchDate): \Iterator + public function fetch(FamilyCode $assetFamilyCode, ?\DateTimeInterface $lastFetchDate): \Iterator { $response = json_decode($this->getJson(), true); @@ -22,7 +22,7 @@ public function fetch(AssetFamilyCode $assetFamilyCode, ?\DateTimeInterface $las } } - private function denormalize(array $data, AssetFamilyCode $assetFamilyCode): DamAsset + private function denormalize(array $data, FamilyCode $assetFamilyCode): DamAsset { $asset = new DamAsset( new DamAssetIdentifier($data['uid']), diff --git a/src/Infrastructure/Pim/AttributeOptionsApi.php b/src/Infrastructure/Pim/AttributeOptionsApi.php index 0a17790..96436a8 100644 --- a/src/Infrastructure/Pim/AttributeOptionsApi.php +++ b/src/Infrastructure/Pim/AttributeOptionsApi.php @@ -5,7 +5,7 @@ namespace AkeneoDAMConnector\Infrastructure\Pim; use Akeneo\PimEnterprise\ApiClient\Api\AssetManager\AssetAttributeOptionApiInterface; -use AkeneoDAMConnector\Domain\AssetFamilyCode; +use AkeneoDAMConnector\Domain\Model\FamilyCode; /** * @author Willy Mesnage @@ -28,7 +28,7 @@ public function __construct(ClientBuilder $clientBuilder) $this->pimStructure = []; } - public function upsertAttributeOptions(AssetFamilyCode $familyCode, array $assetValues): void + public function upsertAttributeOptions(FamilyCode $familyCode, array $assetValues): void { if (!isset($this->attributeOptions[(string) $familyCode])) { $this->attributeOptions[(string) $familyCode] = []; @@ -51,7 +51,7 @@ public function upsertAttributeOptions(AssetFamilyCode $familyCode, array $asset } } - public function flush(AssetFamilyCode $familyCode): void + public function flush(FamilyCode $familyCode): void { foreach ($this->attributeOptions[(string) $familyCode] as $attributeCode => $attributeOptions) { $pimOptions = $this->get((string) $familyCode, $attributeCode); diff --git a/src/Infrastructure/Pim/UpdateAssetApi.php b/src/Infrastructure/Pim/UpdateAssetApi.php index 95c03dc..5d8745e 100644 --- a/src/Infrastructure/Pim/UpdateAssetApi.php +++ b/src/Infrastructure/Pim/UpdateAssetApi.php @@ -6,8 +6,8 @@ use Akeneo\PimEnterprise\ApiClient\Api\AssetManager\AssetApiInterface; use AkeneoDAMConnector\Application\PimAdapter\UpdateAsset; -use AkeneoDAMConnector\Domain\Asset\PimAsset; -use AkeneoDAMConnector\Domain\AssetFamilyCode; +use AkeneoDAMConnector\Domain\Model\Pim\PimAsset; +use AkeneoDAMConnector\Domain\Model\FamilyCode; class UpdateAssetApi implements UpdateAsset { @@ -27,7 +27,7 @@ public function __construct(ClientBuilder $clientBuilder, AttributeOptionsApi $a $this->attributeOptionsApi = $attributeOptionsApi; } - public function upsert(AssetFamilyCode $assetFamilyCode, PimAsset $asset): void + public function upsert(FamilyCode $assetFamilyCode, PimAsset $asset): void { $this->assets[(string) $assetFamilyCode][] = $asset->normalize(); $this->attributeOptionsApi->upsertAttributeOptions($assetFamilyCode, $asset->getAttributeOptions()); @@ -36,7 +36,7 @@ public function upsert(AssetFamilyCode $assetFamilyCode, PimAsset $asset): void } } - public function flush(AssetFamilyCode $assetFamilyCode): void + public function flush(FamilyCode $assetFamilyCode): void { $this->attributeOptionsApi->flush($assetFamilyCode); diff --git a/symfony.lock b/symfony.lock index 14139f9..e508220 100644 --- a/symfony.lock +++ b/symfony.lock @@ -38,6 +38,9 @@ "doctrine/event-manager": { "version": "1.0.x-dev" }, + "doctrine/instantiator": { + "version": "1.2.0" + }, "doctrine/lexer": { "version": "1.2.x-dev" }, @@ -86,6 +89,24 @@ "php-http/promise": { "version": "1.0-dev" }, + "phpdocumentor/reflection-common": { + "version": "2.0.0" + }, + "phpdocumentor/reflection-docblock": { + "version": "4.3.2" + }, + "phpdocumentor/type-resolver": { + "version": "1.0.1" + }, + "phpspec/php-diff": { + "version": "v1.1.0" + }, + "phpspec/phpspec": { + "version": "4.3.4" + }, + "phpspec/prophecy": { + "version": "1.8.1" + }, "psr/cache": { "version": "1.0.1" }, @@ -107,6 +128,18 @@ "ralouphie/getallheaders": { "version": "3.0.3" }, + "sebastian/comparator": { + "version": "3.0.2" + }, + "sebastian/diff": { + "version": "3.0.2" + }, + "sebastian/exporter": { + "version": "3.1.2" + }, + "sebastian/recursion-context": { + "version": "3.0.0" + }, "symfony/cache": { "version": "v4.3.3" }, @@ -234,5 +267,8 @@ }, "symfony/yaml": { "version": "v4.3.3" + }, + "webmozart/assert": { + "version": "1.5.0" } } diff --git a/tests/Specification/Application/Mapping/AssetAttributeBuilderSpec.php b/tests/Specification/Application/Mapping/AssetAttributeBuilderSpec.php new file mode 100644 index 0000000..4208020 --- /dev/null +++ b/tests/Specification/Application/Mapping/AssetAttributeBuilderSpec.php @@ -0,0 +1,64 @@ +beConstructedWith($structureConfigLoader); + } + + function it_is_initializable(): void + { + $this->shouldHaveType(AssetAttributeBuilder::class); + } + + function it_builds_an_attribute($structureConfigLoader): void + { + $structureConfigLoader->load()->willReturn($this->getConfig()); + + $familyCode = new FamilyCode('packshot'); + $attributeCode = new AttributeCode('locale'); + + $attribute = $this->build($familyCode, $attributeCode); + $attribute->getCode()->shouldReturn($attributeCode); + $attribute->getType()->shouldReturn('text'); + $attribute->isLocalizable()->shouldReturn(false); + } + + function it_throws_an_exception_if_attribute_does_not_exist($structureConfigLoader): void + { + $structureConfigLoader->load()->willReturn($this->getConfig()); + + $familyCode = new FamilyCode('packshot'); + $attributeCode = new AttributeCode('description'); + + $this + ->shouldThrow( + new \RuntimeException() + ) + ->during('build', [$familyCode, $attributeCode]); + } + + private function getConfig(): array + { + return [ + 'packshot' => [ + 'attributes' => [ + [ + 'code' => 'locale', + 'type' => 'text' + ], + ], + ], + ]; + } +} diff --git a/tests/Specification/Application/Mapping/AssetMapperSpec.php b/tests/Specification/Application/Mapping/AssetMapperSpec.php new file mode 100644 index 0000000..6f3690f --- /dev/null +++ b/tests/Specification/Application/Mapping/AssetMapperSpec.php @@ -0,0 +1,90 @@ +beConstructedWith($mappingConfigLoader, $assetAttributeBuilder); + } + + public function it_provides_mapped_properties_of_a_family($mappingConfigLoader): void + { + $mappingConfigLoader->load()->willReturn($this->getMapping()); + $familyCode = new FamilyCode('packshot'); + + $this->getMappedProperties($familyCode)->shouldReturn(['sku', 'url', 'colors']); + } + + public function it_throws_an_exception_if_no_mapping_can_be_provided($mappingConfigLoader): void + { + $mappingConfigLoader->load()->willReturn($this->getMapping()); + $familyCode = new FamilyCode('family'); + + $this + ->shouldThrow( + new FamilyMappingNotFound() + ) + ->during('getMappedProperties', [$familyCode]); + } + + public function it_maps_a_dam_property_to_a_pim_attribute( + $mappingConfigLoader, + $assetAttributeBuilder + ): void { + $mappingConfigLoader->load()->willReturn($this->getMapping()); + $familyCode = new FamilyCode('packshot'); + $attribute = TestAttributeBuilder::build('preview', 'text'); + + $assetAttributeBuilder + ->build('packshot', Argument::that(function ($argument) { + return $argument instanceof AttributeCode && + 'preview' === $argument->__toString(); + })) + ->shouldBeCalled() + ->willReturn($attribute); + + $this->mapAttribute($familyCode, 'url')->shouldReturn($attribute); + } + + public function it_throws_an_exception_if_the_dam_property_does_not_match_a_pim_attribute( + $mappingConfigLoader + ): void { + $mappingConfigLoader->load()->willReturn($this->getMapping()); + $familyCode = new FamilyCode('packshot'); + + $this + ->shouldThrow( + new AttributeMappingNotFound() + ) + ->during('mapAttribute', [$familyCode, 'roustifouette']); + } + + private function getMapping(): array + { + return [ + 'packshot' => [ + 'sku' => 'product_ref', + 'url' => 'preview', + 'colors' => 'main_colors', + ], + 'user_instruction' => [ + 'sku' => 'product_ref', + 'url' => 'media_link', + 'pages' => 'number_of_pages', + ], + ]; + } +} diff --git a/tests/Specification/Application/Mapping/AssetTransformerSpec.php b/tests/Specification/Application/Mapping/AssetTransformerSpec.php new file mode 100644 index 0000000..bc020c1 --- /dev/null +++ b/tests/Specification/Application/Mapping/AssetTransformerSpec.php @@ -0,0 +1,78 @@ +beConstructedWith($assetMapper, $assetConverter); + } + + public function it_transforms_a_dam_asset_to_pim_asset($assetMapper, $assetConverter): void + { + $mappedProperties = ['sku', 'colors', 'url']; + + $familyCode = new FamilyCode('packshot'); + $damAsset = DamAssetBuilder::build( + 'dam_identifier', + 'packshot', + [ + 'sku' => '123456', + 'colors' => 'blue, green', + 'designed_by' => 'stark', + ] + ); + $skuValue = new DamAssetValue('sku', '123456'); + $colorsValue = new DamAssetValue('colors', 'blue, green'); + $designedByValue = new DamAssetValue('designed_by', 'stark'); + + $skuAttribute = AssetAttributeBuilder::build('sku', 'text'); + $colorsAttribute = AssetAttributeBuilder::build('all_colors', 'multiple_options'); + $skuPimValue = new PimAssetValue($skuAttribute, '123456'); + $colorsPimValue = new PimAssetValue($colorsAttribute, ['blue', 'green']); + + $assetMapper->getMappedProperties($familyCode)->willReturn($mappedProperties); + $assetMapper->mapAttribute($familyCode, 'sku')->willReturn($skuAttribute); + $assetMapper->mapAttribute($familyCode, 'colors')->willReturn($colorsAttribute); + $assetMapper->mapAttribute($familyCode, 'designed_by')->shouldNotBeCalled(); + + $assetConverter->convert($damAsset, $skuValue, $skuAttribute)->shouldBeCalled()->willReturn($skuPimValue); + $assetConverter->convert($damAsset, $designedByValue, Argument::any())->shouldNotBeCalled(); + $assetConverter + ->convert($damAsset, $colorsValue, $colorsAttribute) + ->shouldBeCalled() + ->willReturn($colorsPimValue); + + $pimAsset = $this->damToPim($damAsset); + $pimAsset->getCode()->shouldReturn('dam_identifier'); + $pimAsset->normalize()->shouldReturn([ + 'code' => 'dam_identifier', + 'values' => [ + 'sku' => [[ + 'locale' => null, + 'channel' => null, + 'data' => '123456', + ]], + 'all_colors' => [[ + 'locale' => null, + 'channel' => null, + 'data' => ['blue', 'green'], + ]], + ] + ]); + } +} diff --git a/tests/Specification/Application/Mapping/AssetValueConverter/MediaLinkConverterSpec.php b/tests/Specification/Application/Mapping/AssetValueConverter/MediaLinkConverterSpec.php new file mode 100644 index 0000000..9887b09 --- /dev/null +++ b/tests/Specification/Application/Mapping/AssetValueConverter/MediaLinkConverterSpec.php @@ -0,0 +1,51 @@ +shouldHaveType(MediaLinkConverter::class); + $this->shouldImplement(AssetValueConverter::class); + } + + public function it_provides_a_supported_type(): void + { + $this->getSupportedType()->shouldReturn('media_link'); + } + + public function it_converts_a_dam_asset_value_into_a_localized_pim_asset_value(): void + { + $damAsset = DamAssetBuilder::build('table', 'packshot', ['url' => 'here.com'], 'en_US'); + $attribute = AssetAttributeBuilder::build('url', 'media_link', true); + $damAssetValue = new DamAssetValue('url', 'here.com'); + + $pimValue = $this->convert($damAsset, $damAssetValue, $attribute); + $pimValue->getAttribute()->shouldReturn($attribute); + $pimValue->getData()->shouldReturn('here.com'); + $pimValue->getLocale()->shouldReturn('en_US'); + $pimValue->getChannel()->shouldReturn(null); + } + + public function it_converts_a_dam_asset_value_into_a_not_localized_pim_asset_value(): void + { + $damAsset = DamAssetBuilder::build('table', 'packshot', ['url' => 'here.com']); + $attribute = AssetAttributeBuilder::build('url', 'media_link', false); + $damAssetValue = new DamAssetValue('url', 'here.com'); + + $pimValue = $this->convert($damAsset, $damAssetValue, $attribute); + $pimValue->getAttribute()->shouldReturn($attribute); + $pimValue->getData()->shouldReturn('here.com'); + $pimValue->getLocale()->shouldReturn(null); + $pimValue->getChannel()->shouldReturn(null); + } +} diff --git a/tests/Specification/Application/Mapping/AssetValueConverter/MultiOptionConverterSpec.php b/tests/Specification/Application/Mapping/AssetValueConverter/MultiOptionConverterSpec.php new file mode 100644 index 0000000..ed580be --- /dev/null +++ b/tests/Specification/Application/Mapping/AssetValueConverter/MultiOptionConverterSpec.php @@ -0,0 +1,51 @@ +shouldHaveType(MultiOptionConverter::class); + $this->shouldImplement(AssetValueConverter::class); + } + + public function it_provides_a_supported_type(): void + { + $this->getSupportedType()->shouldReturn('multiple_options'); + } + + public function it_converts_a_dam_asset_value_into_a_localized_pim_asset_value(): void + { + $damAsset = DamAssetBuilder::build('table', 'packshot', ['colors' => 'simic, blue, green'], 'en_US'); + $attribute = AssetAttributeBuilder::build('colors', 'multiple_options', true); + $damAssetValue = new DamAssetValue('colors', 'simic, blue, green'); + + $pimValue = $this->convert($damAsset, $damAssetValue, $attribute); + $pimValue->getAttribute()->shouldReturn($attribute); + $pimValue->getData()->shouldReturn(['simic', 'blue', 'green']); + $pimValue->getLocale()->shouldReturn('en_US'); + $pimValue->getChannel()->shouldReturn(null); + } + + public function it_converts_a_dam_asset_value_into_a_not_localized_pim_asset_value(): void + { + $damAsset = DamAssetBuilder::build('table', 'packshot', ['colors' => 'simic, blue, green']); + $attribute = AssetAttributeBuilder::build('colors', 'multiple_options', false); + $damAssetValue = new DamAssetValue('colors', 'simic, blue, green'); + + $pimValue = $this->convert($damAsset, $damAssetValue, $attribute); + $pimValue->getAttribute()->shouldReturn($attribute); + $pimValue->getData()->shouldReturn(['simic', 'blue', 'green']); + $pimValue->getLocale()->shouldReturn(null); + $pimValue->getChannel()->shouldReturn(null); + } +} diff --git a/tests/Specification/Application/Mapping/AssetValueConverter/SingleOptionConverterSpec.php b/tests/Specification/Application/Mapping/AssetValueConverter/SingleOptionConverterSpec.php new file mode 100644 index 0000000..ecd8671 --- /dev/null +++ b/tests/Specification/Application/Mapping/AssetValueConverter/SingleOptionConverterSpec.php @@ -0,0 +1,51 @@ +shouldHaveType(SingleOptionConverter::class); + $this->shouldImplement(AssetValueConverter::class); + } + + public function it_provides_a_supported_type(): void + { + $this->getSupportedType()->shouldReturn('single_option'); + } + + public function it_converts_a_dam_asset_value_into_a_localized_pim_asset_value(): void + { + $damAsset = DamAssetBuilder::build('table', 'packshot', ['color' => 'temur'], 'en_US'); + $attribute = AssetAttributeBuilder::build('color', 'single_option', true); + $damAssetValue = new DamAssetValue('color', 'temur'); + + $pimValue = $this->convert($damAsset, $damAssetValue, $attribute); + $pimValue->getAttribute()->shouldReturn($attribute); + $pimValue->getData()->shouldReturn('temur'); + $pimValue->getLocale()->shouldReturn('en_US'); + $pimValue->getChannel()->shouldReturn(null); + } + + public function it_converts_a_dam_asset_value_into_a_not_localized_pim_asset_value(): void + { + $damAsset = DamAssetBuilder::build('table', 'packshot', ['color' => 'temur']); + $attribute = AssetAttributeBuilder::build('color', 'single_option', false); + $damAssetValue = new DamAssetValue('color', 'temur'); + + $pimValue = $this->convert($damAsset, $damAssetValue, $attribute); + $pimValue->getAttribute()->shouldReturn($attribute); + $pimValue->getData()->shouldReturn('temur'); + $pimValue->getLocale()->shouldReturn(null); + $pimValue->getChannel()->shouldReturn(null); + } +} diff --git a/tests/Specification/Application/Mapping/AssetValueConverter/TextConverterSpec.php b/tests/Specification/Application/Mapping/AssetValueConverter/TextConverterSpec.php new file mode 100644 index 0000000..1110bc1 --- /dev/null +++ b/tests/Specification/Application/Mapping/AssetValueConverter/TextConverterSpec.php @@ -0,0 +1,54 @@ +shouldHaveType(TextConverter::class); + $this->shouldImplement(AssetValueConverter::class); + } + + public function it_provides_a_supported_type(): void + { + $this->getSupportedType()->shouldReturn('text'); + } + + public function it_converts_a_dam_asset_value_into_a_localized_pim_asset_value(): void + { + $damAsset = DamAssetBuilder::build('table', 'packshot', ['description' => 'pretty'], 'en_US'); + $attribute = AssetAttributeBuilder::build('description', 'text', true); + $damAssetValue = new DamAssetValue('description', 'pretty'); + + $pimValue = $this->convert($damAsset, $damAssetValue, $attribute); + $pimValue->getAttribute()->shouldReturn($attribute); + $pimValue->getData()->shouldReturn('pretty'); + $pimValue->getLocale()->shouldReturn('en_US'); + $pimValue->getChannel()->shouldReturn(null); + } + + public function it_converts_a_dam_asset_value_into_a_not_localized_pim_asset_value(): void + { + $damAsset = DamAssetBuilder::build('table', 'packshot', ['description' => 'pretty']); + $attribute = AssetAttributeBuilder::build('description', 'text', false); + $damAssetValue = new DamAssetValue('description', 'pretty'); + + $pimValue = $this->convert($damAsset, $damAssetValue, $attribute); + $pimValue->getAttribute()->shouldReturn($attribute); + $pimValue->getData()->shouldReturn('pretty'); + $pimValue->getLocale()->shouldReturn(null); + $pimValue->getChannel()->shouldReturn(null); + } +} diff --git a/tests/Specification/Application/Service/SynchronizeAssetsSpec.php b/tests/Specification/Application/Service/SynchronizeAssetsSpec.php new file mode 100644 index 0000000..242392c --- /dev/null +++ b/tests/Specification/Application/Service/SynchronizeAssetsSpec.php @@ -0,0 +1,57 @@ +beConstructedWith($fetchAssets, $assetTransformer, $assetApi); + } + + function it_is_initializable() + { + $this->shouldHaveType(SynchronizeAssets::class); + } + + function it_synchronizes_assets( + $fetchAssets, + $assetTransformer, + $assetApi, + \Iterator $damAssets + ) { + $assetFamilyCode = new FamilyCode('packshot'); + $damTable = DamAssetBuilder::build('table', 'packshot'); + $damMug = DamAssetBuilder::build('mug', 'packshot'); + $pimTable = PimAssetBuilder::build('table', 'packshot'); + $pimMug = PimAssetBuilder::build('mug', 'packshot'); + + $damAssets->rewind()->shouldBeCalled(); + $damAssets->valid()->willReturn(true, true, false); + $damAssets->current()->willReturn($damTable, $damMug); + $damAssets->next()->shouldBeCalled(); + + $fetchAssets->fetch($assetFamilyCode, null)->willReturn($damAssets); + $assetTransformer->damToPim($damTable)->willReturn($pimTable); + $assetTransformer->damToPim($damMug)->willReturn($pimMug); + + $assetApi->upsert($assetFamilyCode, $pimTable)->shouldBeCalled(); + $assetApi->upsert($assetFamilyCode, $pimMug)->shouldBeCalled(); + $assetApi->flush($assetFamilyCode)->shouldBeCalled(); + + $this->execute($assetFamilyCode, null); + } +} diff --git a/tests/Specification/Application/Service/SynchronizeAssetsStructureSpec.php b/tests/Specification/Application/Service/SynchronizeAssetsStructureSpec.php new file mode 100644 index 0000000..4bcf9e7 --- /dev/null +++ b/tests/Specification/Application/Service/SynchronizeAssetsStructureSpec.php @@ -0,0 +1,115 @@ +beConstructedWith($structureConfigLoader, $updateAssetStructure); + } + + function it_is_initializable() + { + $this->shouldHaveType(SynchronizeAssetsStructure::class); + } + + function it_synchronizes_assets_structure( + $structureConfigLoader, + $updateAssetStructure + ) { + $config = $this->getConfig(); + $structureConfigLoader->load()->willReturn($config); + + $packshotData = [ + 'code' => 'packshot', + 'product_link_rules' => [ + [ + 'product_selections' => [ + 'field' => 'sku', + 'operator' => 'EQUALS', + 'value' => '{{product_ref}}', + ], + ] + ] + ]; + $userInstructionData = [ + 'code' => 'user_instruction', + 'product_link_rules' => [ + [ + 'product_selections' => [ + 'field' => 'sku', + 'operator' => 'EQUALS', + 'value' => '{{product_ref}}', + ], + ] + ] + ]; + + $updateAssetStructure->upsertFamily('packshot', ['code' => 'packshot'])->shouldBeCalled(); + $updateAssetStructure->upsertFamily('packshot', $packshotData)->shouldBeCalled(); + + $updateAssetStructure->upsertFamily('user_instruction', ['code' => 'user_instruction'])->shouldBeCalled(); + $updateAssetStructure->upsertFamily('user_instruction', $userInstructionData)->shouldBeCalled(); + + $updateAssetStructure->upsertAttribute('packshot', 'locale', ['code' => 'locale', 'type' => 'text'])->shouldBeCalled(); + $updateAssetStructure->upsertAttribute('packshot', 'product_ref', ['code' => 'product_ref', 'type' => 'text'])->shouldBeCalled(); + + $updateAssetStructure->upsertAttribute('user_instruction', 'locale', ['code' => 'locale', 'type' => 'text'])->shouldBeCalled(); + $updateAssetStructure->upsertAttribute('user_instruction', 'product_ref', ['code' => 'product_ref', 'type' => 'text'])->shouldBeCalled(); + + $this->execute(); + } + + private function getConfig(): array + { + return [ + 'packshot' => [ + 'product_link_rules' => [ + 'product_selections' => [ + 'field' => 'sku', + 'operator' => 'EQUALS', + 'value' => '{{product_ref}}', + ], + ], + 'attributes' => [ + [ + 'code' => 'locale', + 'type' => 'text' + ], + [ + 'code' => 'product_ref', + 'type' => 'text' + ], + ], + ], + 'user_instruction' => [ + 'product_link_rules' => [ + 'product_selections' => [ + 'field' => 'sku', + 'operator' => 'EQUALS', + 'value' => '{{product_ref}}', + ], + ], + 'attributes' => [ + [ + 'code' => 'locale', + 'type' => 'text' + ], + [ + 'code' => 'product_ref', + 'type' => 'text' + ], + ], + ], + ]; + } +} diff --git a/tests/Specification/Builder/AssetAttributeBuilder.php b/tests/Specification/Builder/AssetAttributeBuilder.php new file mode 100644 index 0000000..cb370c7 --- /dev/null +++ b/tests/Specification/Builder/AssetAttributeBuilder.php @@ -0,0 +1,15 @@ + $value) { + $damAsset->addValue($property, $value); + } + + return $damAsset; + } +} diff --git a/tests/Specification/Builder/PimAssetBuilder.php b/tests/Specification/Builder/PimAssetBuilder.php new file mode 100644 index 0000000..e4f9e07 --- /dev/null +++ b/tests/Specification/Builder/PimAssetBuilder.php @@ -0,0 +1,17 @@ +