From f85ca9d444e7ac707b849cd7f7616d8190f9c9d5 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko <igavryshko@ebay.com> Date: Mon, 11 May 2015 00:31:15 -0500 Subject: [PATCH] MAGETWO-36070: Move dev/tools/performance-toolkit/generate.php - moved and refactored classes --- .../Test/Legacy/_files/obsolete_classes.php | 14 ++ .../Magento/ToolkitFramework/Config.php | 60 -------- .../Magento/ToolkitFramework/Helper/Cli.php | 53 ------- .../framework/bootstrap.php | 12 -- .../tests/unit/framework/bootstrap.php | 8 - .../framework/tests/unit/phpunit.xml.dist | 21 --- .../Magento/ToolkitFramework/ConfigTest.php | 18 --- .../ToolkitFramework/Helper/CliTest.php | 83 ----------- .../_files/application_test/fixture1.php | 7 - .../_files/application_test/fixture2.php | 7 - dev/tools/performance-toolkit/generate.php | 82 ----------- .../performance-toolkit/README.txt | 2 +- .../performance-toolkit/benchmark.jmx | 0 .../profiles/ce/extra_large.xml | 0 .../performance-toolkit/profiles/ce/large.xml | 0 .../profiles/ce/medium.xml | 0 .../performance-toolkit/profiles/ce/small.xml | 0 .../Command/GenerateFixturesCommand.php | 19 ++- .../Setup/Fixtures/CartPriceRulesFixture.php | 18 +-- .../Fixtures/CatalogPriceRulesFixture.php | 16 +- .../Setup/Fixtures/CategoriesFixture.php | 16 +- .../Setup/Fixtures/ConfigsApplyFixture.php | 14 +- .../Fixtures/ConfigurableProductsFixture.php | 23 +-- .../Setup/Fixtures/CustomersFixture.php | 20 +-- .../Setup/Fixtures/EavVariationsFixture.php | 26 ++-- .../src/Magento/Setup/Fixtures}/Fixture.php | 12 +- .../Magento/Setup/Fixtures/FixtureModel.php | 137 +++++++++--------- .../Setup/Fixtures/SimpleProductsFixture.php | 20 +-- .../Magento/Setup/Fixtures/StoresFixture.php | 18 +-- .../Setup/Fixtures/TaxRatesFixture.php | 16 +- .../src/Magento/Setup/Fixtures}/tax_rates.csv | 0 .../Setup/Model}/Complex/Generator.php | 8 +- .../Magento/Setup/Model}/Complex/Pattern.php | 2 +- .../src/Magento/Setup/Model}/Generator.php | 6 +- .../Model}/Complex/ComplexGeneratorTest.php | 17 ++- .../Test/Unit/Model}/Complex/PatternTest.php | 12 +- .../Setup/Test/Unit/Model}/GeneratorTest.php | 6 +- 37 files changed, 223 insertions(+), 550 deletions(-) delete mode 100644 dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/Config.php delete mode 100644 dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/Helper/Cli.php delete mode 100644 dev/tools/performance-toolkit/framework/bootstrap.php delete mode 100644 dev/tools/performance-toolkit/framework/tests/unit/framework/bootstrap.php delete mode 100644 dev/tools/performance-toolkit/framework/tests/unit/phpunit.xml.dist delete mode 100644 dev/tools/performance-toolkit/framework/tests/unit/testsuite/Magento/ToolkitFramework/ConfigTest.php delete mode 100644 dev/tools/performance-toolkit/framework/tests/unit/testsuite/Magento/ToolkitFramework/Helper/CliTest.php delete mode 100644 dev/tools/performance-toolkit/framework/tests/unit/testsuite/Magento/ToolkitFramework/_files/application_test/fixture1.php delete mode 100644 dev/tools/performance-toolkit/framework/tests/unit/testsuite/Magento/ToolkitFramework/_files/application_test/fixture2.php delete mode 100644 dev/tools/performance-toolkit/generate.php rename {dev/tools => setup}/performance-toolkit/README.txt (98%) rename {dev/tools => setup}/performance-toolkit/benchmark.jmx (100%) rename {dev/tools => setup}/performance-toolkit/profiles/ce/extra_large.xml (100%) rename {dev/tools => setup}/performance-toolkit/profiles/ce/large.xml (100%) rename {dev/tools => setup}/performance-toolkit/profiles/ce/medium.xml (100%) rename {dev/tools => setup}/performance-toolkit/profiles/ce/small.xml (100%) rename dev/tools/performance-toolkit/fixtures/cart_price_rules.php => setup/src/Magento/Setup/Fixtures/CartPriceRulesFixture.php (91%) rename dev/tools/performance-toolkit/fixtures/catalog_price_rules.php => setup/src/Magento/Setup/Fixtures/CatalogPriceRulesFixture.php (90%) rename dev/tools/performance-toolkit/fixtures/categories.php => setup/src/Magento/Setup/Fixtures/CategoriesFixture.php (82%) rename dev/tools/performance-toolkit/fixtures/configs_apply.php => setup/src/Magento/Setup/Fixtures/ConfigsApplyFixture.php (69%) rename dev/tools/performance-toolkit/fixtures/configurable_products.php => setup/src/Magento/Setup/Fixtures/ConfigurableProductsFixture.php (98%) rename dev/tools/performance-toolkit/fixtures/customers.php => setup/src/Magento/Setup/Fixtures/CustomersFixture.php (86%) rename dev/tools/performance-toolkit/fixtures/eav_variations.php => setup/src/Magento/Setup/Fixtures/EavVariationsFixture.php (80%) rename {dev/tools/performance-toolkit/framework/Magento/ToolkitFramework => setup/src/Magento/Setup/Fixtures}/Fixture.php (76%) rename dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/Application.php => setup/src/Magento/Setup/Fixtures/FixtureModel.php (57%) rename dev/tools/performance-toolkit/fixtures/simple_products.php => setup/src/Magento/Setup/Fixtures/SimpleProductsFixture.php (89%) rename dev/tools/performance-toolkit/fixtures/stores.php => setup/src/Magento/Setup/Fixtures/StoresFixture.php (90%) rename dev/tools/performance-toolkit/fixtures/tax_rates.php => setup/src/Magento/Setup/Fixtures/TaxRatesFixture.php (78%) rename {dev/tools/performance-toolkit/fixtures => setup/src/Magento/Setup/Fixtures}/tax_rates.csv (100%) rename {dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/ImportExport/Fixture => setup/src/Magento/Setup/Model}/Complex/Generator.php (91%) rename {dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/ImportExport/Fixture => setup/src/Magento/Setup/Model}/Complex/Pattern.php (97%) rename {dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/ImportExport/Fixture => setup/src/Magento/Setup/Model}/Generator.php (93%) rename {dev/tools/performance-toolkit/framework/tests/unit/testsuite/Magento/ToolkitFramework/ImportExport/Fixture => setup/src/Magento/Setup/Test/Unit/Model}/Complex/ComplexGeneratorTest.php (75%) rename {dev/tools/performance-toolkit/framework/tests/unit/testsuite/Magento/ToolkitFramework/ImportExport/Fixture => setup/src/Magento/Setup/Test/Unit/Model}/Complex/PatternTest.php (88%) rename {dev/tools/performance-toolkit/framework/tests/unit/testsuite/Magento/ToolkitFramework/ImportExport/Fixture => setup/src/Magento/Setup/Test/Unit/Model}/GeneratorTest.php (84%) diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php index 5a4ac04f025..669cebf2dc5 100755 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php @@ -3530,4 +3530,18 @@ return [ ['Magento\Tools\SampleData\Module\Wishlist\Setup\Wishlist', 'Magento\SampleData\Module\Wishlist\Setup\Wishlist'], ['Magento\Tools\SampleData\Module\Wishlist\Setup', 'Magento\SampleData\Module\Wishlist\Setup'], ['Magento\Tools\SampleData\InstallerApp'], + [ + 'Magento\ToolkitFramework\ImportExport\Fixture\Complex\Generator', + 'Magento\Setup\Model\Complex\Generator' + ], + [ + 'Magento\ToolkitFramework\ImportExport\Fixture\Complex\Pattern', + 'Magento\Setup\Model\Complex\Pattern' + ], + [ + 'Magento\ToolkitFramework\ImportExport\Fixture\Generator', + 'Magento\Setup\Model\Generator' + ], + ['Magento\ToolkitFramework\Helper\Cli'], + ['Magento\ToolkitFramework\Config'], ]; diff --git a/dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/Config.php b/dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/Config.php deleted file mode 100644 index 0572b043a8c..00000000000 --- a/dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/Config.php +++ /dev/null @@ -1,60 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -namespace Magento\ToolkitFramework; - -class Config -{ - /** - * Configuration array - * - * @var array - */ - protected $_config = []; - - /** - * Get config instance - * - * @return \Magento\ToolkitFramework\Config - */ - public static function getInstance() - { - static $instance; - if (!$instance instanceof static) { - $instance = new static(); - } - return $instance; - } - - /** - * Load config from file - * - * @param string $filename - * @throws \Exception - * - * @return void - */ - public function loadConfig($filename) - { - if (!is_readable($filename)) { - throw new \Exception("Profile configuration file `{$filename}` is not readable or does not exists."); - } - $this->_config = (new \Magento\Framework\Xml\Parser())->load($filename)->xmlToArray(); - } - - /** - * Get profile configuration value - * - * @param string $key - * @param null|mixed $default - * - * @return mixed - */ - public function getValue($key, $default = null) - { - return isset($this->_config['config']['profile'][$key]) ? $this->_config['config']['profile'][$key] : $default; - } -} diff --git a/dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/Helper/Cli.php b/dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/Helper/Cli.php deleted file mode 100644 index 0ef33d75c16..00000000000 --- a/dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/Helper/Cli.php +++ /dev/null @@ -1,53 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -namespace Magento\ToolkitFramework\Helper; - -/** - * Class Cli static helper - * - */ -class Cli -{ - /** - * Getopt object - * - * @var \Zend_Console_Getopt - */ - protected static $_getopt; - - /** - * Set GetOpt object - * - * @param \Zend_Console_Getopt $getopt - * - * @return void - */ - public static function setOpt(\Zend_Console_Getopt $getopt) - { - static::$_getopt = $getopt; - } - - /** - * Get option value - * - * @param string $key - * @param mixed $default - * - * @return mixed|null - */ - public static function getOption($key, $default = null) - { - if (!static::$_getopt instanceof \Zend_Console_Getopt) { - return $default; - } - $value = static::$_getopt->getOption($key); - if ($value === null) { - return $default; - } - return $value; - } -} diff --git a/dev/tools/performance-toolkit/framework/bootstrap.php b/dev/tools/performance-toolkit/framework/bootstrap.php deleted file mode 100644 index 1fd4767308a..00000000000 --- a/dev/tools/performance-toolkit/framework/bootstrap.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php -/** - * Toolkit framework bootstrap script - * - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -$magentoBaseDir = realpath(__DIR__ . '/../../../../'); - -require_once "$magentoBaseDir/app/bootstrap.php"; -return $magentoBaseDir; diff --git a/dev/tools/performance-toolkit/framework/tests/unit/framework/bootstrap.php b/dev/tools/performance-toolkit/framework/tests/unit/framework/bootstrap.php deleted file mode 100644 index be6dd10e823..00000000000 --- a/dev/tools/performance-toolkit/framework/tests/unit/framework/bootstrap.php +++ /dev/null @@ -1,8 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -$magentoBaseDir = realpath(__DIR__ . '/../../../../../../../'); -require_once "$magentoBaseDir/app/bootstrap.php"; diff --git a/dev/tools/performance-toolkit/framework/tests/unit/phpunit.xml.dist b/dev/tools/performance-toolkit/framework/tests/unit/phpunit.xml.dist deleted file mode 100644 index 7652ddf0556..00000000000 --- a/dev/tools/performance-toolkit/framework/tests/unit/phpunit.xml.dist +++ /dev/null @@ -1,21 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ ---> -<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd" - colors="true" - bootstrap="./framework/bootstrap.php" -> - <testsuites> - <testsuite name="Unit Tests for Preformance Toolkit Framework"> - <directory suffix="Test.php">testsuite</directory> - </testsuite> - </testsuites> - <php> - <ini name="date.timezone" value="America/Los_Angeles"/> - </php> -</phpunit> diff --git a/dev/tools/performance-toolkit/framework/tests/unit/testsuite/Magento/ToolkitFramework/ConfigTest.php b/dev/tools/performance-toolkit/framework/tests/unit/testsuite/Magento/ToolkitFramework/ConfigTest.php deleted file mode 100644 index a474456aefb..00000000000 --- a/dev/tools/performance-toolkit/framework/tests/unit/testsuite/Magento/ToolkitFramework/ConfigTest.php +++ /dev/null @@ -1,18 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\ToolkitFramework; - -class ConfigTest extends \PHPUnit_Framework_TestCase -{ - /** - * @return void - */ - public function testUnaccessibleConfig() - { - $this->setExpectedException('Exception', 'Profile configuration file `))` is not readable or does not exists.'); - \Magento\ToolkitFramework\Config::getInstance()->loadConfig('))'); - } -} diff --git a/dev/tools/performance-toolkit/framework/tests/unit/testsuite/Magento/ToolkitFramework/Helper/CliTest.php b/dev/tools/performance-toolkit/framework/tests/unit/testsuite/Magento/ToolkitFramework/Helper/CliTest.php deleted file mode 100644 index 4db21a63017..00000000000 --- a/dev/tools/performance-toolkit/framework/tests/unit/testsuite/Magento/ToolkitFramework/Helper/CliTest.php +++ /dev/null @@ -1,83 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -namespace Magento\ToolkitFramework\Helper; - -/** - * Class CliTest - * - */ -class CliTest extends \PHPUnit_Framework_TestCase -{ - /** - * Getopt object - * - * @var \Zend_Console_Getopt - */ - protected $_getOpt; - - /** - * Param constants - */ - const TEST_OPTION_NAME = 'name'; - const TEST_OPTION_VALUE = 'test_option_value'; - - /** - * Set up before test - * - * @return void - */ - public function setUp() - { - $this->_getOpt = $this->getMock( - 'Zend_Console_Getopt', - ['getOption'], - [[]] - ); - $this->_getOpt->expects($this->any())->method('getOption')->will( - $this->returnValueMap( - [ - [self::TEST_OPTION_NAME, self::TEST_OPTION_VALUE], - ['xxx', null], - ] - ) - ); - - \Magento\ToolkitFramework\Helper\Cli::setOpt($this->_getOpt); - } - - /** - * Tear down after test - * - * @return void - */ - public function tearDown() - { - $this->_getOpt = null; - $this->_object = null; - } - - /** - * Test CLI helper - * - * @return void - */ - public function testCli() - { - $this->assertEquals( - self::TEST_OPTION_VALUE, - \Magento\ToolkitFramework\Helper\Cli::getOption(self::TEST_OPTION_NAME) - ); - $this->assertEquals( - null, - \Magento\ToolkitFramework\Helper\Cli::getOption('xxx') - ); - $this->assertEquals( - 'default', - \Magento\ToolkitFramework\Helper\Cli::getOption('xxx', 'default') - ); - } -} diff --git a/dev/tools/performance-toolkit/framework/tests/unit/testsuite/Magento/ToolkitFramework/_files/application_test/fixture1.php b/dev/tools/performance-toolkit/framework/tests/unit/testsuite/Magento/ToolkitFramework/_files/application_test/fixture1.php deleted file mode 100644 index 5d49951b678..00000000000 --- a/dev/tools/performance-toolkit/framework/tests/unit/testsuite/Magento/ToolkitFramework/_files/application_test/fixture1.php +++ /dev/null @@ -1,7 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -$this->applied[] = 'fixture1'; diff --git a/dev/tools/performance-toolkit/framework/tests/unit/testsuite/Magento/ToolkitFramework/_files/application_test/fixture2.php b/dev/tools/performance-toolkit/framework/tests/unit/testsuite/Magento/ToolkitFramework/_files/application_test/fixture2.php deleted file mode 100644 index bc915c0a490..00000000000 --- a/dev/tools/performance-toolkit/framework/tests/unit/testsuite/Magento/ToolkitFramework/_files/application_test/fixture2.php +++ /dev/null @@ -1,7 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -$this->applied[] = 'fixture2'; diff --git a/dev/tools/performance-toolkit/generate.php b/dev/tools/performance-toolkit/generate.php deleted file mode 100644 index 861abee07ef..00000000000 --- a/dev/tools/performance-toolkit/generate.php +++ /dev/null @@ -1,82 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -$applicationBaseDir = require_once __DIR__ . '/framework/bootstrap.php'; - -try { - $totalStartTime = microtime(true); - - $shell = new Zend_Console_Getopt( - [ - 'profile-s' => 'Profile configuration file', - ] - ); - - \Magento\ToolkitFramework\Helper\Cli::setOpt($shell); - - $args = $shell->getOptions(); - if (empty($args)) { - echo $shell->getUsageMessage(); - exit(0); - } - - $logWriter = new \Zend_Log_Writer_Stream('php://output'); - $logWriter->setFormatter(new \Zend_Log_Formatter_Simple('%message%' . PHP_EOL)); - $logger = new \Zend_Log($logWriter); - - $shell = new \Magento\Framework\Shell(new \Magento\Framework\Shell\CommandRenderer(), $logger); - - $application = new \Magento\ToolkitFramework\Application($applicationBaseDir, $shell, []); - $application->bootstrap(); - $application->loadFixtures(); - - $config = \Magento\ToolkitFramework\Config::getInstance(); - $config->loadConfig(\Magento\ToolkitFramework\Helper\Cli::getOption('profile')); - - echo 'Generating profile with following params:' . PHP_EOL; - foreach ($application->getParamLabels() as $configKey => $label) { - echo ' |- ' . $label . ': ' . $config->getValue($configKey) . PHP_EOL; - } - - /** @var $config \Magento\Indexer\Model\Config */ - $config = $application->getObjectManager()->get('Magento\Indexer\Model\Config'); - $indexerListIds = $config->getIndexers(); - /** @var $indexerRegistry \Magento\Indexer\Model\IndexerRegistry */ - $indexerRegistry = $application->getObjectManager()->create('Magento\Indexer\Model\IndexerRegistry'); - $indexersState = []; - foreach ($indexerListIds as $key => $indexerId) { - $indexer = $indexerRegistry->get($indexerId['indexer_id']); - $indexersState[$indexerId['indexer_id']] = $indexer->isScheduled(); - $indexer->setScheduled(true); - } - - foreach ($application->getFixtures() as $fixture) { - echo $fixture->getActionTitle() . '... '; - $startTime = microtime(true); - $fixture->execute(); - $endTime = microtime(true); - $resultTime = $endTime - $startTime; - echo ' done in ' . gmdate('H:i:s', $resultTime) . PHP_EOL; - } - - foreach ($indexerListIds as $indexerId) { - /** @var $indexer \Magento\Indexer\Model\Indexer */ - $indexer = $indexerRegistry->get($indexerId['indexer_id']); - $indexer->setScheduled($indexersState[$indexerId['indexer_id']]); - } - - $application->reindex(); - $totalEndTime = microtime(true); - $totalResultTime = $totalEndTime - $totalStartTime; - - echo 'Total execution time: ' . gmdate('H:i:s', $totalResultTime) . PHP_EOL; -} catch (\Zend_Console_Getopt_Exception $e) { - fwrite(STDERR, $e->getMessage() . "\n\n" . $e->getUsageMessage() . "\n"); - exit(1); -} catch (\Exception $e) { - fwrite(STDERR, $e->getMessage() . "\n"); - exit(1); -} diff --git a/dev/tools/performance-toolkit/README.txt b/setup/performance-toolkit/README.txt similarity index 98% rename from dev/tools/performance-toolkit/README.txt rename to setup/performance-toolkit/README.txt index 24e2a3cafd0..fda8a78c11c 100644 --- a/dev/tools/performance-toolkit/README.txt +++ b/setup/performance-toolkit/README.txt @@ -15,7 +15,7 @@ Plugins (only if you want to use additional reports (like graphs)): Usage ----------- -Before running the jMeter tests for the first time, you will need to first use generate.php to generate the test data. +Before running the jMeter tests for the first time, you will need to first use bin/magento setup:perf:generate-fixtures command to generate the test data. 1. Run via console Scenario can accept parameters that are described bellow in format <parameter_name:default_value>: diff --git a/dev/tools/performance-toolkit/benchmark.jmx b/setup/performance-toolkit/benchmark.jmx similarity index 100% rename from dev/tools/performance-toolkit/benchmark.jmx rename to setup/performance-toolkit/benchmark.jmx diff --git a/dev/tools/performance-toolkit/profiles/ce/extra_large.xml b/setup/performance-toolkit/profiles/ce/extra_large.xml similarity index 100% rename from dev/tools/performance-toolkit/profiles/ce/extra_large.xml rename to setup/performance-toolkit/profiles/ce/extra_large.xml diff --git a/dev/tools/performance-toolkit/profiles/ce/large.xml b/setup/performance-toolkit/profiles/ce/large.xml similarity index 100% rename from dev/tools/performance-toolkit/profiles/ce/large.xml rename to setup/performance-toolkit/profiles/ce/large.xml diff --git a/dev/tools/performance-toolkit/profiles/ce/medium.xml b/setup/performance-toolkit/profiles/ce/medium.xml similarity index 100% rename from dev/tools/performance-toolkit/profiles/ce/medium.xml rename to setup/performance-toolkit/profiles/ce/medium.xml diff --git a/dev/tools/performance-toolkit/profiles/ce/small.xml b/setup/performance-toolkit/profiles/ce/small.xml similarity index 100% rename from dev/tools/performance-toolkit/profiles/ce/small.xml rename to setup/performance-toolkit/profiles/ce/small.xml diff --git a/setup/src/Magento/Setup/Console/Command/GenerateFixturesCommand.php b/setup/src/Magento/Setup/Console/Command/GenerateFixturesCommand.php index d6277e9fef3..3f20ef0693b 100644 --- a/setup/src/Magento/Setup/Console/Command/GenerateFixturesCommand.php +++ b/setup/src/Magento/Setup/Console/Command/GenerateFixturesCommand.php @@ -10,10 +10,11 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Magento\ToolkitFramework\Config; -use Magento\ToolkitFramework\Application; - +use Magento\Setup\Fixtures\FixtureModel; +/** + * Command generates fixtures for performance tests + */ class GenerateFixturesCommand extends Command { /** @@ -32,12 +33,10 @@ class GenerateFixturesCommand extends Command private $config; /** - * @param Application $application - * @param Config $config + * @param FixtureModel $application */ - public function __construct(Application $application, Config $config) + public function __construct(FixtureModel $application) { - $this->config = $config; $this->application = $application; parent::__construct(); } @@ -69,7 +68,7 @@ class GenerateFixturesCommand extends Command $application = $this->application; - $application->bootstrap(); + $application->initObjectManager(); $application->loadFixtures(); $application->loadConfig($input->getArgument(self::PROFILE_ARGUMENT)); @@ -92,12 +91,12 @@ class GenerateFixturesCommand extends Command } foreach ($application->getFixtures() as $fixture) { - echo $fixture->getActionTitle() . '... '; + $output->write($fixture->getActionTitle() . '... '); $startTime = microtime(true); $fixture->execute(); $endTime = microtime(true); $resultTime = $endTime - $startTime; - echo ' done in ' . gmdate('H:i:s', $resultTime) . PHP_EOL; + $output->writeln(' done in ' . gmdate('H:i:s', $resultTime)); } foreach ($indexerListIds as $indexerId) { diff --git a/dev/tools/performance-toolkit/fixtures/cart_price_rules.php b/setup/src/Magento/Setup/Fixtures/CartPriceRulesFixture.php similarity index 91% rename from dev/tools/performance-toolkit/fixtures/cart_price_rules.php rename to setup/src/Magento/Setup/Fixtures/CartPriceRulesFixture.php index 03f39bac448..b5d18c63d12 100644 --- a/dev/tools/performance-toolkit/fixtures/cart_price_rules.php +++ b/setup/src/Magento/Setup/Fixtures/CartPriceRulesFixture.php @@ -4,10 +4,12 @@ * See COPYING.txt for license details. */ +namespace Magento\Setup\Fixtures; + /** * Class CartPriceRulesFixture */ -class CartPriceRulesFixture extends \Magento\ToolkitFramework\Fixture +class CartPriceRulesFixture extends Fixture { /** * @var int @@ -19,16 +21,16 @@ class CartPriceRulesFixture extends \Magento\ToolkitFramework\Fixture */ public function execute() { - $this->application->resetObjectManager(); - $cartPriceRulesCount = $this->application->getValue('cart_price_rules', 9); - $cartPriceRulesProductsFloor = $this->application->getValue('cart_price_rules_floor', 3); + $this->fixtureModel->resetObjectManager(); + $cartPriceRulesCount = $this->fixtureModel->getValue('cart_price_rules', 9); + $cartPriceRulesProductsFloor = $this->fixtureModel->getValue('cart_price_rules_floor', 3); /** @var \Magento\Store\Model\StoreManager $storeManager */ - $storeManager = $this->application->getObjectManager()->create('Magento\Store\Model\StoreManager'); + $storeManager = $this->fixtureModel->getObjectManager()->create('Magento\Store\Model\StoreManager'); /** @var $category \Magento\Catalog\Model\Category */ - $category = $this->application->getObjectManager()->get('Magento\Catalog\Model\Category'); + $category = $this->fixtureModel->getObjectManager()->get('Magento\Catalog\Model\Category'); /** @var $model \Magento\SalesRule\Model\Rule*/ - $model = $this->application->getObjectManager()->get('Magento\SalesRule\Model\Rule'); + $model = $this->fixtureModel->getObjectManager()->get('Magento\SalesRule\Model\Rule'); //Get all websites $categoriesArray = []; @@ -186,5 +188,3 @@ class CartPriceRulesFixture extends \Magento\ToolkitFramework\Fixture ]; } } - -return new CartPriceRulesFixture($this); diff --git a/dev/tools/performance-toolkit/fixtures/catalog_price_rules.php b/setup/src/Magento/Setup/Fixtures/CatalogPriceRulesFixture.php similarity index 90% rename from dev/tools/performance-toolkit/fixtures/catalog_price_rules.php rename to setup/src/Magento/Setup/Fixtures/CatalogPriceRulesFixture.php index d6f9bc849be..4a33e4a3cde 100644 --- a/dev/tools/performance-toolkit/fixtures/catalog_price_rules.php +++ b/setup/src/Magento/Setup/Fixtures/CatalogPriceRulesFixture.php @@ -4,10 +4,12 @@ * See COPYING.txt for license details. */ +namespace Magento\Setup\Fixtures; + /** * Class CatalogPriceRulesFixture */ -class CatalogPriceRulesFixture extends \Magento\ToolkitFramework\Fixture +class CatalogPriceRulesFixture extends Fixture { /** * @var int @@ -19,15 +21,15 @@ class CatalogPriceRulesFixture extends \Magento\ToolkitFramework\Fixture */ public function execute() { - $catalogPriceRulesCount = $this->application->getValue('catalog_price_rules', 3); - $this->application->resetObjectManager(); + $catalogPriceRulesCount = $this->fixtureModel->getValue('catalog_price_rules', 3); + $this->fixtureModel->resetObjectManager(); /** @var \Magento\Store\Model\StoreManager $storeManager */ - $storeManager = $this->application->getObjectManager()->create('Magento\Store\Model\StoreManager'); + $storeManager = $this->fixtureModel->getObjectManager()->create('Magento\Store\Model\StoreManager'); /** @var $category \Magento\Catalog\Model\Category */ - $category = $this->application->getObjectManager()->get('Magento\Catalog\Model\Category'); + $category = $this->fixtureModel->getObjectManager()->get('Magento\Catalog\Model\Category'); /** @var $model \Magento\CatalogRule\Model\Rule*/ - $model = $this->application->getObjectManager()->get('Magento\CatalogRule\Model\Rule'); + $model = $this->fixtureModel->getObjectManager()->get('Magento\CatalogRule\Model\Rule'); //Get all websites $categoriesArray = []; $websites = $storeManager->getWebsites(); @@ -143,5 +145,3 @@ class CatalogPriceRulesFixture extends \Magento\ToolkitFramework\Fixture ]; } } - -return new CatalogPriceRulesFixture($this); diff --git a/dev/tools/performance-toolkit/fixtures/categories.php b/setup/src/Magento/Setup/Fixtures/CategoriesFixture.php similarity index 82% rename from dev/tools/performance-toolkit/fixtures/categories.php rename to setup/src/Magento/Setup/Fixtures/CategoriesFixture.php index 7e2222385d2..9cbba51d1be 100644 --- a/dev/tools/performance-toolkit/fixtures/categories.php +++ b/setup/src/Magento/Setup/Fixtures/CategoriesFixture.php @@ -4,10 +4,12 @@ * See COPYING.txt for license details. */ +namespace Magento\Setup\Fixtures; + /** * Class CategoriesFixture */ -class CategoriesFixture extends \Magento\ToolkitFramework\Fixture +class CategoriesFixture extends Fixture { /** * @var int @@ -19,14 +21,14 @@ class CategoriesFixture extends \Magento\ToolkitFramework\Fixture */ public function execute() { - $categoriesNumber = $this->application->getValue('categories', 18); - $maxNestingLevel = $this->application->getValue('categories_nesting_level', 3); - $this->application->resetObjectManager(); + $categoriesNumber = $this->fixtureModel->getValue('categories', 18); + $maxNestingLevel = $this->fixtureModel->getValue('categories_nesting_level', 3); + $this->fixtureModel->resetObjectManager(); /** @var \Magento\Store\Model\StoreManager $storeManager */ - $storeManager = $this->application->getObjectManager()->create('Magento\Store\Model\StoreManager'); + $storeManager = $this->fixtureModel->getObjectManager()->create('Magento\Store\Model\StoreManager'); /** @var $category \Magento\Catalog\Model\Category */ - $category = $this->application->getObjectManager()->create('Magento\Catalog\Model\Category'); + $category = $this->fixtureModel->getObjectManager()->create('Magento\Catalog\Model\Category'); $groups = []; $storeGroups = $storeManager->getGroups(); @@ -93,5 +95,3 @@ class CategoriesFixture extends \Magento\ToolkitFramework\Fixture ]; } } - -return new CategoriesFixture($this); diff --git a/dev/tools/performance-toolkit/fixtures/configs_apply.php b/setup/src/Magento/Setup/Fixtures/ConfigsApplyFixture.php similarity index 69% rename from dev/tools/performance-toolkit/fixtures/configs_apply.php rename to setup/src/Magento/Setup/Fixtures/ConfigsApplyFixture.php index a517c91a563..d69e54d3851 100644 --- a/dev/tools/performance-toolkit/fixtures/configs_apply.php +++ b/setup/src/Magento/Setup/Fixtures/ConfigsApplyFixture.php @@ -4,10 +4,12 @@ * See COPYING.txt for license details. */ +namespace Magento\Setup\Fixtures; + /** * Class ConfigsApplyFixture */ -class ConfigsApplyFixture extends \Magento\ToolkitFramework\Fixture +class ConfigsApplyFixture extends Fixture { /** * @var int @@ -19,21 +21,21 @@ class ConfigsApplyFixture extends \Magento\ToolkitFramework\Fixture */ public function execute() { - $configs = $this->application->getValue('configs', array()); - $this->application->resetObjectManager(); + $configs = $this->fixtureModel->getValue('configs', array()); + $this->fixtureModel->resetObjectManager(); foreach ($configs['config'] as $config) { /** * @var \Magento\Framework\App\Config\Value $configData */ - $configData = $this->application->getObjectManager()->create('Magento\Framework\App\Config\Value'); + $configData = $this->fixtureModel->getObjectManager()->create('Magento\Framework\App\Config\Value'); $configData->setPath($config['path']) ->setScope($config['scope']) ->setScopeId($config['scopeId']) ->setValue($config['value']) ->save(); } - $this->application->getObjectManager()->get('Magento\Framework\App\CacheInterface') + $this->fixtureModel->getObjectManager()->get('Magento\Framework\App\CacheInterface') ->clean([\Magento\Framework\App\Config::CACHE_TAG]); } @@ -53,5 +55,3 @@ class ConfigsApplyFixture extends \Magento\ToolkitFramework\Fixture return []; } } - -return new ConfigsApplyFixture($this); diff --git a/dev/tools/performance-toolkit/fixtures/configurable_products.php b/setup/src/Magento/Setup/Fixtures/ConfigurableProductsFixture.php similarity index 98% rename from dev/tools/performance-toolkit/fixtures/configurable_products.php rename to setup/src/Magento/Setup/Fixtures/ConfigurableProductsFixture.php index 7005c04b122..73af579e0fc 100644 --- a/dev/tools/performance-toolkit/fixtures/configurable_products.php +++ b/setup/src/Magento/Setup/Fixtures/ConfigurableProductsFixture.php @@ -4,10 +4,15 @@ * See COPYING.txt for license details. */ +namespace Magento\Setup\Fixtures; + +use Magento\Setup\Model\Complex\Pattern; +use Magento\Setup\Model\Complex\Generator; + /** * Class ConfigurableProductsFixture */ -class ConfigurableProductsFixture extends \Magento\ToolkitFramework\Fixture +class ConfigurableProductsFixture extends Fixture { /** * @var int @@ -820,13 +825,13 @@ class ConfigurableProductsFixture extends \Magento\ToolkitFramework\Fixture */ public function execute() { - $configurablesCount = $this->application->getValue('configurable_products', 90); - $this->application->resetObjectManager(); + $configurablesCount = $this->fixtureModel->getValue('configurable_products', 90); + $this->fixtureModel->resetObjectManager(); /** @var \Magento\Store\Model\StoreManager $storeManager */ - $storeManager = $this->application->getObjectManager()->create('Magento\Store\Model\StoreManager'); + $storeManager = $this->fixtureModel->getObjectManager()->create('Magento\Store\Model\StoreManager'); /** @var $category \Magento\Catalog\Model\Category */ - $category = $this->application->getObjectManager()->get('Magento\Catalog\Model\Category'); + $category = $this->fixtureModel->getObjectManager()->get('Magento\Catalog\Model\Category'); $result = []; //Get all websites @@ -878,17 +883,17 @@ class ConfigurableProductsFixture extends \Magento\ToolkitFramework\Fixture /** * Create configurable products */ - $pattern = new \Magento\ToolkitFramework\ImportExport\Fixture\Complex\Pattern(); + $pattern = new Pattern(); $pattern->setHeaders($this->getHeaders()); $pattern->setRowsSet($this->getRows($productCategory, $productRootCategory, $productWebsite)); /** @var \Magento\ImportExport\Model\Import $import */ - $import = $this->application->getObjectManager()->create( + $import = $this->fixtureModel->getObjectManager()->create( 'Magento\ImportExport\Model\Import', ['data' => ['entity' => 'catalog_product', 'behavior' => 'replace']] ); - $source = new \Magento\ToolkitFramework\ImportExport\Fixture\Complex\Generator($pattern, $configurablesCount); + $source = new Generator($pattern, $configurablesCount); // it is not obvious, but the validateSource() will actually save import queue data to DB $import->validateSource($source); // this converts import queue into actual entities @@ -914,5 +919,3 @@ class ConfigurableProductsFixture extends \Magento\ToolkitFramework\Fixture ]; } } - -return new ConfigurableProductsFixture($this); diff --git a/dev/tools/performance-toolkit/fixtures/customers.php b/setup/src/Magento/Setup/Fixtures/CustomersFixture.php similarity index 86% rename from dev/tools/performance-toolkit/fixtures/customers.php rename to setup/src/Magento/Setup/Fixtures/CustomersFixture.php index 2ad72b2a70c..e1f7c7e7cf0 100644 --- a/dev/tools/performance-toolkit/fixtures/customers.php +++ b/setup/src/Magento/Setup/Fixtures/CustomersFixture.php @@ -4,10 +4,14 @@ * See COPYING.txt for license details. */ +namespace Magento\Setup\Fixtures; + +use Magento\Setup\Model\Generator; + /** * Class CustomersFixture */ -class CustomersFixture extends \Magento\ToolkitFramework\Fixture +class CustomersFixture extends Fixture { /** * @var int @@ -19,13 +23,13 @@ class CustomersFixture extends \Magento\ToolkitFramework\Fixture */ public function execute() { - $customersNumber = $this->application->getValue('customers', 10); - $this->application->resetObjectManager(); + $customersNumber = $this->fixtureModel->getValue('customers', 10); + $this->fixtureModel->resetObjectManager(); /** @var \Magento\Store\Model\StoreManager $storeManager */ - $storeManager = $this->application->getObjectManager()->create('Magento\Store\Model\StoreManager'); + $storeManager = $this->fixtureModel->getObjectManager()->create('Magento\Store\Model\StoreManager'); /** @var $category \Magento\Catalog\Model\Category */ - $category = $this->application->getObjectManager()->get('Magento\Catalog\Model\Category'); + $category = $this->fixtureModel->getObjectManager()->get('Magento\Catalog\Model\Category'); /** @var $defaultStoreView \Magento\Store\Model\Store */ $defaultStoreView = $storeManager->getDefaultStoreView(); $defaultStoreViewId = $defaultStoreView->getStoreId(); @@ -85,9 +89,9 @@ class CustomersFixture extends \Magento\ToolkitFramework\Fixture '_address_default_billing_' => '1', '_address_default_shipping_' => '1', ]; - $generator = new \Magento\ToolkitFramework\ImportExport\Fixture\Generator($pattern, $customersNumber); + $generator = new Generator($pattern, $customersNumber); /** @var Magento\ImportExport\Model\Import $import */ - $import = $this->application->getObjectManager()->create( + $import = $this->fixtureModel->getObjectManager()->create( 'Magento\ImportExport\Model\Import', ['data' => ['entity' => 'customer_composite', 'behavior' => 'append']] ); @@ -115,5 +119,3 @@ class CustomersFixture extends \Magento\ToolkitFramework\Fixture ]; } } - -return new CustomersFixture($this); diff --git a/dev/tools/performance-toolkit/fixtures/eav_variations.php b/setup/src/Magento/Setup/Fixtures/EavVariationsFixture.php similarity index 80% rename from dev/tools/performance-toolkit/fixtures/eav_variations.php rename to setup/src/Magento/Setup/Fixtures/EavVariationsFixture.php index 2d2fbc89517..b06da8f8612 100644 --- a/dev/tools/performance-toolkit/fixtures/eav_variations.php +++ b/setup/src/Magento/Setup/Fixtures/EavVariationsFixture.php @@ -4,31 +4,33 @@ * See COPYING.txt for license details. */ -define('ATTRIBUTE_SET_ID', 4); +namespace Magento\Setup\Fixtures; /** * Class EavVariationsFixture */ -class EavVariationsFixture extends \Magento\ToolkitFramework\Fixture +class EavVariationsFixture extends Fixture { /** * @var int */ protected $priority = 40; + const ATTRIBUTE_SET_ID = 4; + /** * {@inheritdoc} */ public function execute() { - $this->application->resetObjectManager(); + $this->fixtureModel->resetObjectManager(); /* @var $model \Magento\Catalog\Model\Resource\Eav\Attribute */ - $model = $this->application->getObjectManager()->create('Magento\Catalog\Model\Resource\Eav\Attribute'); + $model = $this->fixtureModel->getObjectManager()->create('Magento\Catalog\Model\Resource\Eav\Attribute'); /* @var $helper \Magento\Catalog\Helper\Product */ - $helper = $this->application->getObjectManager()->get('Magento\Catalog\Helper\Product'); + $helper = $this->fixtureModel->getObjectManager()->get('Magento\Catalog\Helper\Product'); /** @var \Magento\Store\Model\StoreManager $storeManager */ - $storeManager = $this->application->getObjectManager()->create('Magento\Store\Model\StoreManager'); + $storeManager = $this->fixtureModel->getObjectManager()->create('Magento\Store\Model\StoreManager'); $stores = $storeManager->getStores(); $storeViewsCount = count($stores); @@ -85,17 +87,17 @@ class EavVariationsFixture extends \Magento\ToolkitFramework\Fixture * See MAGETWO-16492 */ $model->addData($data); - $attributeSet = $this->application->getObjectManager()->get('Magento\Eav\Model\Entity\Attribute\Set'); - $attributeSet->load(ATTRIBUTE_SET_ID); - $model->setAttributeSetId(ATTRIBUTE_SET_ID) + $attributeSet = $this->fixtureModel->getObjectManager()->get('Magento\Eav\Model\Entity\Attribute\Set'); + $attributeSet->load(self::ATTRIBUTE_SET_ID); + $model->setAttributeSetId(self::ATTRIBUTE_SET_ID) ->setAttributeGroupId($attributeSet->getDefaultGroupId(4)) ->save(); - $model->setAttributeSetId(ATTRIBUTE_SET_ID); + $model->setAttributeSetId(self::ATTRIBUTE_SET_ID); $model->save(); /* @var $cache \Magento\Framework\App\CacheInterface */ - $cache = $this->application->getObjectManager()->get('Magento\Framework\App\CacheInterface'); + $cache = $this->fixtureModel->getObjectManager()->get('Magento\Framework\App\CacheInterface'); $cacheKey = \Magento\Eav\Model\Config::ATTRIBUTES_CACHE_ID . \Magento\Catalog\Model\Product::ENTITY; $cache->remove($cacheKey); @@ -117,5 +119,3 @@ class EavVariationsFixture extends \Magento\ToolkitFramework\Fixture return []; } } - -return new EavVariationsFixture($this); diff --git a/dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/Fixture.php b/setup/src/Magento/Setup/Fixtures/Fixture.php similarity index 76% rename from dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/Fixture.php rename to setup/src/Magento/Setup/Fixtures/Fixture.php index 9a6a1a7e3d4..ba5c3fe0af9 100644 --- a/dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/Fixture.php +++ b/setup/src/Magento/Setup/Fixtures/Fixture.php @@ -4,7 +4,7 @@ * See COPYING.txt for license details. */ -namespace Magento\ToolkitFramework; +namespace Magento\Setup\Fixtures; /** * Class Fixture @@ -18,16 +18,16 @@ abstract class Fixture protected $priority; /** - * @var Application + * @var FixtureModel */ - protected $application; + protected $fixtureModel; /** - * @param Application $application + * @param FixtureModel $fixtureModel */ - public function __construct(\Magento\ToolkitFramework\Application $application) + public function __construct(FixtureModel $fixtureModel) { - $this->application = $application; + $this->fixtureModel = $fixtureModel; } /** diff --git a/dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/Application.php b/setup/src/Magento/Setup/Fixtures/FixtureModel.php similarity index 57% rename from dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/Application.php rename to setup/src/Magento/Setup/Fixtures/FixtureModel.php index 892850a7137..8f508565d11 100644 --- a/dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/Application.php +++ b/setup/src/Magento/Setup/Fixtures/FixtureModel.php @@ -5,64 +5,58 @@ */ /** - * Magento application for performance tests + * Magento model for performance tests */ -namespace Magento\ToolkitFramework; +namespace Magento\Setup\Fixtures; -use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Indexer\Console\Command\IndexerReindexCommand; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\OutputInterface; +use Magento\Framework\Xml\Parser; -class Application +class FixtureModel { /** * Area code */ const AREA_CODE = 'adminhtml'; - /** - * Fixtures directory - */ - const FIXTURES_DIR = '/../../../fixtures'; - /** * Fixtures file name pattern */ - const FIXTURE_PATTERN = '*.php'; + const FIXTURE_PATTERN = '?*Fixture.php'; /** * Application object * * @var \Magento\Framework\AppInterface */ - protected $_application; + protected $application; /** * @var \Magento\Framework\ObjectManagerInterface */ - protected $_objectManager; + protected $objectManager; /** * List of fixtures applied to the application * * @var \Magento\ToolkitFramework\Fixture[] */ - protected $_fixtures = []; + protected $fixtures = []; /** * Parameters labels * * @var array */ - protected $_paramLabels = []; + protected $paramLabels = []; /** * @var array */ - protected $_initArguments; + protected $initArguments; /** * Configuration array @@ -72,54 +66,31 @@ class Application protected $config = []; /** - * Constructor - * - */ - public function __construct(IndexerReindexCommand $reindexCommand, $initArguments = []) - { - $this->_initArguments = $initArguments; - $this->reindexCommand = $reindexCommand; - } - - /** - * Update permissions for `var` directory + * XML file parser * - * @return void + * @var Parser */ - protected function _updateFilesystemPermissions() - { - /** @var \Magento\Framework\Filesystem\Directory\Write $varDirectory */ - $varDirectory = $this->getObjectManager()->get('Magento\Framework\Filesystem') - ->getDirectoryWrite(DirectoryList::VAR_DIR); - $varDirectory->changePermissions('', 0777); - } + protected $fileParser; /** - * Bootstrap application, so it is possible to use its resources - * - * @return \Magento\ToolkitFramework\Application - */ - protected function _bootstrap() - { - $this->getObjectManager()->configure( - $this->getObjectManager()->get('Magento\Framework\App\ObjectManager\ConfigLoader')->load(self::AREA_CODE) - ); - $this->getObjectManager()->get('Magento\Framework\Config\ScopeInterface')->setCurrentScope(self::AREA_CODE); - return $this; - } - - /** - * Bootstrap + * Constructor * - * @return Application + * @param IndexerReindexCommand $reindexCommand + * @param Parser $fileParser + * @param array $initArguments */ - public function bootstrap() + public function __construct(IndexerReindexCommand $reindexCommand, Parser $fileParser, $initArguments = []) { - return $this->_bootstrap(); + $this->initArguments = $initArguments; + $this->reindexCommand = $reindexCommand; + $this->fileParser = $fileParser; } /** * Run reindex + * + * @param OutputInterface $output + * @return void */ public function reindex(OutputInterface $output) { @@ -135,20 +106,28 @@ class Application */ public function loadFixtures() { - if (!is_readable(__DIR__ . self::FIXTURES_DIR)) { + if (!is_readable(__DIR__)) { throw new \Exception( - 'Fixtures set directory `' . __DIR__ . self::FIXTURES_DIR . '` is not readable or does not exists.' + 'Fixtures set directory `' . __DIR__ . '` is not readable or does not exists.' ); } - $files = glob(__DIR__ . self::FIXTURES_DIR . DIRECTORY_SEPARATOR . self::FIXTURE_PATTERN); + $files = glob(__DIR__ . DIRECTORY_SEPARATOR . self::FIXTURE_PATTERN); + foreach ($files as $file) { - /** @var \Magento\ToolkitFramework\Fixture $fixture */ - $fixture = require realpath($file); - $this->_fixtures[$fixture->getPriority()] = $fixture; + $file = basename($file, '.php'); + /** @var \Magento\Setup\Fixtures\Fixture $fixture */ + $fixture = $this->objectManager->create( + 'Magento\Setup\Fixtures' . '\\' . $file, + [ + 'fixtureModel' => $this + ] + ); + $this->fixtures[$fixture->getPriority()] = $fixture; } - ksort($this->_fixtures); - foreach ($this->_fixtures as $fixture) { - $this->_paramLabels = array_merge($this->_paramLabels, $fixture->introduceParamLabels()); + + ksort($this->fixtures); + foreach ($this->fixtures as $fixture) { + $this->paramLabels = array_merge($this->paramLabels, $fixture->introduceParamLabels()); } return $this; } @@ -160,7 +139,7 @@ class Application */ public function getParamLabels() { - return $this->_paramLabels; + return $this->paramLabels; } /** @@ -170,7 +149,7 @@ class Application */ public function getFixtures() { - return $this->_fixtures; + return $this->fixtures; } /** @@ -180,15 +159,29 @@ class Application */ public function getObjectManager() { - if (!$this->_objectManager) { + if (!$this->objectManager) { $objectManagerFactory = \Magento\Framework\App\Bootstrap::createObjectManagerFactory( BP, - $this->_initArguments + $this->initArguments ); - $this->_objectManager = $objectManagerFactory->create($this->_initArguments); - $this->_objectManager->get('Magento\Framework\App\State')->setAreaCode(self::AREA_CODE); + $this->objectManager = $objectManagerFactory->create($this->initArguments); + $this->objectManager->get('Magento\Framework\App\State')->setAreaCode(self::AREA_CODE); } - return $this->_objectManager; + return $this->objectManager; + } + + /** + * Init Object Manager + * + * @return FixtureModel + */ + public function initObjectManager() + { + $this->getObjectManager()->configure( + $this->getObjectManager()->get('Magento\Framework\App\ObjectManager\ConfigLoader')->load(self::AREA_CODE) + ); + $this->getObjectManager()->get('Magento\Framework\Config\ScopeInterface')->setCurrentScope(self::AREA_CODE); + return $this; } /** @@ -198,8 +191,8 @@ class Application */ public function resetObjectManager() { - $this->_objectManager = null; - $this->bootstrap(); + $this->objectManager = null; + $this->initObjectManager(); return $this; } @@ -216,7 +209,7 @@ class Application if (!is_readable($filename)) { throw new \Exception("Profile configuration file `{$filename}` is not readable or does not exists."); } - $this->config = (new \Magento\Framework\Xml\Parser())->load($filename)->xmlToArray(); + $this->config = $this->fileParser->load($filename)->xmlToArray(); } /** diff --git a/dev/tools/performance-toolkit/fixtures/simple_products.php b/setup/src/Magento/Setup/Fixtures/SimpleProductsFixture.php similarity index 89% rename from dev/tools/performance-toolkit/fixtures/simple_products.php rename to setup/src/Magento/Setup/Fixtures/SimpleProductsFixture.php index a061f3d3007..ef1f3941915 100644 --- a/dev/tools/performance-toolkit/fixtures/simple_products.php +++ b/setup/src/Magento/Setup/Fixtures/SimpleProductsFixture.php @@ -4,10 +4,14 @@ * See COPYING.txt for license details. */ +namespace Magento\Setup\Fixtures; + +use Magento\Setup\Model\Generator; + /** * Class SimpleProductsFixture */ -class SimpleProductsFixture extends \Magento\ToolkitFramework\Fixture +class SimpleProductsFixture extends Fixture { /** * @var int @@ -19,13 +23,13 @@ class SimpleProductsFixture extends \Magento\ToolkitFramework\Fixture */ public function execute() { - $simpleProductsCount = $this->application->getValue('simple_products', 180); - $this->application->resetObjectManager(); + $simpleProductsCount = $this->fixtureModel->getValue('simple_products', 180); + $this->fixtureModel->resetObjectManager(); /** @var \Magento\Store\Model\StoreManager $storeManager */ - $storeManager = $this->application->getObjectManager()->create('Magento\Store\Model\StoreManager'); + $storeManager = $this->fixtureModel->getObjectManager()->create('Magento\Store\Model\StoreManager'); /** @var $category \Magento\Catalog\Model\Category */ - $category = $this->application->getObjectManager()->get('Magento\Catalog\Model\Category'); + $category = $this->fixtureModel->getObjectManager()->get('Magento\Catalog\Model\Category'); $result = []; //Get all websites @@ -70,12 +74,12 @@ class SimpleProductsFixture extends \Magento\ToolkitFramework\Fixture return $result[$index % count($result)][1]; }; - $generator = new \Magento\ToolkitFramework\ImportExport\Fixture\Generator( + $generator = new Generator( $this->getPattern($productWebsite, $productCategory), $simpleProductsCount ); /** @var \Magento\ImportExport\Model\Import $import */ - $import = $this->application->getObjectManager()->create( + $import = $this->fixtureModel->getObjectManager()->create( 'Magento\ImportExport\Model\Import', ['data' => ['entity' => 'catalog_product', 'behavior' => 'append']] ); @@ -143,5 +147,3 @@ class SimpleProductsFixture extends \Magento\ToolkitFramework\Fixture ]; } } - -return new SimpleProductsFixture($this); diff --git a/dev/tools/performance-toolkit/fixtures/stores.php b/setup/src/Magento/Setup/Fixtures/StoresFixture.php similarity index 90% rename from dev/tools/performance-toolkit/fixtures/stores.php rename to setup/src/Magento/Setup/Fixtures/StoresFixture.php index d568706aba5..0a8a6c1fa77 100644 --- a/dev/tools/performance-toolkit/fixtures/stores.php +++ b/setup/src/Magento/Setup/Fixtures/StoresFixture.php @@ -4,10 +4,12 @@ * See COPYING.txt for license details. */ +namespace Magento\Setup\Fixtures; + /** * Class StoresFixture */ -class StoresFixture extends \Magento\ToolkitFramework\Fixture +class StoresFixture extends Fixture { /** * @var int @@ -19,15 +21,15 @@ class StoresFixture extends \Magento\ToolkitFramework\Fixture */ public function execute() { - $websitesCount = $this->application->getValue('websites', 2); - $storeGroupsCount = $this->application->getValue('store_groups', 3); - $storesCount = $this->application->getValue('store_views', 5); - $this->application->resetObjectManager(); + $websitesCount = $this->fixtureModel->getValue('websites', 2); + $storeGroupsCount = $this->fixtureModel->getValue('store_groups', 3); + $storesCount = $this->fixtureModel->getValue('store_views', 5); + $this->fixtureModel->resetObjectManager(); /** @var \Magento\Store\Model\StoreManager $storeManager */ - $storeManager = $this->application->getObjectManager()->create('Magento\Store\Model\StoreManager'); + $storeManager = $this->fixtureModel->getObjectManager()->create('Magento\Store\Model\StoreManager'); /** @var $category \Magento\Catalog\Model\Category */ - $category = $this->application->getObjectManager()->create('Magento\Catalog\Model\Category'); + $category = $this->fixtureModel->getObjectManager()->create('Magento\Catalog\Model\Category'); /** @var $defaultWebsite \Magento\Store\Model\Website */ $defaultWebsite = $storeManager->getWebsite(); @@ -175,5 +177,3 @@ class StoresFixture extends \Magento\ToolkitFramework\Fixture ]; } } - -return new StoresFixture($this); diff --git a/dev/tools/performance-toolkit/fixtures/tax_rates.php b/setup/src/Magento/Setup/Fixtures/TaxRatesFixture.php similarity index 78% rename from dev/tools/performance-toolkit/fixtures/tax_rates.php rename to setup/src/Magento/Setup/Fixtures/TaxRatesFixture.php index d4a9cbbba16..9380f683369 100644 --- a/dev/tools/performance-toolkit/fixtures/tax_rates.php +++ b/setup/src/Magento/Setup/Fixtures/TaxRatesFixture.php @@ -4,10 +4,12 @@ * See COPYING.txt for license details. */ +namespace Magento\Setup\Fixtures; + /** * Class TaxRatesFixture */ -class TaxRatesFixture extends \Magento\ToolkitFramework\Fixture +class TaxRatesFixture extends Fixture { /** * @var int @@ -19,14 +21,14 @@ class TaxRatesFixture extends \Magento\ToolkitFramework\Fixture */ public function execute() { - $this->application->resetObjectManager(); + $this->fixtureModel->resetObjectManager(); /** Clean predefined tax rates to maintain consistency */ /** @var $collection Magento\Tax\Model\Resource\Calculation\Rate\Collection */ - $collection = $this->application->getObjectManager() + $collection = $this->fixtureModel->getObjectManager() ->get('Magento\Tax\Model\Resource\Calculation\Rate\Collection'); /** @var $model Magento\Tax\Model\Calculation\Rate */ - $model = $this->application->getObjectManager() + $model = $this->fixtureModel->getObjectManager() ->get('Magento\Tax\Model\Calculation\Rate'); foreach ($collection->getAllIds() as $id) { @@ -39,12 +41,12 @@ class TaxRatesFixture extends \Magento\ToolkitFramework\Fixture $filename = realpath(__DIR__ . '/tax_rates.csv'); $file = [ 'name' => $filename, - 'type' => 'application/vnd.ms-excel', + 'type' => 'fixtureModel/vnd.ms-excel', 'tmp_name' => $filename, 'error' => 0, 'size' => filesize($filename), ]; - $importHandler = $this->application->getObjectManager() + $importHandler = $this->fixtureModel->getObjectManager() ->create('Magento\TaxImportExport\Model\Rate\CsvImportHandler'); $importHandler->importFromCsvFile($file); @@ -66,5 +68,3 @@ class TaxRatesFixture extends \Magento\ToolkitFramework\Fixture return []; } } - -return new TaxRatesFixture($this); diff --git a/dev/tools/performance-toolkit/fixtures/tax_rates.csv b/setup/src/Magento/Setup/Fixtures/tax_rates.csv similarity index 100% rename from dev/tools/performance-toolkit/fixtures/tax_rates.csv rename to setup/src/Magento/Setup/Fixtures/tax_rates.csv diff --git a/dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/ImportExport/Fixture/Complex/Generator.php b/setup/src/Magento/Setup/Model/Complex/Generator.php similarity index 91% rename from dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/ImportExport/Fixture/Complex/Generator.php rename to setup/src/Magento/Setup/Model/Complex/Generator.php index 59f341057ef..d2001b2a3ff 100644 --- a/dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/ImportExport/Fixture/Complex/Generator.php +++ b/setup/src/Magento/Setup/Model/Complex/Generator.php @@ -4,19 +4,21 @@ * See COPYING.txt for license details. */ -namespace Magento\ToolkitFramework\ImportExport\Fixture\Complex; +namespace Magento\Setup\Model\Complex; + +use Magento\ImportExport\Model\Import\AbstractSource; /** * Class Generator * * */ -class Generator extends \Magento\ImportExport\Model\Import\AbstractSource +class Generator extends AbstractSource { /** * Data row pattern * - * @var \Magento\ToolkitFramework\ImportExport\Fixture\Complex\Pattern + * @var Pattern */ protected $_pattern; diff --git a/dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/ImportExport/Fixture/Complex/Pattern.php b/setup/src/Magento/Setup/Model/Complex/Pattern.php similarity index 97% rename from dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/ImportExport/Fixture/Complex/Pattern.php rename to setup/src/Magento/Setup/Model/Complex/Pattern.php index 78f8405cf58..04ddf96ff35 100644 --- a/dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/ImportExport/Fixture/Complex/Pattern.php +++ b/setup/src/Magento/Setup/Model/Complex/Pattern.php @@ -4,7 +4,7 @@ * See COPYING.txt for license details. */ -namespace Magento\ToolkitFramework\ImportExport\Fixture\Complex; +namespace Magento\Setup\Model\Complex; /** * Complex pattern class for complex generator (used for creating configurable products) diff --git a/dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/ImportExport/Fixture/Generator.php b/setup/src/Magento/Setup/Model/Generator.php similarity index 93% rename from dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/ImportExport/Fixture/Generator.php rename to setup/src/Magento/Setup/Model/Generator.php index e7fdaabdea4..5c59b2319b3 100644 --- a/dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/ImportExport/Fixture/Generator.php +++ b/setup/src/Magento/Setup/Model/Generator.php @@ -7,9 +7,11 @@ /** * A custom "Import" adapter for Magento_ImportExport module that allows generating arbitrary data rows */ -namespace Magento\ToolkitFramework\ImportExport\Fixture; +namespace Magento\Setup\Model; -class Generator extends \Magento\ImportExport\Model\Import\AbstractSource +use Magento\ImportExport\Model\Import\AbstractSource; + +class Generator extends AbstractSource { /** * Data row pattern diff --git a/dev/tools/performance-toolkit/framework/tests/unit/testsuite/Magento/ToolkitFramework/ImportExport/Fixture/Complex/ComplexGeneratorTest.php b/setup/src/Magento/Setup/Test/Unit/Model/Complex/ComplexGeneratorTest.php similarity index 75% rename from dev/tools/performance-toolkit/framework/tests/unit/testsuite/Magento/ToolkitFramework/ImportExport/Fixture/Complex/ComplexGeneratorTest.php rename to setup/src/Magento/Setup/Test/Unit/Model/Complex/ComplexGeneratorTest.php index e36f8b2ddc9..1481a3c6ee9 100644 --- a/dev/tools/performance-toolkit/framework/tests/unit/testsuite/Magento/ToolkitFramework/ImportExport/Fixture/Complex/ComplexGeneratorTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/Complex/ComplexGeneratorTest.php @@ -4,7 +4,10 @@ * See COPYING.txt for license details. */ -namespace Magento\ToolkitFramework\ImportExport\Fixture\Complex; +namespace Magento\Setup\Test\Unit\Model\Complex; + +use Magento\Setup\Model\Complex\Pattern; +use Magento\Setup\Model\Complex\Generator; /** * Class ComplexGeneratorTest @@ -15,18 +18,18 @@ class ComplexGeneratorTest extends \PHPUnit_Framework_TestCase /** * Pattern instance * - * @var \Magento\ToolkitFramework\ImportExport\Fixture\Complex\Pattern + * @var Pattern */ protected $_pattern; /** * Get pattern instance * - * @return \Magento\ToolkitFramework\ImportExport\Fixture\Complex\Pattern + * @return Pattern */ protected function getPattern() { - if (!$this->_pattern instanceof \Magento\ToolkitFramework\ImportExport\Fixture\Complex\Pattern) { + if (!$this->_pattern instanceof Pattern) { $patternData = [ [ 'id' => '%s', @@ -42,7 +45,7 @@ class ComplexGeneratorTest extends \PHPUnit_Framework_TestCase 'name' => 'yyy %s' ], ]; - $this->_pattern = new \Magento\ToolkitFramework\ImportExport\Fixture\Complex\Pattern(); + $this->_pattern = new Pattern(); $this->_pattern->setHeaders(array_keys($patternData[0])); $this->_pattern->setRowsSet($patternData); } @@ -56,7 +59,7 @@ class ComplexGeneratorTest extends \PHPUnit_Framework_TestCase */ public function testIteratorInterface() { - $model = new \Magento\ToolkitFramework\ImportExport\Fixture\Complex\Generator($this->getPattern(), 2); + $model = new Generator($this->getPattern(), 2); $rows = []; foreach ($model as $row) { $rows[] = $row; @@ -81,7 +84,7 @@ class ComplexGeneratorTest extends \PHPUnit_Framework_TestCase */ public function testGetIndex() { - $model = new \Magento\ToolkitFramework\ImportExport\Fixture\Complex\Generator($this->getPattern(), 4); + $model = new Generator($this->getPattern(), 4); for ($i = 0; $i < 32; $i++) { $this->assertEquals($model->getIndex($i), floor($i / $this->getPattern()->getRowsCount()) + 1); } diff --git a/dev/tools/performance-toolkit/framework/tests/unit/testsuite/Magento/ToolkitFramework/ImportExport/Fixture/Complex/PatternTest.php b/setup/src/Magento/Setup/Test/Unit/Model/Complex/PatternTest.php similarity index 88% rename from dev/tools/performance-toolkit/framework/tests/unit/testsuite/Magento/ToolkitFramework/ImportExport/Fixture/Complex/PatternTest.php rename to setup/src/Magento/Setup/Test/Unit/Model/Complex/PatternTest.php index d01751fbbb7..e1c89934f7a 100644 --- a/dev/tools/performance-toolkit/framework/tests/unit/testsuite/Magento/ToolkitFramework/ImportExport/Fixture/Complex/PatternTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/Complex/PatternTest.php @@ -4,7 +4,9 @@ * See COPYING.txt for license details. */ -namespace Magento\ToolkitFramework\ImportExport\Fixture\Complex; +namespace Magento\Setup\Test\Unit\Model\Complex; + +use Magento\Setup\Model\Complex\Pattern; /** * Class PatternTest @@ -17,11 +19,11 @@ class PatternTest extends \PHPUnit_Framework_TestCase * * @param array $patternData * - * @return \Magento\ToolkitFramework\ImportExport\Fixture\Complex\Pattern + * @return \Magento\Setup\Model\Complex\Pattern */ protected function getPattern($patternData) { - $pattern = new \Magento\ToolkitFramework\ImportExport\Fixture\Complex\Pattern(); + $pattern = new Pattern(); $pattern->setHeaders(array_keys($patternData[0])); $pattern->setRowsSet($patternData); return $pattern; @@ -32,7 +34,7 @@ class PatternTest extends \PHPUnit_Framework_TestCase * * @return array */ - public function patternDataPrivider() + public function patternDataProvider() { $result = [ 0 => [ @@ -82,7 +84,7 @@ class PatternTest extends \PHPUnit_Framework_TestCase * @param int $expectedRowsCount * @param array $expectedRowsResult * - * @dataProvider patternDataPrivider + * @dataProvider patternDataProvider * @test * * @return void diff --git a/dev/tools/performance-toolkit/framework/tests/unit/testsuite/Magento/ToolkitFramework/ImportExport/Fixture/GeneratorTest.php b/setup/src/Magento/Setup/Test/Unit/Model/GeneratorTest.php similarity index 84% rename from dev/tools/performance-toolkit/framework/tests/unit/testsuite/Magento/ToolkitFramework/ImportExport/Fixture/GeneratorTest.php rename to setup/src/Magento/Setup/Test/Unit/Model/GeneratorTest.php index 64d91414f69..343a67ade69 100644 --- a/dev/tools/performance-toolkit/framework/tests/unit/testsuite/Magento/ToolkitFramework/ImportExport/Fixture/GeneratorTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/GeneratorTest.php @@ -4,7 +4,9 @@ * See COPYING.txt for license details. */ -namespace Magento\ToolkitFramework\ImportExport\Fixture; +namespace Magento\Setup\Test\Unit\Model\Complex; + +use Magento\Setup\Model\Generator; class GeneratorTest extends \PHPUnit_Framework_TestCase { @@ -22,7 +24,7 @@ class GeneratorTest extends \PHPUnit_Framework_TestCase return $index * 10; }, ]; - $model = new \Magento\ToolkitFramework\ImportExport\Fixture\Generator($pattern, 2); + $model = new Generator($pattern, 2); $rows = []; foreach ($model as $row) { $rows[] = $row; -- GitLab