diff --git a/dev/tests/integration/etc/install-config-mysql.php.dist b/dev/tests/integration/etc/install-config-mysql.php.dist index 0d8fb591eb14454b4d3c46045e3606ab6e47dea3..975ad9c0be47ff2dd031f2c58980a3e4fbf38ec6 100644 --- a/dev/tests/integration/etc/install-config-mysql.php.dist +++ b/dev/tests/integration/etc/install-config-mysql.php.dist @@ -7,7 +7,7 @@ return [ 'db_host' => 'localhost', 'db_user' => 'root', - 'db_password' => '', + 'db_password' => 'root', 'db_name' => 'magento_integration_tests', 'db_prefix' => '', 'backend_frontname' => 'backend', diff --git a/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/DependenciesShowFrameworkCommandTest.php b/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/DependenciesShowFrameworkCommandTest.php new file mode 100644 index 0000000000000000000000000000000000000000..9e73b16468a1b3cec7759ef2ee688f1e27e30336 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/DependenciesShowFrameworkCommandTest.php @@ -0,0 +1,56 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Test\Tool\Console\Command; + +use Magento\Tools\Console\Command\DependenciesShowFrameworkCommand; +use Symfony\Component\Console\Tester\CommandTester; + +class DependenciesShowFrameworkCommandTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var DependenciesShowFrameworkCommand + */ + private $command; + + /** + * @var CommandTester + */ + private $commandTester; + + public function setUp() + { + $this->command = new DependenciesShowFrameworkCommand(); + $this->commandTester = new CommandTester($this->command); + } + + public function tearDown() + { + if (file_exists(__DIR__ . '/_files/output/framework.csv')) { + unlink(__DIR__ . '/_files/output/framework.csv'); + } + } + + public function testExecute() + { + $this->commandTester->execute( + ['--directory' => __DIR__ . '/_files/root', '--output' => __DIR__ . '/_files/output/framework.csv'] + ); + $this->assertEquals('Report successfully processed.' . PHP_EOL , $this->commandTester->getDisplay()); + $this->assertFileEquals( + __DIR__ . '/_files/expected/framework.csv', + __DIR__ . '/_files/output/framework.csv' + ); + } + + public function testExecuteInvalidDirectory() + { + $this->commandTester->execute(['--directory' => '/invalid/path']); + $this->assertContains( + 'Please, check passed path. Dependencies report generator failed:', + $this->commandTester->getDisplay() + ); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/DependenciesShowModulesCircularCommandTest.php b/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/DependenciesShowModulesCircularCommandTest.php new file mode 100644 index 0000000000000000000000000000000000000000..914faeeaef95f180c3580117ac31c0155a5defac --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/DependenciesShowModulesCircularCommandTest.php @@ -0,0 +1,56 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Test\Tool\Console\Command; + +use Magento\Tools\Console\Command\DependenciesShowModulesCircularCommand; +use Symfony\Component\Console\Tester\CommandTester; + +class DependenciesShowModulesCircularCommandTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var DependenciesShowModulesCircularCommand + */ + private $command; + + /** + * @var CommandTester + */ + private $commandTester; + + public function setUp() + { + $this->command = new DependenciesShowModulesCircularCommand(); + $this->commandTester = new CommandTester($this->command); + } + + public function tearDown() + { + if (file_exists(__DIR__ . '/_files/output/circular.csv')) { + unlink(__DIR__ . '/_files/output/circular.csv'); + } + } + + public function testExecute() + { + $this->commandTester->execute( + ['--directory' => __DIR__ . '/_files/root', '--output' => __DIR__ . '/_files/output/circular.csv'] + ); + $this->assertEquals('Report successfully processed.' . PHP_EOL , $this->commandTester->getDisplay()); + $this->assertFileEquals( + __DIR__ . '/_files/expected/circular.csv', + __DIR__ . '/_files/output/circular.csv' + ); + } + + public function testExecuteInvalidDirectory() + { + $this->commandTester->execute(['--directory' => '/invalid/path']); + $this->assertContains( + 'Please, check passed path. Dependencies report generator failed:', + $this->commandTester->getDisplay() + ); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/DependenciesShowModulesCommandTest.php b/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/DependenciesShowModulesCommandTest.php new file mode 100644 index 0000000000000000000000000000000000000000..4b9f0fcca27f8a9b1e27db666121087c81cd94df --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/DependenciesShowModulesCommandTest.php @@ -0,0 +1,56 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Test\Tool\Console\Command; + +use Magento\Tools\Console\Command\DependenciesShowModulesCommand; +use Symfony\Component\Console\Tester\CommandTester; + +class DependenciesShowModulesCommandTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var DependenciesShowModulesCommand + */ + private $command; + + /** + * @var CommandTester + */ + private $commandTester; + + public function setUp() + { + $this->command = new DependenciesShowModulesCommand(); + $this->commandTester = new CommandTester($this->command); + } + + public function tearDown() + { + if (file_exists(__DIR__ . '/_files/output/modules.csv')) { + unlink(__DIR__ . '/_files/output/modules.csv'); + } + } + + public function testExecute() + { + $this->commandTester->execute( + ['--directory' => __DIR__ . '/_files/root', '--output' => __DIR__ . '/_files/output/modules.csv'] + ); + $this->assertEquals('Report successfully processed.' . PHP_EOL , $this->commandTester->getDisplay()); + $this->assertFileEquals( + __DIR__ . '/_files/expected/modules.csv', + __DIR__ . '/_files/output/modules.csv' + ); + } + + public function testExecuteInvalidDirectory() + { + $this->commandTester->execute(['--directory' => '/invalid/path']); + $this->assertContains( + 'Please, check passed path. Dependencies report generator failed:', + $this->commandTester->getDisplay() + ); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/_files/expected/circular.csv b/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/_files/expected/circular.csv new file mode 100644 index 0000000000000000000000000000000000000000..6d00c9f4815548d8bbd880ebb06aebd44ccffe6d --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/_files/expected/circular.csv @@ -0,0 +1,9 @@ +"Circular dependencies:","Total number of chains" +"","2" + +"Circular dependencies for each module:","" +"magento/module-a","1" +"magento/module-a->magento/module-b->magento/module-a" + +"magento/module-b","1" +"magento/module-b->magento/module-a->magento/module-b" diff --git a/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/_files/expected/framework.csv b/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/_files/expected/framework.csv new file mode 100644 index 0000000000000000000000000000000000000000..b6abb23cd683f2651f147138297602b2c51da494 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/_files/expected/framework.csv @@ -0,0 +1,9 @@ +"Dependencies of framework:","Total number" +"","2" + +"Dependencies for each module:","" +"Magento\A","1" +" -- Magento\Framework","1" + +"Magento\B","1" +" -- Magento\Framework","1" diff --git a/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/_files/expected/modules.csv b/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/_files/expected/modules.csv new file mode 100644 index 0000000000000000000000000000000000000000..41deca9466eca3a56292a26c5f28bc4121afafc1 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/_files/expected/modules.csv @@ -0,0 +1,9 @@ +"","All","Hard","Soft" +"Total number of dependencies","2","2","0" + +"Dependencies for each module:","All","Hard","Soft" +"magento/module-a","1","1","0" +" -- magento/module-b","","1","0" + +"magento/module-b","1","1","0" +" -- magento/module-a","","1","0" diff --git a/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/_files/output/.gitignore b/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/_files/output/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/_files/root/app/code/Magento/A/Model/Foo.php b/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/_files/root/app/code/Magento/A/Model/Foo.php new file mode 100644 index 0000000000000000000000000000000000000000..f09ea6085233fe6efe1adc0d4014921a697307bd --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/_files/root/app/code/Magento/A/Model/Foo.php @@ -0,0 +1,14 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\A\Model; + +class Foo +{ + public function foo() + { + $frameworkDependencies = new \Magento\Framework\A(); + } +} \ No newline at end of file diff --git a/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/_files/root/app/code/Magento/A/composer.json b/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/_files/root/app/code/Magento/A/composer.json new file mode 100644 index 0000000000000000000000000000000000000000..a5e72e273a3eb6d700ae1414e9b68cf2df41ce12 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/_files/root/app/code/Magento/A/composer.json @@ -0,0 +1,10 @@ +{ + "name": "magento/module-a", + "require": { + "php": "~5.5.0|~5.6.0", + "magento/framework": "0.1", + "magento/magento-composer-installer": "*", + "magento/module-b": "0.1" + }, + "version": "0.1" +} diff --git a/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/_files/root/app/code/Magento/A/etc/module.xml b/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/_files/root/app/code/Magento/A/etc/module.xml new file mode 100644 index 0000000000000000000000000000000000000000..dd60aeb295b79ab9516a5482f221a1748bf27382 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/_files/root/app/code/Magento/A/etc/module.xml @@ -0,0 +1,14 @@ +<?xml version="1.0"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd"> + <module name="Magento_AdminNotification" setup_version="2.0.0"> + <sequence> + <module name="Magento_Store"/> + </sequence> + </module> +</config> diff --git a/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/_files/root/app/code/Magento/B/Model/Foo.php b/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/_files/root/app/code/Magento/B/Model/Foo.php new file mode 100644 index 0000000000000000000000000000000000000000..b42c3197030088ebbd101dae4e0d734f459cc290 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/_files/root/app/code/Magento/B/Model/Foo.php @@ -0,0 +1,14 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\B\Model; + +class Foo +{ + public function foo() + { + $frameworkDependencies = new \Magento\Framework\B(); + } +} \ No newline at end of file diff --git a/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/_files/root/app/code/Magento/B/composer.json b/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/_files/root/app/code/Magento/B/composer.json new file mode 100644 index 0000000000000000000000000000000000000000..3d25220200c58b861aa446a96d38e59e59325bb6 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/_files/root/app/code/Magento/B/composer.json @@ -0,0 +1,10 @@ +{ + "name": "magento/module-b", + "require": { + "php": "~5.5.0|~5.6.0", + "magento/framework": "0.74.0-beta6", + "magento/magento-composer-installer": "*", + "magento/module-a": "0.1" + }, + "version": "0.1" +} diff --git a/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/_files/root/app/code/Magento/B/etc/module.xml b/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/_files/root/app/code/Magento/B/etc/module.xml new file mode 100644 index 0000000000000000000000000000000000000000..6c30cdc5c72ecb5d340044fbb39f171fb354b316 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Test/Tools/Console/Command/_files/root/app/code/Magento/B/etc/module.xml @@ -0,0 +1,14 @@ +<?xml version="1.0"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd"> + <module name="Magento_Authorization" setup_version="2.0.0"> + <sequence> + <module name="Magento_Backend"/> + </sequence> + </module> +</config> diff --git a/dev/tools/Magento/Tools/Console/Command/AbstractDependenciesCommand.php b/dev/tools/Magento/Tools/Console/Command/AbstractDependenciesCommand.php index da55debb00b5492d1247a837412de4392bbb00d9..51649929b7a433a14f842942c22e135c90e4d0fd 100644 --- a/dev/tools/Magento/Tools/Console/Command/AbstractDependenciesCommand.php +++ b/dev/tools/Magento/Tools/Console/Command/AbstractDependenciesCommand.php @@ -18,6 +18,11 @@ abstract class AbstractDependenciesCommand extends Command */ const INPUT_KEY_DIRECTORY = 'directory'; + /** + * Input key for output path of report file + */ + const INPUT_KEY_OUTPUT = 'output'; + /** * {@inheritdoc} */ @@ -30,6 +35,13 @@ abstract class AbstractDependenciesCommand extends Command InputOption::VALUE_REQUIRED, 'Path to base directory for parsing', BP + ), + new InputOption( + self::INPUT_KEY_OUTPUT, + 'o', + InputOption::VALUE_REQUIRED, + 'Path to report file', + $this->getDefaultOutputPath() ) ] ); @@ -39,9 +51,17 @@ abstract class AbstractDependenciesCommand extends Command /** * Build dependencies report * + * @param string $outputPath * @return void */ - abstract protected function buildReport(); + abstract protected function buildReport($outputPath); + + /** + * Get path to the default output report file + * + * @return string + */ + abstract protected function getDefaultOutputPath(); /** * {@inheritdoc} @@ -49,8 +69,8 @@ abstract class AbstractDependenciesCommand extends Command protected function execute(InputInterface $input, OutputInterface $output) { try { - Files::setInstance(new \Magento\Framework\App\Utility\Files($input->getOption(self::INPUT_KEY_DIRECTORY))); - $this->buildReport(); + Files::setInstance(new Files($input->getOption(self::INPUT_KEY_DIRECTORY))); + $this->buildReport($input->getOption(self::INPUT_KEY_OUTPUT)); $output->writeln('<info>Report successfully processed.</info>'); } catch (\Exception $e) { $output->writeln( diff --git a/dev/tools/Magento/Tools/Console/Command/DependenciesShowFrameworkCommand.php b/dev/tools/Magento/Tools/Console/Command/DependenciesShowFrameworkCommand.php index 9dc7ff43f46139e4435593675b4a498635ff3914..87306ba0f9970b2ee86f524a5b50733bfd28c588 100644 --- a/dev/tools/Magento/Tools/Console/Command/DependenciesShowFrameworkCommand.php +++ b/dev/tools/Magento/Tools/Console/Command/DependenciesShowFrameworkCommand.php @@ -23,12 +23,23 @@ class DependenciesShowFrameworkCommand extends AbstractDependenciesCommand parent::configure(); } + /** + * Return default output file for framework dependencies report + * + * @return string + */ + protected function getDefaultOutputPath() + { + return 'framework-dependencies.csv'; + } + /** * Build Framework dependencies report * + * @param string $outputPath * @return void */ - protected function buildReport() + protected function buildReport($outputPath) { $filesForParse = Files::init()->getFiles([Files::init()->getPathToSource() . '/app/code/Magento'], '*'); $configFiles = Files::init()->getConfigFiles('module.xml', [], false); @@ -40,7 +51,7 @@ class DependenciesShowFrameworkCommand extends AbstractDependenciesCommand 'config_files' => $configFiles, 'declared_namespaces' => Files::init()->getNamespaces(), ], - 'write' => ['report_filename' => 'framework-dependencies.csv'], + 'write' => ['report_filename' => $outputPath], ] ); } diff --git a/dev/tools/Magento/Tools/Console/Command/DependenciesShowModulesCircularCommand.php b/dev/tools/Magento/Tools/Console/Command/DependenciesShowModulesCircularCommand.php index 10ac41906e4b14c93903296f271752cfc336746d..11916895c0ec94085bd5284baff40df9bd97adf7 100644 --- a/dev/tools/Magento/Tools/Console/Command/DependenciesShowModulesCircularCommand.php +++ b/dev/tools/Magento/Tools/Console/Command/DependenciesShowModulesCircularCommand.php @@ -23,19 +23,30 @@ class DependenciesShowModulesCircularCommand extends AbstractDependenciesCommand parent::configure(); } + /** + * Return default output file for modules circular dependencies report + * + * @return string + */ + protected function getDefaultOutputPath() + { + return 'modules-circular-dependencies.csv'; + } + /** * Build circular dependencies between modules report * + * @param string $outputPath * @return void */ - protected function buildReport() + protected function buildReport($outputPath) { $filesForParse = Files::init()->getComposerFiles('code', false); ServiceLocator::getCircularDependenciesReportBuilder()->build( [ 'parse' => ['files_for_parse' => $filesForParse], - 'write' => ['report_filename' => 'modules-circular-dependencies.csv'], + 'write' => ['report_filename' => $outputPath], ] ); } diff --git a/dev/tools/Magento/Tools/Console/Command/DependenciesShowModulesCommand.php b/dev/tools/Magento/Tools/Console/Command/DependenciesShowModulesCommand.php index 838327d0d4788f1197236f0eb92f271b2d8fd774..31aacdb259f45f695c3714f30efbfcf68b1ee21f 100644 --- a/dev/tools/Magento/Tools/Console/Command/DependenciesShowModulesCommand.php +++ b/dev/tools/Magento/Tools/Console/Command/DependenciesShowModulesCommand.php @@ -23,19 +23,30 @@ class DependenciesShowModulesCommand extends AbstractDependenciesCommand parent::configure(); } + /** + * Return default output file for modules dependencies report + * + * @return string + */ + protected function getDefaultOutputPath() + { + return 'modules-dependencies.csv'; + } + /** * Build circular dependencies between modules report * + * @param string $outputPath * @return void */ - protected function buildReport() + protected function buildReport($outputPath) { $filesForParse = Files::init()->getComposerFiles('code', false); ServiceLocator::getDependenciesReportBuilder()->build( [ 'parse' => ['files_for_parse' => $filesForParse], - 'write' => ['report_filename' => 'modules-dependencies.csv'], + 'write' => ['report_filename' => $outputPath], ] ); } diff --git a/dev/tools/Magento/Tools/Dependency/ServiceLocator.php b/dev/tools/Magento/Tools/Dependency/ServiceLocator.php index eb4427480652acc158f9fe72877e6735204a233e..16ce14b9ae2207f6795ced740a0dc64ed7f795cf 100644 --- a/dev/tools/Magento/Tools/Dependency/ServiceLocator.php +++ b/dev/tools/Magento/Tools/Dependency/ServiceLocator.php @@ -164,7 +164,7 @@ class ServiceLocator private static function getCsvWriter() { if (null === self::$csvWriter) { - self::$csvWriter = (new Csv())->setDelimiter(';'); + self::$csvWriter = (new Csv())->setDelimiter(','); } return self::$csvWriter; }