diff --git a/.travis.yml b/.travis.yml index 110d6d2..025f74d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ dist: trusty language: php php: - - 7.0 - - 7.1 + - 7.2 + - 7.3 services: - mysql sudo: required @@ -11,32 +11,34 @@ env: - TEST_SUITE=unit - TEST_SUITE=phpcs - TEST_SUITE=configurator - MAGE_VERSION=2.1.15 + MAGE_VERSION=2.2.5 - TEST_SUITE=configurator - MAGE_VERSION=2.2.4 + MAGE_VERSION=2.3.1 - TEST_SUITE=configurator - MAGE_VERSION=2.2.5 + MAGE_VERSION=2.3.2 - TEST_SUITE=configurator - MAGE_VERSION=2.2.6 + MAGE_VERSION=2.3.3 matrix: allow_failures: - - php: 7.0 - - env: TEST_SUITE=configurator MAGE_VERSION=2.1.15 + - php: 7.2 + - env: TEST_SUITE=configurator MAGE_VERSION=2.2.5 + - env: TEST_SUITE=configurator MAGE_VERSION=2.3.1 + - env: TEST_SUITE=configurator MAGE_VERSION=2.3.2 before_install: - echo "{\"http-basic\":{\"repo.magento.com\":{\"username\":\"${MAGENTO_USERNAME}\",\"password\":\"${MAGENTO_PASSWORD}\"}}}" > auth.json - - sh -c "if [ '$TEST_SUITE' = 'phpcs' ]; then composer require magento/framework:~101.0.0; fi" - - sh -c "if [ '$TEST_SUITE' = 'unit' ]; then composer require magento/framework:~101.0.0; fi" - - sh -c "if [ '$TEST_SUITE' = 'unit' ]; then composer require magento/module-catalog:~102.0.0; fi" - - sh -c "if [ '$TEST_SUITE' = 'unit' ]; then composer require magento/zendframework1:~1.13.0; fi" + - sh -c "if [ '$TEST_SUITE' = 'phpcs' ]; then composer require magento/framework:^102.0.3; fi" + - sh -c "if [ '$TEST_SUITE' = 'unit' ]; then composer require magento/framework:^102.0.3; fi" + - sh -c "if [ '$TEST_SUITE' = 'unit' ]; then composer require magento/module-catalog; fi" + - sh -c "if [ '$TEST_SUITE' = 'unit' ]; then composer require magento/zendframework1; fi" install: - sh -c "if [ '$TEST_SUITE' = 'phpcs' ]; then composer install --prefer-dist; fi" - sh -c "if [ '$TEST_SUITE' = 'unit' ]; then composer install --prefer-dist; fi" before_script: - sh -c "if [ '$TEST_SUITE' = 'configurator' ]; then ./Test/Integration/setup-magento.sh $MAGE_VERSION; fi" script: - - sh -c "if [ '$TEST_SUITE' = 'phpcs' ]; then php vendor/bin/phpcs --standard=PSR2 Model/ Console/ Test/ Component/ Api/ Exception/; fi" + - sh -c "if [ '$TEST_SUITE' = 'phpcs' ]; then php vendor/bin/phpcs --standard=vendor/magento/magento-coding-standard/Magento2/ruleset.xml Model/ Console/ Test/ Component/ Api/ Exception/; fi" - sh -c "if [ '$TEST_SUITE' = 'phpcs' ]; then php vendor/bin/phpmd Model/,Console/,Test/,Component/,Api/,Exception/ text cleancode,codesize,controversial,design,naming,unusedcode; fi" - sh -c "if [ '$TEST_SUITE' = 'phpcs' ]; then php vendor/bin/phpcpd Model/ Console/ Test/ Component/ Api/ Exception/; fi" - sh -c "if [ '$TEST_SUITE' = 'unit' ]; then php vendor/bin/phpunit --coverage-clover build/logs/clover.xml Test/Unit/; fi" diff --git a/Api/ComponentInterface.php b/Api/ComponentInterface.php new file mode 100644 index 0000000..d4d8513 --- /dev/null +++ b/Api/ComponentInterface.php @@ -0,0 +1,22 @@ +roleFactory = $roleFactory; $this->rulesFactory = $rulesFactory; + $this->log = $log; } /** * @param $data */ - protected function processData($data = null) + public function execute($data = null) { - if (isset($data['adminroles'])) { foreach ($data['adminroles'] as $role) { try { @@ -128,4 +128,20 @@ private function setResourceIds($role, array $resources = null) sprintf('Admin Role "%s" Resources are empty, please check your yaml file', $roleName) ); } + + /** + * @return string + */ + public function getAlias() + { + return $this->alias; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } } diff --git a/Component/AdminUsers.php b/Component/AdminUsers.php index 3e17ccd..78e34bb 100644 --- a/Component/AdminUsers.php +++ b/Component/AdminUsers.php @@ -1,14 +1,13 @@ userFactory = $userFactory; $this->roleFactory = $roleFactory; + $this->log = $log; } /** * @param data */ - protected function processData($data = null) + public function execute($data = null) { //Get Each Role foreach ($data['adminusers'] as $roleSet) { @@ -171,4 +172,20 @@ private function dataValidator($userData) return true; } + + /** + * @return string + */ + public function getAlias() + { + return $this->alias; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } } diff --git a/Component/ApiIntegrations.php b/Component/ApiIntegrations.php index 06907b7..1ccbc6c 100644 --- a/Component/ApiIntegrations.php +++ b/Component/ApiIntegrations.php @@ -1,7 +1,7 @@ integrationFactory = $integrationFactory; $this->integrationService = $integrationService; $this->authorizationService = $authorizationService; $this->tokenFactory = $tokenFactory; + $this->log = $log; } /** * @param array $data */ - protected function processData($data = null) + public function execute($data = null) { if (isset($data['apiintegrations'])) { foreach ($data['apiintegrations'] as $integrationData) { @@ -166,4 +168,20 @@ private function activateAndAuthorize($consumerId) $token->setType('access'); $token->save(); } + + /** + * @return string + */ + public function getAlias() + { + return $this->alias; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } } diff --git a/Component/AttributeSets.php b/Component/AttributeSets.php index 16ac00b..ef8764e 100644 --- a/Component/AttributeSets.php +++ b/Component/AttributeSets.php @@ -2,21 +2,19 @@ namespace CtiDigital\Configurator\Component; +use CtiDigital\Configurator\Api\ComponentInterface; use CtiDigital\Configurator\Exception\ComponentException; use CtiDigital\Configurator\Api\LoggerInterface; use Magento\Eav\Api\AttributeSetRepositoryInterface; use Magento\Catalog\Model\Product; use Magento\Eav\Api\Data\AttributeSetInterface; use Magento\Eav\Setup\EavSetup; -use Magento\Framework\ObjectManagerInterface; use Magento\Eav\Model\AttributeSetRepository; /** - * Class AttributeSets - * @package CtiDigital\Configurator\Model\Component * @SuppressWarnings(PHPMD.LongVariable) */ -class AttributeSets extends YamlComponentAbstract +class AttributeSets implements ComponentInterface { protected $alias = 'attribute_sets'; protected $name = 'Attribute Sets'; @@ -32,6 +30,11 @@ class AttributeSets extends YamlComponentAbstract */ protected $attributeSetRepository; + /** + * @var LoggerInterface + */ + private $log; + /** * AttributeSets constructor. * @param LoggerInterface $log @@ -40,22 +43,19 @@ class AttributeSets extends YamlComponentAbstract * @param AttributeSetRepositoryInterface $attributeSetRepository */ public function __construct( - LoggerInterface $log, - ObjectManagerInterface $objectManager, EavSetup $eavSetup, - AttributeSetRepositoryInterface $attributeSetRepository + AttributeSetRepositoryInterface $attributeSetRepository, + LoggerInterface $log ) { - - parent::__construct($log, $objectManager); - $this->eavSetup = $eavSetup; $this->attributeSetRepository = $attributeSetRepository; + $this->log = $log; } /** * @param array $attributeConfigurationData */ - protected function processData($attributeConfigurationData = null) + public function execute($attributeConfigurationData = null) { try { foreach ($attributeConfigurationData['attribute_sets'] as $attributeSetConfiguration) { @@ -177,4 +177,20 @@ protected function getAttributeSetId($attributeSetName) throw new ComponentException('Could not find attribute set name.'); } + + /** + * @return string + */ + public function getAlias() + { + return $this->alias; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } } diff --git a/Component/Attributes.php b/Component/Attributes.php index 809ea1f..914dd2f 100644 --- a/Component/Attributes.php +++ b/Component/Attributes.php @@ -2,20 +2,18 @@ namespace CtiDigital\Configurator\Component; +use CtiDigital\Configurator\Api\ComponentInterface; use CtiDigital\Configurator\Exception\ComponentException; use CtiDigital\Configurator\Api\LoggerInterface; use Magento\Catalog\Model\Product; use Magento\Eav\Api\AttributeRepositoryInterface; use Magento\Eav\Setup\EavSetup; use Magento\Framework\Exception\NoSuchEntityException; -use Magento\Framework\ObjectManagerInterface; /** - * Class Attributes - * @package CtiDigital\Configurator\Model\Component * @SuppressWarnings(PHPMD.LongVariable) */ -class Attributes extends YamlComponentAbstract +class Attributes implements ComponentInterface { protected $alias = 'attributes'; @@ -37,6 +35,11 @@ class Attributes extends YamlComponentAbstract */ protected $attributeRepository; + /** + * @var LoggerInterface + */ + private $log; + /** * @var array */ @@ -76,30 +79,35 @@ class Attributes extends YamlComponentAbstract protected $entityTypeId = Product::ENTITY; /** - * @var bool + * @var bool */ protected $updateAttribute = true; /** - * @var bool + * @var bool */ protected $attributeExists = false; + /** + * Attributes constructor. + * @param EavSetup $eavSetup + * @param AttributeRepositoryInterface $attributeRepository + * @param LoggerInterface $log + */ public function __construct( - LoggerInterface $log, - ObjectManagerInterface $objectManager, EavSetup $eavSetup, - AttributeRepositoryInterface $attributeRepository + AttributeRepositoryInterface $attributeRepository, + LoggerInterface $log ) { - parent::__construct($log, $objectManager); $this->eavSetup = $eavSetup; $this->attributeRepository = $attributeRepository; + $this->log = $log; } /** * @param array $attributeConfigurationData */ - protected function processData($attributeConfigurationData = null) + public function execute($attributeConfigurationData = null) { try { foreach ($attributeConfigurationData['attributes'] as $attributeCode => $attributeConfiguration) { @@ -236,11 +244,11 @@ private function manageAttributeOptions($attributeCode, $option) $attributeCode, $e->getMessage() )); - return array(); + return []; } // Loop through existing attributes options - $existingAttributeOptions = array(); + $existingAttributeOptions = []; foreach ($attributeOptions as $attributeOption) { $value = $attributeOption->getLabel(); $existingAttributeOptions[] = $value; @@ -251,4 +259,20 @@ private function manageAttributeOptions($attributeCode, $option) return $optionsToAdd; } + + /** + * @return string + */ + public function getAlias() + { + return $this->alias; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } } diff --git a/Component/Blocks.php b/Component/Blocks.php index 5af4ebb..732da2e 100644 --- a/Component/Blocks.php +++ b/Component/Blocks.php @@ -2,12 +2,13 @@ namespace CtiDigital\Configurator\Component; +use CtiDigital\Configurator\Api\ComponentInterface; use CtiDigital\Configurator\Exception\ComponentException; use CtiDigital\Configurator\Api\LoggerInterface; use Magento\Cms\Api\Data\BlockInterfaceFactory; -use Magento\Framework\ObjectManagerInterface; +use Magento\Store\Model\Store; -class Blocks extends YamlComponentAbstract +class Blocks implements ComponentInterface { protected $alias = 'blocks'; @@ -29,6 +30,11 @@ class Blocks extends YamlComponentAbstract */ protected $searchBuilder; + /** + * @var LoggerInterface + */ + private $log; + /** * Blocks constructor. * @param LoggerInterface $log @@ -36,20 +42,19 @@ class Blocks extends YamlComponentAbstract * @param BlockInterfaceFactory $blockFactory */ public function __construct( - LoggerInterface $log, - ObjectManagerInterface $objectManager, - BlockInterfaceFactory $blockFactory + BlockInterfaceFactory $blockFactory, + Store $store, + LoggerInterface $log ) { - parent::__construct($log, $objectManager); - $this->blockFactory = $blockFactory; - $this->storeManager = $this->objectManager->create(\Magento\Store\Model\Store::class); + $this->storeManager = $store; + $this->log = $log; } /** * @param $data */ - protected function processData($data = null) + public function execute($data = null) { try { foreach ($data as $identifier => $data) { @@ -81,7 +86,7 @@ private function processBlock($identifier, $blockData) // Check if there are existing blocks if ($blocks->count()) { - $stores = array(); + $stores = []; // Check if stores are specified if (isset($data['stores'])) { @@ -93,7 +98,7 @@ private function processBlock($identifier, $blockData) } // If there is still no block to play with, create a new block object. - if (is_null($block)) { + if ($block === null) { $block = $this->blockFactory->create(); $block->setIdentifier($identifier); $canSave = true; @@ -105,6 +110,7 @@ private function processBlock($identifier, $blockData) if ($key == "source") { $key = 'content'; //TODO load this with Magento's code, and also check for file existing + // phpcs:ignore Magento2.Functions.DiscouragedFunction $value = file_get_contents(BP . '/' . $value); } @@ -142,7 +148,7 @@ private function processBlock($identifier, $blockData) if (isset($data['stores'])) { $block->unsetData('store_id'); $block->unsetData('store_data'); - $stores = array(); + $stores = []; foreach ($data['stores'] as $code) { $stores[] = $this->getStoreByCode($code)->getId(); } @@ -163,7 +169,6 @@ private function processBlock($identifier, $blockData) } } - /** * Find the block to process given the identifier, block collection and optionally stores * @@ -175,7 +180,7 @@ private function processBlock($identifier, $blockData) private function getBlockToProcess( $identifier, \Magento\Cms\Model\ResourceModel\Block\Collection $blocks, - $stores = array() + $stores = [] ) { // If there is only 1 block and stores hasn't been specified if ($blocks->count() == 1 && count($stores) == 0) { @@ -219,4 +224,20 @@ private function getStoreByCode($code) return $store; } + + /** + * @return string + */ + public function getAlias() + { + return $this->alias; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } } diff --git a/Component/CatalogPriceRules.php b/Component/CatalogPriceRules.php index 3e9c802..f329e70 100644 --- a/Component/CatalogPriceRules.php +++ b/Component/CatalogPriceRules.php @@ -7,15 +7,12 @@ namespace CtiDigital\Configurator\Component; +use CtiDigital\Configurator\Api\ComponentInterface; use CtiDigital\Configurator\Api\ComponentProcessorInterface; use CtiDigital\Configurator\Api\LoggerInterface; use Magento\CatalogRule\Api\Data\RuleInterfaceFactory; -use Magento\Framework\ObjectManagerInterface; -/** - * Class CatalogPriceRules - */ -class CatalogPriceRules extends YamlComponentAbstract +class CatalogPriceRules implements ComponentInterface { /** * @var string @@ -37,6 +34,11 @@ class CatalogPriceRules extends YamlComponentAbstract */ private $processor; + /** + * @var LoggerInterface + */ + private $log; + /** * CatalogPriceRules constructor. * @@ -45,13 +47,11 @@ class CatalogPriceRules extends YamlComponentAbstract * @param ComponentProcessorInterface $processor */ public function __construct( - LoggerInterface $log, - ObjectManagerInterface $objectManager, - ComponentProcessorInterface $processor + ComponentProcessorInterface $processor, + LoggerInterface $log ) { - parent::__construct($log, $objectManager); - $this->processor = $processor; + $this->log = $log; } /** @@ -61,7 +61,7 @@ public function __construct( * * @return void */ - protected function processData($data = null) + public function execute($data = null) { $rules = $data['rules'] ?: []; $config = $data['config'] ?: []; @@ -70,4 +70,20 @@ protected function processData($data = null) ->setConfig($config) ->process(); } + + /** + * @return string + */ + public function getAlias() + { + return $this->alias; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } } diff --git a/Component/CatalogPriceRules/CatalogPriceRulesProcessor.php b/Component/CatalogPriceRules/CatalogPriceRulesProcessor.php index 08366ab..2d04349 100644 --- a/Component/CatalogPriceRules/CatalogPriceRulesProcessor.php +++ b/Component/CatalogPriceRules/CatalogPriceRulesProcessor.php @@ -15,9 +15,6 @@ use Magento\CatalogRule\Model\Rule; use Magento\CatalogRule\Model\Rule\Job; -/** - * Class CatalogPriceRulesProcessor - */ class CatalogPriceRulesProcessor implements ComponentProcessorInterface { /** @@ -38,7 +35,7 @@ class CatalogPriceRulesProcessor implements ComponentProcessorInterface /** * @var CatalogRuleRepositoryInterface */ - private $catalogRuleRepository; + private $catalogRuleRepo; /** * @var Job @@ -66,7 +63,7 @@ public function __construct( ) { $this->logger = $logger; $this->ruleFactory = $ruleFactory; - $this->catalogRuleRepository = $catalogRuleRepo; + $this->catalogRuleRepo = $catalogRuleRepo; $this->ruleJob = $ruleJob; } @@ -128,7 +125,7 @@ public function process() $rule = $ruleCollection->getFirstItem(); // If the rule does not exist, create a new one - if (is_null($rule->getId())) { + if ($rule->getId() === null) { $rule = $this->ruleFactory->create(); } @@ -137,7 +134,7 @@ public function process() try { // Save the rule - $this->catalogRuleRepository->save($rule); + $this->catalogRuleRepo->save($rule); } catch (\Exception $ex) { $this->logger->logError($ex->getMessage()); } diff --git a/Component/Categories.php b/Component/Categories.php index 89b6ea6..4a8ec38 100644 --- a/Component/Categories.php +++ b/Component/Categories.php @@ -2,17 +2,39 @@ namespace CtiDigital\Configurator\Component; +use CtiDigital\Configurator\Api\ComponentInterface; +use CtiDigital\Configurator\Api\LoggerInterface; use CtiDigital\Configurator\Exception\ComponentException; -use Magento\Framework\Webapi\Exception; -use Symfony\Component\Yaml\Yaml; +use Magento\Catalog\Model\CategoryFactory; +use Magento\Store\Model\GroupFactory; +use Magento\Framework\App\Filesystem\DirectoryList; -class Categories extends YamlComponentAbstract +class Categories implements ComponentInterface { protected $alias = 'categories'; protected $name = 'Categories'; protected $description = 'Component to import categories.'; - protected $groupFactory; - protected $category; + + /** + * @var GroupFactory + */ + private $groupFactory; + + /** + * @var DirectoryList + */ + private $dirList; + + /** + * @var CategoryFactory + */ + private $category; + + /** + * @var LoggerInterface + */ + private $log; + private $mainAttributes = [ 'name', 'is_active', @@ -21,39 +43,41 @@ class Categories extends YamlComponentAbstract 'description' ]; + /** + * Categories constructor. + * @param CategoryFactory $category + * @param GroupFactory $groupFactory + * @param DirectoryList $dirList + * @param LoggerInterface $log + */ public function __construct( - \CtiDigital\Configurator\Api\LoggerInterface $log, - \Magento\Framework\ObjectManagerInterface $objectManager, - \Magento\Catalog\Model\CategoryFactory $category, - \Magento\Store\Model\GroupFactory $groupFactory, - \Magento\Framework\App\Filesystem\DirectoryList $dirList + CategoryFactory $category, + GroupFactory $groupFactory, + DirectoryList $dirList, + LoggerInterface $log ) { $this->category = $category; $this->groupFactory = $groupFactory; $this->dirList = $dirList; - parent::__construct($log, $objectManager); + $this->log = $log; } - public function processData($data = null) + public function execute($data = null) { if (isset($data['categories'])) { foreach ($data['categories'] as $store) { try { - if (isset($store['store_group'])) { - // Get the default category - $category = $this->getDefaultCategory($store['store_group']); - if ($category === false) { - throw new ComponentException( - sprintf('No default category was found for the store group "%s"', $store['store_group']) - ); - } - - if (isset($store['categories'])) { - $this->log->logInfo( - sprintf('Updating categories for "%s"', $store['store_group']) - ); - $this->createOrUpdateCategory($category, $store['categories']); - } + $group = $this->getStoreGroup($store); + // Get the default category + $category = $this->getDefaultCategory($group); + if ($category === false) { + throw new ComponentException( + sprintf('No default category was found for the store group "%s"', $group) + ); + } + if (isset($store['categories'])) { + $this->log->logInfo(sprintf('Updating categories for "%s"', $group)); + $this->createOrUpdateCategory($category, $store['categories']); } } catch (ComponentException $e) { $this->log->logError($e->getMessage()); @@ -99,10 +123,11 @@ public function getDefaultCategory($store = null) * @param array $categories * @param \Magento\Catalog\Model\Category $parentCategory * @SuppressWarnings(PHPMD) + * @throws \Magento\Framework\Exception\FileSystemException */ public function createOrUpdateCategory( \Magento\Catalog\Model\Category $parentCategory, - $categories = array() + $categories = [] ) { foreach ($categories as $categoryValues) { // Load the category using its name and parent category @@ -123,15 +148,18 @@ public function createOrUpdateCategory( case 'category': break; case 'image': + // phpcs:ignore Magento2.Functions.DiscouragedFunction $img = basename($value); + // phpcs:ignore Magento2.Functions.DiscouragedFunction $path = parse_url($value); $catMediaDir = $this->dirList->getPath('media') . '/' . 'catalog' . '/' . 'category' . '/'; - if (! array_key_exists('host', $path)) { - $value = BP . '/'. trim($value, '/'); + if (!array_key_exists('host', $path)) { + $value = BP . '/' . trim($value, '/'); } - if (! @copy($value, $catMediaDir . $img)) { + // phpcs:ignore + if (!@copy($value, $catMediaDir . $img)) { $this->log->logError('Failed to find image: ' . $value, 1); break; } @@ -168,4 +196,32 @@ public function createOrUpdateCategory( } } } + + /** + * @param $data + * @return string + */ + private function getStoreGroup($data) + { + if (isset($data['store_group']) === true) { + return $data['store_group']; + } + return 'Main Website Store'; + } + + /** + * @return string + */ + public function getAlias() + { + return $this->alias; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } } diff --git a/Component/ComponentAbstract.php b/Component/ComponentAbstract.php deleted file mode 100644 index 1fed656..0000000 --- a/Component/ComponentAbstract.php +++ /dev/null @@ -1,139 +0,0 @@ -log = $log; - $this->objectManager = $objectManager; - } - - /** - * Obtain the source of the data. - * Most likely to be a file path from the master.yaml - * - * @param $source - * @return ComponentAbstract - */ - public function setSource($source) - { - $this->source = $source; - return $this; - } - - /** - * This is a human friendly component name for logging purposes. - * - * @return string - */ - public function getComponentName() - { - return $this->name; - } - - /** - * This is to provide a system friendly alias that can be used on the command line - * so a component can be ran on its own as well as for logging purposes. - * - * @return string - */ - public function getComponentAlias() - { - return $this->alias; - } - - /** - * Gets a small description of the component used for when listing the component - * - * @return string - */ - public function getDescription() - { - return $this->description; - } - - /** - * The function that runs the component (and every other component) - */ - public function process() - { - try { - // Check if a component can be parsed and processed - if (!$this->canParseAndProcess()) { - return; // @todo show some kind of logging - } - - // @todo Include some events to dispatch. -// $this->eventManager->dispatch('configurator_parse_component_before',array('object'=>$this)); -// $this->eventManager->dispatch('configurator_parse_component_before'.$this->alias,array('object'=>$this)); - - $this->log->logComment(sprintf("Starting to parse data for %s", $this->getComponentName())); - $this->parsedData = $this->parseData($this->source); - $this->log->logComment(sprintf("Finished parsing data for %s", $this->getComponentName())); - -// $this->eventManager->dispatch( -// 'configurator_process_component_before', -// array('object'=>$this,'source'=>$this->source) -// ); -// $this->eventManager->dispatch('configurator_process_component_before'.$this->alias, -// array('object'=>$this,'source'=>$this->source) -// ); - - $this->log->logComment(sprintf("Starting to process data for %s", $this->getComponentName())); - $this->processData($this->parsedData); - $this->log->logComment(sprintf("Finished processing data for %s", $this->getComponentName())); - -// $this->eventManager->dispatch('configurator_process_component_after',array('object'=>$this)); -// $this->eventManager->dispatch('configurator_process_component_after'.$this->alias,array('object'=>$this)); - } catch (ComponentException $e) { - $this->log->logError($e->getMessage()); - } - } - - /** - * This method is used to check whether the data from file or a third party - * can be parsed and processed. (e.g. does a YAML file exist for it?) - * - * This will determine whether the component is enabled or disabled. - * - * @return bool - */ - abstract protected function canParseAndProcess(); - - /** - * Whether it be from many files or an external database, parsing (pre-processing) - * the data is done here. - * - * @param $source - * @return mixed - */ - abstract protected function parseData($source = null); - - /** - * This method should be used to process the data and populate the Magento Database. - * - * @param $data - * @return void - */ - abstract protected function processData($data = null); -} diff --git a/Component/ComponentList.php b/Component/ComponentList.php new file mode 100644 index 0000000..cc0b93e --- /dev/null +++ b/Component/ComponentList.php @@ -0,0 +1,38 @@ +components = $components; + } + + /** + * @inheritDoc + */ + public function getComponent($componentAlias) + { + if (array_key_exists($componentAlias, $this->components) === true) { + return $this->components[$componentAlias]; + } + return false; + } + + /** + * @inheritDoc + */ + public function getAllComponents() + { + return $this->components; + } +} diff --git a/Component/Config.php b/Component/Config.php index 5d2e5c8..84e9f8e 100644 --- a/Component/Config.php +++ b/Component/Config.php @@ -2,17 +2,19 @@ namespace CtiDigital\Configurator\Component; +use CtiDigital\Configurator\Api\ComponentInterface; use CtiDigital\Configurator\Exception\ComponentException; use CtiDigital\Configurator\Api\LoggerInterface; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Encryption\EncryptorInterface; -use Magento\Framework\ObjectManagerInterface; use Magento\Store\Model\StoreFactory; use Magento\Store\Model\WebsiteFactory; use Magento\Theme\Model\ResourceModel\Theme\Collection; use Magento\Theme\Model\ResourceModel\Theme\CollectionFactory; -use Symfony\Component\Yaml\Yaml; +use Magento\Config\Model\ResourceModel\Config as ConfigResource; +use Magento\Framework\App\Config as ScopeConfig; -class Config extends YamlComponentAbstract +class Config implements ComponentInterface { const PATH_THEME_ID = 'design/theme/theme_id'; @@ -21,12 +23,12 @@ class Config extends YamlComponentAbstract protected $description = 'Component to set the store/system configuration values'; /** - * @var \Magento\Config\Model\ResourceModel\Config + * @var ConfigResource */ protected $configResource; /** - * @var \Magento\Framework\App\Config + * @var ScopeConfig */ protected $scopeConfig; @@ -40,35 +42,54 @@ class Config extends YamlComponentAbstract */ protected $encryptor; + /** + * @var WebsiteFactory + */ + protected $websiteFactory; + + /** + * @var StoreFactory + */ + protected $storeFactory; + + /** + * @var LoggerInterface + */ + private $log; + /** * Config constructor. - * - * @param LoggerInterface $log - * @param ObjectManagerInterface $objectManager + * @param ConfigResource $configResource + * @param ScopeConfig $scopeConfig * @param CollectionFactory $collectionFactory + * @param EncryptorInterface $encryptor */ public function __construct( - LoggerInterface $log, - ObjectManagerInterface $objectManager, + ConfigResource $configResource, + ScopeConfig $scopeConfig, CollectionFactory $collectionFactory, - EncryptorInterface $encryptor + EncryptorInterface $encryptor, + WebsiteFactory $websiteFactory, + StoreFactory $storeFactory, + LoggerInterface $log ) { - parent::__construct($log, $objectManager); - - $this->configResource = $this->objectManager->create(\Magento\Config\Model\ResourceModel\Config::class); - $this->scopeConfig = $this->objectManager->create(\Magento\Framework\App\Config::class); + $this->configResource = $configResource; + $this->scopeConfig = $scopeConfig; $this->collectionFactory = $collectionFactory; $this->encryptor = $encryptor; + $this->websiteFactory = $websiteFactory; + $this->storeFactory = $storeFactory; + $this->log = $log; } /** * @param $data * @SuppressWarnings(PHPMD) */ - protected function processData($data = null) + public function execute($data = null) //phpcs:ignore Generic.Metrics.NestingLevel { try { - $validScopes = array('global', 'websites', 'stores'); + $validScopes = ['global', 'websites', 'stores']; foreach ($data as $scope => $configurations) { if (!in_array($scope, $validScopes)) { throw new ComponentException(sprintf("This is not a valid scope '%s' in your config.", $scope)); @@ -93,13 +114,12 @@ protected function processData($data = null) if ($scope == "websites") { foreach ($configurations as $code => $websiteConfigurations) { - // Handle encryption parameter - $encryption = 0; - if (isset($configuration['encryption']) && $configuration['encryption'] == 1) { - $encryption = 1; - } - foreach ($websiteConfigurations as $configuration) { + // Handle encryption parameter + $encryption = 0; + if (isset($configuration['encryption']) && $configuration['encryption'] == 1) { + $encryption = 1; + } $convertedConfiguration = $this->convert($configuration); $this->setWebsiteConfig( $convertedConfiguration['path'], @@ -140,7 +160,7 @@ private function setGlobalConfig($path, $value, $encrypted = 0) { try { // Check existing value, skip if the same - $scope = \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT; + $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT; $existingValue = $this->scopeConfig->getValue($path, $scope); if ($value == $existingValue) { $this->log->logComment(sprintf("Global Config Already: %s = %s", $path, $value)); @@ -165,9 +185,8 @@ private function setWebsiteConfig($path, $value, $code, $encrypted = 0) $logNest = 1; $scope = 'websites'; - // Prepare Website ID - $websiteFactory = new WebsiteFactory($this->objectManager, \Magento\Store\Model\Website::class); - $website = $websiteFactory->create(); + // Prepare Website ID; + $website = $this->websiteFactory->create(); $website->load($code, 'code'); if (!$website->getId()) { throw new ComponentException(sprintf("There is no website with the code '%s'", $code)); @@ -216,8 +235,7 @@ private function setStoreConfig($path, $value, $code, $encrypted = 0) $logNest = 2; $scope = 'stores'; - $storeFactory = new StoreFactory($this->objectManager, \Magento\Store\Model\Store::class); - $storeView = $storeFactory->create(); + $storeView = $this->storeFactory->create(); $storeView->load($code, 'code'); if (!$storeView->getId()) { throw new ComponentException(sprintf("There is no store view with the code '%s'", $code)); @@ -278,4 +296,20 @@ private function encrypt($value) { return $this->encryptor->encrypt($value); } + + /** + * @return string + */ + public function getAlias() + { + return $this->alias; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } } diff --git a/Component/CsvComponentAbstract.php b/Component/CsvComponentAbstract.php deleted file mode 100644 index 1c593a1..0000000 --- a/Component/CsvComponentAbstract.php +++ /dev/null @@ -1,57 +0,0 @@ -source; - if (!file_exists($path)) { - throw new ComponentException( - sprintf("Could not find file in path %s", $path) - ); - } - return true; - } - - /** - * Convert CSV to array - * @param null $source - * @return array - */ - protected function parseData($source = null) - { - try { - if ($source == null) { - throw new ComponentException( - sprintf('The %s component requires to have a file source definition.', $this->alias) - ); - } - - $file = new File(); - $parser = new Csv($file); - - return $parser->getData($source); - } catch (ComponentException $e) { - $this->log->logError($e->getMessage()); - } - - return null; - } -} diff --git a/Component/CustomerAttributes.php b/Component/CustomerAttributes.php index 2d86f9c..355b5d4 100644 --- a/Component/CustomerAttributes.php +++ b/Component/CustomerAttributes.php @@ -7,15 +7,12 @@ use Magento\Customer\Model\Customer; use Magento\Eav\Setup\EavSetup; use Magento\Framework\Exception\LocalizedException; -use Magento\Framework\ObjectManagerInterface; use Magento\Eav\Model\AttributeRepository; use Magento\Customer\Setup\CustomerSetupFactory; use Magento\Customer\Setup\CustomerSetup; use Magento\Customer\Model\ResourceModel\Attribute; /** - * Class CustomerAttributes - * @package CtiDigital\Configurator\Model\Component * @SuppressWarnings(PHPMD.LongVariable) */ class CustomerAttributes extends Attributes @@ -48,6 +45,11 @@ class CustomerAttributes extends Attributes */ protected $attributeResource; + /** + * @var LoggerInterface + */ + private $log; + /** * @var array */ @@ -60,24 +62,32 @@ class CustomerAttributes extends Attributes ] ]; + /** + * CustomerAttributes constructor. + * @param EavSetup $eavSetup + * @param AttributeRepository $attributeRepository + * @param CustomerSetupFactory $customerSetupFactory + * @param Attribute $attributeResource + * @param LoggerInterface $log + */ public function __construct( - LoggerInterface $log, - ObjectManagerInterface $objectManager, EavSetup $eavSetup, AttributeRepository $attributeRepository, CustomerSetupFactory $customerSetupFactory, - Attribute $attributeResource + Attribute $attributeResource, + LoggerInterface $log ) { + parent::__construct($eavSetup, $attributeRepository, $log); $this->attributeConfigMap = array_merge($this->attributeConfigMap, $this->customerConfigMap); $this->customerSetup = $customerSetupFactory; $this->attributeResource = $attributeResource; - parent::__construct($log, $objectManager, $eavSetup, $attributeRepository); + $this->log = $log; } /** * @param array $attributeConfigurationData */ - protected function processData($attributeConfigurationData = null) + public function execute($attributeConfigurationData = null) { try { foreach ($attributeConfigurationData['customer_attributes'] as $attributeCode => $attributeConfiguration) { @@ -131,4 +141,20 @@ protected function addAdditionalValues($attributeCode, $attributeConfiguration) )); } } + + /** + * @return string + */ + public function getAlias() + { + return $this->alias; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } } diff --git a/Component/CustomerGroups.php b/Component/CustomerGroups.php index ba8b32e..7023d16 100644 --- a/Component/CustomerGroups.php +++ b/Component/CustomerGroups.php @@ -1,14 +1,13 @@ groupFactory = $groupFactory; $this->classModelFactory = $classModelFactory; + $this->log = $log; } /** * @param $data */ - protected function processData($data = null) + public function execute($data = null) { foreach ($data['customergroups'] as $taxClass) { $taxClassName = $taxClass['taxclass']; @@ -91,12 +92,9 @@ private function createCustomerGroup($groupName, $taxClassId) ->setTaxClassId($taxClassId) ->save(); - $this->log->logInfo( sprintf('Customer Group "%s" created', $groupName) ); - - return; } /** @@ -121,4 +119,20 @@ private function getTaxClassIdFromName($taxClassName) return $taxclassId; } + + /** + * @return string + */ + public function getAlias() + { + return $this->alias; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } } diff --git a/Component/Customers.php b/Component/Customers.php index 6bb51e8..8396125 100644 --- a/Component/Customers.php +++ b/Component/Customers.php @@ -1,16 +1,17 @@ importerFactory = $importerFactory; $this->groupRepository = $groupRepository; $this->groupManagement = $groupManagement; $this->criteriaBuilder = $criteriaBuilder; $this->indexerFactory = $indexerFactory; - parent::__construct($log, $objectManager); + $this->log = $log; } /** @@ -87,7 +92,7 @@ public function __construct( * * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ - protected function processData($data = null) + public function execute($data = null) { $this->getColumnHeaders($data); unset($data[0]); @@ -220,4 +225,20 @@ private function reindex() $customerGrid->load('customer_grid'); $customerGrid->reindexAll(); } + + /** + * @return string + */ + public function getAlias() + { + return $this->alias; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } } diff --git a/Component/Factory/ComponentFactory.php b/Component/Factory/ComponentFactory.php deleted file mode 100644 index 2eb88ac..0000000 --- a/Component/Factory/ComponentFactory.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @copyright 2017 CtiDigital - */ - -namespace CtiDigital\Configurator\Component\Factory; - -use CtiDigital\Configurator\Component\ComponentAbstract; -use Magento\Framework\ObjectManagerInterface; - -/** - * Class ComponentFactory - */ -class ComponentFactory implements ComponentFactoryInterface -{ - /** - * @var ObjectManagerInterface - */ - private $objectManager; - - /** - * ComponentFactory constructor. - * - * @param ObjectManagerInterface $objectManager - */ - public function __construct(ObjectManagerInterface $objectManager) - { - $this->objectManager = $objectManager; - } - - /** - * @param string $componentClass - * @param array $args - * - * @return ComponentAbstract - */ - public function create($componentClass, array $args = []) - { - return $this->objectManager->create($componentClass, $args); - } -} diff --git a/Component/Factory/ComponentFactoryInterface.php b/Component/Factory/ComponentFactoryInterface.php deleted file mode 100644 index 1548890..0000000 --- a/Component/Factory/ComponentFactoryInterface.php +++ /dev/null @@ -1,24 +0,0 @@ - - * @copyright 2017 CtiDigital - */ - -namespace CtiDigital\Configurator\Component\Factory; - -use CtiDigital\Configurator\Component\ComponentAbstract; - -/** - * Interface ComponentFactoryInterface - */ -interface ComponentFactoryInterface -{ - /** - * @param string $componentClass - * @param array $args - * - * @return ComponentAbstract - */ - public function create($componentClass, array $args = []); -} diff --git a/Component/Media.php b/Component/Media.php index a23b904..70091e8 100644 --- a/Component/Media.php +++ b/Component/Media.php @@ -2,34 +2,41 @@ namespace CtiDigital\Configurator\Component; +use CtiDigital\Configurator\Api\ComponentInterface; use CtiDigital\Configurator\Exception\ComponentException; use CtiDigital\Configurator\Api\LoggerInterface; use Magento\Framework\App\Filesystem\DirectoryList; -use Magento\Framework\ObjectManagerInterface; -class Media extends YamlComponentAbstract +class Media implements ComponentInterface { - const FULL_ACCESS = 0777; protected $alias = 'media'; protected $name = 'Media'; protected $description = 'Component to download/maintain media.'; + + /** + * @var DirectoryList + */ protected $directoryList; + /** + * @var LoggerInterface + */ + private $log; + public function __construct( - LoggerInterface $log, - ObjectManagerInterface $objectManager, - DirectoryList $directoryList + DirectoryList $directoryList, + LoggerInterface $log ) { - parent::__construct($log, $objectManager); $this->directoryList = $directoryList; + $this->log = $log; } /** * @param $data */ - protected function processData($data = null) + public function execute($data = null) { try { // Load root media path @@ -77,6 +84,7 @@ private function createChildFolderFileItem($currentPath, $name, $node, $nest = 0 $newPath = $currentPath . DIRECTORY_SEPARATOR . $node['name']; + // phpcs:ignore Magento2.Functions.DiscouragedFunction if (file_exists($newPath)) { $this->log->logComment(sprintf('File already exists: %s', $newPath), $nest); return; @@ -97,10 +105,12 @@ private function createChildFolderFileItem($currentPath, $name, $node, $nest = 0 private function checkAndCreateFolder($newPath, $name, $nest) { // Check if the file/folder exists + // phpcs:ignore Magento2.Functions.DiscouragedFunction if (!file_exists($newPath)) { // If the node does not have a numeric index if (!is_numeric($name)) { // Then it is a directory so create it + // phpcs:ignore Magento2.Functions.DiscouragedFunction mkdir($newPath, $this::FULL_ACCESS, true); $this->log->logInfo(sprintf('Created new media directory %s', $name), $nest); } @@ -122,9 +132,26 @@ private function checkAndCreateFolder($newPath, $name, $nest) private function downloadAndSetFile($path, $node, $nest) { $this->log->logInfo(sprintf('Downloading contents of file from %s', $node['location']), $nest); + // phpcs:ignore Magento2.Functions.DiscouragedFunction $fileContents = file_get_contents($node['location']); - + // phpcs:ignore Magento2.Functions.DiscouragedFunction file_put_contents($path, $fileContents); $this->log->logInfo(sprintf('Created new file: %s', $path), $nest); } + + /** + * @return string + */ + public function getAlias() + { + return $this->alias; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } } diff --git a/Component/Pages.php b/Component/Pages.php index 570ac2a..2e2c3a6 100644 --- a/Component/Pages.php +++ b/Component/Pages.php @@ -2,22 +2,16 @@ namespace CtiDigital\Configurator\Component; +use CtiDigital\Configurator\Api\ComponentInterface; use CtiDigital\Configurator\Exception\ComponentException; use CtiDigital\Configurator\Api\LoggerInterface; use Magento\Cms\Api\Data\PageInterfaceFactory; use Magento\Cms\Api\PageRepositoryInterface; use Magento\Framework\Exception\NoSuchEntityException; -use Magento\Framework\ObjectManagerInterface; use Magento\Store\Api\StoreRepositoryInterface; use Magento\Store\Model\StoreManagerInterface; -/** - * Class Pages - * Process Magento CMS Pages - * - * @package CtiDigital\Configurator\Model\Component - */ -class Pages extends YamlComponentAbstract +class Pages implements ComponentInterface { protected $alias = 'pages'; protected $name = 'Pages'; @@ -39,37 +33,37 @@ class Pages extends YamlComponentAbstract */ private $storeRepository; + /** + * @var LoggerInterface + */ + private $log; + /** * Pages constructor. - * - * @param LoggerInterface $log - * @param ObjectManagerInterface $objectManager * @param PageRepositoryInterface $pageRepository * @param PageInterfaceFactory $pageFactory * @param StoreRepositoryInterface $storeRepository + * @param LoggerInterface $log */ public function __construct( - LoggerInterface $log, - ObjectManagerInterface $objectManager, PageRepositoryInterface $pageRepository, PageInterfaceFactory $pageFactory, - StoreRepositoryInterface $storeRepository + StoreRepositoryInterface $storeRepository, + LoggerInterface $log ) { $this->pageFactory = $pageFactory; $this->pageRepository = $pageRepository; $this->storeRepository = $storeRepository; - - parent::__construct($log, $objectManager); + $this->log = $log; } - /** * Loop through the data array and process page data * * @param $data * @return void */ - protected function processData($data = null) + public function execute($data = null) { try { foreach ($data as $identifier => $data) { @@ -117,6 +111,7 @@ protected function processPage($identifier, $data) // Check if content is from a file source if ($key == "source") { $key = 'content'; + // phpcs:ignore Magento2.Functions.DiscouragedFunction $value = file_get_contents(BP . '/' . $value); } @@ -152,7 +147,7 @@ protected function processPage($identifier, $data) $page->unsetData('store_id'); $page->unsetData('store_data'); - $stores = array(); + $stores = []; foreach ($pageData['stores'] as $code) { $stores[] = $store = $this->storeRepository->get($code)->getId(); } @@ -200,4 +195,20 @@ protected function setDefaultFields(&$pageData) } } } + + /** + * @return string + */ + public function getAlias() + { + return $this->alias; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } } diff --git a/Component/Processor/SqlSplitProcessor.php b/Component/Processor/SqlSplitProcessor.php index b536b21..6d861d2 100644 --- a/Component/Processor/SqlSplitProcessor.php +++ b/Component/Processor/SqlSplitProcessor.php @@ -11,9 +11,6 @@ use Magento\Framework\App\ResourceConnection; use Magento\Framework\DB\Adapter\AdapterInterface; -/** - * Class SqlSplitProcessor - */ class SqlSplitProcessor { /** @@ -45,7 +42,7 @@ public function __construct( /** * @param string $name - * @param string $fileContent + * @param string $filePath * * return void */ @@ -85,40 +82,40 @@ public function process($name, $filePath) * Split file content string into separate queries, allowing for * multi-line queries using preg_match * - * @param string $fileContent + * @param string $filePath + * @param string $delimiter * * @return array */ private function extractQueriesFromFile($filePath, $delimiter = ';') { + $obBaseLevel = ob_get_level(); $queries = []; + // phpcs:ignore Magento2.Functions.DiscouragedFunction $file = fopen($filePath, 'r'); - if (is_resource($file) === true) - { + if (is_resource($file) === true) { $query = []; - while (feof($file) === false) - { + while (feof($file) === false) { + // phpcs:ignore Magento2.Functions.DiscouragedFunction $query[] = fgets($file); - if (preg_match('~' . preg_quote($delimiter, '~') . '\s*$~iS', end($query)) === 1) - { + if (preg_match('~' . preg_quote($delimiter, '~') . '\s*$~iS', end($query)) === 1) { $query = trim(implode('', $query)); $queries[] = $query; - while (ob_get_level() > 0) - { + while (ob_get_level() > $obBaseLevel) { ob_end_flush(); } flush(); } - if (is_string($query) === true) - { + if (is_string($query) === true) { $query = []; } } } + // phpcs:ignore Magento2.Functions.DiscouragedFunction fclose($file); return $queries; } diff --git a/Component/Product/AttributeOption.php b/Component/Product/AttributeOption.php index 368e6b5..f18408d 100644 --- a/Component/Product/AttributeOption.php +++ b/Component/Product/AttributeOption.php @@ -146,7 +146,7 @@ public function saveOptions() * @var AttributeOptionInterface $option */ $option = $this->optionFactory->create(); - $option->setLabel($optionLabel); + $option->setLabel($label); $option->setStoreLabels([$optionLabel]); $option->setSortOrder(0); $option->setIsDefault(false); diff --git a/Component/Product/Image.php b/Component/Product/Image.php index fc3f7d3..564e4cd 100644 --- a/Component/Product/Image.php +++ b/Component/Product/Image.php @@ -4,6 +4,9 @@ use CtiDigital\Configurator\Api\LoggerInterface; use Magento\Framework\Filesystem; use Magento\Framework\App\Filesystem\DirectoryList; +use FireGento\FastSimpleImport\Helper\Config; +use Magento\Framework\HTTP\ZendClient; +use Magento\Framework\HTTP\ZendClientFactory; class Image { @@ -13,7 +16,7 @@ class Image protected $log; /** - * @var \Magento\Framework\Http\ZendClientFactory + * @var ZendClientFactory */ protected $httpClientFactory; @@ -23,28 +26,48 @@ class Image protected $filesystem; /** - * @var \FireGento\FastSimpleImport\Helper\Config + * @var Config */ protected $importerConfig; + /** + * @var string + */ + private $separator = ';'; + /** * Image constructor. - * - * @param LoggerInterface $log * @param Filesystem $filesystem - * @param \FireGento\FastSimpleImport\Helper\Config $importerConfig - * @param \Magento\Framework\Http\ZendClientFactory $httpClientFactory + * @param Config $importerConfig + * @param ZendClientFactory $httpClientFactory + * @param LoggerInterface $log */ public function __construct( - LoggerInterface $log, Filesystem $filesystem, - \FireGento\FastSimpleImport\Helper\Config $importerConfig, - \Magento\Framework\HTTP\ZendClientFactory $httpClientFactory + Config $importerConfig, + ZendClientFactory $httpClientFactory, + LoggerInterface $log ) { - $this->log = $log; $this->filesystem = $filesystem; $this->importerConfig = $importerConfig; $this->httpClientFactory = $httpClientFactory; + $this->log = $log; + } + + /** + * @param $separator + */ + public function setSeparator($separator) + { + $this->separator = $separator; + } + + /** + * @return string + */ + public function getSeparator() + { + return $this->separator; } /** @@ -67,7 +90,7 @@ public function isValueURL($url) public function downloadFile($value) { /** - * @var \Magento\Framework\HTTP\ZendClient $client + * @var ZendClient $client */ $client = $this->httpClientFactory->create(); $response = ''; @@ -91,7 +114,13 @@ public function downloadFile($value) */ public function getFileName($url) { - return basename($url); + // phpcs:ignore Magento2.Functions.DiscouragedFunction + $imageName = basename($url); + // Remove any URL entities + $imageName = urldecode($imageName); + // Replace spaces with - + $imageName = preg_replace('/\s+/', '-', $imageName); + return $imageName; } /** @@ -103,7 +132,9 @@ public function getFileName($url) */ public function saveFile($fileName, $value) { + // phpcs:ignore Magento2.Functions.DiscouragedFunction $name = pathinfo($fileName, PATHINFO_FILENAME); + // phpcs:ignore Magento2.Functions.DiscouragedFunction $ext = pathinfo($fileName, PATHINFO_EXTENSION); $writeDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA); @@ -144,20 +175,28 @@ private function isValidImage($file) */ public function getImage($value) { - if ($this->isValueURL($value) === false) { - return $value; - } - if ($this->localFileExists($value)) { - return $this->getFileName($value); - } - $this->log->logInfo(sprintf('Downloading image %s', $value)); - $file = $this->downloadFile($value); - if (strlen($file) > 0) { - $fileName = $this->getFileName($value); - $fileContent = $this->saveFile($fileName, $file); - return $fileContent; + $validImages = []; + $images = explode(',', $value); + foreach ($images as $image) { + if ($this->isValueURL($image) === false) { + $validImages[] = $image; + continue; + } + if ($this->localFileExists($image)) { + $validImages[] = $this->getFileName($image); + continue; + } + $this->log->logInfo(sprintf('Downloading image %s', $image)); + $file = $this->downloadFile($image); + if (strlen($file) > 0) { + $fileName = $this->getFileName($image); + $fileContent = $this->saveFile($fileName, $file); + if ($fileContent !== '') { + $validImages[] = $fileContent; + } + } } - return $value; + return implode($this->getSeparator(), $validImages); } /** diff --git a/Component/ProductLinks.php b/Component/ProductLinks.php index fd7f6c7..42bc41d 100644 --- a/Component/ProductLinks.php +++ b/Component/ProductLinks.php @@ -2,37 +2,50 @@ namespace CtiDigital\Configurator\Component; +use CtiDigital\Configurator\Api\ComponentInterface; use CtiDigital\Configurator\Api\LoggerInterface; use Magento\Catalog\Api\ProductRepositoryInterface; use Magento\Catalog\Api\Data\ProductLinkInterfaceFactory; -use Magento\Framework\ObjectManagerInterface; use CtiDigital\Configurator\Exception\ComponentException; -class ProductLinks extends YamlComponentAbstract +class ProductLinks implements ComponentInterface { - protected $alias = 'product_links'; protected $name = 'Product Links'; protected $description = 'Component to create and maintain product links (related/up-sells/cross-sells)'; - - // @var Magento\Catalog\Api\Data\ProductLinkInterfaceFactory $productLinkFactory + /** + * @var ProductLinkInterfaceFactory + */ protected $productLinkFactory; + /** + * @var ProductRepositoryInterface + */ protected $productRepository; + /** + * @var LoggerInterface + */ + private $log; + protected $allowedLinks = ['relation', 'up_sell', 'cross_sell']; protected $linkTypeMap = ['relation' => 'related', 'up_sell' => 'upsell', 'cross_sell' => 'crosssell']; + /** + * ProductLinks constructor. + * @param ProductRepositoryInterface $productRepository + * @param ProductLinkInterfaceFactory $productLinkFactory + * @param LoggerInterface $log + */ public function __construct( - LoggerInterface $log, - ObjectManagerInterface $objectManager, ProductRepositoryInterface $productRepository, - ProductLinkInterfaceFactory $productLinkFactory + ProductLinkInterfaceFactory $productLinkFactory, + LoggerInterface $log ) { - parent::__construct($log, $objectManager); $this->productRepository = $productRepository; $this->productLinkFactory = $productLinkFactory; + $this->log = $log; } /** @@ -40,7 +53,7 @@ public function __construct( * * @param $data */ - public function processData($data = null) + public function execute($data = null) { try { // Loop through all the product link types - if there are multiple link types in the yaml file @@ -97,7 +110,7 @@ private function processSkus(array $data, $linkType) private function processLinks($sku, $linkSkus, $linkType) { try { - $productLinks = array(); + $productLinks = []; // Loop through all the products that require linking to a product foreach ($linkSkus as $position => $linkSku) { @@ -138,4 +151,20 @@ private function doesProductExist($sku) } return false; } + + /** + * @return string + */ + public function getAlias() + { + return $this->alias; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } } diff --git a/Component/Products.php b/Component/Products.php index d024ba5..459348a 100644 --- a/Component/Products.php +++ b/Component/Products.php @@ -1,8 +1,8 @@ productFactory= $productFactory; $this->importerFactory = $importerFactory; $this->image = $image; $this->attributeOption = $attributeOption; + $this->log = $log; } /** @@ -120,7 +121,7 @@ public function __construct( * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ - protected function processData($data = null) + public function execute($data = null) { // Get the first row of the CSV file for the attribute columns. if (!isset($data[0])) { @@ -129,19 +130,20 @@ protected function processData($data = null) ); } $attributeKeys = $this->getAttributesFromCsv($data); + $this->image->setSeparator(self::SEPARATOR); $this->skuColumn = $this->getSkuColumnIndex($attributeKeys); $totalColumnCount = count($attributeKeys); unset($data[0]); // Prepare the data - $productsArray = array(); + $productsArray = []; foreach ($data as $product) { if (count($product) !== $totalColumnCount) { $this->skippedProducts[] = $product[$this->skuColumn]; continue; } - $productArray = array(); + $productArray = []; foreach ($attributeKeys as $column => $code) { $product[$column] = $this->clean($product[$column], $code); if (in_array($code, $this->imageAttributes)) { @@ -179,6 +181,7 @@ protected function processData($data = null) $import->setMultipleValueSeparator(self::SEPARATOR); $import->processImport($productsArray); } catch (\Exception $e) { + $this->log->logError($e->getMessage()); } $this->log->logInfo($import->getLogTrace()); $this->log->logError($import->getErrorMessages()); @@ -193,6 +196,7 @@ protected function processData($data = null) public function getFileType($source = null) { // Get the file extension so we know how to load the file + // phpcs:ignore Magento2.Functions.DiscouragedFunction $sourceFileInfo = pathinfo($source); if (!isset($sourceFileInfo['extension'])) { throw new ComponentException( @@ -211,7 +215,7 @@ public function getFileType($source = null) */ public function getAttributesFromCsv($data = null) { - $attributes = array(); + $attributes = []; foreach ($data[0] as $attributeCode) { $attributes[] = $attributeCode; } @@ -224,7 +228,7 @@ public function getAttributesFromCsv($data = null) * @param array $data * @return bool */ - public function isConfigurable($data = array()) + public function isConfigurable($data = []) { if (isset($data['product_type']) && $data['product_type'] === 'configurable') { return true; @@ -385,6 +389,7 @@ private function insertParagraphs($data, $column) */ private function spotHtmlTags($string, $tagname) { + $matches = []; $pattern = "/<$tagname?.*>(.*)<\/$tagname>/"; preg_match($pattern, $string, $matches); return count($matches); @@ -416,4 +421,20 @@ public function getSkuColumnIndex($headers) { return array_search(self::SKU_COLUMN_HEADING, $headers); } + + /** + * @return string + */ + public function getAlias() + { + return $this->alias; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } } diff --git a/Component/ReviewRating.php b/Component/ReviewRating.php index b477aed..f60e1db 100644 --- a/Component/ReviewRating.php +++ b/Component/ReviewRating.php @@ -1,8 +1,8 @@ ratingFactory = $ratingFactory; $this->storeRepository = $storeRepository; $this->optionFactory = $optionFactory; $this->entityFactory = $entityFactory; - parent::__construct($log, $objectManager); + $this->log = $log; } - public function processData($data = null) + public function execute($data = null) { $reviewRatings = $this->getReviewRatings($data); @@ -219,4 +230,20 @@ private function getReviewEntityId() } return $this->entityId; } + + /** + * @return string + */ + public function getAlias() + { + return $this->alias; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } } diff --git a/Component/Rewrites.php b/Component/Rewrites.php index 8665d7c..d55fa79 100644 --- a/Component/Rewrites.php +++ b/Component/Rewrites.php @@ -2,13 +2,13 @@ namespace CtiDigital\Configurator\Component; -use Magento\Framework\ObjectManagerInterface; -use Magento\UrlRewrite\Model\UrlRewriteFactory; -use Magento\UrlRewrite\Model\UrlPersistInterface; +use CtiDigital\Configurator\Api\ComponentInterface; use CtiDigital\Configurator\Exception\ComponentException; use CtiDigital\Configurator\Api\LoggerInterface; +use Magento\UrlRewrite\Model\UrlRewriteFactory; +use Magento\UrlRewrite\Model\UrlPersistInterface; -class Rewrites extends CsvComponentAbstract +class Rewrites implements ComponentInterface { protected $alias = "rewrites"; protected $name = "rewrites"; @@ -33,28 +33,31 @@ class Rewrites extends CsvComponentAbstract */ protected $urlRewriteFactory; + /** + * @var LoggerInterface + */ + private $log; + /** * Rewrites constructor. - * @param LoggerInterface $log - * @param ObjectManagerInterface $objectManager * @param UrlPersistInterface $urlPersist * @param UrlRewriteFactory $urlRewriteFactory + * @param LoggerInterface $log */ public function __construct( - LoggerInterface $log, - ObjectManagerInterface $objectManager, UrlPersistInterface $urlPersist, - UrlRewriteFactory $urlRewriteFactory + UrlRewriteFactory $urlRewriteFactory, + LoggerInterface $log ) { - parent::__construct($log, $objectManager); $this->urlPersist = $urlPersist; $this->urlRewriteFactory = $urlRewriteFactory; + $this->log = $log; } /** * @param array|null $data */ - public function processData($data = null) + public function execute($data = null) { $headerRowAttributes = $this->getAttributesFromHeaderRow($data); @@ -97,7 +100,7 @@ public function processData($data = null) public function getAttributesFromHeaderRow($data = null) { $this->checkHeaderRowExists($data); - $attributes = array(); + $attributes = []; foreach ($data[0] as $attributeCode) { $attributes[] = $attributeCode; } @@ -172,4 +175,20 @@ public function extractCsvDataIntoArray($attributeKeys, $rewriteDataCsvRow, $rew } return $rewriteArray; } + + /** + * @return string + */ + public function getAlias() + { + return $this->alias; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } } diff --git a/Component/ShippingTableRates.php b/Component/ShippingTableRates.php index 861ad98..c6d01b3 100644 --- a/Component/ShippingTableRates.php +++ b/Component/ShippingTableRates.php @@ -1,10 +1,8 @@ tablerateFactory = $tablerateFactory; $this->websiteFactory = $websiteFactory; $this->regionFactory = $regionFactory; + $this->log = $log; } - /** * This method should be used to process the data and populate the Magento Database. * * @param array $data * @return void */ - public function processData($data = null) + public function execute($data = null) { /** @var Tablerate $tablerateModel */ $tablerateModel = $this->tablerateFactory->create(); @@ -121,7 +121,7 @@ private function createNewShippingTableRate( $regionModel = $this->regionFactory->create(); $regionModel = $regionModel->loadByCode($shippingRate['dest_region_code'], $shippingRate['dest_country_id']); $regionId = $regionModel->getId(); - if (is_null($regionId)) { + if ($regionId === null) { $regionId = 0; } @@ -153,4 +153,20 @@ private function removeYamlKeysFromDatabaseInsert(array &$shippingRate) unset($shippingRate['dest_region_code']); unset($shippingRate['website_code']); } + + /** + * @return string + */ + public function getAlias() + { + return $this->alias; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } } diff --git a/Component/Sql.php b/Component/Sql.php index ff30866..5a83125 100644 --- a/Component/Sql.php +++ b/Component/Sql.php @@ -7,16 +7,14 @@ namespace CtiDigital\Configurator\Component; +use CtiDigital\Configurator\Api\ComponentInterface; use CtiDigital\Configurator\Api\LoggerInterface; use CtiDigital\Configurator\Component\Processor\SqlSplitProcessor; -use Magento\Framework\App\ResourceConnection; -use Magento\Framework\DB\Adapter\AdapterInterface; -use Magento\Framework\ObjectManagerInterface; /** - * Class Sql + * Class Sql - Runs raw SQL queries - generally a fallback for when a configurator component is not available. */ -class Sql extends YamlComponentAbstract +class Sql implements ComponentInterface { /** * @var string @@ -39,20 +37,21 @@ class Sql extends YamlComponentAbstract private $processor; /** - * {@inheritdoc} - * + * @var LoggerInterface + */ + private $log; + + /** + * Sql constructor. + * @param SqlSplitProcessor $processor * @param LoggerInterface $log - * @param ResourceConnection $resource - * @param ObjectManagerInterface $objectManager */ public function __construct( - LoggerInterface $log, - ObjectManagerInterface $objectManager, - SqlSplitProcessor $processor + SqlSplitProcessor $processor, + LoggerInterface $log ) { - parent::__construct($log, $objectManager); - $this->processor = $processor; + $this->log = $log; } /** @@ -62,7 +61,7 @@ public function __construct( * * @return void */ - protected function processData($data = null) + public function execute($data = null) { if (!isset($data['sql'])) { return; @@ -71,6 +70,7 @@ protected function processData($data = null) $this->log->logInfo('Beginning of custom queries configuration:'); foreach ($data['sql'] as $name => $sqlFile) { $path = BP . '/' . $sqlFile; + // phpcs:ignore Magento2.Functions.DiscouragedFunction if (false === file_exists($path)) { $this->log->logError("{$path} does not exist. Skipping."); continue; @@ -78,4 +78,20 @@ protected function processData($data = null) $this->processor->process($name, $path); } } + + /** + * @return string + */ + public function getAlias() + { + return $this->alias; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } } diff --git a/Component/TaxRates.php b/Component/TaxRates.php index 9f9bae0..12dbd96 100755 --- a/Component/TaxRates.php +++ b/Component/TaxRates.php @@ -2,12 +2,13 @@ namespace CtiDigital\Configurator\Component; -use Magento\Framework\ObjectManagerInterface; +use CtiDigital\Configurator\Api\FileComponentInterface; use CtiDigital\Configurator\Api\LoggerInterface; -use Magento\TaxImportExport\Model\Rate\CsvImportHandler; use CtiDigital\Configurator\Exception\ComponentException; +use Magento\Framework\Exception\LocalizedException; +use Magento\TaxImportExport\Model\Rate\CsvImportHandler; -class TaxRates extends CsvComponentAbstract +class TaxRates implements FileComponentInterface { protected $alias = 'taxrates'; protected $name = 'Tax Rates'; @@ -19,34 +20,31 @@ class TaxRates extends CsvComponentAbstract protected $csvImportHandler; /** - * TaxRules constructor. - * @param LoggerInterface $log - * @param ObjectManagerInterface $objectManager + * @var LoggerInterface + */ + private $log; + + /** + * TaxRates constructor. * @param CsvImportHandler $csvImportHandler + * @param LoggerInterface $log */ public function __construct( - LoggerInterface $log, - ObjectManagerInterface $objectManager, - CsvImportHandler $csvImportHandler + CsvImportHandler $csvImportHandler, + LoggerInterface $log ) { - parent::__construct($log, $objectManager); $this->csvImportHandler = $csvImportHandler; + $this->log = $log; } /** - * @param array|null $data + * @param null $data + * @throws LocalizedException */ - protected function processData($data = null) + public function execute($data = null) { - //Check Row Data exists - if (!isset($data[0])) { - throw new ComponentException( - sprintf('No row data found.') - ); - } - try { - $filePath = BP . '/' . $this->source; + $filePath = BP . '/' . $data; $this->log->logInfo( sprintf('"%s" is being imported', $filePath) ); @@ -59,4 +57,20 @@ protected function processData($data = null) $this->log->logError($e->getMessage()); } } + + /** + * @return string + */ + public function getAlias() + { + return $this->alias; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } } diff --git a/Component/TaxRules.php b/Component/TaxRules.php index b2a2d08..11a07cb 100644 --- a/Component/TaxRules.php +++ b/Component/TaxRules.php @@ -2,14 +2,14 @@ namespace CtiDigital\Configurator\Component; -use Magento\Framework\ObjectManagerInterface; +use CtiDigital\Configurator\Api\ComponentInterface; use CtiDigital\Configurator\Api\LoggerInterface; +use CtiDigital\Configurator\Exception\ComponentException; use Magento\Tax\Model\Calculation\RuleFactory; use Magento\Tax\Model\Calculation\RateFactory; use Magento\Tax\Model\ClassModelFactory; -use CtiDigital\Configurator\Exception\ComponentException; -class TaxRules extends CsvComponentAbstract +class TaxRules implements ComponentInterface { protected $alias = 'taxrules'; protected $name = 'Tax Rules'; @@ -40,31 +40,34 @@ class TaxRules extends CsvComponentAbstract */ protected $classModelFactory; + /** + * @var LoggerInterface + */ + private $log; + /** * TaxRules constructor. - * @param LoggerInterface $log - * @param ObjectManagerInterface $objectManager * @param RateFactory $rateFactory * @param ClassModelFactory $classModelFactory * @param RuleFactory $ruleFactory + * @param LoggerInterface $log */ public function __construct( - LoggerInterface $log, - ObjectManagerInterface $objectManager, RateFactory $rateFactory, ClassModelFactory $classModelFactory, - RuleFactory $ruleFactory + RuleFactory $ruleFactory, + LoggerInterface $log ) { - parent::__construct($log, $objectManager); $this->rateFactory = $rateFactory; $this->classModelFactory = $classModelFactory; $this->ruleFactory = $ruleFactory; + $this->log = $log; } /** * @param array|null $data */ - protected function processData($data = null) + public function execute($data = null) { //Check Row Data exists if (!isset($data[0])) { @@ -235,4 +238,20 @@ private function createTaxRule(array $ruleData) sprintf('Tax Rule "%s" created.', $ruleData['code']) ); } + + /** + * @return string + */ + public function getAlias() + { + return $this->alias; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } } diff --git a/Component/TieredPrices.php b/Component/TieredPrices.php index bcbb392..0f3b025 100644 --- a/Component/TieredPrices.php +++ b/Component/TieredPrices.php @@ -2,19 +2,16 @@ namespace CtiDigital\Configurator\Component; -use Magento\Framework\ObjectManagerInterface; +use CtiDigital\Configurator\Api\ComponentInterface; use CtiDigital\Configurator\Api\LoggerInterface; use CtiDigital\Configurator\Component\Product\AttributeOption; -use FireGento\FastSimpleImport\Model\ImporterFactory; use CtiDigital\Configurator\Exception\ComponentException; +use FireGento\FastSimpleImport\Model\ImporterFactory; /** - * Class Products - * @package CtiDigital\Configurator\Model\Component - * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class TieredPrices extends CsvComponentAbstract +class TieredPrices implements ComponentInterface { const SKU_COLUMN_HEADING = 'sku'; const SEPARATOR = ';'; @@ -33,6 +30,11 @@ class TieredPrices extends CsvComponentAbstract */ protected $attributeOption; + /** + * @var LoggerInterface + */ + private $log; + /** * @var [] */ @@ -49,22 +51,19 @@ class TieredPrices extends CsvComponentAbstract private $skuColumn; /** - * Products constructor. - * - * @param LoggerInterface $log - * @param ObjectManagerInterface $objectManager + * TieredPrices constructor. * @param ImporterFactory $importerFactory * @param AttributeOption $attributeOption + * @param LoggerInterface $log */ public function __construct( - LoggerInterface $log, - ObjectManagerInterface $objectManager, ImporterFactory $importerFactory, - AttributeOption $attributeOption + AttributeOption $attributeOption, + LoggerInterface $log ) { - parent::__construct($log, $objectManager); $this->importerFactory = $importerFactory; $this->attributeOption = $attributeOption; + $this->log = $log; } /** @@ -73,7 +72,7 @@ public function __construct( * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ - protected function processData($data = null) + public function execute($data = null) { // Get the first row of the CSV file for the attribute columns. if (!isset($data[0])) { @@ -119,6 +118,7 @@ protected function processData($data = null) $import->setMultipleValueSeparator(self::SEPARATOR); $import->processImport($pricesArray); } catch (\Exception $e) { + $this->log->logError($e->getMessage()); } $this->log->logInfo($import->getLogTrace()); $this->log->logError($import->getErrorMessages()); @@ -132,7 +132,7 @@ protected function processData($data = null) */ public function getAttributesFromCsv($data = null) { - $attributes = array(); + $attributes = []; foreach ($data[0] as $attributeCode) { $attributes[] = $attributeCode; } @@ -150,4 +150,20 @@ public function getSkuColumnIndex($headers) { return array_search(self::SKU_COLUMN_HEADING, $headers); } + + /** + * @return string + */ + public function getAlias() + { + return $this->alias; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } } diff --git a/Component/Websites.php b/Component/Websites.php index 47bd5ca..a0c8238 100644 --- a/Component/Websites.php +++ b/Component/Websites.php @@ -2,8 +2,8 @@ namespace CtiDigital\Configurator\Component; +use CtiDigital\Configurator\Api\ComponentInterface; use CtiDigital\Configurator\Api\LoggerInterface; -use Magento\Framework\ObjectManagerInterface; use CtiDigital\Configurator\Exception\ComponentException; use Magento\Store\Model\Group; use Magento\Store\Model\GroupFactory; @@ -13,11 +13,9 @@ use Magento\Store\Model\WebsiteFactory; use Magento\Indexer\Model\IndexerFactory; use Magento\Framework\Event\ManagerInterface; -use Symfony\Component\Yaml\Yaml; -class Websites extends YamlComponentAbstract +class Websites implements ComponentInterface { - protected $alias = 'websites'; protected $name = 'Websites'; protected $description = 'Component to manage Websites, Stores and Store Views'; @@ -43,35 +41,41 @@ class Websites extends YamlComponentAbstract */ protected $groupFactory; + /** + * @var LoggerInterface + */ + private $log; + + /** + * Websites constructor. + * @param IndexerFactory $indexerFactory + * @param ManagerInterface $eventManager + * @param WebsiteFactory $websiteFactory + * @param StoreFactory $storeFactory + * @param GroupFactory $groupFactory + * @param LoggerInterface $log + */ public function __construct( - LoggerInterface $log, - ObjectManagerInterface $objectManager, IndexerFactory $indexerFactory, ManagerInterface $eventManager, WebsiteFactory $websiteFactory, StoreFactory $storeFactory, - GroupFactory $groupFactory + GroupFactory $groupFactory, + LoggerInterface $log ) { - parent::__construct($log, $objectManager); - $this->indexer = $indexerFactory; $this->eventManager = $eventManager; $this->websiteFactory = $websiteFactory; $this->storeFactory = $storeFactory; $this->groupFactory = $groupFactory; + $this->log = $log; } - - protected function processData($data = null) + public function execute($data = null) { try { if (!isset($data['websites'])) { - throw new ComponentException( - sprintf( - "No websites found. Are you sure this component '%s' should be enabled?", - $this->getComponentAlias() - ) - ); + throw new ComponentException("No websites found."); } // Loop through the websites @@ -102,7 +106,7 @@ protected function processData($data = null) $indexProcess->load('catalog_product_price'); $indexProcess->reindexAll(); } - } catch (ComponentException $e) { + } catch (\Exception $e) { $this->log->logError($e->getMessage()); } } @@ -393,4 +397,20 @@ protected function setDefaultStore(Group $storeGroup, $storeGroupData) $this->log->logError($e->getMessage(), $logNest); } } + + /** + * @return string + */ + public function getAlias() + { + return $this->alias; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } } diff --git a/Component/Widgets.php b/Component/Widgets.php index 3e76abc..61f5ebf 100644 --- a/Component/Widgets.php +++ b/Component/Widgets.php @@ -2,37 +2,79 @@ namespace CtiDigital\Configurator\Component; +use CtiDigital\Configurator\Api\ComponentInterface; use CtiDigital\Configurator\Api\LoggerInterface; -use Magento\Framework\ObjectManagerInterface; use CtiDigital\Configurator\Exception\ComponentException; use Magento\Widget\Model\ResourceModel\Widget\Instance\Collection as WidgetCollection; +use Magento\Widget\Model\Widget\Instance; +use Magento\Widget\Model\Widget\InstanceFactory as WidgetInstanceFactory; use Magento\Theme\Model\ResourceModel\Theme\Collection as ThemeCollection; use Magento\Store\Model\StoreFactory; +use Magento\Framework\Serialize\SerializerInterface; -class Widgets extends YamlComponentAbstract +class Widgets implements ComponentInterface { protected $alias = 'widgets'; protected $name = 'Widgets'; protected $description = 'Component to manage CMS Widgets'; - protected $widgetCollection; - protected $themeCollection; - protected $storeFactory; + /** + * @var WidgetCollection + */ + private $widgetCollection; + + /** + * @var WidgetInstanceFactory + */ + private $widgetFactory; + + /** + * @var ThemeCollection + */ + private $themeCollection; + + /** + * @var StoreFactory + */ + private $storeFactory; + + /** + * @var SerializerInterface + */ + private $serializer; + + /** + * @var LoggerInterface + */ + private $log; + + /** + * Widgets constructor. + * @param WidgetCollection $collection + * @param WidgetInstanceFactory $widgetFactory + * @param StoreFactory $storeFactory + * @param ThemeCollection $themeCollection + * @param SerializerInterface $serializer + * @param LoggerInterface $log + */ public function __construct( - LoggerInterface $log, - ObjectManagerInterface $objectManager, WidgetCollection $collection, + WidgetInstanceFactory $widgetFactory, StoreFactory $storeFactory, - ThemeCollection $themeCollection + ThemeCollection $themeCollection, + SerializerInterface $serializer, + LoggerInterface $log ) { - parent::__construct($log, $objectManager); $this->widgetCollection = $collection; + $this->widgetFactory = $widgetFactory; $this->themeCollection = $themeCollection; $this->storeFactory = $storeFactory; + $this->serializer = $serializer; + $this->log = $log; } - protected function processData($data = null) + public function execute($data = null) { try { foreach ($data as $widgetData) { @@ -46,14 +88,15 @@ protected function processData($data = null) public function processWidget($widgetData) { try { - $this->validateInstanceType($widgetData['instance_type']); - $widget = $this->findWidgetByInstanceTypeAndTitle($widgetData['instance_type'], $widgetData['title']); $canSave = false; - if (is_null($widget)) { + if ($widget === null) { $canSave = true; - $widget = $this->objectManager->create(\Magento\Widget\Model\Widget\Instance::class); + /** + * @var Instance $widget + */ + $widget = $this->widgetFactory->create(); } foreach ($widgetData as $key => $value) { @@ -93,18 +136,6 @@ public function processWidget($widgetData) } } - public function validateInstanceType($instanceType) - { - $this->log->logComment(sprintf("Checking if %s is a valid instance", $instanceType)); - $instanceType = '\\' . $instanceType; - $instance = $this->objectManager->create($instanceType); - if (!$instance instanceof $instanceType) { - throw new ComponentException("Instance %s is invalid", $instanceType); - } - $this->log->logComment(sprintf("Found instance %s.", $instanceType)); - // @todo validate parameters somehow using the $fields - } - /** * @param $widgetInstanceType * @param $widgetTitle @@ -126,7 +157,6 @@ public function getWidgetByInstanceTypeAndTitle($widgetInstanceType, $widgetTitl ->load(); // @todo add store filter - // If we have more than 1, throw an exception for now. Needs store filter to drill down the widgets further // into a single widget. if ($widgets->count() > 1) { @@ -186,9 +216,8 @@ public function getThemeId($themeCode) */ public function populateWidgetParameters(array $parameters) { - // Default property return - return serialize($parameters); + return $this->serializer->serialize($parameters); } /** @@ -197,7 +226,7 @@ public function populateWidgetParameters(array $parameters) */ public function getCommaSeparatedStoreIds($stores) { - $storeIds = array(); + $storeIds = []; foreach ($stores as $code) { $storeView = $this->storeFactory->create(); $storeView->load($code, 'code'); @@ -208,4 +237,20 @@ public function getCommaSeparatedStoreIds($stores) } return implode(',', $storeIds); } + + /** + * @return string + */ + public function getAlias() + { + return $this->alias; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } } diff --git a/Component/YamlComponentAbstract.php b/Component/YamlComponentAbstract.php deleted file mode 100644 index bb6c7fd..0000000 --- a/Component/YamlComponentAbstract.php +++ /dev/null @@ -1,63 +0,0 @@ -source; - if (!file_exists($path)) { - throw new ComponentException( - sprintf("Could not find file in path %s", $path) - ); - } - return true; - } - - - /** - * Convert YAML to array - * - * @param null $source - * @return mixed - */ - protected function parseData($source = null) - { - try { - if ($source == null) { - throw new ComponentException( - sprintf('The %s component requires to have a file source definition.', $this->alias) - ); - } - - $path = BP . '/' . $source; - $data = file_get_contents($path); - return (new Yaml())->parse($data); - } catch (ParseException $e) { - throw new ComponentException( - sprintf('The %s component failed to parse. Error: %s.', $source, $e->getMessage()) - ); - } catch (ComponentException $e) { - $this->log->logError($e->getMessage()); - } - } -} diff --git a/Console/Command/ConfiguratorCommand.php b/Console/Command/ConfiguratorCommand.php deleted file mode 100644 index 6b3a6c6..0000000 --- a/Console/Command/ConfiguratorCommand.php +++ /dev/null @@ -1,44 +0,0 @@ -configuratorAdapter = $configuratorAdapter; - } - - protected function configure() - { - $this->setName('configurator'); - $this->setDescription('List configurator commands'); - } - - /** - * @param InputInterface $input - * @param OutputInterface $output - * @return void - * @SuppressWarnings(PHPMD) - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - try { - $output->writeln('To do'); - } catch (ConfiguratorAdapterException $e) { - $output->writeln('' . $e->getMessage() . ''); - } - } -} diff --git a/Console/Command/ListCommand.php b/Console/Command/ListCommand.php index e4106b7..fc2a4d8 100644 --- a/Console/Command/ListCommand.php +++ b/Console/Command/ListCommand.php @@ -2,11 +2,8 @@ namespace CtiDigital\Configurator\Console\Command; -use CtiDigital\Configurator\Model\ComponentList; +use CtiDigital\Configurator\Api\ComponentListInterface; use CtiDigital\Configurator\Exception\ConfiguratorAdapterException; -use CtiDigital\Configurator\Api\ConfigInterface; -use CtiDigital\Configurator\Api\ConfiguratorAdapterInterface; -use Magento\Framework\ObjectManagerInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -14,29 +11,19 @@ class ListCommand extends Command { /** - * @var ConfiguratorAdapterInterface + * @var ComponentListInterface */ - private $configuratorAdapter; + private $componentList; /** - * @var ConfigInterface|CtiDigital\Configurator\Console\Command\ListCommand + * ListCommand constructor. + * @param ComponentListInterface $componentList */ - private $configInterface; - - /** - * @var ObjectManagerInterface - */ - private $objectManagerInterface; - public function __construct( - ConfiguratorAdapterInterface $configuratorAdapter, - ConfigInterface $config, - ObjectManagerInterface $objectManager + ComponentListInterface $componentList ) { parent::__construct(); - $this->objectManagerInterface = $objectManager; - $this->configuratorAdapter = $configuratorAdapter; - $this->configInterface = $config; + $this->componentList = $componentList; } protected function configure() @@ -55,13 +42,11 @@ protected function execute(InputInterface $input, OutputInterface $output) { try { $count = 1; - foreach ($this->configInterface->getAllComponents() as $component) { - /* @var \CtiDigital\Configurator\Component\ComponentAbstract $componentClass */ - $componentClass = $this->objectManagerInterface->create($component['class']); + foreach ($this->componentList->getAllComponents() as $component) { $comment = str_pad($count.') ', 4) - . str_pad($componentClass->getComponentAlias(), 20) - . ' - ' . $componentClass->getDescription(); + . str_pad($component->getAlias(), 20) + . ' - ' . $component->getDescription(); $output->writeln('' . $comment . ''); $count++; } diff --git a/Console/Command/RunCommand.php b/Console/Command/RunCommand.php index 9d02273..49030df 100644 --- a/Console/Command/RunCommand.php +++ b/Console/Command/RunCommand.php @@ -3,8 +3,6 @@ namespace CtiDigital\Configurator\Console\Command; use CtiDigital\Configurator\Exception\ConfiguratorAdapterException; -use CtiDigital\Configurator\Api\ConfigInterface; -use CtiDigital\Configurator\Api\ConfiguratorAdapterInterface; use CtiDigital\Configurator\Model\Processor; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputDefinition; @@ -14,29 +12,15 @@ class RunCommand extends Command { - /** - * @var ConfiguratorAdapterInterface - */ - private $configuratorAdapter; - - /** - * @var ConfigInterface|CtiDigital\Configurator\Console\Command\RunCommand - */ - private $configInterface; - /** * @var Processor */ private $processor; public function __construct( - ConfiguratorAdapterInterface $configuratorAdapter, - ConfigInterface $config, Processor $processor ) { parent::__construct(); - $this->configuratorAdapter = $configuratorAdapter; - $this->configInterface = $config; $this->processor = $processor; } @@ -53,18 +37,27 @@ protected function configure() 'component', 'c', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, - 'Test', - array() + 'The component to be run', + [] + ); + + $ignoreMissingFiles = new InputOption( + 'ignore-missing-files', + 'i', + InputOption::VALUE_OPTIONAL, + 'Configurator continues if a source file is missing', + false ); $this ->setName('configurator:run') ->setDescription('Run configurator components') ->setDefinition( - new InputDefinition(array( + new InputDefinition([ $environmentOption, - $componentOption - )) + $componentOption, + $ignoreMissingFiles + ]) ); } @@ -83,6 +76,9 @@ protected function execute(InputInterface $input, OutputInterface $output) $environment = $input->getOption('env'); $components = $input->getOption('component'); + if ($input->getOption('ignore-missing-files') !== false) { + $this->processor->setIgnoreMissingFiles(true); + } $logLevel = OutputInterface::VERBOSITY_NORMAL; $verbose = $input->getOption('verbose'); @@ -107,7 +103,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if ($output->getVerbosity() > OutputInterface::VERBOSITY_NORMAL) { $output->writeln('Finished Configurator'); } - } catch (ConfiguratorAdapterException $e) { + } catch (\Exception $e) { $output->writeln('' . $e->getMessage() . ''); } } diff --git a/Model/Configurator/Config.php b/Model/Configurator/Config.php deleted file mode 100644 index d64c265..0000000 --- a/Model/Configurator/Config.php +++ /dev/null @@ -1,27 +0,0 @@ -get('components'); - } - - public function getComponentByName($name) - { - return $this->get('components/' . $name . '/class'); - } -} diff --git a/Model/Configurator/Config/Converter.php b/Model/Configurator/Config/Converter.php deleted file mode 100644 index c3f4140..0000000 --- a/Model/Configurator/Config/Converter.php +++ /dev/null @@ -1,26 +0,0 @@ -evaluate('/config/component'); - /** @var $typeNode \DOMNode */ - foreach ($components as $component) { - $name = $component->getAttribute('name'); - $class = $component->getAttribute('class'); - $output['components'][$name] = array('name' => $name, 'class' => $class); - } - - return $output; - } -} diff --git a/Model/Configurator/Config/Reader.php b/Model/Configurator/Config/Reader.php deleted file mode 100644 index a8336c1..0000000 --- a/Model/Configurator/Config/Reader.php +++ /dev/null @@ -1,47 +0,0 @@ -_idAttributes = array('/config/component' => 'name'); - - parent::__construct( - $fileResolver, - $converter, - $schemaLocator, - $validationState, - $fileName, - $idAttributes, - $domDocumentClass, - $defaultScope - ); - } -} diff --git a/Model/Configurator/Config/SchemaLocator.php b/Model/Configurator/Config/SchemaLocator.php deleted file mode 100644 index 80a3e03..0000000 --- a/Model/Configurator/Config/SchemaLocator.php +++ /dev/null @@ -1,38 +0,0 @@ -schema = - $reader->getModuleDir(Dir::MODULE_ETC_DIR, 'CtiDigital_Configurator') - . '/' - . 'configurator.xsd'; - } - - /** - * {@inheritdoc} - */ - public function getSchema() - { - return $this->schema; - } - - /** - * Only one schema will every be required once merged. - * - * @return null - */ - public function getPerFileSchema() - { - return null; - } -} diff --git a/Model/Processor.php b/Model/Processor.php index 96a690e..f024b94 100644 --- a/Model/Processor.php +++ b/Model/Processor.php @@ -2,65 +2,71 @@ namespace CtiDigital\Configurator\Model; +use CtiDigital\Configurator\Api\ComponentInterface; +use CtiDigital\Configurator\Api\FileComponentInterface; +use CtiDigital\Configurator\Api\ComponentListInterface; use CtiDigital\Configurator\Api\LoggerInterface; -use CtiDigital\Configurator\Component\ComponentAbstract; use CtiDigital\Configurator\Exception\ComponentException; -use CtiDigital\Configurator\Api\ConfigInterface; -use CtiDigital\Configurator\Component\Factory\ComponentFactoryInterface; use Symfony\Component\Yaml\Parser; use Magento\Framework\App\State; use Magento\Framework\App\Area; +use Symfony\Component\Yaml\Yaml; +/** + * Class Processor - The overarching class that reads and processes the configurator files. + * + * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) + */ class Processor { + const SOURCE_YAML = 'yaml'; + const SOURCE_CSV = 'csv'; + const SOURCE_JSON = 'json'; + /** * @var string */ protected $environment; /** - * @var array + * @var [] */ - protected $components = array(); + protected $components = []; /** - * @var ConfigInterface + * @var ComponentListInterface */ - protected $configInterface; + protected $componentList; /** - * @var LoggerInterface + * @var State */ - protected $log; + protected $state; /** - * @var State + * @var LoggerInterface */ - protected $state; + protected $log; /** - * @var ComponentFactoryInterface + * @var bool */ - protected $componentFactory; + protected $ignoreMissingFiles = false; /** * Processor constructor. - * - * @param ConfigInterface $configInterface - * @param ComponentFactoryInterface $componentFactory - * @param LoggerInterface $logging + * @param ComponentListInterface $componentList * @param State $state + * @param LoggerInterface $logging */ public function __construct( - ConfigInterface $configInterface, - LoggerInterface $logging, + ComponentListInterface $componentList, State $state, - ComponentFactoryInterface $componentFactory + LoggerInterface $logging ) { - $this->log = $logging; - $this->configInterface = $configInterface; + $this->componentList = $componentList; $this->state = $state; - $this->componentFactory = $componentFactory; + $this->log = $logging; } public function getLogger() @@ -68,6 +74,23 @@ public function getLogger() return $this->log; } + /** + * @param bool $setting + * @return void + */ + public function setIgnoreMissingFiles($setting) + { + $this->ignoreMissingFiles = $setting; + } + + /** + * @return bool + */ + public function isIgnoreMissingFiles() + { + return $this->ignoreMissingFiles; + } + /** * @param string $componentName * @return Processor @@ -167,6 +190,13 @@ private function runAllComponents() } } + /** + * @param $componentAlias + * @param $componentConfig + * + * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @SuppressWarnings(PHPMD.NPathComplexity) + */ public function runComponent($componentAlias, $componentConfig) { $this->log->logComment(""); @@ -174,13 +204,25 @@ public function runComponent($componentAlias, $componentConfig) $this->log->logComment(sprintf("| Loading component %s |", $componentAlias)); $this->log->logComment(str_pad("----------------------", (22 + strlen($componentAlias)), "-")); - $componentClass = $this->configInterface->getComponentByName($componentAlias); + /* @var ComponentInterface $component */ + $component = $this->componentList->getComponent($componentAlias); + + $sourceType = (isset($componentConfig['type']) === true) ? $componentConfig['type'] : null; - /* @var ComponentAbstract $component */ - $component = $this->componentFactory->create($componentClass); if (isset($componentConfig['sources'])) { foreach ($componentConfig['sources'] as $source) { - $component->setSource($source)->process(); + try { + $sourceData = ($component instanceof FileComponentInterface) ? + $source : + $this->parseData($source, $sourceType); + $component->execute($sourceData); + } catch (ComponentException $e) { + if ($this->isIgnoreMissingFiles() === true) { + $this->log->logInfo("Skipping file {$source} as it could not be found."); + continue; + } + throw $e; + } } } @@ -188,7 +230,7 @@ public function runComponent($componentAlias, $componentConfig) if (!isset($componentConfig['env'])) { // If not, continue to next component $this->log->logComment( - sprintf("No environment node for '%s' component", $component->getComponentName()) + sprintf("No environment node for '%s' component", $componentAlias) ); return; } @@ -200,7 +242,7 @@ public function runComponent($componentAlias, $componentConfig) sprintf( "No '%s' environment specific node for '%s' component", $this->getEnvironment(), - $component->getComponentName() + $componentAlias ) ); return; @@ -213,15 +255,25 @@ public function runComponent($componentAlias, $componentConfig) sprintf( "No '%s' environment specific sources for '%s' component", $this->getEnvironment(), - $component->getComponentName() + $componentAlias ) ); return; } - + // If there are sources for the environment, process them foreach ((array) $componentConfig['env'][$this->getEnvironment()]['sources'] as $source) { - $component->setSource($source)->process(); + try { + $sourceType = (isset($componentConfig['type']) === true) ? $componentConfig['type'] : null; + $sourceData = $this->parseData($source, $sourceType); + $component->execute($sourceData); + } catch (ComponentException $e) { + if ($this->isIgnoreMissingFiles() === true) { + $this->log->logInfo("Skipping file {$source} as it could not be found."); + continue; + } + throw $e; + } } } @@ -232,10 +284,12 @@ private function getMasterYaml() { // Read master yaml $masterPath = BP . '/app/etc/master.yaml'; + // phpcs:ignore Magento2.Functions.DiscouragedFunction if (!file_exists($masterPath)) { throw new ComponentException("Master YAML does not exist. Please create one in $masterPath"); } $this->log->logComment(sprintf("Found Master YAML")); + // phpcs:ignore Magento2.Functions.DiscouragedFunction $yamlContents = file_get_contents($masterPath); $yaml = new Parser(); $master = $yaml->parse($yamlContents); @@ -257,16 +311,9 @@ private function isValidComponent($componentName) if ($this->log->getLogLevel() > \Symfony\Component\Console\Output\OutputInterface::VERBOSITY_NORMAL) { $this->log->logQuestion(sprintf("Does the %s component exist?", $componentName)); } - $componentClass = $this->configInterface->getComponentByName($componentName); - - if (!$componentClass) { - $this->log->logError(sprintf("The %s component has no class name.", $componentName)); - return false; - } + $component = $this->componentList->getComponent($componentName); - $this->log->logComment(sprintf("The %s component has %s class name.", $componentName, $componentClass)); - $component = $this->componentFactory->create($componentClass); - if ($component instanceof ComponentAbstract) { + if ($component instanceof ComponentInterface) { return true; } return false; @@ -288,26 +335,29 @@ private function validateMasterYaml($master) sprintf('It appears %s does not have a "enabled" node. This is required.', $componentAlias) ); } - // Check it has at least 1 data source - $sourceCount = 0; - if (isset($componentConfig['sources'])) { - foreach ($componentConfig['sources'] as $i => $source) { - $sourceCount++; - } + $componentHasSource = false; + + if (isset($componentConfig['sources']) && + is_array($componentConfig['sources']) && + count($componentConfig['sources']) > 0 === true + ) { + $componentHasSource = true; } - if (isset($componentConfig['env'])) { + if (isset($componentConfig['env']) === true) { foreach ($componentConfig['env'] as $envData) { - if (isset($envData['sources'])) { - foreach ($envData['sources'] as $i => $source) { - $sourceCount++; - } + if (isset($envData['sources']) && + is_array($envData['sources']) && + count($envData['sources']) > 0 === true + ) { + $componentHasSource = true; + break; } } } - if ($sourceCount < 1) { + if ($componentHasSource === false) { throw new ComponentException( sprintf('It appears there are no data sources for the %s component.', $componentAlias) ); @@ -327,4 +377,139 @@ private function validateMasterYaml($master) $this->log->logError($e->getMessage()); } } + + private function parseData($source, $sourceType) + { + if ($this->canParseAndProcess($source) === true) { + $ext = ($sourceType !== null) ? $sourceType : $this->getExtension($source); + $sourceData = $this->getData($source); + if ($ext === self::SOURCE_YAML) { + return $this->parseYamlData($sourceData); + } + if ($ext === self::SOURCE_CSV) { + return $this->parseCsvData($sourceData); + } + if ($ext === self::SOURCE_JSON) { + return $this->parseJsonData($sourceData); + } + } + } + + /** + * This method is used to check whether the data from file or a third party + * can be parsed and processed. (e.g. does a YAML file exist for it?) + * + * This will determine whether the component is enabled or disabled. + * + * @return bool + */ + private function canParseAndProcess($source) + { + $path = BP . '/' . $source; + // phpcs:ignore Magento2.Functions.DiscouragedFunction + if ($this->isSourceRemote($source) === false && !file_exists($path)) { + throw new ComponentException( + sprintf("Could not find file in path %s", $path) + ); + } + return true; + } + + /** + * @return true + */ + public function isSourceRemote($source) + { + return (filter_var($source, FILTER_VALIDATE_URL) !== false) ? true : false; + } + + /** + * @param $source + * @return string + * @throws \Exception + */ + private function getExtension($source) + { + // phpcs:ignore Magento2.Functions.DiscouragedFunction + $extension = pathinfo($source, PATHINFO_EXTENSION); + if (strtolower($extension) === 'yaml') { + return self::SOURCE_YAML; + } + if (strtolower($extension) === 'csv') { + return self::SOURCE_CSV; + } + if (strtolower($extension) === 'json') { + return self::SOURCE_JSON; + } + throw new ComponentException(sprintf('Source "%s" does not have a valid file extension.', $source)); + } + + /** + * @param $source + * @return array|bool|false|float|int|mixed|string|null + * @throws \Exception + */ + private function getData($source) + { + return ($this->isSourceRemote($source) === true) ? + $this->getRemoteData($source) : + file_get_contents(BP . '/' . $source); // phpcs:ignore Magento2.Functions.DiscouragedFunction + } + + /** + * @param $source + * @return array|bool|float|int|mixed|string|null + * @throws \Exception + */ + public function getRemoteData($source) + { + try { + // phpcs:ignore Magento2.Functions.DiscouragedFunction + $streamContext = stream_context_create(['ssl' => ['verify_peer' => false, 'verify_peer_name' => false]]); + } catch (\Exception $e) { + return ''; + } + // phpcs:ignore Magento2.Functions.DiscouragedFunction + $remoteFile = file_get_contents($source, false, $streamContext); + return $remoteFile; + } + + /** + * @param $source + * @return mixed + */ + private function parseYamlData($source) + { + return (new Yaml())->parse($source); + } + + /** + * @param $source + * @return array + * @throws \Exception + */ + private function parseCsvData($source) + { + $lines = explode("\n", $source); + $headerRow = str_getcsv(array_shift($lines)); + $csvData = [$headerRow]; + foreach ($lines as $line) { + $csvLine = str_getcsv($line); + $csvRow = []; + foreach (array_keys($headerRow) as $key) { + $csvRow[$key] = (array_key_exists($key, $csvLine) === true) ? $csvLine[$key] : ''; + } + $csvData[] = $csvRow; + } + return $csvData; + } + + /** + * @param $source + * @return array|bool|float|int|mixed|string|null + */ + private function parseJsonData($source) + { + return json_decode($source); + } } diff --git a/README.md b/README.md index dd8f83e..b1d3aba 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ This is a work in progress and by no means for use with production environments If you are contributing the module, please run the following commands to stand the best chance with Travis CI liking your code. These test include PHP Code Sniffer, PHP Mess Detector, PHP Copy and Paste Detector, PHP Unit ``` -php vendor/bin/phpcs --standard=PSR2 vendor/ctidigital/magento2-configurator/Model/ vendor/ctidigital/magento2-configurator/Console/ vendor/ctidigital/magento2-configurator/Test/ vendor/ctidigital/magento2-configurator/Api/ vendor/ctidigital/magento2-configurator/Component/ vendor/ctidigital/magento2-configurator/Exception/ +php vendor/bin/phpcs --standard=vendor/magento/magento-coding-standard/Magento2/ruleset.xml vendor/ctidigital/magento2-configurator/Model/ vendor/ctidigital/magento2-configurator/Console/ vendor/ctidigital/magento2-configurator/Test/ vendor/ctidigital/magento2-configurator/Api/ vendor/ctidigital/magento2-configurator/Component/ vendor/ctidigital/magento2-configurator/Exception/ php vendor/bin/phpmd vendor/ctidigital/magento2-configurator/Model/,vendor/ctidigital/magento2-configurator/Console/,vendor/ctidigital/magento2-configurator/Test/,vendor/ctidigital/magento2-configurator/Api/,vendor/ctidigital/magento2-configurator/Component/,vendor/ctidigital/magento2-configurator/Exception/ text cleancode,codesize,controversial,design,naming,unusedcode php vendor/bin/phpcpd vendor/ctidigital/magento2-configurator/Model/ vendor/ctidigital/magento2-configurator/Console vendor/ctidigital/magento2-configurator/Test/ vendor/ctidigital/magento2-configurator/Api/ vendor/ctidigital/magento2-configurator/Component/ vendor/ctidigital/magento2-configurator/Exception/ php vendor/bin/phpunit vendor/ctidigital/magento2-configurator/Test/Unit/ diff --git a/Samples/Components/Attributes/attribute_sets.yaml b/Samples/Components/Attributes/attribute_sets.yaml index dad9d01..6a8b6c4 100644 --- a/Samples/Components/Attributes/attribute_sets.yaml +++ b/Samples/Components/Attributes/attribute_sets.yaml @@ -1,4 +1,13 @@ attribute_sets: +- + name: Default + inherit: Default + groups: + - + name: General + code: general + attributes: + - color - name: Shirts inherit: Default diff --git a/Samples/Components/catalog_price_rules.yaml b/Samples/Components/catalog_price_rules.yaml index 628d03c..98ae609 100644 --- a/Samples/Components/catalog_price_rules.yaml +++ b/Samples/Components/catalog_price_rules.yaml @@ -1,5 +1,5 @@ config: - apply_all: true + apply_all: true rules: rule1: name: Test Rule @@ -14,8 +14,8 @@ rules: from_date: ### Date format dd/mm/yyyy to_date: 11/10/2021 - conditions_serialized: a:7:{s:4:"type";s:48:"Magento\CatalogRule\Model\Rule\Condition\Combine";s:9:"attribute";N;s:8:"operator";N;s:5:"value";s:1:"1";s:18:"is_value_processed";N;s:10:"aggregator";s:3:"all";s:10:"conditions";a:1:{i:0;a:5:{s:4:"type";s:48:"Magento\CatalogRule\Model\Rule\Condition\Product";s:9:"attribute";s:3:"sku";s:8:"operator";s:2:"==";s:5:"value";s:5:"12asd";s:18:"is_value_processed";b:0;}}} - actions_serialized: a:4:{s:4:"type";s:48:"Magento\CatalogRule\Model\Rule\Action\Collection";s:9:"attribute";N;s:8:"operator";s:1:"=";s:5:"value";N;} + conditions_serialized: '{"type":"Magento\\CatalogRule\\Model\\Rule\\Condition\\Combine","attribute":null,"operator":null,"value":"1","is_value_processed":null,"aggregator":"all","conditions":[{"type":"Magento\\CatalogRule\\Model\\Rule\\Condition\\Product","attribute":"sku","operator":"==","value":"12asd","is_value_processed":false}]}' + actions_serialized: '{"type":"Magento\\CatalogRule\\Model\\Rule\\Action\\Collection","attribute":null,"operator":"=","value":null}' ### Values: [by_fixed|by_percent|to_percent|to_fixed] simple_action: by_fixed ### Range: 0-100 @@ -32,8 +32,8 @@ rules: - 0 from_date: 11/2/2018 to_date: 11/10/2021 - conditions_serialized: a:7:{s:4:"type";s:48:"Magento\CatalogRule\Model\Rule\Condition\Combine";s:9:"attribute";N;s:8:"operator";N;s:5:"value";s:1:"1";s:18:"is_value_processed";N;s:10:"aggregator";s:3:"all";s:10:"conditions";a:1:{i:0;a:5:{s:4:"type";s:48:"Magento\CatalogRule\Model\Rule\Condition\Product";s:9:"attribute";s:3:"sku";s:8:"operator";s:2:"==";s:5:"value";s:5:"12asd";s:18:"is_value_processed";b:0;}}} - actions_serialized: a:4:{s:4:"type";s:48:"Magento\CatalogRule\Model\Rule\Action\Collection";s:9:"attribute";N;s:8:"operator";s:1:"=";s:5:"value";N;} + conditions_serialized: '{"type":"Magento\\CatalogRule\\Model\\Rule\\Condition\\Combine","attribute":null,"operator":null,"value":"1","is_value_processed":null,"aggregator":"all","conditions":[{"type":"Magento\\CatalogRule\\Model\\Rule\\Condition\\Product","attribute":"sku","operator":"==","value":"12asd","is_value_processed":false}]}' + actions_serialized: '{"type":"Magento\\CatalogRule\\Model\\Rule\\Action\\Collection","attribute":null,"operator":"=","value":null}' simple_action: by_percent discount_amount: 100 stop_rules_processing: 1 diff --git a/Test/Integration/ShippingTablesRatesTest.php b/Test/Integration/ShippingTablesRatesTest.php index c439f89..e94b939 100644 --- a/Test/Integration/ShippingTablesRatesTest.php +++ b/Test/Integration/ShippingTablesRatesTest.php @@ -8,8 +8,7 @@ use Magento\Framework\DB\Adapter\AdapterInterface; /** - * Class ShippingTablesRatesTest - * @package CtiDigital\Configurator\Component + * Class ShippingTablesRatesTest - Test to run against Shipping Table Rates * @SuppressWarnings(PHPMD.LongVariable) */ class ShippingTablesRatesTest extends \PHPUnit\Framework\TestCase @@ -33,7 +32,7 @@ class ShippingTablesRatesTest extends \PHPUnit\Framework\TestCase * From directory_country_region table * @var array */ - private $regionIdMap = array('BER' => 82); + private $regionIdMap = ['BER' => 82]; /** * @var ShippingTableRates diff --git a/Test/Integration/setup-magento.sh b/Test/Integration/setup-magento.sh index b18349f..2b94dfe 100755 --- a/Test/Integration/setup-magento.sh +++ b/Test/Integration/setup-magento.sh @@ -14,12 +14,10 @@ cd magento2 git checkout tags/$1 -b $1 +# Update symfony/service-contracts as recommended in https://github.com/magento/magento2/issues/24937 +composer update symfony/service-contracts composer install -echo Temporary change versions to attempt to resolve any dependency issue -composer require symfony/config:4.1.* -composer require symfony/dependency-injection:3.3.* - if [ -z "${TRAVIS_TAG}" ]; then echo Require configurator branch: ${TRAVIS_BRANCH} commit: ${TRAVIS_COMMIT} composer require ctidigital/magento2-configurator dev-${TRAVIS_BRANCH}\#${TRAVIS_COMMIT} @@ -28,7 +26,7 @@ else composer require ctidigital/magento2-configurator ${TRAVIS_TAG:1} fi -php bin/magento setup:install --admin-email "test@test.com" --admin-firstname "CTI" --admin-lastname "Test" --admin-password "password123" --admin-user "admin" --backend-frontname admin --base-url "http://configurator.dev" --db-host 127.0.0.1 --db-name configurator --db-user root --session-save files --use-rewrites 1 --use-secure 0 -vvv +php bin/magento setup:install --cleanup-database --admin-email "test@test.com" --admin-firstname "CTI" --admin-lastname "Test" --admin-password "password123" --admin-user "admin" --backend-frontname admin --base-url "http://configurator.dev" --db-host 127.0.0.1 --db-name configurator --db-user root --session-save files --use-rewrites 1 --use-secure 0 -vvv echo Go to app etc folder cd app/etc diff --git a/Test/Unit/Component/AdminRolesTest.php b/Test/Unit/Component/AdminRolesTest.php deleted file mode 100644 index 9c49cc5..0000000 --- a/Test/Unit/Component/AdminRolesTest.php +++ /dev/null @@ -1,29 +0,0 @@ -getMockBuilder(RoleFactory::class) - ->disableOriginalConstructor() - ->getMock(); - $rulesFactory = $this->getMockBuilder(RulesFactory::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->component = new AdminRoles( - $this->logInterface, - $this->objectManager, - $roleFactory, - $rulesFactory - ); - $this->className = AdminRoles::class; - } -} diff --git a/Test/Unit/Component/AdminUsersTest.php b/Test/Unit/Component/AdminUsersTest.php deleted file mode 100644 index 64dcbd1..0000000 --- a/Test/Unit/Component/AdminUsersTest.php +++ /dev/null @@ -1,29 +0,0 @@ -getMockBuilder(UserFactory::class) - ->disableOriginalConstructor() - ->getMock(); - $rulesFactory = $this->getMockBuilder(RoleFactory::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->component = new AdminUsers( - $this->logInterface, - $this->objectManager, - $userFactory, - $rulesFactory - ); - $this->className = AdminUsers::class; - } -} diff --git a/Test/Unit/Component/ApiIntegrationsTest.php b/Test/Unit/Component/ApiIntegrationsTest.php deleted file mode 100644 index 1711c1c..0000000 --- a/Test/Unit/Component/ApiIntegrationsTest.php +++ /dev/null @@ -1,44 +0,0 @@ -getMockBuilder(AuthorizationService::class) - ->disableOriginalConstructor() - ->getMock(); - $integrationFactory = $this->getMockBuilder(IntegrationFactory::class) - ->disableOriginalConstructor() - ->getMock(); - $integrationService = $this->getMockBuilder(IntegrationServiceInterface::class) - ->disableOriginalConstructor() - ->getMock(); - $tokenFactory = $this->getMockBuilder(TokenFactory::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->component = new ApiIntegrations( - $this->logInterface, - $this->objectManager, - $integrationFactory, - $integrationService, - $authorizationService, - $tokenFactory - ); - $this->className = ApiIntegrations::class; - } -} diff --git a/Test/Unit/Component/AttributeSetsTest.php b/Test/Unit/Component/AttributeSetsTest.php deleted file mode 100644 index c37a8ce..0000000 --- a/Test/Unit/Component/AttributeSetsTest.php +++ /dev/null @@ -1,35 +0,0 @@ -getMockBuilder(EavSetup::class) - ->disableOriginalConstructor() - ->getMock(); - $attributeSetsRepositoryInterface = $this->getMockBuilder(AttributeSetRepositoryInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->component = new AttributeSets( - $this->logInterface, - $this->objectManager, - $eavSetup, - $attributeSetsRepositoryInterface - ); - - $this->className = AttributeSets::class; - } -} diff --git a/Test/Unit/Component/AttributesTest.php b/Test/Unit/Component/AttributesTest.php deleted file mode 100644 index 2caa2f4..0000000 --- a/Test/Unit/Component/AttributesTest.php +++ /dev/null @@ -1,21 +0,0 @@ -getMockBuilder(EavSetup::class) - ->disableOriginalConstructor() - ->getMock(); - $attributeRepository = $this->getMockBuilder(AttributeRepositoryInterface::class)->getMock(); - $this->component = new Attributes($this->logInterface, $this->objectManager, $eavSetup, $attributeRepository); - $this->className = Attributes::class; - } -} diff --git a/Test/Unit/Component/BlocksTest.php b/Test/Unit/Component/BlocksTest.php deleted file mode 100644 index 9f79ede..0000000 --- a/Test/Unit/Component/BlocksTest.php +++ /dev/null @@ -1,19 +0,0 @@ -getMockBuilder(BlockInterfaceFactory::class) - ->disableOriginalConstructor() - ->getMock(); - $this->component = new Blocks($this->logInterface, $this->objectManager, $blockInterface); - $this->className = Blocks::class; - } -} diff --git a/Test/Unit/Component/CatalogPriceRulesTest.php b/Test/Unit/Component/CatalogPriceRulesTest.php index 0e37644..852a77a 100644 --- a/Test/Unit/Component/CatalogPriceRulesTest.php +++ b/Test/Unit/Component/CatalogPriceRulesTest.php @@ -10,39 +10,49 @@ use CtiDigital\Configurator\Api\ComponentProcessorInterface; use CtiDigital\Configurator\Component\CatalogPriceRules; use CtiDigital\Configurator\Component\CatalogPriceRules\CatalogPriceRulesProcessor; +use CtiDigital\Configurator\Api\LoggerInterface; /** * Class CatalogPriceRulesTest * @codingStandardsIgnoreStart * @SuppressWarnings(PHPMD) */ -class CatalogPriceRulesTest extends ComponentAbstractTestCase +class CatalogPriceRulesTest extends \PHPUnit\Framework\TestCase { + /** + * @var CatalogPriceRules + */ + private $catalogPriceRules; + + /** + * @var LoggerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $log; + /** * @var ComponentProcessorInterface|\PHPUnit_Framework_MockObject_MockObject */ private $mockComponentProcessor; - protected function componentSetUp() + protected function setUp() { $this->mockComponentProcessor = $this->getMockBuilder(CatalogPriceRulesProcessor::class) ->disableOriginalConstructor() ->setMethods(['setData', 'setConfig', 'process']) ->getMock(); - $this->component = new CatalogPriceRules( - $this->logInterface, - $this->objectManager, - $this->mockComponentProcessor - ); + $this->log = $this->getMockBuilder(LoggerInterface::class) + ->disableOriginalConstructor() + ->getMock(); - $this->className = CatalogPriceRules::class; + $this->catalogPriceRules = new CatalogPriceRules( + $this->mockComponentProcessor, + $this->log + ); } public function testProcessDataExecution() { - $this->markTestSkipped('Test will be skipped until CI configuration will be fixed'); - $this->mockComponentProcessor->expects($this->once()) ->method('setData') ->willReturn($this->mockComponentProcessor); @@ -54,6 +64,6 @@ public function testProcessDataExecution() $this->mockComponentProcessor->expects($this->once()) ->method('process'); - $this->component->process(); + $this->catalogPriceRules->execute(); } } diff --git a/Test/Unit/Component/ComponentAbstractTestCase.php b/Test/Unit/Component/ComponentAbstractTestCase.php deleted file mode 100644 index c53851c..0000000 --- a/Test/Unit/Component/ComponentAbstractTestCase.php +++ /dev/null @@ -1,69 +0,0 @@ -testObjectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->objectManager = $this->getMockBuilder(ObjectManagerInterface::class) - ->disableOriginalConstructor() - ->getMock(); - $this->logInterface = $this->getMockBuilder(LoggerInterface::class) - ->disableOriginalConstructor() - ->getMock(); - $this->componentSetUp(); - } - - public function testItExtendsAbstract() - { - $this->assertInstanceOf(ComponentAbstract::class, $this->component); - } - - public function testItHasAnAlias() - { - $this->assertClassHasAttribute('alias', $this->className); - $this->assertNotEmpty( - $this->component->getComponentAlias(), - sprintf('No alias specified in component %s', $this->className) - ); - } - - public function testItHasAName() - { - $this->assertClassHasAttribute('name', $this->className); - $this->assertNotEmpty( - $this->component->getComponentName(), - sprintf('No name specified in component %s', $this->className) - ); - } -} diff --git a/Test/Unit/Component/ConfigTest.php b/Test/Unit/Component/ConfigTest.php index 63462e3..d3c4e57 100644 --- a/Test/Unit/Component/ConfigTest.php +++ b/Test/Unit/Component/ConfigTest.php @@ -3,24 +3,99 @@ namespace CtiDigital\Configurator\Test\Unit\Component; use CtiDigital\Configurator\Component\Config; +use Magento\Config\Model\ResourceModel\Config as ConfigResource; +use Magento\Framework\App\Config as ScopeConfig; +use Magento\Theme\Model\ResourceModel\Theme\Collection; +use Magento\Theme\Model\ResourceModel\Theme\CollectionFactory; use Magento\Framework\Encryption\EncryptorInterface; +use Magento\Store\Model\StoreFactory; +use Magento\Store\Model\WebsiteFactory; +use CtiDigital\Configurator\Api\LoggerInterface; -class ConfigTest extends ComponentAbstractTestCase +class ConfigTest extends \PHPUnit\Framework\TestCase { + /** + * @var Config + */ + private $config; + + /** + * @var ConfigResource|\PHPUnit\Framework\MockObject\MockObject + */ + private $configResource; + + /** + * @var ScopeConfig|\PHPUnit\Framework\MockObject\MockObject + */ + private $scopeConfig; + + /** + * @var Collection|\PHPUnit\Framework\MockObject\MockObject + */ + private $collection; + + /** + * @var CollectionFactory|\PHPUnit\Framework\MockObject\MockObject + */ + private $collectionFactory; + + /** + * @var EncryptorInterface|\PHPUnit\Framework\MockObject\MockObject + */ + private $encryptorInterface; + + /** + * @var WebsiteFactory|\PHPUnit\Framework\MockObject\MockObject + */ + private $websiteFactory; + + /** + * @var StoreFactory|\PHPUnit\Framework\MockObject\MockObject + */ + private $storeFactory; + + /** + * @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject + */ + private $log; - protected function componentSetUp() + protected function setUp() { - $collectionFactory = $this->getMockBuilder('\Magento\Theme\Model\ResourceModel\Theme\CollectionFactory') + $this->configResource = $this->getMockBuilder(ConfigResource::class) ->disableOriginalConstructor() ->getMock(); - $encrypterInterface = $this->getMockBuilder(EncryptorInterface::class)->getMock(); - $this->component = new Config( - $this->logInterface, - $this->objectManager, - $collectionFactory, - $encrypterInterface + $this->scopeConfig = $this->getMockBuilder(ScopeConfig::class) + ->disableOriginalConstructor() + ->getMock(); + $this->collection = $this->getMockBuilder(Collection::class) + ->disableOriginalConstructor() + ->getMock(); + $this->collectionFactory = $this->getMockBuilder(CollectionFactory::class) + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->collectionFactory->expects($this->any())->method('create')->willReturn($this->collection); + $this->encryptorInterface = $this->getMockBuilder(EncryptorInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $this->websiteFactory = $this->getMockBuilder(WebsiteFactory::class) + ->disableOriginalConstructor() + ->getMock(); + $this->storeFactory = $this->getMockBuilder(StoreFactory::class) + ->disableOriginalConstructor() + ->getMock(); + $this->log = $this->getMockBuilder(LoggerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $this->config = new Config( + $this->configResource, + $this->scopeConfig, + $this->collectionFactory, + $this->encryptorInterface, + $this->websiteFactory, + $this->storeFactory, + $this->log ); - $this->className = Config::class; } /** @@ -28,11 +103,7 @@ protected function componentSetUp() */ public function testIsConfigTheme() { - /** - * @var Config $config - */ - $config = $this->testObjectManager->getObject(Config::class); - $this->assertTrue($config->isConfigTheme($config::PATH_THEME_ID, 'theme')); + $this->assertTrue($this->config->isConfigTheme(Config::PATH_THEME_ID, 'theme')); } /** @@ -40,11 +111,7 @@ public function testIsConfigTheme() */ public function testIsConfigThemeWithAnId() { - /** - * @var Config $config - */ - $config = $this->testObjectManager->getObject(Config::class); - $this->assertTrue($config->isConfigTheme($config::PATH_THEME_ID, '1')); + $this->assertTrue($this->config->isConfigTheme(Config::PATH_THEME_ID, '1')); } /** @@ -52,11 +119,7 @@ public function testIsConfigThemeWithAnId() */ public function testNotConfigTheme() { - /** - * @var Config $config - */ - $config = $this->testObjectManager->getObject(Config::class); - $this->assertFalse($config->isConfigTheme('a/path', '1')); + $this->assertFalse($this->config->isConfigTheme('a/path', '1')); } /** @@ -73,32 +136,11 @@ public function testGetThemeById() ->method('getThemeId') ->willReturn(3); - $mockFactory = $this->getMockBuilder('Magento\Theme\Model\ResourceModel\Theme\CollectionFactory') - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); - - $mockCollection = $this->getMockBuilder('Magento\Theme\Model\ResourceModel\Theme\Collection') - ->disableOriginalConstructor() - ->setMethods(['getThemeByFullPath']) - ->getMock(); - - $mockCollection->expects($this->once()) + $this->collection->expects($this->once()) ->method('getThemeByFullPath') ->with('frontend/test/theme') ->willReturn($mockThemeModel); - $mockFactory->expects($this->once()) - ->method('create') - ->willReturn($mockCollection); - - $config = $this->testObjectManager->getObject( - Config::class, - [ - 'collectionFactory' => $mockFactory - ] - ); - - $this->assertEquals(3, $config->getThemeIdByPath('frontend/test/theme')); + $this->assertEquals(3, $this->config->getThemeIdByPath('frontend/test/theme')); } } diff --git a/Test/Unit/Component/CustomerGroupsTest.php b/Test/Unit/Component/CustomerGroupsTest.php deleted file mode 100644 index c99326c..0000000 --- a/Test/Unit/Component/CustomerGroupsTest.php +++ /dev/null @@ -1,28 +0,0 @@ -getMockBuilder(GroupFactory::class) - ->disableOriginalConstructor() - ->getMock(); - $classModelFactory = $this->getMockBuilder(ClassModelFactory::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->component = new CustomerGroups( - $this->logInterface, - $this->objectManager, - $groupFactory, - $classModelFactory - ); - $this->className = CustomerGroups::class; - } -} diff --git a/Test/Unit/Component/CustomersTest.php b/Test/Unit/Component/CustomersTest.php index 0f6b486..d82f517 100644 --- a/Test/Unit/Component/CustomersTest.php +++ b/Test/Unit/Component/CustomersTest.php @@ -3,47 +3,76 @@ use CtiDigital\Configurator\Component\Customers; use CtiDigital\Configurator\Exception\ComponentException; - -class CustomersTest extends ComponentAbstractTestCase +use FireGento\FastSimpleImport\Model\ImporterFactory; +use Magento\Customer\Api\GroupRepositoryInterface; +use Magento\Customer\Api\GroupManagementInterface; +use Magento\Framework\Api\SearchCriteriaBuilder; +use Magento\Framework\Api\SearchCriteria; +use Magento\Framework\Api\SearchResults; +use Magento\Indexer\Model\IndexerFactory; +use CtiDigital\Configurator\Api\LoggerInterface; +use Magento\Customer\Model\Data\Group; + +class CustomersTest extends \PHPUnit\Framework\TestCase { /** - * @var \Magento\Customer\Model\ResourceModel\GroupRepository | |PHPUnit_Framework_MockObject_MockObject + * @var Customers + */ + private $customers; + + /** + * @var ImporterFactory|\PHPUnit\Framework\MockObject\MockObject + */ + private $importerFactory; + + /** + * @var GroupRepositoryInterface | |PHPUnit_Framework_MockObject_MockObject */ private $groupRepository; /** - * @var \Magento|Framework\Api\SearchResults | \PHPUnit_Framework_MockObject_MockObject + * @var GroupManagementInterface | \PHPUnit_Framework_MockObject_MockObject */ - private $searchResults; + private $groupManagement; /** - * @var \Magento\Framework\Api\SearchCriteria | \PHPUnit_Framework_MockObject_MockObject + * @var SearchCriteriaBuilder | \PHPUnit_Framework_MockObject_MockObject + */ + private $searchBuilder; + + /** + * @var SearchCriteria | \PHPUnit_Framework_MockObject_MockObject */ private $searchCriteria; /** - * @var \Magento\Framework\Api\SearchCriteriaBuilder | \PHPUnit_Framework_MockObject_MockObject + * @var SearchResults | \PHPUnit_Framework_MockObject_MockObject */ - private $searchCriteriaBuilder; + private $searchResults; /** - * @var \Magento\Customer\Api\GroupManagementInterface | \PHPUnit_Framework_MockObject_MockObject + * @var IndexerFactory|\PHPUnit\Framework\MockObject\MockObject */ - private $groupManagement; + private $indexerFactory; - protected function componentSetUp() + /** + * @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject + */ + private $log; + + protected function setUp() { - $this->importerFactory = $this->getMockBuilder('FireGento\FastSimpleImport\Model\ImporterFactory') + $this->importerFactory = $this->getMockBuilder(ImporterFactory::class) ->setMethods(['create']) ->disableOriginalConstructor() ->getMock(); - $this->searchResults = $this->getMockBuilder('Magento\Framework\Api\SearchResults') + $this->searchResults = $this->getMockBuilder(SearchResults::class) ->setMethods(['getItems']) ->disableOriginalConstructor() ->getMock(); - $this->groupRepository = $this->getMockBuilder('Magento\Customer\Api\GroupRepositoryInterface') + $this->groupRepository = $this->getMockBuilder(GroupRepositoryInterface::class) ->setMethods(['save', 'getById', 'delete', 'deleteById', 'getList']) ->disableOriginalConstructor() ->getMock(); @@ -52,21 +81,9 @@ protected function componentSetUp() ->method('getList') ->willReturn($this->searchResults); - $this->searchCriteria = $this->getMockBuilder('Magento\Framework\Api\SearchCriteria') - ->disableOriginalConstructor() - ->getMock(); - - $this->searchCriteriaBuilder = $this->getMockBuilder('Magento\Framework\Api\SearchCriteriaBuilder') - ->setMethods(['create']) - ->disableOriginalConstructor() - ->getMock(); - $this->searchCriteriaBuilder->expects($this->any()) - ->method('create') - ->willReturn($this->searchCriteria); - $groupDefault = $this->createCustomerGroup(1); - $this->groupManagement = $this->getMockBuilder('Magento\Customer\Api\GroupManagementInterface') + $this->groupManagement = $this->getMockBuilder(GroupManagementInterface::class) ->setMethods( ['isReadOnly', 'getNotLoggedInGroup', 'getLoggedInGroups', 'getAllCustomersGroup', 'getDefaultGroup'] ) @@ -77,34 +94,49 @@ protected function componentSetUp() ->method('getDefaultGroup') ->willReturn($groupDefault); - $this->indexerFactory = $this->getMockBuilder('\Magento\Indexer\Model\IndexerFactory') + $this->searchCriteria = $this->getMockBuilder(SearchCriteria::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->searchBuilder = $this->getMockBuilder(SearchCriteriaBuilder::class) ->setMethods(['create']) ->disableOriginalConstructor() ->getMock(); + $this->searchBuilder->expects($this->any()) + ->method('create') + ->willReturn($this->searchCriteria); + + $this->indexerFactory = $this->getMockBuilder(IndexerFactory::class) + ->setMethods(['create']) + ->disableOriginalConstructor() + ->getMock(); + + $this->log = $this->getMockBuilder(LoggerInterface::class) + ->disableOriginalConstructor() + ->getMock(); - $this->component = $this->testObjectManager->getObject( - Customers::class, - [ - 'groupRepository' => $this->groupRepository, - 'groupManagement' => $this->groupManagement, - 'criteriaBuilder' => $this->searchCriteriaBuilder, - ] + $this->customers = new Customers( + $this->importerFactory, + $this->groupRepository, + $this->groupManagement, + $this->searchBuilder, + $this->indexerFactory, + $this->log ); - $this->className = Customers::class; } public function testDataMissingRows() { $testData = []; $this->expectException(ComponentException::class); - $this->component->getColumnHeaders($testData); + $this->customers->getColumnHeaders($testData); } public function testColumnsNotFound() { $testData = [['_website', '_store', 'firstname', 'notallowed']]; $this->expectException(ComponentException::class, 'The column "email" is required.'); - $this->component->getColumnHeaders($testData); + $this->customers->getColumnHeaders($testData); } public function testGetColumns() @@ -114,8 +146,8 @@ public function testGetColumns() ['email', '_website', '_store', 'firstname', 'lastname'], ['example@example.com', 'base', 'Default', 'Test', 'Test'] ]; - $this->component->getColumnHeaders($testData); - $this->assertEquals($expected, $this->component->getHeaders()); + $this->customers->getColumnHeaders($testData); + $this->assertEquals($expected, $this->customers->getHeaders()); } public function testGroupIsValid() @@ -126,7 +158,7 @@ public function testGroupIsValid() $this->searchResults->expects($this->any()) ->method('getItems') ->willReturn($groups); - $this->assertTrue($this->component->isValidGroup(1)); + $this->assertTrue($this->customers->isValidGroup(1)); } public function testGroupNotValid() @@ -137,17 +169,17 @@ public function testGroupNotValid() $this->searchResults->expects($this->any()) ->method('getItems') ->willReturn($groups); - $this->assertFalse($this->component->isValidGroup(4)); + $this->assertFalse($this->customers->isValidGroup(4)); } public function testGetDefault() { - $this->assertEquals(1, $this->component->getDefaultGroupId()); + $this->assertEquals(1, $this->customers->getDefaultGroupId()); } private function createCustomerGroup($groupId) { - $group = $this->getMockBuilder('Magento\Customer\Model\Data\Group') + $group = $this->getMockBuilder(Group::class) ->setMethods(['getId']) ->disableOriginalConstructor() ->getMock(); diff --git a/Test/Unit/Component/MediaTest.php b/Test/Unit/Component/MediaTest.php deleted file mode 100644 index 959ab00..0000000 --- a/Test/Unit/Component/MediaTest.php +++ /dev/null @@ -1,18 +0,0 @@ -getMockBuilder(\Magento\Framework\App\Filesystem\DirectoryList::class) - ->disableOriginalConstructor() - ->getMock(); - $this->component = new Media($this->logInterface, $this->objectManager, $directoryList); - $this->className = Media::class; - } -} diff --git a/Test/Unit/Component/PagesTest.php b/Test/Unit/Component/PagesTest.php deleted file mode 100644 index 68ee63e..0000000 --- a/Test/Unit/Component/PagesTest.php +++ /dev/null @@ -1,39 +0,0 @@ -getMockBuilder(PageRepositoryInterface::class) - ->disableOriginalConstructor() - ->getMock(); - /** @var PageInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject $pageFactory */ - $pageFactory = $this->getMockBuilder(PageInterfaceFactory::class) - ->disableOriginalConstructor() - ->getMock(); - /** @var StoreRepository|\PHPUnit_Framework_MockObject_MockObject $storeRepository */ - $storeRepository = $this->getMockBuilder(StoreRepositoryInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->component = - new Pages( - $this->logInterface, - $this->objectManager, - $pageRepository, - $pageFactory, - $storeRepository - ); - - $this->className = Pages::class; - } -} diff --git a/Test/Unit/Component/Product/AttributeOptionTest.php b/Test/Unit/Component/Product/AttributeOptionTest.php index b988247..394fa82 100644 --- a/Test/Unit/Component/Product/AttributeOptionTest.php +++ b/Test/Unit/Component/Product/AttributeOptionTest.php @@ -2,53 +2,88 @@ namespace CtiDigital\Configurator\Test\Unit\Component\Product; use CtiDigital\Configurator\Component\Product\AttributeOption; -use Magento\Eav\Api\Data\AttributeOptionInterfaceFactory; +use Magento\Catalog\Api\ProductAttributeRepositoryInterface; +use Magento\Eav\Api\AttributeOptionManagementInterface; use Magento\Eav\Api\Data\AttributeOptionLabelInterfaceFactory; +use Magento\Eav\Api\Data\AttributeOptionInterfaceFactory; +use CtiDigital\Configurator\Api\LoggerInterface; +use Magento\Catalog\Model\ResourceModel\Eav\Attribute; +use Magento\Eav\Model\Entity\Attribute\Option; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; +use PHPUnit_Framework_MockObject_MockObject; -class AttributeOptionTest extends \PHPUnit\Framework\TestCase +class AttributeOptionTest extends TestCase { /** - * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager + * @var ProductAttributeRepositoryInterface | PHPUnit_Framework_MockObject_MockObject + */ + private $attrRepository; + + /** + * @var AttributeOptionManagementInterface|MockObject + */ + private $attrOptionManagement; + + /** + * @var AttributeOptionLabelInterfaceFactory|MockObject + */ + private $attrOptionLabelFact; + + /** + * @var AttributeOptionInterfaceFactory|MockObject */ - protected $objectManager; + private $attrOptionFactory; /** - * @var \Magento\Catalog\Api\ProductAttributeRepositoryInterface | \PHPUnit_Framework_MockObject_MockObject + * @var LoggerInterface|MockObject */ - protected $attrRepositoryMock; + private $log; + /** * @var AttributeOption */ - protected $attributeOption; + private $attributeOption; protected function setUp() { - $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->attrRepositoryMock = $this->getMockBuilder('Magento\Catalog\Api\ProductAttributeRepositoryInterface') + $this->attrRepository = $this->getMockBuilder(ProductAttributeRepositoryInterface::class) ->disableOriginalConstructor() ->setMethods(['getList', 'get', 'save', 'delete', 'deleteById', 'getCustomAttributesMetadata']) ->getMock(); - $optionLabelFactory = $this->getMockBuilder(AttributeOptionLabelInterfaceFactory::class)->getMock(); - $optionFactory = $this->getMockBuilder(AttributeOptionInterfaceFactory::class)->getMock(); + $this->attrOptionManagement = $this->getMockBuilder(AttributeOptionManagementInterface::class) + ->disableOriginalConstructor() + ->getMock(); - $this->attributeOption = $this->objectManager->getObject( - AttributeOption::class, - [ - 'attributeRepository' => $this->attrRepositoryMock, - 'optionFactory' => $optionFactory, - 'labelFactory' => $optionLabelFactory - ] + $this->attrOptionLabelFact = $this->getMockBuilder(AttributeOptionLabelInterfaceFactory::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->attrOptionFactory = $this->getMockBuilder(AttributeOptionInterfaceFactory::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->log = $this->getMockBuilder(LoggerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->attributeOption = new AttributeOption( + $this->attrRepository, + $this->attrOptionManagement, + $this->attrOptionLabelFact, + $this->attrOptionFactory, + $this->log ); } public function testAttributeIsDropdown() { /** - * @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attributeMock + * @var Attribute $attributeMock */ $attributeMock = $this->createMockAttribute('colour', 'select', []); - $this->attrRepositoryMock->expects($this->once()) + $this->attrRepository->expects($this->once()) ->method('get') ->willReturn($attributeMock); $this->assertTrue($this->attributeOption->isOptionAttribute('colour')); @@ -57,10 +92,10 @@ public function testAttributeIsDropdown() public function testAttributeIsMultiSelect() { /** - * @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attributeMock + * @var Attribute $attributeMock */ $attributeMock = $this->createMockAttribute('colour', 'multiselect', []); - $this->attrRepositoryMock->expects($this->once()) + $this->attrRepository->expects($this->once()) ->method('get') ->willReturn($attributeMock); $this->assertTrue($this->attributeOption->isOptionAttribute('colour')); @@ -69,10 +104,10 @@ public function testAttributeIsMultiSelect() public function testAttributeIsNotAllowed() { /** - * @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attributeMock + * @var Attribute $attributeMock */ $attributeMock = $this->createMockAttribute('colour', 'text', null); - $this->attrRepositoryMock->expects($this->once()) + $this->attrRepository->expects($this->once()) ->method('get') ->willReturn($attributeMock); $this->assertFalse($this->attributeOption->isOptionAttribute('colour')); @@ -81,13 +116,13 @@ public function testAttributeIsNotAllowed() public function testAttributeBackendModelIsNotProcessed() { /** - * @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attributeMock + * @var Attribute $attributeMock */ $attributeMock = $this->createMockAttribute('colour', 'select', []); $attributeMock->expects($this->once()) ->method('getBackendModel') ->willReturn('/test/'); - $this->attrRepositoryMock->expects($this->once()) + $this->attrRepository->expects($this->once()) ->method('get') ->willReturn($attributeMock); $this->assertFalse($this->attributeOption->isOptionAttribute('colour')); @@ -96,10 +131,10 @@ public function testAttributeBackendModelIsNotProcessed() public function testOptionValueDoesNotExist() { /** - * @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attributeMock + * @var Attribute $attributeMock */ $attributeMock = $this->createMockAttribute('colour', 'select', ['Red']); - $this->attrRepositoryMock->expects($this->once()) + $this->attrRepository->expects($this->once()) ->method('get') ->willReturn($attributeMock); $this->assertFalse($this->attributeOption->isOptionValueExists('colour', 'White')); @@ -108,10 +143,10 @@ public function testOptionValueDoesNotExist() public function testOptionValueExists() { /** - * @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attributeMock + * @var Attribute $attributeMock */ $attributeMock = $this->createMockAttribute('colour', 'select', ['Red']); - $this->attrRepositoryMock->expects($this->once()) + $this->attrRepository->expects($this->once()) ->method('get') ->willReturn($attributeMock); $this->assertTrue($this->attributeOption->isOptionValueExists('colour', 'Red')); @@ -120,10 +155,10 @@ public function testOptionValueExists() public function testNewOptionIsNotDuplicated() { /** - * @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attributeMock + * @var Attribute $attributeMock */ $attributeMock = $this->createMockAttribute('colour', 'select', ['Red']); - $this->attrRepositoryMock->expects($this->once()) + $this->attrRepository->expects($this->once()) ->method('get') ->willReturn($attributeMock); $newValues = [ @@ -150,10 +185,10 @@ public function testNewOptionIsNotDuplicated() public function testAddOption() { /** - * @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attributeMock + * @var Attribute $attributeMock */ $attributeMock = $this->createMockAttribute('colour', 'select', ['Red', 'Green']); - $this->attrRepositoryMock->expects($this->once()) + $this->attrRepository->expects($this->once()) ->method('get') ->willReturn($attributeMock); $values = [ @@ -171,9 +206,9 @@ public function testAddOption() private function createMockAttribute($code, $input, $values) { /** - * @var \PHPUnit_Framework_MockObject_MockObject $attributeMock + * @var PHPUnit_Framework_MockObject_MockObject $attributeMock */ - $attributeMock = $this->getMockBuilder('Magento\Catalog\Model\ResourceModel\Eav\Attribute') + $attributeMock = $this->getMockBuilder(Attribute::class) ->disableOriginalConstructor() ->setMethods(['getAttributeCode', 'getFrontendInput', 'getOptions', 'getBackendModel', 'getIsUserDefined']) ->getMock(); @@ -186,7 +221,7 @@ private function createMockAttribute($code, $input, $values) if (is_array($values)) { $attributeOptions = []; foreach ($values as $attributeValue) { - $option = $this->getMockBuilder('Magento\Eav\Model\Entity\Attribute\Option') + $option = $this->getMockBuilder(Option::class) ->disableOriginalConstructor() ->setMethods(['getLabel']) ->getMock(); diff --git a/Test/Unit/Component/Product/ImageTest.php b/Test/Unit/Component/Product/ImageTest.php index 600b462..84d529d 100644 --- a/Test/Unit/Component/Product/ImageTest.php +++ b/Test/Unit/Component/Product/ImageTest.php @@ -2,39 +2,60 @@ namespace CtiDigital\Configurator\Test\Unit\Component\Product; use CtiDigital\Configurator\Component\Product\Image; +use Magento\Framework\Filesystem; +use FireGento\FastSimpleImport\Helper\Config; +use Magento\Framework\HTTP\ZendClient; +use Magento\Framework\HTTP\ZendClientFactory; +use CtiDigital\Configurator\Api\LoggerInterface; class ImageTest extends \PHPUnit\Framework\TestCase { /** - * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager + * @var Image */ - protected $objectManager; + private $image; /** - * @var Image + * @var Filesystem|\PHPUnit\Framework\MockObject\MockObject + */ + private $fileSystem; + + /** + * @var Config|\PHPUnit\Framework\MockObject\MockObject + */ + private $config; + + /** + * @var ZendClientFactory | \PHPUnit_Framework_MockObject_MockObject */ - protected $component; + private $httpFactoryMock; /** - * @var \Magento\Framework\HTTP\ZendClientFactory | \PHPUnit_Framework_MockObject_MockObject + * @var ZendClient | \PHPUnit_Framework_MockObject_MockObject */ - protected $httpFactoryMock; + private $httpMock; /** - * @var \Magento\Framework\HTTP\ZendClient | \PHPUnit_Framework_MockObject_MockObject + * @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */ - protected $httpMock; + private $log; protected function setUp() { - $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->fileSystem = $this->getMockBuilder(Filesystem::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->config = $this->getMockBuilder(Config::class) + ->disableOriginalConstructor() + ->getMock(); - $this->httpMock = $this->getMockBuilder('Magento\Framework\HTTP\ZendClient') + $this->httpMock = $this->getMockBuilder(ZendClient::class) ->disableOriginalConstructor() ->setMethods(['setUri', 'request', 'getBody']) ->getMock(); - $this->httpFactoryMock = $this->getMockBuilder('Magento\Framework\HTTP\ZendClientFactory') + $this->httpFactoryMock = $this->getMockBuilder(ZendClientFactory::class) ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); @@ -43,11 +64,15 @@ protected function setUp() ->method('create') ->willReturn($this->httpMock); - $this->component = $this->objectManager->getObject( - Image::class, - [ - 'httpClientFactory' => $this->httpFactoryMock - ] + $this->log = $this->getMockBuilder(LoggerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->image = new Image( + $this->fileSystem, + $this->config, + $this->httpFactoryMock, + $this->log ); } @@ -55,8 +80,8 @@ public function testIsValueUrl() { $testUrl = "http://test.com/media/item.png"; $testFilename = 'item.png'; - $this->assertNotFalse($this->component->isValueUrl($testUrl)); - $this->assertFalse($this->component->isValueUrl($testFilename)); + $this->assertNotFalse($this->image->isValueUrl($testUrl)); + $this->assertFalse($this->image->isValueUrl($testFilename)); } public function testDownloadFile() @@ -64,12 +89,12 @@ public function testDownloadFile() $this->httpMock->expects($this->any())->method('setUri')->willReturnSelf(); $this->httpMock->expects($this->any())->method('request')->willReturnSelf(); $this->httpMock->expects($this->any())->method('getBody')->willReturn('testbinarycontent'); - $this->assertEquals('testbinarycontent', $this->component->downloadFile('http://test.com/media/item.png')); + $this->assertEquals('testbinarycontent', $this->image->downloadFile('http://test.com/media/item.png')); } public function testGetFileName() { $testUrl = "http://test.com/media/item.png"; - $this->assertEquals('item.png', $this->component->getFileName($testUrl)); + $this->assertEquals('item.png', $this->image->getFileName($testUrl)); } } diff --git a/Test/Unit/Component/ProductLinksTest.php b/Test/Unit/Component/ProductLinksTest.php deleted file mode 100644 index 4933d9c..0000000 --- a/Test/Unit/Component/ProductLinksTest.php +++ /dev/null @@ -1,24 +0,0 @@ -className = ProductLinks::class; - $productLinkFactory = $this->getMockBuilder(ProductLinkInterfaceFactory::class)->getMock(); - $productRepository = $this->getMockBuilder(ProductRepositoryInterface::class)->getMock(); - $this->component = new ProductLinks( - $this->logInterface, - $this->objectManager, - $productRepository, - $productLinkFactory - ); - } -} diff --git a/Test/Unit/Component/ProductsTest.php b/Test/Unit/Component/ProductsTest.php index 490ca7b..56e6699 100644 --- a/Test/Unit/Component/ProductsTest.php +++ b/Test/Unit/Component/ProductsTest.php @@ -2,46 +2,76 @@ namespace CtiDigital\Configurator\Test\Unit\Component; use CtiDigital\Configurator\Component\Products; +use FireGento\FastSimpleImport\Model\ImporterFactory; use Magento\Catalog\Model\ProductFactory; -use Magento\Framework\App\Response\Http\FileFactory; +use Magento\Catalog\Model\Product; +use CtiDigital\Configurator\Component\Product\Image; +use CtiDigital\Configurator\Component\Product\AttributeOption; +use CtiDigital\Configurator\Api\LoggerInterface; +use Magento\Eav\Model\Entity\Attribute; -class ProductsTest extends ComponentAbstractTestCase +class ProductsTest extends \PHPUnit\Framework\TestCase { + /** + * @var Products + */ + private $products; + + /** + * @var ImporterFactory|\PHPUnit\Framework\MockObject\MockObject + */ + private $importerFactory; + /** * @var ProductFactory | \PHPUnit_Framework_MockObject_MockObject */ - private $productFactoryMock; + private $productFactory; + + /** + * @var Image|\PHPUnit\Framework\MockObject\MockObject + */ + private $image; + + /** + * @var AttributeOption|\PHPUnit\Framework\MockObject\MockObject + */ + private $attributeOption; - protected function componentSetUp() + /** + * @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject + */ + private $log; + + protected function setUp() { - $importerFactoryMock = $this->getMockBuilder('Firegento\FastSimpleImport\Model\ImporterFactory') + $this->importerFactory = $this->getMockBuilder(ImporterFactory::class) ->disableOriginalConstructor() ->getMock(); - $this->productFactoryMock = $this->getMockBuilder('Magento\Catalog\Model\ProductFactory') + $this->productFactory = $this->getMockBuilder(ProductFactory::class) ->setMethods(['create']) ->disableOriginalConstructor() ->getMock(); - $httpClientMock = $this->getMockBuilder('Magento\Framework\HTTP\ZendClientFactory') + $this->image = $this->getMockBuilder(Image::class) ->disableOriginalConstructor() - ->setMethods(['create']) ->getMock(); - $mockFileFactory = $this->getMockBuilder(FileFactory::class) + + $this->attributeOption = $this->getMockBuilder(AttributeOption::class) ->disableOriginalConstructor() - ->setMethods(['create']) ->getMock(); - $this->component = $this->testObjectManager->getObject( - Products::class, - [ - 'importerFactory' => $importerFactoryMock, - 'productFactory' => $this->productFactoryMock, - 'httpClientFactory' => $httpClientMock, - 'fileFactory' => $mockFileFactory - ] + $this->log = $this->getMockBuilder(LoggerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->products = new Products( + $this->importerFactory, + $this->productFactory, + $this->image, + $this->attributeOption, + $this->log ); - $this->className = Products::class; } public function testGetSkuColumnIndex() @@ -58,7 +88,7 @@ public function testGetSkuColumnIndex() ]; $expected = 4; - $this->assertEquals($expected, $this->component->getSkuColumnIndex($columns)); + $this->assertEquals($expected, $this->products->getSkuColumnIndex($columns)); } public function testGetAttributesFromCsv() @@ -97,7 +127,7 @@ public function testGetAttributesFromCsv() 'description' ]; - $this->assertEquals($expected, $this->component->getAttributesFromCsv($importData)); + $this->assertEquals($expected, $this->products->getAttributesFromCsv($importData)); } public function testIsConfigurable() @@ -105,7 +135,7 @@ public function testIsConfigurable() $importData = [ 'product_type' => 'configurable' ]; - $this->assertTrue($this->component->isConfigurable($importData)); + $this->assertTrue($this->products->isConfigurable($importData)); } public function testIsNotAConfigurable() @@ -113,7 +143,7 @@ public function testIsNotAConfigurable() $importData = [ 'product_type' => 'simple' ]; - $this->assertFalse($this->component->isConfigurable($importData)); + $this->assertFalse($this->products->isConfigurable($importData)); } public function testConstructVariations() @@ -176,15 +206,15 @@ public function testConstructVariations() ) ); - $this->productFactoryMock->expects($this->at(0)) + $this->productFactory->expects($this->at(0)) ->method('create') ->willReturn($simpleMockA); - $this->productFactoryMock->expects($this->at(1)) + $this->productFactory->expects($this->at(1)) ->method('create') ->willReturn($simpleMockB); - $this->assertEquals($expected, $this->component->constructConfigurableVariations($configurableData)); + $this->assertEquals($expected, $this->products->constructConfigurableVariations($configurableData)); } public function testIsStockSet() @@ -194,7 +224,7 @@ public function testIsStockSet() 'is_in_stock' => 1, 'qty' => 1 ]; - $this->assertTrue($this->component->isStockSpecified($testData)); + $this->assertTrue($this->products->isStockSpecified($testData)); } public function testStockIsNotSet() @@ -203,7 +233,7 @@ public function testStockIsNotSet() 'sku' => 1, 'name' => 'Test' ]; - $this->assertFalse($this->component->isStockSpecified($testData)); + $this->assertFalse($this->products->isStockSpecified($testData)); } public function testSetStock() @@ -219,7 +249,7 @@ public function testSetStock() 'is_in_stock' => 1, 'qty' => 1 ]; - $this->assertEquals($expectedData, $this->component->setStock($testData)); + $this->assertEquals($expectedData, $this->products->setStock($testData)); } public function testNotSetStock() @@ -234,12 +264,12 @@ public function testNotSetStock() 'name' => 'Test', 'is_in_stock' => 0, ]; - $this->assertEquals($expectedData, $this->component->setStock($testData)); + $this->assertEquals($expectedData, $this->products->setStock($testData)); } private function createProduct($productId) { - $productMock = $this->getMockBuilder('Magento\Catalog\Model\Product') + $productMock = $this->getMockBuilder(Product::class) ->disableOriginalConstructor() ->setMethods(['hasData', 'getSku', 'getIdBySku', 'load', 'getId', 'getResource', 'getAttribute']) ->getMock(); @@ -260,7 +290,7 @@ private function createProduct($productId) private function createMockAttribute($attributeCode, $value) { - $attr = $this->getMockBuilder('Magento\Eav\Model\Entity\Attribute') + $attr = $this->getMockBuilder(Attribute::class) ->disableOriginalConstructor() ->setMethods(['getFrontend', 'getValue', 'getAttributeCode']) ->getMock(); diff --git a/Test/Unit/Component/ReviewRatingTest.php b/Test/Unit/Component/ReviewRatingTest.php index 40d41c8..92087de 100644 --- a/Test/Unit/Component/ReviewRatingTest.php +++ b/Test/Unit/Component/ReviewRatingTest.php @@ -2,27 +2,68 @@ namespace CtiDigital\Configurator\Test\Unit\Component; use CtiDigital\Configurator\Component\ReviewRating; -use Magento\Review\Model\Rating\EntityFactory; -use Magento\Review\Model\Rating\OptionFactory; use Magento\Review\Model\RatingFactory; use Magento\Store\Api\StoreRepositoryInterface; +use Magento\Review\Model\Rating\OptionFactory; +use Magento\Review\Model\Rating\EntityFactory; +use CtiDigital\Configurator\Api\LoggerInterface; -class ReviewRatingTest extends ComponentAbstractTestCase +class ReviewRatingTest extends \PHPUnit\Framework\TestCase { - protected function componentSetUp() + /** + * @var ReviewRating + */ + private $reviewRating; + + /** + * @var RatingFactory|\PHPUnit\Framework\MockObject\MockObject + */ + private $ratingFactory; + + /** + * @var StoreRepositoryInterface|\PHPUnit\Framework\MockObject\MockObject + */ + private $storeRepository; + + /** + * @var OptionFactory|\PHPUnit\Framework\MockObject\MockObject + */ + private $optionFactory; + + /** + * @var EntityFactory|\PHPUnit\Framework\MockObject\MockObject + */ + private $entityFactory; + + /** + * @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject + */ + private $log; + + protected function setUp() { - $ratingFactory = $this->getMockBuilder(RatingFactory::class)->getMock(); - $storeRepository = $this->getMockBuilder(StoreRepositoryInterface::class)->getMock(); - $optionFactory = $this->getMockBuilder(OptionFactory::class)->getMock(); - $entityFactory = $this->getMockBuilder(EntityFactory::class)->getMock(); - $this->className = ReviewRating::class; - $this->component = new ReviewRating( - $this->logInterface, - $this->objectManager, - $ratingFactory, - $storeRepository, - $optionFactory, - $entityFactory + $this->ratingFactory = $this->getMockBuilder(RatingFactory::class) + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->storeRepository = $this->getMockBuilder(StoreRepositoryInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $this->optionFactory = $this->getMockBuilder(OptionFactory::class) + ->disableOriginalConstructor() + ->getMock(); + $this->entityFactory = $this->getMockBuilder(EntityFactory::class) + ->disableOriginalConstructor() + ->getMock(); + $this->log = $this->getMockBuilder(LoggerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $this->reviewRating = new ReviewRating( + $this->ratingFactory, + $this->storeRepository, + $this->optionFactory, + $this->entityFactory, + $this->log ); } @@ -45,11 +86,7 @@ public function testGetReviewRatings() 'Price' => [] ]; - /** - * @var ReviewRating $reviewRating - */ - $reviewRating = $this->testObjectManager->getObject(ReviewRating::class); - $this->assertEquals($expectedData, $reviewRating->getReviewRatings($data)); + $this->assertEquals($expectedData, $this->reviewRating->getReviewRatings($data)); } /** @@ -70,24 +107,10 @@ public function testGetReviewRating() ->method('getId') ->willReturn(1); - $mockRatingFactory = $this->getMockBuilder('\Magento\Review\Model\RatingFactory') - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); - - $mockRatingFactory->expects($this->once()) + $this->ratingFactory->expects($this->once()) ->method('create') ->willReturn($mockRating); - /** - * @var ReviewRating $reviewRating - */ - $reviewRating = $this->testObjectManager->getObject( - ReviewRating::class, - [ - 'ratingFactory' => $mockRatingFactory - ] - ); - $rating = $reviewRating->getReviewRating('value'); + $rating = $this->reviewRating->getReviewRating('value'); $this->assertEquals(1, $rating->getId()); } @@ -109,24 +132,11 @@ public function testGetNewRating() ->method('getId') ->willReturn(null); - $mockRatingFactory = $this->getMockBuilder('\Magento\Review\Model\RatingFactory') - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); - - $mockRatingFactory->expects($this->once()) + $this->ratingFactory->expects($this->once()) ->method('create') ->willReturn($mockRating); - /** - * @var ReviewRating $reviewRating - */ - $reviewRating = $this->testObjectManager->getObject( - ReviewRating::class, - [ - 'ratingFactory' => $mockRatingFactory - ] - ); - $rating = $reviewRating->getReviewRating('price'); + + $rating = $this->reviewRating->getReviewRating('price'); $this->assertNull($rating->getId()); } } diff --git a/Test/Unit/Component/RewritesTest.php b/Test/Unit/Component/RewritesTest.php deleted file mode 100644 index f55d52c..0000000 --- a/Test/Unit/Component/RewritesTest.php +++ /dev/null @@ -1,28 +0,0 @@ -getMockBuilder(UrlPersistInterface::class) - ->disableOriginalConstructor() - ->getMock(); - $urlRewriteFactory = $this->getMockBuilder(UrlRewriteFactory::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->component = new Rewrites( - $this->logInterface, - $this->objectManager, - $urlPersistInterface, - $urlRewriteFactory - ); - - $this->className = Rewrites::class; - } -} diff --git a/Test/Unit/Component/SqlTest.php b/Test/Unit/Component/SqlTest.php deleted file mode 100644 index 4eceaac..0000000 --- a/Test/Unit/Component/SqlTest.php +++ /dev/null @@ -1,25 +0,0 @@ -getMockBuilder(SqlSplitProcessor::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->component = new Sql( - $this->logInterface, - $this->objectManager, - $mockSqlSplitProc - ); - - $this->className = Sql::class; - } -} diff --git a/Test/Unit/Component/TaxRatesTest.php b/Test/Unit/Component/TaxRatesTest.php deleted file mode 100755 index 1e1df1b..0000000 --- a/Test/Unit/Component/TaxRatesTest.php +++ /dev/null @@ -1,23 +0,0 @@ -getMockBuilder(CsvImportHandler::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->component = new TaxRates( - $this->logInterface, - $this->objectManager, - $csvImportHandler - ); - - $this->className = TaxRates::class; - } -} diff --git a/Test/Unit/Component/TaxRulesTest.php b/Test/Unit/Component/TaxRulesTest.php deleted file mode 100644 index 5106e6b..0000000 --- a/Test/Unit/Component/TaxRulesTest.php +++ /dev/null @@ -1,32 +0,0 @@ -getMockBuilder(RateFactory::class) - ->disableOriginalConstructor() - ->getMock(); - $classModelFactory = $this->getMockBuilder(ClassModelFactory::class) - ->disableOriginalConstructor() - ->getMock(); - $ruleFactory = $this->getMockBuilder(RuleFactory::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->component = new TaxRules( - $this->logInterface, - $this->objectManager, - $rateFactory, - $classModelFactory, - $ruleFactory - ); - $this->className = TaxRules::class; - } -} diff --git a/Test/Unit/Component/WebsitesTest.php b/Test/Unit/Component/WebsitesTest.php deleted file mode 100644 index 2b0158e..0000000 --- a/Test/Unit/Component/WebsitesTest.php +++ /dev/null @@ -1,40 +0,0 @@ -className = Websites::class; - $this->websiteFactory = $this->getMockBuilder(WebsiteFactory::class)->setMethods(['create'])->getMock(); - $this->storeFactory = $this->getMockBuilder(StoreFactory::class)->setMethods(['create'])->getMock(); - $this->groupFactory = $this->getMockBuilder(GroupFactory::class)->setMethods(['create'])->getMock(); - $this->indexerFactory = $this->getMockBuilder('\Magento\Indexer\Model\IndexerFactory') - ->setMethods(['create']) - ->disableOriginalConstructor() - ->getMock(); - $this->eventManager = $this->getMockBuilder('Magento\Framework\Event\ManagerInterface')->getMock(); - - $this->component = new Websites( - $this->logInterface, - $this->objectManager, - $this->indexerFactory, - $this->eventManager, - $this->websiteFactory, - $this->storeFactory, - $this->groupFactory - ); - } -} diff --git a/Test/Unit/Component/WidgetsTest.php b/Test/Unit/Component/WidgetsTest.php deleted file mode 100644 index b5ec86a..0000000 --- a/Test/Unit/Component/WidgetsTest.php +++ /dev/null @@ -1,33 +0,0 @@ -getMockBuilder(StoreFactory::class) - ->disableOriginalConstructor() - ->getMock(); - $widgetCollection = $this->getMockBuilder(WidgetCollection::class) - ->disableOriginalConstructor() - ->getMock(); - $themeCollection = $this->getMockBuilder(ThemeCollection::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->component = new Widgets( - $this->logInterface, - $this->objectManager, - $widgetCollection, - $storeFactory, - $themeCollection - ); - $this->className = Widgets::class; - } -} diff --git a/Test/Unit/Console/Command/ConfiguratorCommandTest.php b/Test/Unit/Console/Command/ConfiguratorCommandTest.php deleted file mode 100644 index b219d4c..0000000 --- a/Test/Unit/Console/Command/ConfiguratorCommandTest.php +++ /dev/null @@ -1,57 +0,0 @@ -configuratorCommandAdapter = $this->getMockBuilder(ConfiguratorAdapterInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->command = new ConfiguratorCommand($this->configuratorCommandAdapter); - $this->mockInput = $this->getMockBuilder(InputInterface::class) - ->disableOriginalConstructor() - ->getMock(); - $this->mockOutput = $this->getMockBuilder(OutputInterface::class) - ->disableOriginalConstructor() - ->getMock(); - } - - public function testItIsAConsoleCommand() - { - $this->assertInstanceOf(Command::class, $this->command); - } - - public function testItHasTheCorrectName() - { - $this->assertSame('configurator', $this->command->getName()); - } -} diff --git a/Test/Unit/Console/Command/ListCommandTest.php b/Test/Unit/Console/Command/ListCommandTest.php deleted file mode 100644 index 0baa8a7..0000000 --- a/Test/Unit/Console/Command/ListCommandTest.php +++ /dev/null @@ -1,81 +0,0 @@ -listCommandAdapter = $this->getMockBuilder(ConfiguratorAdapterInterface::class) - ->disableOriginalConstructor() - ->getMock(); - $this->configInterface = $this->getMockBuilder(ConfigInterface::class) - ->disableOriginalConstructor() - ->getMock(); - $this->objectManager = $this->getMockBuilder(ObjectManagerInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->command = new ListCommand( - $this->listCommandAdapter, - $this->configInterface, - $this->objectManager - ); - - $this->mockInput = $this->getMockBuilder(InputInterface::class) - ->disableOriginalConstructor() - ->getMock(); - $this->mockOutput = $this->getMockBuilder(OutputInterface::class) - ->disableOriginalConstructor() - ->getMocK(); - } - - public function testItIsAConsoleCommand() - { - $this->assertInstanceOf(Command::class, $this->command); - } - - public function testItHasTheCorrectName() - { - $this->assertSame('configurator:list', $this->command->getName()); - } -} diff --git a/Test/Unit/Console/Command/RunCommandTest.php b/Test/Unit/Console/Command/RunCommandTest.php deleted file mode 100644 index a97ea10..0000000 --- a/Test/Unit/Console/Command/RunCommandTest.php +++ /dev/null @@ -1,124 +0,0 @@ -runCommandAdapter = $this->getMockBuilder(ConfiguratorAdapterInterface::class) - ->disableOriginalConstructor() - ->getMock(); - $this->configInterface = $this->getMockBuilder(ConfigInterface::class) - ->disableOriginalConstructor() - ->getMock(); - $this->componentFactory = $this->getMockBuilder(ComponentFactoryInterface::class) - ->disableOriginalConstructor() - ->getMock(); - $consoleOutput = $this->getMockBuilder(ConsoleOutputInterface::class) - ->disableOriginalConstructor() - ->getMock(); - $scopeInterface = $this->getMockBuilder(ScopeInterface::class) - ->disableOriginalConstructor() - ->getMock(); - $state = $this->getMockBuilder(State::class) - ->disableOriginalConstructor() - ->setConstructorArgs([$scopeInterface]) - ->getMock(); - $this->loggerInterface = $this->getMockBuilder(LoggerInterface::class) - ->disableOriginalConstructor() - ->setConstructorArgs([$consoleOutput]) - ->getMock(); - - $this->processor = $this->getMockBuilder(Processor::class) - ->disableOriginalConstructor() - ->setConstructorArgs([ - $this->configInterface, - $this->loggerInterface, - $state, - $this->componentFactory - ]) - ->getMock(); - - $this->command = new RunCommand( - $this->runCommandAdapter, - $this->configInterface, - $this->processor - ); - - $this->mockInput = $this->getMockBuilder(InputInterface::class) - ->disableOriginalConstructor() - ->getMock(); - $this->mockOutput = $this->getMockBuilder(OutputInterface::class) - ->disableOriginalConstructor() - ->getMock(); - } - - public function testItIsAConsoleCommand() - { - $this->assertInstanceOf(Command::class, $this->command); - } - - public function testItHasTheCorrectName() - { - $this->assertSame('configurator:run', $this->command->getName()); - } -} diff --git a/Test/Unit/Processor/SqlSplitProcessorTest.php b/Test/Unit/Processor/SqlSplitProcessorTest.php index 7e1261b..a869ca3 100644 --- a/Test/Unit/Processor/SqlSplitProcessorTest.php +++ b/Test/Unit/Processor/SqlSplitProcessorTest.php @@ -14,6 +14,7 @@ use Magento\Framework\DB\Adapter\AdapterInterface; use Magento\Framework\DB\Adapter\Pdo\Mysql; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use Exception; /** * Class SqlSplitProcessorTest @@ -21,6 +22,8 @@ */ class SqlSplitProcessorTest extends \PHPUnit\Framework\TestCase { + const TEST_SQL_PATH = '/Unit/_files/sql/test.sql'; + /** * @var LoggerInterface|\PHPUnit_Framework_MockObject_MockObject */ @@ -84,14 +87,14 @@ public function sqlDataProvider() public function testExceptionHandling() { + $this->markTestSkipped(); $name = 'name1'; - $fileContent = 'SELECT * FROM unknown'; $exMsg = 'exception message'; $this->mockConnection ->expects($this->any()) ->method('query') - ->willThrowException(new \Exception($exMsg)); + ->willThrowException(new Exception($exMsg)); $this->mockLogger ->expects($this->at(1)) @@ -102,6 +105,6 @@ public function testExceptionHandling() ->expects($this->once()) ->method('rollBack'); - $this->processor->process($name, $fileContent); + $this->processor->process($name, dirname(dirname(__DIR__)) . self::TEST_SQL_PATH); } } diff --git a/Test/Unit/ProcessorTest.php b/Test/Unit/ProcessorTest.php index a72fba1..a5c0e2e 100644 --- a/Test/Unit/ProcessorTest.php +++ b/Test/Unit/ProcessorTest.php @@ -3,9 +3,7 @@ namespace CtiDigital\Configurator\Model; use CtiDigital\Configurator\Api\LoggerInterface; -use CtiDigital\Configurator\Api\ConfigInterface; -use CtiDigital\Configurator\Component\Factory\ComponentFactory; -use CtiDigital\Configurator\Component\Factory\ComponentFactoryInterface; +use CtiDigital\Configurator\Api\ComponentListInterface; use Magento\Framework\App\State; use Magento\Framework\Config\ScopeInterface; use Symfony\Component\Console\Output\ConsoleOutputInterface; @@ -18,14 +16,14 @@ class ProcessorTest extends \PHPUnit\Framework\TestCase private $processor; /** - * @var ConfigInterface|\PHPUnit_Framework_MockObject_MockObject + * @var ComponentListInterface|\PHPUnit\Framework\MockObject\MockObject */ - private $configInterface; + private $componentList; /** - * @var ComponentFactoryInterface|\PHPUnit_Framework_MockObject_MockObject + * @var State|\PHPUnit\Framework\MockObject\MockObject */ - private $mockComponentFactory; + private $state; /** * @var LoggerInterface|\PHPUnit_Framework_MockObject_MockObject @@ -34,42 +32,33 @@ class ProcessorTest extends \PHPUnit\Framework\TestCase protected function setUp() { - $this->configInterface = $this->getMockBuilder(ConfigInterface::class) - ->disableOriginalConstructor() - ->getMock(); - $this->mockComponentFactory = $this->getMockBuilder(ComponentFactory::class) - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); - $consoleOutput = $this->getMockBuilder(ConsoleOutputInterface::class) ->disableOriginalConstructor() ->getMock(); $scopeInterface = $this->getMockBuilder(ScopeInterface::class) ->disableOriginalConstructor() ->getMock(); - $state = $this->getMockBuilder(State::class) + $this->componentList = $this->getMockBuilder(ComponentListInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $this->state = $this->getMockBuilder(State::class) ->disableOriginalConstructor() - ->setConstructorArgs(array($scopeInterface)) + ->setConstructorArgs([$scopeInterface]) ->getMock(); $this->loggerInterface = $this->getMockBuilder(LoggerInterface::class) ->disableOriginalConstructor() - ->setConstructorArgs(array($consoleOutput)) + ->setConstructorArgs([$consoleOutput]) ->getMock(); - $this->processor = $this->getMockBuilder(Processor::class) - ->disableOriginalConstructor() - ->setConstructorArgs(array( - $this->configInterface, - $this->loggerInterface, - $state, - $this->mockComponentFactory, - ))->getMock(); + $this->processor = new Processor( + $this->componentList, + $this->state, + $this->loggerInterface + ); } public function testICanSetAnEnvironment() { - $this->markTestSkipped("To do - Test we can set environments"); $environment = 'stage'; $this->processor->setEnvironment($environment); $this->assertEquals($environment, $this->processor->getEnvironment()); @@ -77,7 +66,6 @@ public function testICanSetAnEnvironment() public function testICanAddASingleComponent() { - $this->markTestSkipped("To do - Test a single component can be added"); $component = 'websites'; $this->processor->addComponent($component); $this->assertArrayHasKey($component, $this->processor->getComponents()); @@ -85,7 +73,6 @@ public function testICanAddASingleComponent() public function testICanAddMultipleComponents() { - $this->markTestSkipped("To do - Test multiple components can be added"); $components = ['website', 'config']; foreach ($components as $component) { $this->processor->addComponent($component); diff --git a/Test/Unit/_files/sql/test.sql b/Test/Unit/_files/sql/test.sql new file mode 100644 index 0000000..abe49a1 --- /dev/null +++ b/Test/Unit/_files/sql/test.sql @@ -0,0 +1 @@ +SELECT * FROM unknown; \ No newline at end of file diff --git a/composer.json b/composer.json index 713f155..27d63f5 100644 --- a/composer.json +++ b/composer.json @@ -9,17 +9,19 @@ } ], "require": { - "symfony/yaml": "~3.3|~4.0", + "symfony/yaml": "~4.0|~5.0", + "symfony/console": "~4.1.0", "firegento/fastsimpleimport": "1.3.1" }, "require-dev": { "phpmd/phpmd": "^2.6", - "squizlabs/php_codesniffer": "3.1.1", - "sebastian/phpcpd": "2.0.4", + "squizlabs/php_codesniffer": "^3.4", + "sebastian/phpcpd": "~3.0 || ~4.0", "satooshi/php-coveralls": "^1.0", - "phpunit/phpunit": "~6.2.0" + "phpunit/phpunit": "^6.2", + "magento/magento-coding-standard": "5" }, - "version": "2.0.8", + "version": "3.0.0", "autoload": { "files": [ "registration.php" ], "psr-4": { diff --git a/etc/configurator.xml b/etc/configurator.xml deleted file mode 100644 index 5ef69dc..0000000 --- a/etc/configurator.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/etc/configurator.xsd b/etc/configurator.xsd deleted file mode 100644 index b83813b..0000000 --- a/etc/configurator.xsd +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/etc/di.xml b/etc/di.xml index 167e52f..fd7d382 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -7,17 +7,50 @@ type="CtiDigital\Configurator\Model\Configurator\Config" /> + - CtiDigital\Configurator\Console\Command\ConfiguratorCommand CtiDigital\Configurator\Console\Command\ListCommand CtiDigital\Configurator\Console\Command\RunCommand + + + + CtiDigital\Configurator\Component\Websites + CtiDigital\Configurator\Component\Config + CtiDigital\Configurator\Component\Attributes + CtiDigital\Configurator\Component\AttributeSets + CtiDigital\Configurator\Component\AdminRoles + CtiDigital\Configurator\Component\AdminUsers + CtiDigital\Configurator\Component\CustomerGroups + CtiDigital\Configurator\Component\Categories + CtiDigital\Configurator\Component\TaxRates + CtiDigital\Configurator\Component\TaxRules + CtiDigital\Configurator\Component\Products + CtiDigital\Configurator\Component\Blocks + CtiDigital\Configurator\Component\Pages + CtiDigital\Configurator\Component\ApiIntegrations + CtiDigital\Configurator\Component\Widgets + CtiDigital\Configurator\Component\Media + CtiDigital\Configurator\Component\Rewrites + CtiDigital\Configurator\Component\ReviewRating + CtiDigital\Configurator\Component\ProductLinks + CtiDigital\Configurator\Component\Customers + CtiDigital\Configurator\Component\CatalogPriceRules + CtiDigital\Configurator\Component\Sql + CtiDigital\Configurator\Component\ShippingTableRates + CtiDigital\Configurator\Component\CustomerAttributes + CtiDigital\Configurator\Component\TieredPrices + + + + Magento\Framework\Module\Setup\Context @@ -30,11 +63,6 @@ - - - CtiDigital\Configurator\Component\Factory\ComponentFactory - - CtiDigital\Configurator\Component\CatalogPriceRules\CatalogPriceRulesProcessor diff --git a/registration.php b/registration.php index d950686..e22775a 100644 --- a/registration.php +++ b/registration.php @@ -3,4 +3,4 @@ \Magento\Framework\Component\ComponentRegistrar::MODULE, 'CtiDigital_Configurator', __DIR__ -); \ No newline at end of file +);