diff --git a/app/code/Magento/Backend/Block/Template.php b/app/code/Magento/Backend/Block/Template.php index 1bcd3033035dc0bf2de89782ad8972b8236e0d96..45d3830793e116f8d7029b4ae5c87ca80a83f280 100644 --- a/app/code/Magento/Backend/Block/Template.php +++ b/app/code/Magento/Backend/Block/Template.php @@ -70,17 +70,12 @@ class Template extends \Magento\Framework\View\Element\Template * * @param string $moduleName Full module name * @return boolean + * @deprecated + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function isOutputEnabled($moduleName = null) { - if ($moduleName === null) { - $moduleName = $this->getModuleName(); - } - - return !$this->_scopeConfig->isSetFlag( - 'advanced/modules_disable_output/' . $moduleName, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); + return true; } /** diff --git a/app/code/Magento/Backend/etc/adminhtml/system.xml b/app/code/Magento/Backend/etc/adminhtml/system.xml index 813a097ea6bf3ca2e615f0848619409c61f2dd9f..fc6c8df551913f5ad34d9875bc7e0e9173424681 100644 --- a/app/code/Magento/Backend/etc/adminhtml/system.xml +++ b/app/code/Magento/Backend/etc/adminhtml/system.xml @@ -16,7 +16,7 @@ <tab id="advanced" translate="label" sortOrder="999999"> <label>Advanced</label> </tab> - <section id="advanced" translate="label" type="text" sortOrder="910" showInDefault="1" showInWebsite="1" showInStore="1"> + <section id="advanced" translate="label" type="text" sortOrder="910" showInDefault="0" showInWebsite="0" showInStore="0"> <label>Advanced</label> <tab>advanced</tab> <resource>Magento_Backend::advanced</resource> diff --git a/app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Options/AjaxTest.php b/app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Options/AjaxTest.php index 0c6f680df486a50c584008b9cee288366c5d0209..1ca01ca6724ce741b58278ffe2d42a8522aa574c 100644 --- a/app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Options/AjaxTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Options/AjaxTest.php @@ -55,12 +55,6 @@ class AjaxTest extends \PHPUnit_Framework_TestCase ->getMock(); $eventManager->expects($this->exactly(2))->method('dispatch')->will($this->returnValue(true)); - $scopeConfig = $this->getMockBuilder(\Magento\Framework\App\Config::class) - ->setMethods(['getValue']) - ->disableOriginalConstructor()->getMock(); - $scopeConfig->expects($this->once())->method('getValue')->withAnyParameters() - ->will($this->returnValue(false)); - $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)->disableOriginalConstructor() ->setMethods(['setStoreId', 'load', 'getId', '__wakeup', '__sleep']) ->getMock(); @@ -93,8 +87,6 @@ class AjaxTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once())->method('getEventManager') ->will($this->returnValue($eventManager)); - $this->context->expects($this->once())->method('getScopeConfig') - ->will($this->returnValue($scopeConfig)); $this->context->expects($this->once())->method('getLayout') ->will($this->returnValue($layout)); $this->context->expects($this->once())->method('getRequest') diff --git a/app/code/Magento/Catalog/Test/Unit/Block/Product/Widget/NewWidgetTest.php b/app/code/Magento/Catalog/Test/Unit/Block/Product/Widget/NewWidgetTest.php index 9c153fb920279c48ac2e36014a178b67de66eb3f..90d76e469b7abe4d0c2e253bd174f0ee8437dc00 100644 --- a/app/code/Magento/Catalog/Test/Unit/Block/Product/Widget/NewWidgetTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Block/Product/Widget/NewWidgetTest.php @@ -63,7 +63,7 @@ class NewWidgetTest extends \PHPUnit_Framework_TestCase false, false ); - $this->scopeConfig = $this->getMock(\Magento\Framework\App\Config::class, ['getValue'], [], '', false, false); + $this->scopeConfig = $this->getMock(\Magento\Framework\App\Config::class, [], [], '', false, false); $this->cacheState = $this->getMock( \Magento\Framework\App\Cache\State::class, ['isEnabled'], @@ -188,8 +188,6 @@ class NewWidgetTest extends \PHPUnit_Framework_TestCase { $this->eventManager->expects($this->exactly(2))->method('dispatch') ->will($this->returnValue(true)); - $this->scopeConfig->expects($this->once())->method('getValue')->withAnyParameters() - ->willReturn(false); $this->cacheState->expects($this->atLeastOnce())->method('isEnabled')->withAnyParameters() ->willReturn(false); $this->catalogConfig->expects($this->once())->method('getProductAttributes') diff --git a/app/code/Magento/Checkout/Test/Unit/Block/Cart/Item/Renderer/ActionsTest.php b/app/code/Magento/Checkout/Test/Unit/Block/Cart/Item/Renderer/ActionsTest.php index 526a1d580a5d5efe0a14109345113edcc22936e9..48c6eb87c4d73755372d66d7172f2a4aa9073bd5 100644 --- a/app/code/Magento/Checkout/Test/Unit/Block/Cart/Item/Renderer/ActionsTest.php +++ b/app/code/Magento/Checkout/Test/Unit/Block/Cart/Item/Renderer/ActionsTest.php @@ -65,10 +65,6 @@ class ActionsTest extends \PHPUnit_Framework_TestCase $childNameTwo = 'child.2'; $childNames = [$childNameOne, $childNameTwo]; - $this->scopeConfigMock->expects($this->once()) - ->method('getValue') - ->willReturn(false); - /** * @var Item|\PHPUnit_Framework_MockObject_MockObject $itemMock */ diff --git a/app/code/Magento/Config/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php b/app/code/Magento/Config/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php index cda1a6a80cce639bf511f8400d4f13119a728e5d..e938de4aad64353d54f279525b142612911963bc 100644 --- a/app/code/Magento/Config/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php +++ b/app/code/Magento/Config/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php @@ -9,6 +9,9 @@ */ namespace Magento\Config\Block\System\Config\Form\Fieldset\Modules; +/** + * @deprecated + */ class DisableOutput extends \Magento\Config\Block\System\Config\Form\Fieldset { /** diff --git a/app/code/Magento/Config/Model/Config/Parser/Comment.php b/app/code/Magento/Config/Model/Config/Parser/Comment.php new file mode 100644 index 0000000000000000000000000000000000000000..56dd38d55d800ec27c95b983d53dbb04a144dc87 --- /dev/null +++ b/app/code/Magento/Config/Model/Config/Parser/Comment.php @@ -0,0 +1,80 @@ +<?php +/** + * Copyright © 2013-2017 Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Config\Model\Config\Parser; + +use Magento\Config\Model\Placeholder\Environment; +use Magento\Config\Model\Placeholder\PlaceholderInterface; +use Magento\Framework\App\Config\CommentParserInterface; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Exception\FileSystemException; +use Magento\Framework\Filesystem; + +/** + * Class Comment. It is used to parse config paths from comment section. + */ +class Comment implements CommentParserInterface +{ + /** + * @var Filesystem + */ + private $filesystem; + + /** + * @var PlaceholderInterface + */ + private $placeholder; + + /** + * @param Filesystem $filesystem + * @param PlaceholderInterface $placeholder + */ + public function __construct( + Filesystem $filesystem, + PlaceholderInterface $placeholder + ) { + $this->filesystem = $filesystem; + $this->placeholder = $placeholder; + } + + /** + * Retrieves config paths from comment section of the file. + * Example of comment: + * * CONFIG__DEFAULT__SOME__CONF__PATH_ONE + * * CONFIG__DEFAULT__SOME__CONF__PATH_TWO + * This method will return: + * array( + * 'CONFIG__DEFAULT__SOME__CONF__PATH_ONE' => 'some/conf/path_one', + * 'CONFIG__DEFAULT__SOME__CONF__PATH_TWO' => 'some/conf/path_two' + * ); + * + * @param string $fileName + * @return array + * @throws FileSystemException + */ + public function execute($fileName) + { + $fileContent = $this->filesystem + ->getDirectoryRead(DirectoryList::CONFIG) + ->readFile($fileName); + + $pattern = sprintf('/\s+\*\s+(?P<placeholder>%s.*?)\s/', preg_quote(Environment::PREFIX)); + preg_match_all($pattern, $fileContent, $matches); + + if (!isset($matches['placeholder'])) { + return []; + } + + $configs = []; + foreach ($matches['placeholder'] as $placeholder) { + $path = $this->placeholder->restore($placeholder); + $path = preg_replace('/^' . ScopeConfigInterface::SCOPE_TYPE_DEFAULT . '\//', '', $path); + $configs[$placeholder] = $path; + } + + return $configs; + } +} diff --git a/app/code/Magento/Config/Test/Unit/Block/System/Config/Form/Fieldset/Modules/DisableOutputTest.php b/app/code/Magento/Config/Test/Unit/Block/System/Config/Form/Fieldset/Modules/DisableOutputTest.php index 218ea75643939fb116512ced43aca46d7566e5c4..b8f420880ff6d231a36ec2e50126d36eaa149adf 100644 --- a/app/code/Magento/Config/Test/Unit/Block/System/Config/Form/Fieldset/Modules/DisableOutputTest.php +++ b/app/code/Magento/Config/Test/Unit/Block/System/Config/Form/Fieldset/Modules/DisableOutputTest.php @@ -7,6 +7,7 @@ namespace Magento\Config\Test\Unit\Block\System\Config\Form\Fieldset\Modules; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * @deprecated */ class DisableOutputTest extends \PHPUnit_Framework_TestCase { diff --git a/app/code/Magento/Config/Test/Unit/Model/Config/Parser/CommentTest.php b/app/code/Magento/Config/Test/Unit/Model/Config/Parser/CommentTest.php new file mode 100644 index 0000000000000000000000000000000000000000..933f18e1e2919ba442028feada14834313d7b617 --- /dev/null +++ b/app/code/Magento/Config/Test/Unit/Model/Config/Parser/CommentTest.php @@ -0,0 +1,80 @@ +<?php +/** + * Copyright © 2013-2017 Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Config\Test\Unit\Model\Config\Parser; + +use Magento\Config\Model\Config\Parser\Comment; +use Magento\Config\Model\Placeholder\PlaceholderInterface; +use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Filesystem; +use Magento\Framework\Filesystem\Directory\ReadInterface; +use PHPUnit_Framework_MockObject_MockObject as MockObject; + +class CommentTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var PlaceholderInterface|MockObject + */ + private $placeholderMock; + + /** + * @var Filesystem|MockObject + */ + private $fileSystemMock; + + /** + * @var Comment + */ + private $model; + + protected function setUp() + { + $this->placeholderMock = $this->getMockBuilder(PlaceholderInterface::class) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $this->fileSystemMock = $this->getMockBuilder(Filesystem::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->model = new Comment( + $this->fileSystemMock, + $this->placeholderMock + ); + } + + public function testExecute() + { + $fileName = 'config.local.php'; + $directoryReadMock = $this->getMockBuilder(ReadInterface::class) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $directoryReadMock->expects($this->once()) + ->method('readFile') + ->with($fileName) + ->willReturn(file_get_contents(__DIR__ . '/../_files/' . $fileName)); + $this->fileSystemMock->expects($this->once()) + ->method('getDirectoryRead') + ->with(DirectoryList::CONFIG) + ->willReturn($directoryReadMock); + $this->placeholderMock->expects($this->any()) + ->method('restore') + ->withConsecutive( + ['CONFIG__DEFAULT__SOME__PAYMENT__PASSWORD'], + ['CONFIG__DEFAULT__SOME__PAYMENT__TOKEN'] + ) + ->willReturnOnConsecutiveCalls( + 'some/payment/password', + 'some/payment/token' + ); + + $this->assertEquals( + $this->model->execute($fileName), + [ + 'CONFIG__DEFAULT__SOME__PAYMENT__PASSWORD' => 'some/payment/password', + 'CONFIG__DEFAULT__SOME__PAYMENT__TOKEN' => 'some/payment/token' + ] + ); + } +} diff --git a/app/code/Magento/Config/Test/Unit/Model/Config/_files/config.local.php b/app/code/Magento/Config/Test/Unit/Model/Config/_files/config.local.php new file mode 100644 index 0000000000000000000000000000000000000000..6c4907567b0320c163e1b0ada2c71259b30a2641 --- /dev/null +++ b/app/code/Magento/Config/Test/Unit/Model/Config/_files/config.local.php @@ -0,0 +1,24 @@ +<?php +/** + * Copyright © 2013-2017 Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +return [ + 'scopes' => [ + 'websites' => [ + 'admin' => [ + 'website_id' => '0' + ], + ], + ], + /** + * The configuration file doesn't contain sensitive data for security reasons. + * Sensitive data can be stored in the following environment variables: + * CONFIG__DEFAULT__SOME__PAYMENT__PASSWORD for some/payment/password + */ + 'system' => [] + /** + * CONFIG__DEFAULT__SOME__PAYMENT__TOKEN for some/payment/token + * test phrase CONFIG__DEFAULT__SOME__PAYMENT__TOKEN for some/payment/token + */ +]; diff --git a/app/code/Magento/Config/etc/di.xml b/app/code/Magento/Config/etc/di.xml index 9579e1ca3191445edd6599eb7b8e779b36c9ab76..ab8973a1a15ceecf227d9de73450b8f906fa0c91 100644 --- a/app/code/Magento/Config/etc/di.xml +++ b/app/code/Magento/Config/etc/di.xml @@ -9,6 +9,7 @@ <preference for="Magento\Config\Model\Config\Structure\SearchInterface" type="Magento\Config\Model\Config\Structure" /> <preference for="Magento\Config\Model\Config\Backend\File\RequestData\RequestDataInterface" type="Magento\Config\Model\Config\Backend\File\RequestData" /> <preference for="Magento\Framework\App\Config\ConfigResource\ConfigInterface" type="Magento\Config\Model\ResourceModel\Config" /> + <preference for="Magento\Framework\App\Config\CommentParserInterface" type="Magento\Config\Model\Config\Parser\Comment" /> <virtualType name="Magento\Framework\View\TemplateEngine\Xhtml\ConfigCompiler" type="Magento\Framework\View\TemplateEngine\Xhtml\Compiler" shared="false"> <arguments> <argument name="compilerText" xsi:type="object">Magento\Framework\View\TemplateEngine\Xhtml\Compiler\Text</argument> @@ -184,4 +185,9 @@ </argument> </arguments> </type> + <type name="Magento\Config\Model\Config\Parser\Comment"> + <arguments> + <argument name="placeholder" xsi:type="object">Magento\Config\Model\Placeholder\Environment</argument> + </arguments> + </type> </config> diff --git a/app/code/Magento/Deploy/Console/Command/App/SensitiveConfigSet/CollectorFactory.php b/app/code/Magento/Deploy/Console/Command/App/SensitiveConfigSet/CollectorFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..e78b4b71d31184a3f44439d4a168766475b9ad09 --- /dev/null +++ b/app/code/Magento/Deploy/Console/Command/App/SensitiveConfigSet/CollectorFactory.php @@ -0,0 +1,68 @@ +<?php +/** + * Copyright © 2013-2017 Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Deploy\Console\Command\App\SensitiveConfigSet; + +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\ObjectManagerInterface; + +/** + * Class CollectorFactory creates instance of CollectorInterface. + */ +class CollectorFactory +{ + /**#@+ + * Constant for collector types. + */ + const TYPE_INTERACTIVE = 'interactive'; + const TYPE_SIMPLE = 'simple'; + /**#@-*/ + + /** + * @var ObjectManagerInterface + */ + private $objectManager; + + /** + * @var array + */ + private $types; + + /** + * @param ObjectManagerInterface $objectManager + * @param array $types + */ + public function __construct( + ObjectManagerInterface $objectManager, + array $types = [] + ) { + $this->objectManager = $objectManager; + $this->types = $types; + } + + /** + * Create instance of CollectorInterface by given type. + * + * @param string $type + * @return CollectorInterface + * @throws LocalizedException If collector type not exist in registered types array. + */ + public function create($type) + { + if (!isset($this->types[$type])) { + throw new LocalizedException(__('Class for type "%1" was not declared', $type)); + } + + $object = $this->objectManager->create($this->types[$type]); + + if (!$object instanceof CollectorInterface) { + throw new LocalizedException( + __('%1 does not implement %2', get_class($object), CollectorInterface::class) + ); + } + + return $object; + } +} diff --git a/app/code/Magento/Deploy/Console/Command/App/SensitiveConfigSet/CollectorInterface.php b/app/code/Magento/Deploy/Console/Command/App/SensitiveConfigSet/CollectorInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..6aecf23adf37d494ba02ae46f2e09bd52fd1079f --- /dev/null +++ b/app/code/Magento/Deploy/Console/Command/App/SensitiveConfigSet/CollectorInterface.php @@ -0,0 +1,27 @@ +<?php +/** + * Copyright © 2013-2017 Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Deploy\Console\Command\App\SensitiveConfigSet; + +use Magento\Framework\Exception\LocalizedException; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +/** + * Interface CollectorInterface + */ +interface CollectorInterface +{ + /** + * Collects values from user input and return result as array. + * + * @param InputInterface $input + * @param OutputInterface $output + * @param array $configPaths list of available config paths. + * @return array + * @throws LocalizedException + */ + public function getValues(InputInterface $input, OutputInterface $output, array $configPaths); +} diff --git a/app/code/Magento/Deploy/Console/Command/App/SensitiveConfigSet/InteractiveCollector.php b/app/code/Magento/Deploy/Console/Command/App/SensitiveConfigSet/InteractiveCollector.php new file mode 100644 index 0000000000000000000000000000000000000000..3f67a98ff1c58d49dba645e4987c833d840260d2 --- /dev/null +++ b/app/code/Magento/Deploy/Console/Command/App/SensitiveConfigSet/InteractiveCollector.php @@ -0,0 +1,67 @@ +<?php +/** + * Copyright © 2013-2017 Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Deploy\Console\Command\App\SensitiveConfigSet; + +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Question\QuestionFactory; +use Symfony\Component\Console\Helper\QuestionHelper; + +/** + * Class InteractiveCollector collects configuration values from user input. + */ +class InteractiveCollector implements CollectorInterface +{ + /** + * @var QuestionFactory + */ + private $questionFactory; + + /** + * @var QuestionHelper + */ + private $questionHelper; + + /** + * @param QuestionFactory $questionFactory + * @param QuestionHelper $questionHelper + */ + public function __construct( + QuestionFactory $questionFactory, + QuestionHelper $questionHelper + ) { + $this->questionFactory = $questionFactory; + $this->questionHelper = $questionHelper; + } + + /** + * Collect list of configuration values from user input. + * For example, this method will return + * + * ```php + * [ + * 'some/configuration/path1' => 'someValue1', + * 'some/configuration/path2' => 'someValue2', + * 'some/configuration/path3' => 'someValue3', + * ] + * ``` + * + * {@inheritdoc} + */ + public function getValues(InputInterface $input, OutputInterface $output, array $configPaths) + { + $output->writeln('<info>Please set configuration values or skip them by pressing [Enter]:</info>'); + $values = []; + foreach ($configPaths as $configPath) { + $question = $this->questionFactory->create([ + 'question' => $configPath . ': ' + ]); + $values[$configPath] = $this->questionHelper->ask($input, $output, $question); + } + + return $values; + } +} diff --git a/app/code/Magento/Deploy/Console/Command/App/SensitiveConfigSet/SimpleCollector.php b/app/code/Magento/Deploy/Console/Command/App/SensitiveConfigSet/SimpleCollector.php new file mode 100644 index 0000000000000000000000000000000000000000..828b4254a53085a986c1b0933912bae3efe7bc0c --- /dev/null +++ b/app/code/Magento/Deploy/Console/Command/App/SensitiveConfigSet/SimpleCollector.php @@ -0,0 +1,131 @@ +<?php +/** + * Copyright © 2013-2017 Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Deploy\Console\Command\App\SensitiveConfigSet; + +use Magento\Deploy\Console\Command\App\SensitiveConfigSetCommand; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Phrase; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Question\Question; +use Symfony\Component\Console\Question\QuestionFactory; +use Symfony\Component\Console\Helper\QuestionHelper; + +/** + * Class SimpleCollector collects configuration value from user input. + */ +class SimpleCollector implements CollectorInterface +{ + /** + * @var QuestionFactory + */ + private $questionFactory; + + /** + * @var QuestionHelper + */ + private $questionHelper; + + /** + * @param QuestionFactory $questionFactory + * @param QuestionHelper $questionHelper + */ + public function __construct( + QuestionFactory $questionFactory, + QuestionHelper $questionHelper + ) { + $this->questionFactory = $questionFactory; + $this->questionHelper = $questionHelper; + } + + /** + * Collects single configuration value from user input. + * For example, this method will return + * + * ```php + * ['some/configuration/path' => 'someValue'] + * ``` + * + * {@inheritdoc} + */ + public function getValues(InputInterface $input, OutputInterface $output, array $configPaths) + { + $inputPath = $input->getArgument(SensitiveConfigSetCommand::INPUT_ARGUMENT_PATH); + $configPathQuestion = $this->getConfigPathQuestion($configPaths); + $configPath = $inputPath === null ? + $this->questionHelper->ask($input, $output, $configPathQuestion) : + $inputPath; + + $this->validatePath($configPath, $configPaths); + + $inputValue = $input->getArgument(SensitiveConfigSetCommand::INPUT_ARGUMENT_VALUE); + $configValueQuestion = $this->getConfigValueQuestion(); + $configValue = $inputValue === null ? + $this->questionHelper->ask($input, $output, $configValueQuestion) : + $inputValue; + + return [$configPath => $configValue]; + } + + /** + * Get Question to fill configuration path with autocompletion in interactive mode. + * + * @param array $configPaths + * @return Question + */ + private function getConfigPathQuestion(array $configPaths) + { + /** @var Question $configPathQuestion */ + $configPathQuestion = $this->questionFactory->create([ + 'question' => 'Please enter config path: ' + ]); + $configPathQuestion->setAutocompleterValues($configPaths); + $configPathQuestion->setValidator(function ($configPath) use ($configPaths) { + $this->validatePath($configPath, $configPaths); + return $configPath; + }); + + return $configPathQuestion; + } + + /** + * Get Question to fill configuration value in interactive mode. + * + * @return Question + */ + private function getConfigValueQuestion() + { + /** @var Question $configValueQuestion */ + $configValueQuestion = $this->questionFactory->create([ + 'question' => 'Please enter value: ' + ]); + $configValueQuestion->setValidator(function ($interviewer) { + if (empty($interviewer)) { + throw new LocalizedException(new Phrase('Value can\'t be empty')); + } + return $interviewer; + }); + + return $configValueQuestion; + } + + /** + * Check if entered configuration path is valid, throw LocalizedException otherwise. + * + * @param string $configPath Path that should be validated. + * @param array $configPaths List of allowed paths. + * @return void + * @throws LocalizedException If config path not exist in allowed config paths. + */ + private function validatePath($configPath, array $configPaths) + { + if (!in_array($configPath, $configPaths)) { + throw new LocalizedException( + new Phrase('A configuration with this path does not exist or is not sensitive') + ); + } + } +} diff --git a/app/code/Magento/Deploy/Console/Command/App/SensitiveConfigSetCommand.php b/app/code/Magento/Deploy/Console/Command/App/SensitiveConfigSetCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..e8555ceb9530f59561dce02ed264b3f0de3ee72b --- /dev/null +++ b/app/code/Magento/Deploy/Console/Command/App/SensitiveConfigSetCommand.php @@ -0,0 +1,196 @@ +<?php +/** + * Copyright © 2013-2017 Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Deploy\Console\Command\App; + +use Magento\Deploy\Console\Command\App\SensitiveConfigSet\CollectorFactory; +use Magento\Deploy\Model\ConfigWriter; +use Magento\Framework\App\Config\CommentParserInterface; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\Scope\ValidatorInterface; +use Magento\Framework\Config\File\ConfigFilePool; +use Magento\Framework\Console\Cli; +use Magento\Framework\Exception\FileSystemException; +use Magento\Framework\Exception\LocalizedException; +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; + +/** + * Command for set sensitive variable through deploy process. + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ +class SensitiveConfigSetCommand extends Command +{ + /**#@+ + * Names of input arguments or options. + */ + const INPUT_OPTION_INTERACTIVE = 'interactive'; + const INPUT_OPTION_SCOPE = 'scope'; + const INPUT_OPTION_SCOPE_CODE = 'scope-code'; + const INPUT_ARGUMENT_PATH = 'path'; + const INPUT_ARGUMENT_VALUE = 'value'; + /**#@-*/ + + /** + * @var CommentParserInterface + */ + private $commentParser; + + /** + * @var ConfigFilePool + */ + private $configFilePool; + + /** + * @var ConfigWriter + */ + private $configWriter; + + /** + * @var ValidatorInterface + */ + private $scopeValidator; + + /** + * @var CollectorFactory + */ + private $collectorFactory; + + /** + * @param ConfigFilePool $configFilePool + * @param CommentParserInterface $commentParser + * @param ConfigWriter $configWriter + * @param ValidatorInterface $scopeValidator + * @param CollectorFactory $collectorFactory + */ + public function __construct( + ConfigFilePool $configFilePool, + CommentParserInterface $commentParser, + ConfigWriter $configWriter, + ValidatorInterface $scopeValidator, + CollectorFactory $collectorFactory + ) { + parent::__construct(); + $this->commentParser = $commentParser; + $this->configFilePool = $configFilePool; + $this->configWriter = $configWriter; + $this->scopeValidator = $scopeValidator; + $this->collectorFactory = $collectorFactory; + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this->addArgument( + self::INPUT_ARGUMENT_PATH, + InputArgument::OPTIONAL, + 'Configuration path for example group/section/field_name' + ); + $this->addArgument( + self::INPUT_ARGUMENT_VALUE, + InputArgument::OPTIONAL, + 'Configuration value' + ); + $this->addOption( + self::INPUT_OPTION_INTERACTIVE, + 'i', + InputOption::VALUE_NONE, + 'Enable interactive mode to set all sensitive variables' + ); + $this->addOption( + self::INPUT_OPTION_SCOPE, + null, + InputOption::VALUE_OPTIONAL, + 'Scope for configuration, if not set use \'default\'', + ScopeConfigInterface::SCOPE_TYPE_DEFAULT + ); + $this->addOption( + self::INPUT_OPTION_SCOPE_CODE, + null, + InputOption::VALUE_OPTIONAL, + 'Scope code for configuration, empty string by default', + '' + ); + $this->setName('config:sensitive:set') + ->setDescription('Set sensitive configuration values'); + parent::configure(); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $scope = $input->getOption(self::INPUT_OPTION_SCOPE); + $scopeCode = $input->getOption(self::INPUT_OPTION_SCOPE_CODE); + + try { + $this->scopeValidator->isValid($scope, $scopeCode); + $configPaths = $this->getConfigPaths(); + $isInteractive = $input->getOption(self::INPUT_OPTION_INTERACTIVE); + $collector = $this->collectorFactory->create( + $isInteractive ? CollectorFactory::TYPE_INTERACTIVE : CollectorFactory::TYPE_SIMPLE + ); + $values = $collector->getValues($input, $output, $configPaths); + $this->configWriter->save($values, $scope, $scopeCode); + } catch (LocalizedException $e) { + $output->writeln(sprintf('<error>%s</error>', $e->getMessage())); + return Cli::RETURN_FAILURE; + } + + $this->writeSuccessMessage($output, $isInteractive); + + return Cli::RETURN_SUCCESS; + } + + /** + * Writes success message. + * + * @param OutputInterface $output + * @param boolean $isInteractive + * @return void + */ + private function writeSuccessMessage(OutputInterface $output, $isInteractive) + { + $output->writeln(sprintf( + '<info>Configuration value%s saved in app/etc/%s</info>', + $isInteractive ? 's' : '', + $this->configFilePool->getPath(ConfigFilePool::APP_CONFIG) + )); + } + + /** + * Get sensitive configuration paths. + * + * @return array + * @throws LocalizedException if configuration file not exists or sensitive configuration is empty + */ + private function getConfigPaths() + { + $configFilePath = $this->configFilePool->getPathsByPool(ConfigFilePool::LOCAL)[ConfigFilePool::APP_CONFIG]; + try { + $configPaths = $this->commentParser->execute($configFilePath); + } catch (FileSystemException $e) { + throw new LocalizedException(__( + 'File app/etc/%1 can\'t be read. Please check if it exists and has read permissions.', + [ + $configFilePath + ] + )); + } + + if (empty($configPaths)) { + throw new LocalizedException(__('There are no sensitive configurations to fill')); + } + + return $configPaths; + } +} diff --git a/app/code/Magento/Deploy/Model/ConfigWriter.php b/app/code/Magento/Deploy/Model/ConfigWriter.php new file mode 100644 index 0000000000000000000000000000000000000000..7a9b70c528ac9e5d9010e0683b651823ecb74c4a --- /dev/null +++ b/app/code/Magento/Deploy/Model/ConfigWriter.php @@ -0,0 +1,109 @@ +<?php +/** + * Copyright © 2013-2017 Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Deploy\Model; + +use Magento\Config\App\Config\Type\System; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\DeploymentConfig\Writer; +use Magento\Framework\Config\File\ConfigFilePool; +use Magento\Framework\Stdlib\ArrayManager; + +/** + * Class ConfigWriter. Save configuration values into config file. + */ +class ConfigWriter +{ + /** + * @var Writer + */ + private $writer; + + /** + * @var ArrayManager + */ + private $arrayManager; + + /** + * @param Writer $writer + * @param ArrayManager $arrayManager + */ + public function __construct( + Writer $writer, + ArrayManager $arrayManager + ) { + $this->writer = $writer; + $this->arrayManager = $arrayManager; + } + + /** + * Save given list of configuration values into config file. + * + * @param array $values the configuration values (path-value pairs) to be saved. + * @param string $scope scope in which configuration would be saved. + * @param string|null $scopeCode + * @return void + */ + public function save(array $values, $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeCode = null) + { + $config = []; + $pathPrefix = $this->getPathPrefix($scope, $scopeCode); + foreach ($values as $configPath => $configValue) { + $fullConfigPath = $pathPrefix . $configPath; + $config = $this->setConfig($config, $fullConfigPath, $configValue); + } + + $this->writer + ->saveConfig( + [ConfigFilePool::APP_CONFIG => $config] + ); + } + + /** + * Apply configuration value into configuration array by given path. + * Ignore values that equal to null. + * + * @param array $config + * @param string $configPath + * @param string $configValue + * @return array + */ + private function setConfig(array $config, $configPath, $configValue) + { + if ($configValue === null) { + return $config; + } + + $config = $this->arrayManager->set( + $configPath, + $config, + $configValue + ); + + return $config; + } + + /** + * Generate config prefix from given $scope and $scopeCode. + * If $scope isn't equal to 'default' and $scopeCode isn't empty put $scopeCode into prefix path, + * otherwise ignore $scopeCode. + * + * @param string $scope + * @param string $scopeCode + * @return string + */ + private function getPathPrefix($scope, $scopeCode) + { + $pathPrefixes = [System::CONFIG_TYPE, $scope]; + if ( + $scope !== ScopeConfigInterface::SCOPE_TYPE_DEFAULT + && !empty($scopeCode) + ) { + $pathPrefixes[] = $scopeCode; + } + + return implode('/', $pathPrefixes) . '/'; + } +} diff --git a/app/code/Magento/Deploy/Model/Filesystem.php b/app/code/Magento/Deploy/Model/Filesystem.php index 83de641c4442a445cceb020cad060ce2c4809f5b..7918207934759bd1cb003e676c3b74a41330777c 100644 --- a/app/code/Magento/Deploy/Model/Filesystem.php +++ b/app/code/Magento/Deploy/Model/Filesystem.php @@ -13,7 +13,8 @@ use Magento\Framework\Exception\LocalizedException; use Magento\User\Model\ResourceModel\User\Collection as UserCollection; /** - * Generate static files, compile; clear var/generation, var/di/, var/view_preprocessed and pub/static directories + * Generate static files, compile + * Сlear generated/code, generated/metadata/, var/view_preprocessed and pub/static directories * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ @@ -129,7 +130,7 @@ class Filesystem public function regenerateStatic( OutputInterface $output ) { - // Сlear var/generation, var/di/, var/view_preprocessed and pub/static directories + // Сlear generated/code, generated/metadata/, var/view_preprocessed and pub/static directories $this->cleanupFilesystem( [ DirectoryList::CACHE, @@ -315,7 +316,7 @@ class Filesystem */ public function lockStaticResources() { - // Lock /var/generation, /var/di/ and /var/view_preprocessed directories + // Lock /generated/code, /generated/metadata/ and /var/view_preprocessed directories $this->changePermissions( [ DirectoryList::GENERATION, diff --git a/app/code/Magento/Deploy/Test/Unit/Console/Command/App/SensitiveConfigSet/CollectorFactoryTest.php b/app/code/Magento/Deploy/Test/Unit/Console/Command/App/SensitiveConfigSet/CollectorFactoryTest.php new file mode 100644 index 0000000000000000000000000000000000000000..c16fa1d7c176db14d525444a3f18e2231258a31f --- /dev/null +++ b/app/code/Magento/Deploy/Test/Unit/Console/Command/App/SensitiveConfigSet/CollectorFactoryTest.php @@ -0,0 +1,81 @@ +<?php +/** + * Copyright © 2013-2017 Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Deploy\Test\Unit\Console\Command\App\SensitiveConfigSet; + +use Magento\Deploy\Console\Command\App\SensitiveConfigSet\CollectorFactory; +use Magento\Deploy\Console\Command\App\SensitiveConfigSet\CollectorInterface; +use Magento\Deploy\Console\Command\App\SensitiveConfigSet\InteractiveCollector; +use Magento\Deploy\Console\Command\App\SensitiveConfigSet\SimpleCollector; +use Magento\Framework\ObjectManagerInterface; +use PHPUnit_Framework_MockObject_MockObject as MockObject; +use stdClass; + +class CollectorFactoryTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var ObjectManagerInterface|MockObject + */ + private $objectManagerMock; + + /** + * @var CollectorFactory + */ + private $model; + + protected function setUp() + { + $this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class) + ->getMockForAbstractClass(); + + $this->model = new CollectorFactory( + $this->objectManagerMock, + [ + CollectorFactory::TYPE_SIMPLE => SimpleCollector::class, + CollectorFactory::TYPE_INTERACTIVE => InteractiveCollector::class, + 'wrongType' => stdClass::class, + ] + ); + } + + public function testCreate() + { + $collectorMock = $this->getMockBuilder(CollectorInterface::class) + ->getMockForAbstractClass(); + $this->objectManagerMock->expects($this->once()) + ->method('create') + ->with(SimpleCollector::class) + ->willReturn($collectorMock); + + $this->assertInstanceOf( + CollectorInterface::class, + $this->model->create(CollectorFactory::TYPE_SIMPLE) + ); + } + + /** + * @expectedException \Magento\Framework\Exception\LocalizedException + * @expectedExceptionMessage Class for type "dummyType" was not declared + */ + public function testCreateNonExisted() + { + $this->model->create('dummyType'); + } + + /** + * @expectedException \Magento\Framework\Exception\LocalizedException + * @expectedExceptionMessage stdClass does not implement + */ + public function testCreateWrongImplementation() + { + $type = 'wrongType'; + $this->objectManagerMock->expects($this->once()) + ->method('create') + ->with(stdClass::class) + ->willReturn(new stdClass()); + + $this->model->create($type); + } +} diff --git a/app/code/Magento/Deploy/Test/Unit/Console/Command/App/SensitiveConfigSet/InteractiveCollectorTest.php b/app/code/Magento/Deploy/Test/Unit/Console/Command/App/SensitiveConfigSet/InteractiveCollectorTest.php new file mode 100644 index 0000000000000000000000000000000000000000..91576c89463726db1e0f034e72ac96e418770083 --- /dev/null +++ b/app/code/Magento/Deploy/Test/Unit/Console/Command/App/SensitiveConfigSet/InteractiveCollectorTest.php @@ -0,0 +1,100 @@ +<?php +/** + * Copyright © 2013-2017 Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Deploy\Test\Unit\Console\Command\App\SensitiveConfigSet; + +use Magento\Deploy\Console\Command\App\SensitiveConfigSet\InteractiveCollector; +use PHPUnit_Framework_MockObject_MockObject as MockObject; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Question\Question; +use Symfony\Component\Console\Question\QuestionFactory; +use Symfony\Component\Console\Helper\QuestionHelper; + +class InteractiveCollectorTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var QuestionFactory|MockObject + */ + private $questionFactoryMock; + + /** + * @var QuestionHelper|MockObject + */ + private $questionHelperMock; + + /** + * @var InputInterface|MockObject + */ + private $inputMock; + + /** + * @var OutputInterface|MockObject + */ + private $outputMock; + + /** + * @var InteractiveCollector + */ + private $model; + + protected function setUp() + { + $this->questionFactoryMock = $this->getMockBuilder(QuestionFactory::class) + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->questionHelperMock = $this->getMockBuilder(QuestionHelper::class) + ->disableOriginalConstructor() + ->getMock(); + $this->inputMock = $this->getMockBuilder(InputInterface::class) + ->getMockForAbstractClass(); + $this->outputMock = $this->getMockBuilder(OutputInterface::class) + ->getMockForAbstractClass(); + + $this->model = new InteractiveCollector( + $this->questionFactoryMock, + $this->questionHelperMock + ); + } + + public function testGetValues() + { + $configPaths = [ + 'some/config/path1', + 'some/config/path2', + 'some/config/path3' + ]; + + $questionMock = $this->getMockBuilder(Question::class) + ->disableOriginalConstructor() + ->getMock(); + $this->questionHelperMock->expects($this->exactly(3)) + ->method('ask') + ->with($this->inputMock, $this->outputMock, $questionMock) + ->willReturn('someValue'); + $this->questionFactoryMock->expects($this->exactly(3)) + ->method('create') + ->withConsecutive( + [['question' => $configPaths[0] . ': ']], + [['question' => $configPaths[1] . ': ']], + [['question' => $configPaths[2] . ': ']] + ) + ->willReturn($questionMock); + + $this->assertEquals( + [ + 'some/config/path1' => 'someValue', + 'some/config/path2' => 'someValue', + 'some/config/path3' => 'someValue' + ], + $this->model->getValues( + $this->inputMock, + $this->outputMock, + $configPaths + ) + ); + } +} diff --git a/app/code/Magento/Deploy/Test/Unit/Console/Command/App/SensitiveConfigSet/SimpleCollectorTest.php b/app/code/Magento/Deploy/Test/Unit/Console/Command/App/SensitiveConfigSet/SimpleCollectorTest.php new file mode 100644 index 0000000000000000000000000000000000000000..124fc4b0119e377f508e8b1b22439446bd9d8fe4 --- /dev/null +++ b/app/code/Magento/Deploy/Test/Unit/Console/Command/App/SensitiveConfigSet/SimpleCollectorTest.php @@ -0,0 +1,187 @@ +<?php +/** + * Copyright © 2013-2017 Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Deploy\Test\Unit\Console\Command\App\SensitiveConfigSet; + +use Magento\Deploy\Console\Command\App\SensitiveConfigSet\SimpleCollector; +use Magento\Deploy\Console\Command\App\SensitiveConfigSetCommand; +use Magento\Framework\Exception\LocalizedException; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Question\Question; +use Symfony\Component\Console\Question\QuestionFactory; +use Symfony\Component\Console\Helper\QuestionHelper; +use PHPUnit_Framework_MockObject_MockObject as MockObject; + +class SimpleCollectorTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var QuestionFactory|MockObject + */ + private $questionFactoryMock; + + /** + * @var QuestionHelper|MockObject + */ + private $questionHelperMock; + + /** + * @var InputInterface|MockObject + */ + private $inputMock; + + /** + * @var OutputInterface|MockObject + */ + private $outputMock; + + /** + * @var SimpleCollector + */ + private $model; + + protected function setUp() + { + $this->questionFactoryMock = $this->getMockBuilder(QuestionFactory::class) + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->questionHelperMock = $this->getMockBuilder(QuestionHelper::class) + ->disableOriginalConstructor() + ->getMock(); + $this->inputMock = $this->getMockBuilder(InputInterface::class) + ->getMockForAbstractClass(); + $this->outputMock = $this->getMockBuilder(OutputInterface::class) + ->getMockForAbstractClass(); + + $this->model = new SimpleCollector( + $this->questionFactoryMock, + $this->questionHelperMock + ); + } + + public function testGetValues() + { + $configPaths = [ + 'some/config/path1', + 'some/config/path2' + ]; + + $pathQuestionMock = $this->getMockBuilder(Question::class) + ->disableOriginalConstructor() + ->getMock(); + $valueQuestionMock = $this->getMockBuilder(Question::class) + ->disableOriginalConstructor() + ->getMock(); + $this->inputMock->expects($this->exactly(2)) + ->method('getArgument') + ->withConsecutive( + [SensitiveConfigSetCommand::INPUT_ARGUMENT_PATH], + [SensitiveConfigSetCommand::INPUT_ARGUMENT_VALUE] + ) + ->willReturnOnConsecutiveCalls( + $configPaths[0], + 'someValue' + ); + $this->questionFactoryMock->expects($this->exactly(2)) + ->method('create') + ->withConsecutive( + [['question' => 'Please enter config path: ']], + [['question' => 'Please enter value: ']] + ) + ->willReturnOnConsecutiveCalls( + $pathQuestionMock, + $valueQuestionMock + ); + + $this->assertEquals( + ['some/config/path1' => 'someValue'], + $this->model->getValues( + $this->inputMock, + $this->outputMock, + $configPaths + ) + ); + } + + /** + * @expectedException \Magento\Framework\Exception\LocalizedException + * @expectedExceptionMessage A configuration with this path does not exist or is not sensitive + */ + public function testWrongConfigPath() + { + $configPaths = [ + 'some/config/path1', + 'some/config/path2' + ]; + + $pathQuestionMock = $this->getMockBuilder(Question::class) + ->disableOriginalConstructor() + ->getMock(); + $this->inputMock->expects($this->once()) + ->method('getArgument') + ->with(SensitiveConfigSetCommand::INPUT_ARGUMENT_PATH) + ->willReturn('some/not_exist/config'); + $this->questionFactoryMock->expects($this->once()) + ->method('create') + ->with(['question' => 'Please enter config path: ']) + ->willReturn($pathQuestionMock); + + $this->model->getValues( + $this->inputMock, + $this->outputMock, + $configPaths + ); + } + + /** + * @expectedException \Magento\Framework\Exception\LocalizedException + */ + public function testEmptyValue() + { + $configPaths = [ + 'some/config/path1', + 'some/config/path2' + ]; + $message = 'exception message'; + + $pathQuestionMock = $this->getMockBuilder(Question::class) + ->disableOriginalConstructor() + ->getMock(); + $valueQuestionMock = $this->getMockBuilder(Question::class) + ->disableOriginalConstructor() + ->getMock(); + $this->questionHelperMock->expects($this->once()) + ->method('ask') + ->with($this->inputMock, $this->outputMock, $valueQuestionMock) + ->willThrowException(new LocalizedException(__($message))); + $this->inputMock->expects($this->exactly(2)) + ->method('getArgument') + ->withConsecutive( + [SensitiveConfigSetCommand::INPUT_ARGUMENT_PATH], + [SensitiveConfigSetCommand::INPUT_ARGUMENT_VALUE] + ) + ->willReturnOnConsecutiveCalls( + $configPaths[0], + null + ); + $this->questionFactoryMock->expects($this->exactly(2)) + ->method('create') + ->withConsecutive( + [['question' => 'Please enter config path: ']], + [['question' => 'Please enter value: ']] + ) + ->willReturnOnConsecutiveCalls( + $pathQuestionMock, + $valueQuestionMock + ); + + $this->model->getValues( + $this->inputMock, + $this->outputMock, + $configPaths + ); + } +} diff --git a/app/code/Magento/Deploy/Test/Unit/Console/Command/App/SensitiveConfigSetCommandTest.php b/app/code/Magento/Deploy/Test/Unit/Console/Command/App/SensitiveConfigSetCommandTest.php new file mode 100644 index 0000000000000000000000000000000000000000..b305ed8249fbff8d80854385f1f3fa79d1204541 --- /dev/null +++ b/app/code/Magento/Deploy/Test/Unit/Console/Command/App/SensitiveConfigSetCommandTest.php @@ -0,0 +1,262 @@ +<?php +/** + * Copyright © 2013-2017 Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Deploy\Test\Unit\Console\Command\App; + +use Magento\Deploy\Console\Command\App\SensitiveConfigSet\CollectorFactory; +use Magento\Deploy\Console\Command\App\SensitiveConfigSet\CollectorInterface; +use Magento\Deploy\Console\Command\App\SensitiveConfigSetCommand; +use Magento\Deploy\Model\ConfigWriter; +use Magento\Framework\App\Config\CommentParserInterface; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\Scope\ValidatorInterface; +use Magento\Framework\Config\File\ConfigFilePool; +use Magento\Framework\Console\Cli; +use Magento\Framework\Exception\FileSystemException; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Phrase; +use PHPUnit_Framework_MockObject_MockObject as MockObject; +use Symfony\Component\Console\Tester\CommandTester; + +/** + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ +class SensitiveConfigSetCommandTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var ConfigFilePool|MockObject + */ + private $configFilePoolMock; + + /** + * @var CommentParserInterface|MockObject + */ + private $commentParserMock; + + /** + * @var ConfigWriter|MockObject + */ + private $configWriterMock; + + /** + * @var ValidatorInterface|MockObject + */ + private $scopeValidatorMock; + + /** + * @var CollectorFactory|MockObject + */ + private $collectorFactoryMock; + + /** + * @var SensitiveConfigSetCommand + */ + private $command; + + public function setUp() + { + $this->configFilePoolMock = $this->getMockBuilder(ConfigFilePool::class) + ->disableOriginalConstructor() + ->getMock(); + $this->commentParserMock = $this->getMockBuilder(CommentParserInterface::class) + ->getMockForAbstractClass(); + $this->configWriterMock = $this->getMockBuilder(ConfigWriter::class) + ->disableOriginalConstructor() + ->getMock(); + $this->scopeValidatorMock = $this->getMockBuilder(ValidatorInterface::class) + ->getMockForAbstractClass(); + $this->collectorFactoryMock = $this->getMockBuilder(CollectorFactory::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->command = new SensitiveConfigSetCommand( + $this->configFilePoolMock, + $this->commentParserMock, + $this->configWriterMock, + $this->scopeValidatorMock, + $this->collectorFactoryMock + ); + } + + public function testConfigFileNotExist() + { + $this->configFilePoolMock->expects($this->once()) + ->method('getPathsByPool') + ->with(ConfigFilePool::LOCAL) + ->willReturn([ + ConfigFilePool::APP_CONFIG => 'config.local.php' + ]); + $this->scopeValidatorMock->expects($this->once()) + ->method('isValid') + ->with('default', '') + ->willReturn(true); + $this->commentParserMock->expects($this->any()) + ->method('execute') + ->willThrowException(new FileSystemException(new Phrase('some message'))); + + $tester = new CommandTester($this->command); + $tester->execute([ + 'path' => 'some/path', + 'value' => 'some value' + ]); + + $this->assertEquals( + Cli::RETURN_FAILURE, + $tester->getStatusCode() + ); + $this->assertContains( + 'File app/etc/config.local.php can\'t be read. ' + . 'Please check if it exists and has read permissions.', + $tester->getDisplay() + ); + } + + public function testWriterException() + { + $exceptionMessage = 'exception'; + $this->scopeValidatorMock->expects($this->once()) + ->method('isValid') + ->with('default', '') + ->willReturn(true); + $this->commentParserMock->expects($this->once()) + ->method('execute') + ->willReturn([ + 'some/config/path1', + 'some/config/path2' + ]); + $collectorMock = $this->getMockBuilder(CollectorInterface::class) + ->getMockForAbstractClass(); + $collectorMock->expects($this->once()) + ->method('getValues') + ->willReturn(['some/config/pathNotExist' => 'value']); + $this->collectorFactoryMock->expects($this->once()) + ->method('create') + ->with(CollectorFactory::TYPE_SIMPLE) + ->willReturn($collectorMock); + $this->configWriterMock->expects($this->once()) + ->method('save') + ->willThrowException(new LocalizedException(__($exceptionMessage))); + + $tester = new CommandTester($this->command); + $tester->execute([ + 'path' => 'some/config/pathNotExist', + 'value' => 'some value' + ]); + + $this->assertEquals( + Cli::RETURN_FAILURE, + $tester->getStatusCode() + ); + $this->assertContains( + $exceptionMessage, + $tester->getDisplay() + ); + } + + public function testEmptyConfigPaths() + { + $this->scopeValidatorMock->expects($this->once()) + ->method('isValid') + ->with('default', '') + ->willReturn(true); + $this->commentParserMock->expects($this->once()) + ->method('execute') + ->willReturn([]); + + $tester = new CommandTester($this->command); + $tester->execute([ + 'path' => 'some/config/pathNotExist', + 'value' => 'some value' + ]); + + $this->assertEquals( + Cli::RETURN_FAILURE, + $tester->getStatusCode() + ); + $this->assertContains( + 'There are no sensitive configurations to fill', + $tester->getDisplay() + ); + } + + public function testExecute() + { + $collectedValues = ['some/config/path1' => 'value']; + $this->scopeValidatorMock->expects($this->once()) + ->method('isValid') + ->with('default', '') + ->willReturn(true); + $this->commentParserMock->expects($this->once()) + ->method('execute') + ->willReturn([ + 'some/config/path1', + 'some/config/path2' + ]); + $collectorMock = $this->getMockBuilder(CollectorInterface::class) + ->getMockForAbstractClass(); + $collectorMock->expects($this->once()) + ->method('getValues') + ->willReturn($collectedValues); + $this->collectorFactoryMock->expects($this->once()) + ->method('create') + ->with(CollectorFactory::TYPE_SIMPLE) + ->willReturn($collectorMock); + $this->configWriterMock->expects($this->once()) + ->method('save') + ->with($collectedValues, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, ''); + + $tester = new CommandTester($this->command); + $tester->execute([]); + + $this->assertEquals( + Cli::RETURN_SUCCESS, + $tester->getStatusCode() + ); + $this->assertContains( + 'Configuration value saved in', + $tester->getDisplay() + ); + } + + public function testExecuteInteractive() + { + $collectedValues = ['some/config/path1' => 'value']; + $this->scopeValidatorMock->expects($this->once()) + ->method('isValid') + ->with('default', '') + ->willReturn(true); + $this->commentParserMock->expects($this->once()) + ->method('execute') + ->willReturn([ + 'some/config/path1', + 'some/config/path2', + 'some/config/path3' + ]); + $collectorMock = $this->getMockBuilder(CollectorInterface::class) + ->getMockForAbstractClass(); + $collectorMock->expects($this->once()) + ->method('getValues') + ->willReturn($collectedValues); + $this->collectorFactoryMock->expects($this->once()) + ->method('create') + ->with(CollectorFactory::TYPE_INTERACTIVE) + ->willReturn($collectorMock); + $this->configWriterMock->expects($this->once()) + ->method('save') + ->with($collectedValues, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, ''); + + $tester = new CommandTester($this->command); + $tester->execute(['--interactive' => true]); + + $this->assertEquals( + Cli::RETURN_SUCCESS, + $tester->getStatusCode() + ); + $this->assertContains( + 'Configuration values saved in', + $tester->getDisplay() + ); + } +} diff --git a/app/code/Magento/Deploy/Test/Unit/Model/ConfigWriterTest.php b/app/code/Magento/Deploy/Test/Unit/Model/ConfigWriterTest.php new file mode 100644 index 0000000000000000000000000000000000000000..9ac0097d5f73b69ea9bf02cafa7cd4773d9a810e --- /dev/null +++ b/app/code/Magento/Deploy/Test/Unit/Model/ConfigWriterTest.php @@ -0,0 +1,93 @@ +<?php +/** + * Copyright © 2013-2017 Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Deploy\Test\Unit\Model; + +use Magento\Deploy\Model\ConfigWriter; +use Magento\Framework\App\DeploymentConfig\Writer; +use Magento\Framework\Config\File\ConfigFilePool; +use Magento\Framework\Stdlib\ArrayManager; +use PHPUnit_Framework_MockObject_MockObject as MockObject; + +class ConfigWriterTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var Writer|MockObject + */ + private $writerMock; + + /** + * @var ArrayManager|MockObject + */ + private $arrayManagerMock; + + /** + * @var ConfigWriter + */ + private $model; + + public function setUp() + { + $this->arrayManagerMock = $this->getMockBuilder(ArrayManager::class) + ->disableOriginalConstructor() + ->getMock(); + $this->writerMock = $this->getMockBuilder(Writer::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->model = new ConfigWriter( + $this->writerMock, + $this->arrayManagerMock + ); + } + + public function testSave() + { + $values = [ + 'some1/config1/path1' => 'someValue1', + 'some2/config2/path2' => 'someValue2', + 'some3/config3/path3' => 'someValue3' + ]; + $config = ['system' => []]; + + $this->arrayManagerMock->expects($this->exactly(3)) + ->method('set') + ->withConsecutive( + ['system/scope/scope_code/some1/config1/path1', $this->anything(), 'someValue1'], + ['system/scope/scope_code/some2/config2/path2', $this->anything(), 'someValue2'], + ['system/scope/scope_code/some3/config3/path3', $this->anything(), 'someValue3'] + ) + ->willReturn($config); + $this->writerMock->expects($this->once()) + ->method('saveConfig') + ->with([ConfigFilePool::APP_CONFIG => $config]); + + $this->model->save($values, 'scope', 'scope_code'); + } + + public function testSaveDefaultScope() + { + $values = [ + 'some1/config1/path1' => 'someValue1', + 'some2/config2/path2' => 'someValue2', + 'some3/config3/path3' => 'someValue3' + ]; + $config = ['system' => []]; + + $this->arrayManagerMock->expects($this->exactly(3)) + ->method('set') + ->withConsecutive( + ['system/default/some1/config1/path1', $this->anything(), 'someValue1'], + ['system/default/some2/config2/path2', $this->anything(), 'someValue2'], + ['system/default/some3/config3/path3', $this->anything(), 'someValue3'] + ) + ->willReturn($config); + $this->writerMock->expects($this->once()) + ->method('saveConfig') + ->with([ConfigFilePool::APP_CONFIG => $config]); + + $this->model->save($values); + } +} diff --git a/app/code/Magento/Deploy/composer.json b/app/code/Magento/Deploy/composer.json index ed0b8520ca645afa8af2506616f9dccde6965f08..436c3a6451c39b3e65ae65e3740b402bbc75fe80 100644 --- a/app/code/Magento/Deploy/composer.json +++ b/app/code/Magento/Deploy/composer.json @@ -6,7 +6,8 @@ "magento/framework": "100.2.*", "magento/module-store": "100.2.*", "magento/module-require-js": "100.2.*", - "magento/module-user": "100.2.*" + "magento/module-user": "100.2.*", + "magento/module-config": "100.2.*" }, "type": "magento2-module", "version": "100.2.0-dev", diff --git a/app/code/Magento/Deploy/etc/di.xml b/app/code/Magento/Deploy/etc/di.xml index 68fa7d909e4df8a3b13f3ef01a8f178d804feb4d..6751dd1e0b161dfee948436818a7f38c50025daf 100644 --- a/app/code/Magento/Deploy/etc/di.xml +++ b/app/code/Magento/Deploy/etc/di.xml @@ -26,6 +26,7 @@ <item name="setModeCommand" xsi:type="object">Magento\Deploy\Console\Command\SetModeCommand</item> <item name="showModeCommand" xsi:type="object">Magento\Deploy\Console\Command\ShowModeCommand</item> <item name="dumpApplicationCommand" xsi:type="object">\Magento\Deploy\Console\Command\App\ApplicationDumpCommand</item> + <item name="sensitiveConfigSetCommand" xsi:type="object">\Magento\Deploy\Console\Command\App\SensitiveConfigSetCommand</item> </argument> </arguments> </type> @@ -34,4 +35,12 @@ <argument name="shell" xsi:type="object">Magento\Framework\App\Shell</argument> </arguments> </type> + <type name="Magento\Deploy\Console\Command\App\SensitiveConfigSet\CollectorFactory"> + <arguments> + <argument name="types" xsi:type="array"> + <item name="interactive" xsi:type="string">Magento\Deploy\Console\Command\App\SensitiveConfigSet\InteractiveCollector</item> + <item name="simple" xsi:type="string">Magento\Deploy\Console\Command\App\SensitiveConfigSet\SimpleCollector</item> + </argument> + </arguments> + </type> </config> diff --git a/app/code/Magento/Fedex/etc/di.xml b/app/code/Magento/Fedex/etc/di.xml new file mode 100644 index 0000000000000000000000000000000000000000..e2f5142cde96b5f82c10175da290e680e79f419c --- /dev/null +++ b/app/code/Magento/Fedex/etc/di.xml @@ -0,0 +1,19 @@ +<?xml version="1.0"?> +<!-- +/** + * Copyright © 2013-2017 Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> + <type name="Magento\Config\Model\Config\Export\ExcludeList"> + <arguments> + <argument name="configs" xsi:type="array"> + <item name="carriers/fedex/account" xsi:type="string">1</item> + <item name="carriers/fedex/key" xsi:type="string">1</item> + <item name="carriers/fedex/meter_number" xsi:type="string">1</item> + <item name="carriers/fedex/password" xsi:type="string">1</item> + </argument> + </arguments> + </type> +</config> \ No newline at end of file diff --git a/app/code/Magento/Payment/Test/Unit/Block/Info/SubstitutionTest.php b/app/code/Magento/Payment/Test/Unit/Block/Info/SubstitutionTest.php index 78946d236391e90eccec0d29def00f810db91eea..f4a2b1a81d7feeead8c6365f5291b6dd9466f02a 100644 --- a/app/code/Magento/Payment/Test/Unit/Block/Info/SubstitutionTest.php +++ b/app/code/Magento/Payment/Test/Unit/Block/Info/SubstitutionTest.php @@ -3,9 +3,6 @@ * Copyright © 2013-2017 Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - -// @codingStandardsIgnoreFile - namespace Magento\Payment\Test\Unit\Block\Info; /** @@ -31,71 +28,23 @@ class SubstitutionTest extends \PHPUnit_Framework_TestCase protected function setUp() { $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - - $this->layout = $this->getMockBuilder( - \Magento\Framework\View\LayoutInterface::class - )->disableOriginalConstructor()->setMethods( - [] - )->getMock(); - - $eventManager = $this->getMockBuilder( - \Magento\Framework\Event\ManagerInterface::class - )->disableOriginalConstructor()->setMethods( - [] - )->getMock(); - - $scopeConfig = $this->getMockBuilder( - \Magento\Framework\App\Config\ScopeConfigInterface::class - )->disableOriginalConstructor()->setMethods( - [] - )->getMock(); - $scopeConfig->expects( - $this->any() - )->method( - 'getValue' - )->with( - $this->stringContains( - 'advanced/modules_disable_output/' - ), - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - )->will( - $this->returnValue( - false - ) - ); - - $context = $this->getMockBuilder( - \Magento\Framework\View\Element\Template\Context::class - )->disableOriginalConstructor()->setMethods( - ['getLayout', 'getEventManager', 'getScopeConfig'] - )->getMock(); - $context->expects( - $this->any() - )->method( - 'getLayout' - )->will( - $this->returnValue( - $this->layout - ) - ); - $context->expects( - $this->any() - )->method( - 'getEventManager' - )->will( - $this->returnValue( - $eventManager - ) - ); - $context->expects( - $this->any() - )->method( - 'getScopeConfig' - )->will( - $this->returnValue( - $scopeConfig - ) - ); + $this->layout = $this->getMockBuilder(\Magento\Framework\View\LayoutInterface::class) + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $eventManager = $this->getMockBuilder(\Magento\Framework\Event\ManagerInterface::class) + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $context = $this->getMockBuilder(\Magento\Framework\View\Element\Template\Context::class) + ->disableOriginalConstructor() + ->setMethods(['getLayout', 'getEventManager', 'getScopeConfig']) + ->getMock(); + $context->expects($this->any()) + ->method('getLayout') + ->willReturn($this->layout); + $context->expects($this->any())->method('getEventManager') + ->willReturn($eventManager); $this->block = $this->objectManager->getObject( \Magento\Payment\Block\Info\Substitution::class, @@ -110,52 +59,45 @@ class SubstitutionTest extends \PHPUnit_Framework_TestCase public function testBeforeToHtml() { - $abstractBlock = $this->getMockBuilder( - \Magento\Framework\View\Element\AbstractBlock::class - )->disableOriginalConstructor()->setMethods( - [] - )->getMock(); - $childAbstractBlock = clone($abstractBlock); - - $abstractBlock->expects($this->any())->method('getParentBlock')->will($this->returnValue($childAbstractBlock)); + $abstractBlock = $this->getMockBuilder(\Magento\Framework\View\Element\AbstractBlock::class) + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $childAbstractBlock = clone $abstractBlock; + + $abstractBlock->expects($this->any()) + ->method('getParentBlock') + ->willReturn($childAbstractBlock); + $this->layout->expects($this->any()) + ->method('getParentName') + ->willReturn('parentName'); + $this->layout->expects($this->any()) + ->method('getBlock') + ->willReturn($abstractBlock); + + $infoMock = $this->getMockBuilder(\Magento\Payment\Model\Info::class) + ->disableOriginalConstructor() + ->getMock(); + $methodMock = $this->getMockBuilder(\Magento\Payment\Model\MethodInterface::class) + ->getMockForAbstractClass(); + $infoMock->expects($this->once()) + ->method('getMethodInstance') + ->willReturn($methodMock); - $this->layout->expects($this->any())->method('getParentName')->will($this->returnValue('parentName')); - $this->layout->expects($this->any())->method('getBlock')->will($this->returnValue($abstractBlock)); - - $infoMock = $this->getMockBuilder( - \Magento\Payment\Model\Info::class - )->disableOriginalConstructor()->setMethods( - [] - )->getMock(); - $methodMock = $this->getMockBuilder( - \Magento\Payment\Model\MethodInterface::class - )->getMockForAbstractClass(); - $infoMock->expects($this->once())->method('getMethodInstance')->will($this->returnValue($methodMock)); $this->block->setInfo($infoMock); $fakeBlock = new \StdClass(); - $this->layout->expects( - $this->any() - )->method( - 'createBlock' - )->with( - \Magento\Framework\View\Element\Template::class, - '', - ['data' => ['method' => $methodMock, 'template' => 'Magento_Payment::info/substitution.phtml']] - )->will( - $this->returnValue( - $fakeBlock - ) - ); - - $childAbstractBlock->expects( - $this->any() - )->method( - 'setChild' - )->with( - 'order_payment_additional', - $fakeBlock - ); + $this->layout->expects($this->any()) + ->method('createBlock') + ->with( + \Magento\Framework\View\Element\Template::class, + '', + ['data' => ['method' => $methodMock, 'template' => 'Magento_Payment::info/substitution.phtml']] + )->willReturn($fakeBlock); + + $childAbstractBlock->expects($this->any()) + ->method('setChild') + ->with('order_payment_additional', $fakeBlock); $this->block->toHtml(); } diff --git a/app/code/Magento/Paypal/Test/Unit/Block/Billing/AgreementsTest.php b/app/code/Magento/Paypal/Test/Unit/Block/Billing/AgreementsTest.php index f478ea085e47a378573fc945a1afdf77b6eb942a..64f278c8e9f118b6b7e564da0c6de434052d4184 100644 --- a/app/code/Magento/Paypal/Test/Unit/Block/Billing/AgreementsTest.php +++ b/app/code/Magento/Paypal/Test/Unit/Block/Billing/AgreementsTest.php @@ -243,10 +243,6 @@ class AgreementsTest extends \PHPUnit_Framework_TestCase ->expects($this->at(1)) ->method('dispatch') ->with('view_block_abstract_to_html_after', ['block' => $this->block, 'transport' => $transport]); - $this->scopeConfig - ->expects($this->once()) - ->method('getValue') - ->willReturn(false); $this->urlBuilder->expects($this->once())->method('getUrl')->with('paypal/billing_agreement/startWizard', []); $this->block->toHtml(); } diff --git a/app/code/Magento/Paypal/Test/Unit/Block/Express/ReviewTest.php b/app/code/Magento/Paypal/Test/Unit/Block/Express/ReviewTest.php index cf16349e5873468cef013f42601895a28244cba5..17468c02578693be75efd4af8bbef3f73d868871 100644 --- a/app/code/Magento/Paypal/Test/Unit/Block/Express/ReviewTest.php +++ b/app/code/Magento/Paypal/Test/Unit/Block/Express/ReviewTest.php @@ -3,11 +3,9 @@ * Copyright © 2013-2017 Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - namespace Magento\Paypal\Test\Unit\Block\Express; use Magento\Paypal\Block\Express\Review; -use Magento\Quote\Model\Quote\Address\Rate; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -35,14 +33,6 @@ class ReviewTest extends \PHPUnit_Framework_TestCase $layout = $this->getMock(\Magento\Framework\View\LayoutInterface::class, [], [], '', false); $eventManager = $this->getMock(\Magento\Framework\Event\ManagerInterface::class, [], [], '', false); - $scopeConfig = $this->getMock(\Magento\Framework\App\Config\ScopeConfigInterface::class, [], [], '', false); - - $scopeConfig->expects($this->any()) - ->method('getValue') - ->with( - $this->stringContains('advanced/modules_disable_output/'), - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - )->will($this->returnValue(false)); $urlBuilder = $this->getMock(\Magento\Framework\UrlInterface::class); $urlBuilder->expects($this->any())->method('getUrl')->will($this->returnArgument(0)); @@ -60,7 +50,6 @@ class ReviewTest extends \PHPUnit_Framework_TestCase $context->expects($this->any())->method('getLayout')->will($this->returnValue($layout)); $context->expects($this->any())->method('getEventManager')->will($this->returnValue($eventManager)); - $context->expects($this->any())->method('getScopeConfig')->will($this->returnValue($scopeConfig)); $context->expects($this->any())->method('getRequest')->will($this->returnValue($this->request)); $context->expects($this->any())->method('getAssetRepository')->will($this->returnValue($this->assetRepo)); $context->expects($this->any())->method('getUrlBuilder')->will($this->returnValue($urlBuilder)); diff --git a/app/code/Magento/Persistent/Test/Unit/Block/Header/AdditionalTest.php b/app/code/Magento/Persistent/Test/Unit/Block/Header/AdditionalTest.php index 44b494f2a41df8c7394c83396387d577bbb5e641..f80c1018d322c35bd8dd823e2c6e1d0d58fca96b 100644 --- a/app/code/Magento/Persistent/Test/Unit/Block/Header/AdditionalTest.php +++ b/app/code/Magento/Persistent/Test/Unit/Block/Header/AdditionalTest.php @@ -149,8 +149,7 @@ class AdditionalTest extends \PHPUnit_Framework_TestCase '', false, true, - true, - ['getValue'] + true ); $this->cacheStateMock = $this->getMockForAbstractClass( \Magento\Framework\App\Cache\StateInterface::class, @@ -267,12 +266,6 @@ class AdditionalTest extends \PHPUnit_Framework_TestCase $this->eventManagerMock->expects($this->at(1)) ->method('dispatch') ->with('view_block_abstract_to_html_after'); - $this->scopeConfigMock->expects($this->once()) - ->method('getValue') - ->with( - 'advanced/modules_disable_output/Magento_Persistent', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - )->willReturn(false); // get cache $this->cacheStateMock->expects($this->at(0)) diff --git a/app/code/Magento/Store/Model/Scope/Validator.php b/app/code/Magento/Store/Model/Scope/Validator.php new file mode 100644 index 0000000000000000000000000000000000000000..f2222fdc476a9a61ee9ed37c285332561f6dd43b --- /dev/null +++ b/app/code/Magento/Store/Model/Scope/Validator.php @@ -0,0 +1,88 @@ +<?php +/** + * Copyright © 2013-2017 Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Store\Model\Scope; + +use InvalidArgumentException; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\Scope\ValidatorInterface; +use Magento\Framework\App\ScopeResolverPool; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Exception\NoSuchEntityException; + +/** + * Class Validator validates scope and scope code. + */ +class Validator implements ValidatorInterface +{ + /** + * @var ScopeResolverPool + */ + private $scopeResolverPool; + + /** + * @param ScopeResolverPool $scopeResolverPool + */ + public function __construct(ScopeResolverPool $scopeResolverPool) + { + $this->scopeResolverPool = $scopeResolverPool; + } + + /** + * {@inheritdoc} + */ + public function isValid($scope, $scopeCode = null) + { + if ($scope === ScopeConfigInterface::SCOPE_TYPE_DEFAULT && empty($scopeCode)) { + return true; + } + + if ($scope === ScopeConfigInterface::SCOPE_TYPE_DEFAULT && !empty($scopeCode)) { + throw new LocalizedException(__( + 'The "%1" scope can\'t include a scope code. Try again without entering a scope code.', + ScopeConfigInterface::SCOPE_TYPE_DEFAULT + )); + } + + if (empty($scope)) { + throw new LocalizedException(__('Enter a scope before proceeding.')); + } + + $this->validateScopeCode($scopeCode); + + try { + $scopeResolver = $this->scopeResolverPool->get($scope); + $scopeResolver->getScope($scopeCode)->getId(); + } catch (InvalidArgumentException $e) { + throw new LocalizedException(__('The "%1" value doesn\'t exist. Enter another value.', $scope)); + } catch (NoSuchEntityException $e) { + throw new LocalizedException(__('The "%1" value doesn\'t exist. Enter another value.', $scopeCode)); + } + + return true; + } + + /** + * Validate scope code + * Throw exception if not valid. + * + * @param string $scopeCode + * @return void + * @throws LocalizedException if scope code is empty or has a wrong format + */ + private function validateScopeCode($scopeCode) + { + if (empty($scopeCode)) { + throw new LocalizedException(__('Enter a scope code before proceeding.')); + } + + if (!preg_match('/^[a-z]+[a-z0-9_]*$/', $scopeCode)) { + throw new LocalizedException(__( + 'The scope code can include only lowercase letters (a-z), numbers (0-9) and underscores (_). ' + . 'Also, the first character must be a letter.' + )); + } + } +} diff --git a/app/code/Magento/Store/Test/Unit/Model/Scope/ValidatorTest.php b/app/code/Magento/Store/Test/Unit/Model/Scope/ValidatorTest.php new file mode 100644 index 0000000000000000000000000000000000000000..51c58739f5ff5c10f19ebcbef9d7a92df33611b0 --- /dev/null +++ b/app/code/Magento/Store/Test/Unit/Model/Scope/ValidatorTest.php @@ -0,0 +1,138 @@ +<?php +/** + * Copyright © 2013-2017 Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Store\Test\Unit\Model\Scope; + +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\ScopeInterface; +use Magento\Framework\App\ScopeResolverInterface; +use Magento\Framework\App\ScopeResolverPool; +use Magento\Framework\Exception\NoSuchEntityException; +use Magento\Store\Model\Scope\Validator; +use PHPUnit_Framework_MockObject_MockObject as MockObject; + +class ValidatorTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var Validator + */ + private $model; + + /** + * @var ScopeResolverPool|MockObject + */ + private $scopeResolverPoolMock; + + protected function setUp() + { + $this->scopeResolverPoolMock = $this->getMockBuilder(ScopeResolverPool::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->model = new Validator( + $this->scopeResolverPoolMock + ); + } + + public function testIsValid() + { + $scope = 'not_default_scope'; + $scopeCode = 'not_exist_scope_code'; + + $scopeResolver = $this->getMockBuilder(ScopeResolverInterface::class) + ->getMockForAbstractClass(); + $scopeObject = $this->getMockBuilder(ScopeInterface::class) + ->getMockForAbstractClass(); + $scopeResolver->expects($this->once()) + ->method('getScope') + ->with($scopeCode) + ->willReturn($scopeObject); + $this->scopeResolverPoolMock->expects($this->once()) + ->method('get') + ->with($scope) + ->willReturn($scopeResolver); + + $this->assertTrue($this->model->isValid($scope, $scopeCode)); + } + + public function testIsValidDefault() + { + $this->assertTrue($this->model->isValid(ScopeConfigInterface::SCOPE_TYPE_DEFAULT)); + } + + /** + * @expectedException \Magento\Framework\Exception\LocalizedException + * @expectedExceptionMessage The "default" scope can't include a scope code. Try again without entering a scope + */ + public function testNotEmptyScopeCodeForDefaultScope() + { + $this->model->isValid(ScopeConfigInterface::SCOPE_TYPE_DEFAULT, 'some_code'); + } + + /** + * @expectedException \Magento\Framework\Exception\LocalizedException + * @expectedExceptionMessage Enter a scope before proceeding. + */ + public function testEmptyScope() + { + $this->model->isValid('', 'some_code'); + } + + /** + * @expectedException \Magento\Framework\Exception\LocalizedException + * @expectedExceptionMessage Enter a scope code before proceeding. + */ + public function testEmptyScopeCode() + { + $this->model->isValid('not_default_scope', ''); + } + + /** + * @expectedException \Magento\Framework\Exception\LocalizedException + * @expectedExceptionMessage The scope code can include only lowercase letters (a-z), numbers (0-9) and underscores + */ + public function testWrongScopeCodeFormat() + { + $this->model->isValid('not_default_scope', '123'); + } + + /** + * @expectedException \Magento\Framework\Exception\LocalizedException + * @expectedExceptionMessage The "not_default_scope" value doesn't exist. Enter another value. + */ + public function testScopeNotExist() + { + $scope = 'not_default_scope'; + $this->scopeResolverPoolMock->expects($this->once()) + ->method('get') + ->with($scope) + ->willThrowException(new \InvalidArgumentException()); + + $this->model->isValid($scope, 'scope_code'); + } + + /** + * @expectedException \Magento\Framework\Exception\LocalizedException + * @expectedExceptionMessage The "not_exist_scope_code" value doesn't exist. Enter another value. + */ + public function testScopeCodeNotExist() + { + $scope = 'not_default_scope'; + $scopeCode = 'not_exist_scope_code'; + + $scopeResolver = $this->getMockBuilder(ScopeResolverInterface::class) + ->getMockForAbstractClass(); + $scopeResolver->expects($this->once()) + ->method('getScope') + ->with($scopeCode) + ->willThrowException(new NoSuchEntityException()); + $this->scopeResolverPoolMock->expects($this->once()) + ->method('get') + ->with($scope) + ->willReturn($scopeResolver); + + $this->model->isValid($scope, $scopeCode); + } +} diff --git a/app/code/Magento/Store/etc/di.xml b/app/code/Magento/Store/etc/di.xml index 48a37dec7d73a9ae9fda07cce9c709b3d0b94284..d3b91a57ef3141fb054239ebd919cb48d77ad5e8 100644 --- a/app/code/Magento/Store/etc/di.xml +++ b/app/code/Magento/Store/etc/di.xml @@ -25,6 +25,7 @@ <preference for="Magento\Framework\App\ScopeFallbackResolverInterface" type="Magento\Store\Model\ScopeFallbackResolver"/> <preference for="Magento\Framework\App\ScopeTreeProviderInterface" type="Magento\Store\Model\ScopeTreeProvider"/> <preference for="Magento\Framework\App\ScopeValidatorInterface" type="Magento\Store\Model\ScopeValidator"/> + <preference for="Magento\Framework\App\Scope\ValidatorInterface" type="Magento\Store\Model\Scope\Validator"/> <type name="Magento\Framework\App\Response\Http"> <plugin name="genericHeaderPlugin" type="Magento\Framework\App\Response\HeaderManager"/> </type> diff --git a/app/code/Magento/Widget/Test/Unit/Block/Adminhtml/Widget/Instance/Edit/Chooser/ContainerTest.php b/app/code/Magento/Widget/Test/Unit/Block/Adminhtml/Widget/Instance/Edit/Chooser/ContainerTest.php index 837b7f7135d29d22580aaf1103b9a5c3ae2579d2..c23a8019e37eeb3ebebd8662aea23a773dff036e 100644 --- a/app/code/Magento/Widget/Test/Unit/Block/Adminhtml/Widget/Instance/Edit/Chooser/ContainerTest.php +++ b/app/code/Magento/Widget/Test/Unit/Block/Adminhtml/Widget/Instance/Edit/Chooser/ContainerTest.php @@ -67,7 +67,6 @@ class ContainerTest extends AbstractContainerTest . '<option value="content.top" >Main Content Top</option></select>'; $this->eventManagerMock->expects($this->exactly(2))->method('dispatch')->willReturn(true); - $this->scopeConfigMock->expects($this->once())->method('getValue')->willReturn(false); $this->themeCollectionFactoryMock->expects($this->once()) ->method('create') @@ -154,7 +153,6 @@ class ContainerTest extends AbstractContainerTest . '<option value="sidebar.main" >Sidebar Main</option></select>'; $this->eventManagerMock->expects($this->exactly(2))->method('dispatch')->willReturn(true); - $this->scopeConfigMock->expects($this->once())->method('getValue')->willReturn(false); $this->themeCollectionFactoryMock->expects($this->once()) ->method('create') @@ -285,7 +283,6 @@ class ContainerTest extends AbstractContainerTest . '<option value="sidebar.main" >Sidebar Main</option></select>'; $this->eventManagerMock->expects($this->exactly(2))->method('dispatch')->willReturn(true); - $this->scopeConfigMock->expects($this->once())->method('getValue')->willReturn(false); $this->themeCollectionFactoryMock->expects($this->once()) ->method('create') @@ -403,7 +400,6 @@ class ContainerTest extends AbstractContainerTest . 'Sidebar Main</option></select>'; $this->eventManagerMock->expects($this->exactly(2))->method('dispatch')->willReturn(true); - $this->scopeConfigMock->expects($this->once())->method('getValue')->willReturn(false); $this->themeCollectionFactoryMock->expects($this->once()) ->method('create') diff --git a/app/code/Magento/Wishlist/Test/Unit/Model/Rss/WishlistTest.php b/app/code/Magento/Wishlist/Test/Unit/Model/Rss/WishlistTest.php index b9dcc8d6fe73f500b1d314b90bf992c672fe14cf..e9c22670b1a104a46aa30525c70593ee40bdf81f 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Model/Rss/WishlistTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Model/Rss/WishlistTest.php @@ -136,7 +136,6 @@ class WishlistTest extends \PHPUnit_Framework_TestCase ); $customerServiceMock = $this->getMock(\Magento\Customer\Api\Data\CustomerInterface::class, [], [], '', false); $wishlistSharingUrl = 'wishlist/shared/index/1'; - $locale = 'en_US'; $productUrl = 'http://product.url/'; $productName = 'Product name'; @@ -160,25 +159,6 @@ class WishlistTest extends \PHPUnit_Framework_TestCase $this->urlBuilderMock->expects($this->once()) ->method('getUrl') ->will($this->returnValue($wishlistSharingUrl)); - $this->scopeConfig->expects($this->any()) - ->method('getValue') - ->will($this->returnValueMap( - [ - [ - 'advanced/modules_disable_output/Magento_Rss', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE, - null, - null, - ], - [ - Data::XML_PATH_DEFAULT_LOCALE, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE, - null, - $locale - ], - ] - ) - ); $staticArgs = [ 'productName' => $productName, diff --git a/bin/magento b/bin/magento index 1cb700def7fa7f3faf073dbd7bb0300892b06332..3fa9221763cf5fca0a09eb4bc6f43d3a5cb22a42 100755 --- a/bin/magento +++ b/bin/magento @@ -28,5 +28,5 @@ try { echo "\n\n"; $e = $e->getPrevious(); } - exit(Cli::RETURN_FAILURE); + exit(Magento\Framework\Console\Cli::RETURN_FAILURE); } diff --git a/composer.json b/composer.json index 11fe00b7ed45add98a8996bea8a480403d44a53c..16c73d23ef6d8a743ed69cfa53e890e8e2642a7f 100644 --- a/composer.json +++ b/composer.json @@ -226,7 +226,7 @@ "psr-0": { "": [ "app/code/", - "var/generation" + "generated/code" ] }, "files": [ diff --git a/composer.lock b/composer.lock index e69e12953fea2c150e1e063ddb9502148aad38ec..43c927cb95a1d5eb07b272dda0b018be12c73fbe 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "01335ef9c76fd6d77bf6bd9236b84d03", + "hash": "e5946b0500f46fab5f05e46957258ed4", "content-hash": "07be52ec4880d0390acff2dd605a194d", "packages": [ { @@ -554,16 +554,16 @@ }, { "name": "magento/magento-composer-installer", - "version": "0.1.11", + "version": "0.1.12", "source": { "type": "git", "url": "https://github.com/magento/magento-composer-installer.git", - "reference": "a12b9577cd9859af67d2365ae38d23ddfc57cf4d" + "reference": "10c600e88ad34fec71bb6b435ea8415ce92d51de" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/magento/magento-composer-installer/zipball/a12b9577cd9859af67d2365ae38d23ddfc57cf4d", - "reference": "a12b9577cd9859af67d2365ae38d23ddfc57cf4d", + "url": "https://api.github.com/repos/magento/magento-composer-installer/zipball/10c600e88ad34fec71bb6b435ea8415ce92d51de", + "reference": "10c600e88ad34fec71bb6b435ea8415ce92d51de", "shasum": "" }, "require": { @@ -629,7 +629,7 @@ "composer-installer", "magento" ], - "time": "2016-06-15 04:02:25" + "time": "2016-10-06 16:05:07" }, { "name": "magento/zendframework1", @@ -1687,7 +1687,7 @@ }, { "name": "zendframework/zend-code", - "version": "2.4.10", + "version": "2.4.11", "source": { "type": "git", "url": "https://github.com/zendframework/zend-code.git", @@ -1740,7 +1740,7 @@ }, { "name": "zendframework/zend-config", - "version": "2.4.10", + "version": "2.4.11", "source": { "type": "git", "url": "https://github.com/zendframework/zend-config.git", @@ -1797,7 +1797,7 @@ }, { "name": "zendframework/zend-console", - "version": "2.4.10", + "version": "2.4.11", "source": { "type": "git", "url": "https://github.com/zendframework/zend-console.git", @@ -1847,7 +1847,7 @@ }, { "name": "zendframework/zend-crypt", - "version": "2.4.10", + "version": "2.4.11", "source": { "type": "git", "url": "https://github.com/zendframework/zend-crypt.git", @@ -1899,7 +1899,7 @@ }, { "name": "zendframework/zend-di", - "version": "2.4.10", + "version": "2.4.11", "source": { "type": "git", "url": "https://github.com/zendframework/zend-di.git", @@ -1950,7 +1950,7 @@ }, { "name": "zendframework/zend-escaper", - "version": "2.4.10", + "version": "2.4.11", "source": { "type": "git", "url": "https://github.com/zendframework/zend-escaper.git", @@ -1995,7 +1995,7 @@ }, { "name": "zendframework/zend-eventmanager", - "version": "2.4.10", + "version": "2.4.11", "source": { "type": "git", "url": "https://github.com/zendframework/zend-eventmanager.git", @@ -2041,7 +2041,7 @@ }, { "name": "zendframework/zend-filter", - "version": "2.4.10", + "version": "2.4.11", "source": { "type": "git", "url": "https://github.com/zendframework/zend-filter.git", @@ -2097,7 +2097,7 @@ }, { "name": "zendframework/zend-form", - "version": "2.4.10", + "version": "2.4.11", "source": { "type": "git", "url": "https://github.com/zendframework/zend-form.git", @@ -2168,7 +2168,7 @@ }, { "name": "zendframework/zend-http", - "version": "2.4.10", + "version": "2.4.11", "source": { "type": "git", "url": "https://github.com/zendframework/zend-http.git", @@ -2219,7 +2219,7 @@ }, { "name": "zendframework/zend-i18n", - "version": "2.4.10", + "version": "2.4.11", "source": { "type": "git", "url": "https://github.com/zendframework/zend-i18n.git", @@ -2283,7 +2283,7 @@ }, { "name": "zendframework/zend-inputfilter", - "version": "2.4.10", + "version": "2.4.11", "source": { "type": "git", "url": "https://github.com/zendframework/zend-inputfilter.git", @@ -2334,7 +2334,7 @@ }, { "name": "zendframework/zend-json", - "version": "2.4.10", + "version": "2.4.11", "source": { "type": "git", "url": "https://github.com/zendframework/zend-json.git", @@ -2388,7 +2388,7 @@ }, { "name": "zendframework/zend-loader", - "version": "2.4.10", + "version": "2.4.11", "source": { "type": "git", "url": "https://github.com/zendframework/zend-loader.git", @@ -2433,7 +2433,7 @@ }, { "name": "zendframework/zend-log", - "version": "2.4.10", + "version": "2.4.11", "source": { "type": "git", "url": "https://github.com/zendframework/zend-log.git", @@ -2495,7 +2495,7 @@ }, { "name": "zendframework/zend-math", - "version": "2.4.10", + "version": "2.4.11", "source": { "type": "git", "url": "https://github.com/zendframework/zend-math.git", @@ -2546,7 +2546,7 @@ }, { "name": "zendframework/zend-modulemanager", - "version": "2.4.10", + "version": "2.4.11", "source": { "type": "git", "url": "https://github.com/zendframework/zend-modulemanager.git", @@ -2604,7 +2604,7 @@ }, { "name": "zendframework/zend-mvc", - "version": "2.4.10", + "version": "2.4.11", "source": { "type": "git", "url": "https://github.com/zendframework/zend-mvc.git", @@ -2692,7 +2692,7 @@ }, { "name": "zendframework/zend-serializer", - "version": "2.4.10", + "version": "2.4.11", "source": { "type": "git", "url": "https://github.com/zendframework/zend-serializer.git", @@ -2745,7 +2745,7 @@ }, { "name": "zendframework/zend-server", - "version": "2.4.10", + "version": "2.4.11", "source": { "type": "git", "url": "https://github.com/zendframework/zend-server.git", @@ -2792,7 +2792,7 @@ }, { "name": "zendframework/zend-servicemanager", - "version": "2.4.10", + "version": "2.4.11", "source": { "type": "git", "url": "https://github.com/zendframework/zend-servicemanager.git", @@ -2842,7 +2842,7 @@ }, { "name": "zendframework/zend-soap", - "version": "2.4.10", + "version": "2.4.11", "source": { "type": "git", "url": "https://github.com/zendframework/zend-soap.git", @@ -2894,7 +2894,7 @@ }, { "name": "zendframework/zend-stdlib", - "version": "2.4.10", + "version": "2.4.11", "source": { "type": "git", "url": "https://github.com/zendframework/zend-stdlib.git", @@ -2949,7 +2949,7 @@ }, { "name": "zendframework/zend-text", - "version": "2.4.10", + "version": "2.4.11", "source": { "type": "git", "url": "https://github.com/zendframework/zend-text.git", @@ -2996,7 +2996,7 @@ }, { "name": "zendframework/zend-uri", - "version": "2.4.10", + "version": "2.4.11", "source": { "type": "git", "url": "https://github.com/zendframework/zend-uri.git", @@ -3044,7 +3044,7 @@ }, { "name": "zendframework/zend-validator", - "version": "2.4.10", + "version": "2.4.11", "source": { "type": "git", "url": "https://github.com/zendframework/zend-validator.git", @@ -3109,7 +3109,7 @@ }, { "name": "zendframework/zend-view", - "version": "2.4.10", + "version": "2.4.11", "source": { "type": "git", "url": "https://github.com/zendframework/zend-view.git", diff --git a/dev/tests/functional/.htaccess.sample b/dev/tests/functional/.htaccess.sample index f1e60cf9b67e91779153e4c9d9f780c8f7bc9438..c1fcc7c278c8aa0e79bd372c89ed6ef6e8ec2f0f 100644 --- a/dev/tests/functional/.htaccess.sample +++ b/dev/tests/functional/.htaccess.sample @@ -1,6 +1,6 @@ ############################################## ## Allow access to command.php and website.php - <FilesMatch "command.php|website.php|export.php"> + <FilesMatch "command.php|website.php|export.php|pathChecker.php|deleteMagentoGeneratedCode.php"> order allow,deny allow from all </FilesMatch> diff --git a/dev/tests/functional/lib/Magento/Mtf/Util/Command/Cli/Setup.php b/dev/tests/functional/lib/Magento/Mtf/Util/Command/Cli/Setup.php index 385c11cd74f82e4adbc78f5e26b14e1e03931dae..5f5fe66d96cef6cc25689b315a31d91214e01719 100644 --- a/dev/tests/functional/lib/Magento/Mtf/Util/Command/Cli/Setup.php +++ b/dev/tests/functional/lib/Magento/Mtf/Util/Command/Cli/Setup.php @@ -18,6 +18,11 @@ class Setup extends Cli */ const PARAM_SETUP_UNINSTALL = 'setup:uninstall'; + /** + * Parameter for DI compile Magento command. + */ + const PARAM_SETUP_DI_COMPILE = 'setup:di:compile'; + /** * Options for uninstall Magento command. * @@ -34,4 +39,14 @@ class Setup extends Cli { parent::execute(Setup::PARAM_SETUP_UNINSTALL, $this->options); } + + /** + * DI Compile. + * + * @return void + */ + public function diCompile() + { + parent::execute(Setup::PARAM_SETUP_DI_COMPILE); + } } diff --git a/dev/tests/functional/lib/Magento/Mtf/Util/Command/GeneratedCode.php b/dev/tests/functional/lib/Magento/Mtf/Util/Command/GeneratedCode.php new file mode 100644 index 0000000000000000000000000000000000000000..c82231a9e38f1a10dab7cc822bb4bed2f092cb2d --- /dev/null +++ b/dev/tests/functional/lib/Magento/Mtf/Util/Command/GeneratedCode.php @@ -0,0 +1,49 @@ +<?php +/** + * Copyright © 2013-2017 Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Mtf\Util\Command; + +use Magento\Mtf\Util\Protocol\CurlInterface; +use Magento\Mtf\Util\Protocol\CurlTransport; + +/** + * GeneratedCode removes generated code of Magento (like generated/code and generated/metadata). + */ +class GeneratedCode +{ + /** + * Url to deleteMagentoGeneratedCode.php. + */ + const URL = 'dev/tests/functional/utils/deleteMagentoGeneratedCode.php'; + + /** + * Curl transport protocol. + * + * @var CurlTransport + */ + private $transport; + + /** + * @param CurlTransport $transport + */ + public function __construct(CurlTransport $transport) + { + $this->transport = $transport; + } + + /** + * Remove generated code. + * + * @return void + */ + public function delete() + { + $url = $_ENV['app_frontend_url'] . self::URL; + $curl = $this->transport; + $curl->write($url, [], CurlInterface::GET); + $curl->read(); + $curl->close(); + } +} diff --git a/dev/tests/functional/lib/Magento/Mtf/Util/Command/PathChecker.php b/dev/tests/functional/lib/Magento/Mtf/Util/Command/PathChecker.php new file mode 100644 index 0000000000000000000000000000000000000000..f61210dc554efc910d4d44b2f5f7bed875d4955d --- /dev/null +++ b/dev/tests/functional/lib/Magento/Mtf/Util/Command/PathChecker.php @@ -0,0 +1,52 @@ +<?php +/** + * Copyright © 2013-2017 Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Mtf\Util\Command; + +use Magento\Mtf\Util\Protocol\CurlInterface; +use Magento\Mtf\Util\Protocol\CurlTransport; + +/** + * PathChecker checks that path to file or directory exists. + */ +class PathChecker +{ + /** + * Url to checkPath.php. + */ + const URL = 'dev/tests/functional/utils/pathChecker.php'; + + /** + * Curl transport protocol. + * + * @var CurlTransport + */ + private $transport; + + /** + * @param CurlTransport $transport + */ + public function __construct(CurlTransport $transport) + { + $this->transport = $transport; + } + + /** + * Check that $path exists. + * + * @param string $path + * @return bool + */ + public function pathExists($path) + { + $url = $_ENV['app_frontend_url'] . self::URL . '?path=' . urlencode($path); + $curl = $this->transport; + $curl->write($url, [], CurlInterface::GET); + $result = $curl->read(); + $curl->close(); + + return strpos($result, 'path exists: true') !== false; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Install/Test/Constraint/AssertGenerationFilePathCheck.php b/dev/tests/functional/tests/app/Magento/Install/Test/Constraint/AssertGenerationFilePathCheck.php new file mode 100644 index 0000000000000000000000000000000000000000..64e46ac9b0289f6d0ee265339eff208c35fe7c3f --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Install/Test/Constraint/AssertGenerationFilePathCheck.php @@ -0,0 +1,64 @@ +<?php +/** + * Copyright © 2013-2017 Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Install\Test\Constraint; + +use Magento\Mtf\Constraint\AbstractConstraint; +use Magento\Mtf\Util\Command\PathChecker; + +/** + * Assert that path of generated files is correct. + */ +class AssertGenerationFilePathCheck extends AbstractConstraint +{ + /** + * Assert that path of generated files is correct. + * + * @param PathChecker $pathChecker + * @return void + */ + public function processAssert(PathChecker $pathChecker) + { + $existsPaths = [ + 'generated/code', + 'generated/metadata', + 'generated/metadata/global.ser', + 'generated/metadata/adminhtml.ser', + 'generated/metadata/crontab.ser', + 'generated/metadata/frontend.ser', + 'generated/metadata/webapi_rest.ser', + 'generated/metadata/webapi_soap.ser', + ]; + + $nonExistsPaths = [ + 'var/di', + 'var/generation' + ]; + + foreach ($existsPaths as $path) { + \PHPUnit_Framework_Assert::assertTrue( + $pathChecker->pathExists($path), + 'Path "' . $path . '" does not exist.' + ); + } + + foreach ($nonExistsPaths as $path) { + \PHPUnit_Framework_Assert::assertFalse( + $pathChecker->pathExists($path), + 'Path "' . $path . '" exists.' + ); + } + } + + /** + * Returns a string representation of the object. + * + * @return string + */ + public function toString() + { + return 'Path of generated files is correct.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Install/Test/TestCase/InstallTest.php b/dev/tests/functional/tests/app/Magento/Install/Test/TestCase/InstallTest.php index 657ea4379b46e8d106e93cdddfc978c7c4d7159a..32594facd3a1bce7a6ae59f04840c8fd8e0e0421 100644 --- a/dev/tests/functional/tests/app/Magento/Install/Test/TestCase/InstallTest.php +++ b/dev/tests/functional/tests/app/Magento/Install/Test/TestCase/InstallTest.php @@ -17,6 +17,7 @@ use Magento\Install\Test\Constraint\AssertSuccessfulReadinessCheck; use Magento\Install\Test\Constraint\AssertAdminUriAutogenerated; use Magento\Install\Test\Constraint\AssertDevdocsLink; use Magento\Mtf\Util\Command\Cli\Setup; +use Magento\Mtf\Util\Command\GeneratedCode; use Magento\Mtf\Client\BrowserInterface; /** @@ -76,6 +77,13 @@ class InstallTest extends Injectable */ protected $installPage; + /** + * Setup Magento for tests executions. + * + * @var Setup + */ + private $magentoSetup; + /** * Uninstall Magento before test. * @@ -101,12 +109,17 @@ class InstallTest extends Injectable * @param Install $installPage * @param Setup $magentoSetup * @param DevdocsInstall $devdocsInstallPage + * @param GeneratedCode $generatedCode * @return void */ - public function __inject(Install $installPage, Setup $magentoSetup, DevdocsInstall $devdocsInstallPage) - { - // Uninstall Magento. - $magentoSetup->uninstall(); + public function __inject( + Install $installPage, + Setup $magentoSetup, + DevdocsInstall $devdocsInstallPage, + GeneratedCode $generatedCode + ) { + $generatedCode->delete(); + $this->magentoSetup = $magentoSetup; $this->installPage = $installPage; $this->devdocsInstallPage = $devdocsInstallPage; } @@ -122,8 +135,10 @@ class InstallTest extends Injectable * @param AssertAdminUriAutogenerated $assertAdminUri * @param AssertDevdocsLink $assertDevdocsLink * @param BrowserInterface $browser + * @param bool $diCompile * @param array $install [optional] * @return array + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function test( User $user, @@ -134,8 +149,10 @@ class InstallTest extends Injectable AssertAdminUriAutogenerated $assertAdminUri, AssertDevdocsLink $assertDevdocsLink, BrowserInterface $browser, + $diCompile = false, array $install = [] ) { + $this->magentoSetup->uninstall(); $dataConfig = array_merge($install, $configData); if (isset($dataConfig['httpsFront'])) { $dataConfig['https'] = str_replace('http', 'https', $dataConfig['baseUrl']); @@ -178,6 +195,10 @@ class InstallTest extends Injectable // Step 6: Install. $this->installPage->getInstallBlock()->clickInstallNow(); + if ($diCompile) { + $this->magentoSetup->diCompile(); + } + return ['installConfig' => $installConfig]; } diff --git a/dev/tests/functional/tests/app/Magento/Install/Test/TestCase/InstallTest.xml b/dev/tests/functional/tests/app/Magento/Install/Test/TestCase/InstallTest.xml index cdfc018346b56dad265044131f6719fb3c48ef78..cb785723763be541be0136a40cb12d3c6eecb558 100644 --- a/dev/tests/functional/tests/app/Magento/Install/Test/TestCase/InstallTest.xml +++ b/dev/tests/functional/tests/app/Magento/Install/Test/TestCase/InstallTest.xml @@ -48,10 +48,12 @@ <constraint name="Magento\User\Test\Constraint\AssertUserSuccessLogin" /> <constraint name="Magento\Install\Test\Constraint\AssertSecureUrlEnabled" /> </variation> - <variation name="InstallTestVariation6" summary="Install with default values"> + <variation name="InstallTestVariation6" summary="Install with default values and check DI compile" ticketId="MAGETWO-62817"> <data name="user/dataset" xsi:type="string">default</data> + <data name="diCompile" xsi:type="boolean">true</data> <constraint name="Magento\Install\Test\Constraint\AssertSuccessInstall" /> <constraint name="Magento\User\Test\Constraint\AssertUserSuccessLogin" /> + <constraint name="Magento\Install\Test\Constraint\AssertGenerationFilePathCheck" /> </variation> </testCase> </config> diff --git a/dev/tests/functional/utils/deleteMagentoGeneratedCode.php b/dev/tests/functional/utils/deleteMagentoGeneratedCode.php new file mode 100644 index 0000000000000000000000000000000000000000..b90269a9a21f68a8f2601eb409a4c7c5e912ff87 --- /dev/null +++ b/dev/tests/functional/utils/deleteMagentoGeneratedCode.php @@ -0,0 +1,7 @@ +<?php +/** + * Copyright © 2013-2017 Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +exec('rm -rf ../../../../generated/*'); diff --git a/dev/tests/functional/utils/pathChecker.php b/dev/tests/functional/utils/pathChecker.php new file mode 100644 index 0000000000000000000000000000000000000000..a57ac8d3e07b1d82f777e64dddba3518cf281a94 --- /dev/null +++ b/dev/tests/functional/utils/pathChecker.php @@ -0,0 +1,17 @@ +<?php +/** + * Copyright © 2013-2017 Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +if (isset($_GET['path'])) { + $path = urldecode($_GET['path']); + + if (file_exists('../../../../' . $path)) { + echo 'path exists: true'; + } else { + echo 'path exists: false'; + } +} else { + throw new \InvalidArgumentException("GET parameter 'path' is not set."); +} diff --git a/dev/tests/integration/framework/Magento/TestFramework/Application.php b/dev/tests/integration/framework/Magento/TestFramework/Application.php index 3d76b9774d50976e1f74cab4979f39e1cbd86064..e52976f505710a226e4cf008b8e21341a08fecce 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Application.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Application.php @@ -630,12 +630,13 @@ class Application { $path = DirectoryList::PATH; $var = "{$this->installDir}/var"; + $generated = "{$this->installDir}/generated"; $customDirs = [ DirectoryList::CONFIG => [$path => "{$this->installDir}/etc"], DirectoryList::VAR_DIR => [$path => $var], DirectoryList::MEDIA => [$path => "{$this->installDir}/pub/media"], DirectoryList::STATIC_VIEW => [$path => "{$this->installDir}/pub/static"], - DirectoryList::GENERATION => [$path => "{$var}/generation"], + DirectoryList::GENERATION => [$path => "{$generated}/code"], DirectoryList::CACHE => [$path => "{$var}/cache"], DirectoryList::LOG => [$path => "{$var}/log"], DirectoryList::SESSION => [$path => "{$var}/session"], diff --git a/dev/tests/integration/testsuite/Magento/Backend/Block/TemplateTest.php b/dev/tests/integration/testsuite/Magento/Backend/Block/TemplateTest.php index 2a3441afcd2aad6d1eeab87a1c4c3e7f7c266bd2..ea450cbe81c2ff5bc4ad8a28705dc7ba97a84a82 100644 --- a/dev/tests/integration/testsuite/Magento/Backend/Block/TemplateTest.php +++ b/dev/tests/integration/testsuite/Magento/Backend/Block/TemplateTest.php @@ -34,26 +34,4 @@ class TemplateTest extends \PHPUnit_Framework_TestCase { $this->assertGreaterThan(15, strlen($this->_block->getFormKey())); } - - /** - * @magentoAppArea adminhtml - * @covers \Magento\Backend\Block\Template::isOutputEnabled - * @magentoConfigFixture current_store advanced/modules_disable_output/dummy 1 - */ - public function testIsOutputEnabledTrue() - { - $this->_block->setData('module_name', 'dummy'); - $this->assertFalse($this->_block->isOutputEnabled('dummy')); - } - - /** - * @magentoAppArea adminhtml - * @covers \Magento\Backend\Block\Template::isOutputEnabled - * @magentoConfigFixture current_store advanced/modules_disable_output/dummy 0 - */ - public function testIsOutputEnabledFalse() - { - $this->_block->setData('module_name', 'dummy'); - $this->assertTrue($this->_block->isOutputEnabled('dummy')); - } } diff --git a/dev/tests/integration/testsuite/Magento/Deploy/Console/Command/App/SensitiveConfigSetCommandTest.php b/dev/tests/integration/testsuite/Magento/Deploy/Console/Command/App/SensitiveConfigSetCommandTest.php new file mode 100644 index 0000000000000000000000000000000000000000..1b0fe2de866e817ab78e646087b9ebe248a60818 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Deploy/Console/Command/App/SensitiveConfigSetCommandTest.php @@ -0,0 +1,291 @@ +<?php +/** + * Copyright © 2013-2017 Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Deploy\Console\Command\App; + +use Magento\Deploy\Console\Command\App\SensitiveConfigSet\CollectorFactory; +use Magento\Deploy\Console\Command\App\SensitiveConfigSet\InteractiveCollector; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\DeploymentConfig\Reader; +use Magento\Framework\App\DeploymentConfig\Writer; +use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Config\File\ConfigFilePool; +use Magento\Framework\Filesystem; +use Magento\Framework\ObjectManagerInterface; +use Magento\TestFramework\Helper\Bootstrap; +use Symfony\Component\Console\Helper\QuestionHelper; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +/** + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ +class SensitiveConfigSetCommandTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var ObjectManagerInterface + */ + private $objectManager; + + /** + * @var Reader + */ + private $reader; + + /** + * @var ConfigFilePool + */ + private $configFilePool; + + /** + * @var array + */ + private $config; + + /** + * @var Filesystem + */ + private $filesystem; + + public function setUp() + { + $this->objectManager = Bootstrap::getObjectManager(); + $this->reader = $this->objectManager->get(Reader::class); + $this->configFilePool = $this->objectManager->get(ConfigFilePool::class); + $this->config = $this->loadConfig(); + $this->filesystem = $this->objectManager->get(Filesystem::class); + $this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->writeFile( + $this->getFileName(), + file_get_contents(__DIR__ . '/../../../_files/_config.local.php') + ); + } + + /** + * @param $scope + * @param $scopeCode + * @param callable $assertCallback + * @magentoDataFixture Magento/Store/_files/website.php + * @magentoDbIsolation enabled + * @dataProvider testExecuteDataProvider + */ + public function testExecute($scope, $scopeCode, callable $assertCallback) + { + $outputMock = $this->getMock(OutputInterface::class); + $outputMock->expects($this->at(0)) + ->method('writeln') + ->with('<info>Configuration value saved in app/etc/config.php</info>'); + + $inputMock = $this->getMock(InputInterface::class); + $inputMock->expects($this->exactly(2)) + ->method('getArgument') + ->withConsecutive( + [SensitiveConfigSetCommand::INPUT_ARGUMENT_PATH], + [SensitiveConfigSetCommand::INPUT_ARGUMENT_VALUE] + ) + ->willReturnOnConsecutiveCalls( + 'some/config/path_two', + 'sensitiveValue' + ); + $inputMock->expects($this->exactly(3)) + ->method('getOption') + ->withConsecutive( + [SensitiveConfigSetCommand::INPUT_OPTION_SCOPE], + [SensitiveConfigSetCommand::INPUT_OPTION_SCOPE_CODE], + [SensitiveConfigSetCommand::INPUT_OPTION_INTERACTIVE] + ) + ->willReturnOnConsecutiveCalls( + $scope, + $scopeCode, + null + ); + + /** @var SensitiveConfigSetCommand command */ + $command = $this->objectManager->create(SensitiveConfigSetCommand::class); + $command->run($inputMock, $outputMock); + + $config = $this->loadConfig(); + + $assertCallback($config); + } + + public function testExecuteDataProvider() + { + return [ + [ + ScopeConfigInterface::SCOPE_TYPE_DEFAULT, + null, + function (array $config) { + $this->assertTrue(isset($config['system']['default']['some']['config']['path_two'])); + $this->assertEquals( + 'sensitiveValue', + $config['system']['default']['some']['config']['path_two'] + ); + } + ], + [ + 'website', + 'test', + function (array $config) { + $this->assertTrue(isset($config['system']['website']['test']['some']['config']['path_two'])); + $this->assertEquals( + 'sensitiveValue', + $config['system']['website']['test']['some']['config']['path_two'] + ); + } + ] + ]; + } + + /** + * @param $scope + * @param $scopeCode + * @param callable $assertCallback + * @magentoDataFixture Magento/Store/_files/website.php + * @magentoDbIsolation enabled + * @dataProvider testExecuteInteractiveDataProvider + */ + public function testExecuteInteractive($scope, $scopeCode, callable $assertCallback) + { + $inputMock = $this->getMock(InputInterface::class); + $outputMock = $this->getMock(OutputInterface::class); + $outputMock->expects($this->at(0)) + ->method('writeln') + ->with('<info>Please set configuration values or skip them by pressing [Enter]:</info>'); + $outputMock->expects($this->at(1)) + ->method('writeln') + ->with('<info>Configuration values saved in app/etc/config.php</info>'); + $inputMock->expects($this->exactly(3)) + ->method('getOption') + ->withConsecutive( + [SensitiveConfigSetCommand::INPUT_OPTION_SCOPE], + [SensitiveConfigSetCommand::INPUT_OPTION_SCOPE_CODE], + [SensitiveConfigSetCommand::INPUT_OPTION_INTERACTIVE] + ) + ->willReturnOnConsecutiveCalls( + $scope, + $scopeCode, + true + ); + + $questionHelperMock = $this->getMock(QuestionHelper::class); + $questionHelperMock->expects($this->exactly(3)) + ->method('ask') + ->willReturn('sensitiveValue'); + + $interactiveCollectorMock = $this->objectManager->create( + InteractiveCollector::class, + [ + 'questionHelper' => $questionHelperMock + ] + ); + $collectorFactoryMock = $this->getMockBuilder(CollectorFactory::class) + ->disableOriginalConstructor() + ->getMock(); + + $collectorFactoryMock->expects($this->once()) + ->method('create') + ->with(CollectorFactory::TYPE_INTERACTIVE) + ->willReturn($interactiveCollectorMock); + + /** @var SensitiveConfigSetCommand command */ + $command = $this->objectManager->create( + SensitiveConfigSetCommand::class, + [ + 'collectorFactory' => $collectorFactoryMock + ] + ); + $command->run($inputMock, $outputMock); + + $config = $this->loadConfig(); + + $assertCallback($config); + } + + public function testExecuteInteractiveDataProvider() + { + return [ + [ + ScopeConfigInterface::SCOPE_TYPE_DEFAULT, + null, + function (array $config) { + $this->assertTrue(isset($config['system']['default']['some']['config']['path_one'])); + $this->assertTrue(isset($config['system']['default']['some']['config']['path_two'])); + $this->assertTrue(isset($config['system']['default']['some']['config']['path_three'])); + $this->assertEquals( + 'sensitiveValue', + $config['system']['default']['some']['config']['path_one'] + ); + $this->assertEquals( + 'sensitiveValue', + $config['system']['default']['some']['config']['path_two'] + ); + $this->assertEquals( + 'sensitiveValue', + $config['system']['default']['some']['config']['path_three'] + ); + } + ], + [ + 'website', + 'test', + function (array $config) { + $this->assertTrue(isset($config['system']['website']['test']['some']['config']['path_one'])); + $this->assertTrue(isset($config['system']['website']['test']['some']['config']['path_two'])); + $this->assertTrue(isset($config['system']['website']['test']['some']['config']['path_three'])); + $this->assertEquals( + 'sensitiveValue', + $config['system']['website']['test']['some']['config']['path_one'] + ); + $this->assertEquals( + 'sensitiveValue', + $config['system']['website']['test']['some']['config']['path_two'] + ); + $this->assertEquals( + 'sensitiveValue', + $config['system']['website']['test']['some']['config']['path_three'] + ); + } + ] + ]; + } + + public function tearDown() + { + $this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->delete( + $this->getFileName() + ); + $this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->writeFile( + $this->configFilePool->getPath(ConfigFilePool::APP_CONFIG), + "<?php\n return array();\n" + ); + /** @var Writer $writer */ + $writer = $this->objectManager->get(Writer::class); + $writer->saveConfig([ConfigFilePool::APP_CONFIG => $this->config]); + } + + /** + * @return string + */ + private function getFileName() + { + /** @var ConfigFilePool $configFilePool */ + $configFilePool = $this->objectManager->get(ConfigFilePool::class); + $filePool = $configFilePool->getInitialFilePools(); + + return $filePool[ConfigFilePool::LOCAL][ConfigFilePool::APP_CONFIG]; + } + + /** + * @return array + */ + private function loadConfig() + { + return $this->reader->loadConfigFile( + ConfigFilePool::APP_CONFIG, + $this->configFilePool->getPath(ConfigFilePool::APP_CONFIG), + true + ); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Deploy/_files/_config.local.php b/dev/tests/integration/testsuite/Magento/Deploy/_files/_config.local.php new file mode 100644 index 0000000000000000000000000000000000000000..ae4630b1a2b07e021ba1e7e1e409f4e1e81a99a6 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Deploy/_files/_config.local.php @@ -0,0 +1,23 @@ +<?php +/** + * Copyright © 2013-2017 Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +return [ + 'scopes' => [ + 'websites' => [] + ], + /** + * The configuration file doesn't contain sensitive data for security reasons. + * Sensitive data can be stored in the following environment variables: + * CONFIG__DEFAULT__SOME__CONFIG__PATH_ONE for some/config/path_one + * CONFIG__DEFAULT__SOME__CONFIG__PATH_TWO for some/config/path_two + * CONFIG__DEFAULT__SOME__CONFIG__PATH_THREE for some/config/path_three + */ + 'system' => [ + 'default' => [ + 'web' => [], + 'general' => [] + ] + ] +]; diff --git a/dev/tests/static/framework/autoload.php b/dev/tests/static/framework/autoload.php index a5750d9303c945e6f831c23b88d919b96d50cd44..fc3b62fc97287d9be6d6f72db106436c4ab7f84f 100644 --- a/dev/tests/static/framework/autoload.php +++ b/dev/tests/static/framework/autoload.php @@ -4,6 +4,8 @@ * See COPYING.txt for license details. */ +use \Magento\Framework\App\Filesystem\DirectoryList; + $baseDir = realpath(__DIR__ . '/../../../../'); require $baseDir . '/app/autoload.php'; $testsBaseDir = $baseDir . '/dev/tests/static'; @@ -16,4 +18,6 @@ $autoloadWrapper->addPsr4( $testsBaseDir . '/../integration/framework/Magento/TestFramework/', ] ); -$autoloadWrapper->addPsr4('Magento\\', $baseDir . '/var/generation/Magento/'); + +$generatedCode = DirectoryList::getDefaultConfig()[DirectoryList::GENERATION][DirectoryList::PATH]; +$autoloadWrapper->addPsr4('Magento\\', $baseDir . '/' . $generatedCode . '/Magento/'); diff --git a/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcpd/blacklist/common.txt b/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcpd/blacklist/common.txt index 3afe3af79b14ff3177a0dc1c5ea9fe42e93b6331..ebe8501337efff410bba83f4f291b3433247a893 100644 --- a/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcpd/blacklist/common.txt +++ b/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcpd/blacklist/common.txt @@ -109,7 +109,7 @@ Magento/SalesRule/Model/Resource/Report/Rule Magento/SalesRule/Model/Resource/Rule Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit Magento/User/Block/User/Edit -var/generation +generated/code Magento/Newsletter/Block/Adminhtml/Template/Grid/Renderer Magento/Newsletter/Model/Template/Filter Magento/Newsletter/Model/Resource/Subscriber diff --git a/dev/tests/unit/framework/autoload.php b/dev/tests/unit/framework/autoload.php index 4b2adbe17673fb7f33a60f7183ffd190833d2904..b4987145872d44c854c993fad60cb6ce02422bf0 100644 --- a/dev/tests/unit/framework/autoload.php +++ b/dev/tests/unit/framework/autoload.php @@ -4,10 +4,12 @@ * See COPYING.txt for license details. */ +use Magento\Framework\App\Filesystem\DirectoryList; + $autoloader = new \Magento\Framework\TestFramework\Unit\Autoloader\ExtensionGeneratorAutoloader( new \Magento\Framework\Code\Generator\Io( new \Magento\Framework\Filesystem\Driver\File(), - TESTS_TEMP_DIR . '/var/generation' + TESTS_TEMP_DIR . '/'. DirectoryList::getDefaultConfig()[DirectoryList::GENERATION][DirectoryList::PATH] ) ); spl_autoload_register([$autoloader, 'load']); diff --git a/generated/.htaccess b/generated/.htaccess new file mode 100644 index 0000000000000000000000000000000000000000..896fbc5a341ea313ff3abd503808842757678c1d --- /dev/null +++ b/generated/.htaccess @@ -0,0 +1,2 @@ +Order deny,allow +Deny from all \ No newline at end of file diff --git a/lib/internal/Magento/Framework/App/Config/CommentParserInterface.php b/lib/internal/Magento/Framework/App/Config/CommentParserInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..efc917d31b0c70a1c0ee6a4b8a070f71fdbb322e --- /dev/null +++ b/lib/internal/Magento/Framework/App/Config/CommentParserInterface.php @@ -0,0 +1,23 @@ +<?php +/** + * Copyright © 2013-2017 Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\App\Config; + +use Magento\Framework\Exception\FileSystemException; + +/** + * Interface CommentParserInterface + */ +interface CommentParserInterface +{ + /** + * Retrieve config list from file comments. + * + * @param string $fileName + * @return array + * @throws FileSystemException + */ + public function execute($fileName); +} diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig/Writer/PhpFormatter.php b/lib/internal/Magento/Framework/App/DeploymentConfig/Writer/PhpFormatter.php index ae8a9bd4dc64e66ecf8ab865f61541d9bdc94a6b..28fcbd3692c9e1dffb84b0a2ef98b1ffb0633d96 100644 --- a/lib/internal/Magento/Framework/App/DeploymentConfig/Writer/PhpFormatter.php +++ b/lib/internal/Magento/Framework/App/DeploymentConfig/Writer/PhpFormatter.php @@ -25,7 +25,10 @@ class PhpFormatter implements FormatterInterface foreach ($data as $key => $value) { $comment = ' '; if (!empty($comments[$key])) { - $comment = " /**\n * " . str_replace("\n", "\n * ", var_export($comments[$key], true)) . "\n */\n"; + $exportedComment = is_string($comments[$key]) + ? $comments[$key] + : var_export($comments[$key], true); + $comment = " /**\n * " . str_replace("\n", "\n * ", $exportedComment) . "\n */\n"; } $space = is_array($value) ? " \n" : ' '; $elements[] = $comment . var_export($key, true) . ' =>' . $space . var_export($value, true); diff --git a/lib/internal/Magento/Framework/App/Filesystem/DirectoryList.php b/lib/internal/Magento/Framework/App/Filesystem/DirectoryList.php index ae1a6544ef2cbf05ef8bd4de84188472113ffa9c..57c903b49198cb5b4c99c8b6dcb2fcd8bcb3ed94 100644 --- a/lib/internal/Magento/Framework/App/Filesystem/DirectoryList.php +++ b/lib/internal/Magento/Framework/App/Filesystem/DirectoryList.php @@ -5,6 +5,8 @@ */ namespace Magento\Framework\App\Filesystem; +use Magento\Framework\Code\Generator\Io; + /** * A Magento application specific list of directories */ @@ -120,8 +122,8 @@ class DirectoryList extends \Magento\Framework\Filesystem\DirectoryList self::VAR_DIR => [parent::PATH => 'var'], self::CACHE => [parent::PATH => 'var/cache'], self::LOG => [parent::PATH => 'var/log'], - self::DI => [parent::PATH => 'var/di'], - self::GENERATION => [parent::PATH => 'var/generation'], + self::DI => [parent::PATH => 'generated/metadata'], + self::GENERATION => [parent::PATH => Io::DEFAULT_DIRECTORY], self::SESSION => [parent::PATH => 'var/session'], self::MEDIA => [parent::PATH => 'pub/media', parent::URL_PATH => 'pub/media'], self::STATIC_VIEW => [parent::PATH => 'pub/static', parent::URL_PATH => 'pub/static'], diff --git a/lib/internal/Magento/Framework/App/Scope/ValidatorInterface.php b/lib/internal/Magento/Framework/App/Scope/ValidatorInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..8063d61d8f5b29395183b9742dc45d6084957955 --- /dev/null +++ b/lib/internal/Magento/Framework/App/Scope/ValidatorInterface.php @@ -0,0 +1,22 @@ +<?php +/** + * Copyright © 2013-2017 Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\App\Scope; + +use Magento\Framework\Exception\LocalizedException; + +interface ValidatorInterface +{ + /** + * Validate if exists given scope and scope code + * otherwise, throws an exception with appropriate message. + * + * @param string $scope + * @param string $scopeCode + * @return boolean + * @throws LocalizedException + */ + public function isValid($scope, $scopeCode = null); +} diff --git a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/Writer/PhpFormatterTest.php b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/Writer/PhpFormatterTest.php index 0f86b778a04d2d1c52535adf4f6eafb7d5af2795..9f6894c0a68350e86b9e96a8111de123ac11d574 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/Writer/PhpFormatterTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/Writer/PhpFormatterTest.php @@ -3,7 +3,6 @@ * Copyright © 2013-2017 Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - namespace Magento\Framework\App\Test\Unit\DeploymentConfig\Writer; use \Magento\Framework\App\DeploymentConfig\Writer\PhpFormatter; @@ -48,9 +47,9 @@ class PhpFormatterTest extends \PHPUnit_Framework_TestCase ]; $comments1 = ['ns2' => 'comment for namespace 2']; $comments2 = [ - 'ns1' => 'comment for namespace 1', - 'ns2' => "comment for namespace 2.\nNext comment for namespace 2", - 'ns3' => 'comment for namespace 3', + 'ns1' => 'comment for\' namespace 1', + 'ns2' => "comment for namespace 2.\nNext comment for' namespace 2", + 'ns3' => 'comment for" namespace 3', 'ns4' => 'comment for namespace 4', 'ns5' => 'comment for unexisted namespace 5', ]; @@ -71,7 +70,7 @@ return array ( ), ), /** - * 'comment for namespace 2' + * comment for namespace 2 */ 'ns2' => array ( @@ -89,7 +88,7 @@ TEXT; <?php return array ( /** - * 'comment for namespace 1' + * comment for' namespace 1 */ 'ns1' => array ( @@ -105,8 +104,8 @@ return array ( ), ), /** - * 'comment for namespace 2. - * Next comment for namespace 2' + * comment for namespace 2. + * Next comment for' namespace 2 */ 'ns2' => array ( @@ -116,11 +115,11 @@ return array ( ), ), /** - * 'comment for namespace 3' + * comment for" namespace 3 */ 'ns3' => 'just text', /** - * 'comment for namespace 4' + * comment for namespace 4 */ 'ns4' => 'just text' ); diff --git a/lib/internal/Magento/Framework/Code/GeneratedFiles.php b/lib/internal/Magento/Framework/Code/GeneratedFiles.php index e33b311e74c629735d60485874c42769ad12a11e..9656ef6c4b9fe794b4ca6f915027905f106c1e3d 100644 --- a/lib/internal/Magento/Framework/Code/GeneratedFiles.php +++ b/lib/internal/Magento/Framework/Code/GeneratedFiles.php @@ -57,7 +57,7 @@ class GeneratedFiles } /** - * Clean var/generation, var/di and var/cache + * Clean generated/code, generated/metadata and var/cache * * @return void */ @@ -81,12 +81,12 @@ class GeneratedFiles $generationPath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::GENERATION)); $diPath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::DI)); - // Clean var/generation dir + // Clean generated/code dir if ($this->write->isDirectory($generationPath)) { $this->write->delete($generationPath); } - // Clean var/di + // Clean generated/metadata if ($this->write->isDirectory($diPath)) { $this->write->delete($diPath); } @@ -101,7 +101,7 @@ class GeneratedFiles } /** - * Create flag for cleaning up var/generation, var/di and var/cache directories for subsequent + * Create flag for cleaning up generated/code, generated/metadata and var/cache directories for subsequent * regeneration of this content * * @return void diff --git a/lib/internal/Magento/Framework/Code/Generator/Io.php b/lib/internal/Magento/Framework/Code/Generator/Io.php index 05ddb46e948325eaba29f91a570ddb8412948e40..85449fe61749fa6dcdbb941a5b28c436cf663e90 100644 --- a/lib/internal/Magento/Framework/Code/Generator/Io.php +++ b/lib/internal/Magento/Framework/Code/Generator/Io.php @@ -14,7 +14,7 @@ class Io * Default code generation directory * Should correspond the value from \Magento\Framework\Filesystem */ - const DEFAULT_DIRECTORY = 'var/generation'; + const DEFAULT_DIRECTORY = 'generated/code'; /** * Path to directory where new file must be created diff --git a/lib/internal/Magento/Framework/Console/Cli.php b/lib/internal/Magento/Framework/Console/Cli.php index 5a89d0f6b60571680068463df5b78f85951c809c..855e792ec21b9923ce9020fde7ac3eb41040d0bb 100644 --- a/lib/internal/Magento/Framework/Console/Cli.php +++ b/lib/internal/Magento/Framework/Console/Cli.php @@ -5,102 +5,106 @@ */ namespace Magento\Framework\Console; +use Magento\Framework\App\DeploymentConfig; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\App\State; use Magento\Framework\Composer\ComposerJsonFinder; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Output\ConsoleOutput; -use Symfony\Component\Console\Input\ArgvInput; -use Symfony\Component\Console\Application as SymfonyApplication; +use Magento\Framework\Exception\FileSystemException; +use Magento\Setup\Model\ObjectManagerProvider; +use Symfony\Component\Console; use Magento\Framework\App\Bootstrap; use Magento\Framework\Filesystem\Driver\File; use Magento\Framework\Shell\ComplexParameter; use Magento\Setup\Console\CompilerPreparation; -use \Magento\Framework\App\ProductMetadata; +use Magento\Framework\App\ProductMetadata; +use Magento\Framework\ObjectManagerInterface; +use Zend\ServiceManager\ServiceManager; /** - * Magento 2 CLI Application. This is the hood for all command line tools supported by Magento + * Magento 2 CLI Application. + * This is the hood for all command line tools supported by Magento. * * {@inheritdoc} * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Cli extends SymfonyApplication +class Cli extends Console\Application { /** - * Name of input option + * Name of input option. */ const INPUT_KEY_BOOTSTRAP = 'bootstrap'; - /** - * Cli exit codes + /**#@+ + * Cli exit codes. */ const RETURN_SUCCESS = 0; const RETURN_FAILURE = 1; + /**#@-*/ - /** @var \Zend\ServiceManager\ServiceManager */ + /** + * Service Manager. + * + * @var ServiceManager + */ private $serviceManager; /** - * Initialization exception + * Initialization exception. * * @var \Exception */ private $initException; /** - * @param string $name application name - * @param string $version application version - * @SuppressWarnings(PHPMD.ExitExpression) + * Object Manager. + * + * @var ObjectManagerInterface + */ + private $objectManager; + + /** + * @param string $name the application name + * @param string $version the application version */ public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN') { $this->serviceManager = \Zend\Mvc\Application::init(require BP . '/setup/config/application.config.php') ->getServiceManager(); - $generationDirectoryAccess = new GenerationDirectoryAccess($this->serviceManager); - if (!$generationDirectoryAccess->check()) { - $output = new ConsoleOutput(); - $output->writeln( - '<error>Command line user does not have read and write permissions on var/generation directory. Please' - . ' address this issue before using Magento command line.</error>' - ); - exit(0); - } - /** - * Temporary workaround until the compiler is able to clear the generation directory - * @todo remove after MAGETWO-44493 resolved - */ - if (class_exists(CompilerPreparation::class)) { - $compilerPreparation = new CompilerPreparation($this->serviceManager, new ArgvInput(), new File()); - $compilerPreparation->handleCompilerEnvironment(); - } + + $this->assertCompilerPreparation(); + $this->initObjectManager(); + $this->assertGenerationPermissions(); if ($version == 'UNKNOWN') { - $directoryList = new DirectoryList(BP); + $directoryList = new DirectoryList(BP); $composerJsonFinder = new ComposerJsonFinder($directoryList); - $productMetadata = new ProductMetadata($composerJsonFinder); + $productMetadata = new ProductMetadata($composerJsonFinder); $version = $productMetadata->getVersion(); } + parent::__construct($name, $version); } /** - * Process an error happened during initialization of commands, if any + * {@inheritdoc} * - * @param InputInterface $input - * @param OutputInterface $output - * @return int - * @throws \Exception + * @throws \Exception the exception in case of unexpected error */ - public function doRun(InputInterface $input, OutputInterface $output) + public function doRun(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) { $exitCode = parent::doRun($input, $output); + if ($this->initException) { $output->writeln( "<error>We're sorry, an error occurred. Try clearing the cache and code generation directories. " - . "By default, they are: var/cache, var/di, var/generation, and var/page_cache.</error>" + . "By default, they are: " . $this->getDefaultDirectoryPath(DirectoryList::CACHE) . ", " + . $this->getDefaultDirectoryPath(DirectoryList::DI) . ", " + . $this->getDefaultDirectoryPath(DirectoryList::GENERATION) . ", and var/page_cache.</error>" ); + throw $this->initException; } + return $exitCode; } @@ -113,46 +117,142 @@ class Cli extends SymfonyApplication } /** - * Gets application commands + * Gets application commands. * - * @return array + * @return array a list of available application commands */ protected function getApplicationCommands() { $commands = []; try { - $bootstrapParam = new ComplexParameter(self::INPUT_KEY_BOOTSTRAP); - $params = $bootstrapParam->mergeFromArgv($_SERVER, $_SERVER); - $params[Bootstrap::PARAM_REQUIRE_MAINTENANCE] = null; - $bootstrap = Bootstrap::create(BP, $params); - $objectManager = $bootstrap->getObjectManager(); - /** @var \Magento\Setup\Model\ObjectManagerProvider $omProvider */ - $omProvider = $this->serviceManager->get(\Magento\Setup\Model\ObjectManagerProvider::class); - $omProvider->setObjectManager($objectManager); - if (class_exists(\Magento\Setup\Console\CommandList::class)) { $setupCommandList = new \Magento\Setup\Console\CommandList($this->serviceManager); $commands = array_merge($commands, $setupCommandList->getCommands()); } - if ($objectManager->get(\Magento\Framework\App\DeploymentConfig::class)->isAvailable()) { - /** @var \Magento\Framework\Console\CommandListInterface */ - $commandList = $objectManager->create(\Magento\Framework\Console\CommandListInterface::class); + if ($this->objectManager->get(DeploymentConfig::class)->isAvailable()) { + /** @var CommandListInterface */ + $commandList = $this->objectManager->create(CommandListInterface::class); $commands = array_merge($commands, $commandList->getCommands()); } - $commands = array_merge($commands, $this->getVendorCommands($objectManager)); + $commands = array_merge( + $commands, + $this->getVendorCommands($this->objectManager) + ); } catch (\Exception $e) { $this->initException = $e; } + return $commands; } /** - * Gets vendor commands + * Object Manager initialization. * - * @param \Magento\Framework\ObjectManagerInterface $objectManager - * @return array + * @return void + * @SuppressWarnings(PHPMD.ExitExpression) + */ + private function initObjectManager() + { + try { + $params = (new ComplexParameter(self::INPUT_KEY_BOOTSTRAP))->mergeFromArgv($_SERVER, $_SERVER); + $params[Bootstrap::PARAM_REQUIRE_MAINTENANCE] = null; + + $this->objectManager = Bootstrap::create(BP, $params)->getObjectManager(); + + /** @var ObjectManagerProvider $omProvider */ + $omProvider = $this->serviceManager->get(ObjectManagerProvider::class); + $omProvider->setObjectManager($this->objectManager); + } catch (FileSystemException $exception) { + $this->writeGenerationDirectoryReadError(); + + exit(static::RETURN_FAILURE); + } + } + + /** + * Checks whether generation directory is read-only. + * Depends on the current mode: + * production - application will proceed + * default - application will be terminated + * developer - application will be terminated + * + * @return void + * @SuppressWarnings(PHPMD.ExitExpression) + */ + private function assertGenerationPermissions() + { + /** @var GenerationDirectoryAccess $generationDirectoryAccess */ + $generationDirectoryAccess = $this->objectManager->create( + GenerationDirectoryAccess::class, + ['serviceManager' => $this->serviceManager] + ); + /** @var State $state */ + $state = $this->objectManager->get(State::class); + + if ( + $state->getMode() !== State::MODE_PRODUCTION + && !$generationDirectoryAccess->check() + ) { + $this->writeGenerationDirectoryReadError(); + + exit(static::RETURN_FAILURE); + } + } + + /** + * Checks whether compiler is being prepared. + * + * @return void + * @SuppressWarnings(PHPMD.ExitExpression) + */ + private function assertCompilerPreparation() + { + /** + * Temporary workaround until the compiler is able to clear the generation directory + * @todo remove after MAGETWO-44493 resolved + */ + if (class_exists(CompilerPreparation::class)) { + $compilerPreparation = new CompilerPreparation( + $this->serviceManager, + new Console\Input\ArgvInput(), + new File() + ); + + try { + $compilerPreparation->handleCompilerEnvironment(); + } catch (FileSystemException $e) { + $this->writeGenerationDirectoryReadError(); + + exit(static::RETURN_FAILURE); + } + } + } + + /** + * Writes read error to console. + * + * @return void + */ + private function writeGenerationDirectoryReadError() + { + $output = new \Symfony\Component\Console\Output\ConsoleOutput(); + $output->writeln( + '<error>' + . 'Command line user does not have read and write permissions on ' + . $this->getDefaultDirectoryPath(DirectoryList::GENERATION) . ' directory. ' + . 'Please address this issue before using Magento command line.' + . '</error>' + ); + } + + /** + * Retrieves vendor commands. + * + * @param ObjectManagerInterface $objectManager the object manager + * + * @return array an array with external commands */ protected function getVendorCommands($objectManager) { @@ -165,6 +265,25 @@ class Cli extends SymfonyApplication ); } } + return $commands; } + + /** + * Get default directory path by code + * + * @param string $code + * @return string + */ + private function getDefaultDirectoryPath($code) + { + $config = DirectoryList::getDefaultConfig(); + $result = ''; + + if (isset($config[$code][DirectoryList::PATH])) { + $result = $config[$code][DirectoryList::PATH]; + } + + return $result; + } } diff --git a/lib/internal/Magento/Framework/Console/GenerationDirectoryAccess.php b/lib/internal/Magento/Framework/Console/GenerationDirectoryAccess.php index b0baf410d669f16eab5899e07b9e6103a274bd82..a2a1fc9be20e0a4702734cb7065011aab63ab564 100644 --- a/lib/internal/Magento/Framework/Console/GenerationDirectoryAccess.php +++ b/lib/internal/Magento/Framework/Console/GenerationDirectoryAccess.php @@ -14,7 +14,7 @@ use Zend\ServiceManager\ServiceManager; use Magento\Setup\Mvc\Bootstrap\InitParamListener; /** - * Check var/generation read and write access + * Check generated/code read and write access */ class GenerationDirectoryAccess { @@ -33,7 +33,7 @@ class GenerationDirectoryAccess } /** - * Check var/generation read and write access + * Check generated/code read and write access * * @return bool */ diff --git a/lib/internal/Magento/Framework/Module/Manager.php b/lib/internal/Magento/Framework/Module/Manager.php index 7df83917075651eb63f167aa759f9c931ba5edd7..cf22583184b1c89c79da06513a59c588a09faf25 100644 --- a/lib/internal/Magento/Framework/Module/Manager.php +++ b/lib/internal/Magento/Framework/Module/Manager.php @@ -3,90 +3,94 @@ * Copyright © 2013-2017 Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +namespace Magento\Framework\Module; /** - * Module statuses manager + * Module status manager. + * + * Usage: + * + * $manager->isEnabled('Vendor_Module') */ -namespace Magento\Framework\Module; - class Manager { /** - * @var Output\ConfigInterface + * The checker of output modules. + * + * @var Output\ConfigInterface the config checker of output modules. + * @deprecated */ - private $_outputConfig; + private $outputConfig; /** - * @var ModuleListInterface + * The list of all modules. + * + * @var ModuleListInterface the list of all modules. */ - private $_moduleList; + private $moduleList; /** - * @var array + * The list of config paths to ignore. + * + * @var array the list of config paths to ignore. + * @deprecated */ - private $_outputConfigPaths; + private $outputConfigPaths; /** - * @param Output\ConfigInterface $outputConfig - * @param ModuleListInterface $moduleList - * @param array $outputConfigPaths + * Constructor. + * + * @param Output\ConfigInterface $outputConfig the checker of output modules + * @param ModuleListInterface $moduleList the list of all modules + * @param array $outputConfigPaths the list of config paths to ignore */ public function __construct( Output\ConfigInterface $outputConfig, ModuleListInterface $moduleList, array $outputConfigPaths = [] ) { - $this->_outputConfig = $outputConfig; - $this->_moduleList = $moduleList; - $this->_outputConfigPaths = $outputConfigPaths; + $this->outputConfig = $outputConfig; + $this->moduleList = $moduleList; + $this->outputConfigPaths = $outputConfigPaths; } /** - * Whether a module is enabled in the configuration or not + * Checks whether a module is enabled in the configuration or not. * - * @param string $moduleName Fully-qualified module name - * @return boolean + * @param string $moduleName the fully-qualified module name + * + * @return boolean true if module is enabled, false otherwise */ public function isEnabled($moduleName) { - return $this->_moduleList->has($moduleName); + return $this->moduleList->has($moduleName); } /** - * Whether a module output is permitted by the configuration or not + * Checks whether a module output is permitted by the configuration or not. + * + * @param string $moduleName the fully-qualified module name. * - * @param string $moduleName Fully-qualified module name * @return boolean + * @deprecated + * @see \Magento\Framework\Module\Manager::isEnabled() */ public function isOutputEnabled($moduleName) { - if (!$this->isEnabled($moduleName)) { - return false; - } - if (!$this->_isCustomOutputConfigEnabled($moduleName)) { - return false; - } - if ($this->_outputConfig->isEnabled($moduleName)) { - return false; - } - return true; + return $this->isEnabled($moduleName); } /** - * Whether a configuration switch for a module output permits output or not + * Checks whether a configuration switch for a module output permits output. * * @param string $moduleName Fully-qualified module name + * * @return boolean + * @deprecated + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ protected function _isCustomOutputConfigEnabled($moduleName) { - if (isset($this->_outputConfigPaths[$moduleName])) { - $configPath = $this->_outputConfigPaths[$moduleName]; - if (defined($configPath)) { - $configPath = constant($configPath); - } - return $this->_outputConfig->isSetFlag($configPath); - } return true; } } diff --git a/lib/internal/Magento/Framework/Module/Output/Config.php b/lib/internal/Magento/Framework/Module/Output/Config.php index 27a99fdff4121c6514b51533d9e6626fb5f579f8..ca9d8d742d05cd410409f17161649471b17e08b1 100644 --- a/lib/internal/Magento/Framework/Module/Output/Config.php +++ b/lib/internal/Magento/Framework/Module/Output/Config.php @@ -7,6 +7,9 @@ */ namespace Magento\Framework\Module\Output; +/** + * @deprecated + */ class Config implements \Magento\Framework\Module\Output\ConfigInterface { /** @@ -41,7 +44,7 @@ class Config implements \Magento\Framework\Module\Output\ConfigInterface */ public function isEnabled($moduleName) { - return $this->isSetFlag(sprintf(self::XML_PATH_MODULE_OUTPUT_STATUS, $moduleName)); + return false; } /** @@ -49,6 +52,6 @@ class Config implements \Magento\Framework\Module\Output\ConfigInterface */ public function isSetFlag($path) { - return $this->_scopeConfig->isSetFlag($path, $this->_storeType); + return false; } } diff --git a/lib/internal/Magento/Framework/Module/Output/ConfigInterface.php b/lib/internal/Magento/Framework/Module/Output/ConfigInterface.php index e417391ed547455f1d6ccc2a14edbc7a02dc1ae2..2025f5c6f42c5b3312f0907b4f0deaaa3c6cefb9 100644 --- a/lib/internal/Magento/Framework/Module/Output/ConfigInterface.php +++ b/lib/internal/Magento/Framework/Module/Output/ConfigInterface.php @@ -5,6 +5,9 @@ */ namespace Magento\Framework\Module\Output; +/** + * @deprecated + */ interface ConfigInterface { /** diff --git a/lib/internal/Magento/Framework/Module/Test/Unit/ManagerTest.php b/lib/internal/Magento/Framework/Module/Test/Unit/ManagerTest.php index f8fdc438b940cd5dbf604056c26f6727d03c990e..284367c84a721e3ce0202e9ab1f180c0eba96473 100644 --- a/lib/internal/Magento/Framework/Module/Test/Unit/ManagerTest.php +++ b/lib/internal/Magento/Framework/Module/Test/Unit/ManagerTest.php @@ -5,106 +5,60 @@ */ namespace Magento\Framework\Module\Test\Unit; -use Magento\Framework\Module\Plugin\DbStatusValidator; +use Magento\Framework\Module\Manager; +use Magento\Framework\Module\ModuleListInterface; +use Magento\Framework\Module\Output\ConfigInterface; +use PHPUnit_Framework_MockObject_MockObject as Mock; class ManagerTest extends \PHPUnit_Framework_TestCase { /** * XPath in the configuration of a module output flag + * @deprecated */ const XML_PATH_OUTPUT_ENABLED = 'custom/is_module_output_enabled'; /** - * @var \Magento\Framework\Module\Manager + * @var Manager */ - private $_model; + private $model; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var ModuleListInterface|Mock */ - private $_moduleList; + private $moduleList; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var ConfigInterface|Mock + * @deprecated */ - private $_outputConfig; + private $outputConfig; protected function setUp() { - $this->_moduleList = $this->getMockForAbstractClass(\Magento\Framework\Module\ModuleListInterface::class); - $this->_moduleList->expects($this->any()) - ->method('getOne') - ->will($this->returnValueMap([ - ['Module_One', ['name' => 'One_Module', 'setup_version' => '1']], - ['Module_Two', ['name' => 'Two_Module', 'setup_version' => '2']], - ['Module_Three', ['name' => 'Two_Three']], - ])); - $this->_outputConfig = $this->getMockForAbstractClass(\Magento\Framework\Module\Output\ConfigInterface::class); - $this->_model = new \Magento\Framework\Module\Manager( - $this->_outputConfig, - $this->_moduleList, - [ - 'Module_Two' => self::XML_PATH_OUTPUT_ENABLED, - ] + $this->moduleList = $this->getMockBuilder(ModuleListInterface::class) + ->getMockForAbstractClass(); + $this->outputConfig = $this->getMockBuilder(ConfigInterface::class) + ->getMockForAbstractClass(); + + $this->model = new Manager( + $this->outputConfig, + $this->moduleList ); } public function testIsEnabled() { - $this->_moduleList->expects($this->exactly(2))->method('has')->will($this->returnValueMap([ - ['Module_Exists', true], - ['Module_NotExists', false], - ])); - $this->assertTrue($this->_model->isEnabled('Module_Exists')); - $this->assertFalse($this->_model->isEnabled('Module_NotExists')); - } - - public function testIsOutputEnabledReturnsFalseForDisabledModule() - { - $this->_outputConfig->expects($this->any())->method('isSetFlag')->will($this->returnValue(true)); - $this->assertFalse($this->_model->isOutputEnabled('Disabled_Module')); - } - - /** - * @param bool $configValue - * @param bool $expectedResult - * @dataProvider isOutputEnabledGenericConfigPathDataProvider - */ - public function testIsOutputEnabledGenericConfigPath($configValue, $expectedResult) - { - $this->_moduleList->expects($this->once())->method('has')->will($this->returnValue(true)); - $this->_outputConfig->expects($this->once()) - ->method('isEnabled') - ->with('Module_One') - ->will($this->returnValue($configValue)); - $this->assertEquals($expectedResult, $this->_model->isOutputEnabled('Module_One')); - } + $this->moduleList->expects($this->exactly(2)) + ->method('has') + ->willReturnMap( + [ + ['Module_Exists', true], + ['Module_NotExists', false], + ] + ); - public function isOutputEnabledGenericConfigPathDataProvider() - { - return ['output disabled' => [true, false], 'output enabled' => [false, true]]; - } - - /** - * @param bool $configValue - * @param bool $expectedResult - * @dataProvider isOutputEnabledCustomConfigPathDataProvider - */ - public function testIsOutputEnabledCustomConfigPath($configValue, $expectedResult) - { - $this->_moduleList->expects($this->once())->method('has')->will($this->returnValue(true)); - $this->_outputConfig->expects($this->at(0)) - ->method('isSetFlag') - ->with(self::XML_PATH_OUTPUT_ENABLED) - ->will($this->returnValue($configValue)); - $this->assertEquals($expectedResult, $this->_model->isOutputEnabled('Module_Two')); - } - - public function isOutputEnabledCustomConfigPathDataProvider() - { - return [ - 'path literal, output disabled' => [false, false], - 'path literal, output enabled' => [true, true], - ]; + $this->assertTrue($this->model->isEnabled('Module_Exists')); + $this->assertFalse($this->model->isEnabled('Module_NotExists')); } } diff --git a/lib/internal/Magento/Framework/Setup/FilePermissions.php b/lib/internal/Magento/Framework/Setup/FilePermissions.php index 1ca91b57e2e90ab38afcfecd53dee6f7268ccac6..4cc4a1852f0d725e324e4d18a5a53d7bf2f458a3 100644 --- a/lib/internal/Magento/Framework/Setup/FilePermissions.php +++ b/lib/internal/Magento/Framework/Setup/FilePermissions.php @@ -130,7 +130,7 @@ class FilePermissions } /** - * Check all sub-directories and files except for var/generation and var/di + * Check all sub-directories and files except for generated/code and generated/metadata * * @param string $directory * @return bool diff --git a/lib/internal/Magento/Framework/View/Element/AbstractBlock.php b/lib/internal/Magento/Framework/View/Element/AbstractBlock.php index bebeb7917f5010e768ac6b10ce4ca139de98900d..ee0b51b4b71d0dccae94956fcc44593340bbf992 100644 --- a/lib/internal/Magento/Framework/View/Element/AbstractBlock.php +++ b/lib/internal/Magento/Framework/View/Element/AbstractBlock.php @@ -647,12 +647,7 @@ abstract class AbstractBlock extends \Magento\Framework\DataObject implements Bl public function toHtml() { $this->_eventManager->dispatch('view_block_abstract_to_html_before', ['block' => $this]); - if ($this->_scopeConfig->getValue( - 'advanced/modules_disable_output/' . $this->getModuleName(), - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - )) { - return ''; - } + $this->getModuleName(); $html = $this->_loadCache(); if ($html === false) { diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Element/AbstractBlockTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Element/AbstractBlockTest.php index b6846b52972e8b12287f727e56866c5452d04dcf..b6fde2c0f6a7fe465a82b47108dd9d9dd57b99a8 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Element/AbstractBlockTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Element/AbstractBlockTest.php @@ -3,9 +3,6 @@ * Copyright © 2013-2017 Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - -// @codingStandardsIgnoreFile - namespace Magento\Framework\View\Test\Unit\Element; use Magento\Framework\View\Element\AbstractBlock; @@ -207,13 +204,12 @@ class AbstractBlockTest extends \PHPUnit_Framework_TestCase $moduleName = 'Test'; $this->block->setData('module_name', $moduleName); - $this->eventManagerMock->expects($this->any()) + $this->eventManagerMock->expects($this->exactly(2)) ->method('dispatch') - ->with('view_block_abstract_to_html_before', ['block' => $this->block]); - $this->scopeConfigMock->expects($this->once()) - ->method('getValue') - ->with('advanced/modules_disable_output/' . $moduleName, \Magento\Store\Model\ScopeInterface::SCOPE_STORE) - ->willReturn(true); + ->willReturnMap([ + ['view_block_abstract_to_html_before', ['block' => $this->block]], + ['view_block_abstract_to_html_after', ['block' => $this->block]], + ]); $this->assertSame('', $this->block->toHtml()); } @@ -246,10 +242,6 @@ class AbstractBlockTest extends \PHPUnit_Framework_TestCase $this->eventManagerMock->expects($expectsDispatchEvent) ->method('dispatch'); - $this->scopeConfigMock->expects($this->once()) - ->method('getValue') - ->with('advanced/modules_disable_output/' . $moduleName, \Magento\Store\Model\ScopeInterface::SCOPE_STORE) - ->willReturn(false); $this->cacheStateMock->expects($this->any()) ->method('isEnabled') ->with(AbstractBlock::CACHE_GROUP) diff --git a/setup/src/Magento/Setup/Console/Command/UpgradeCommand.php b/setup/src/Magento/Setup/Console/Command/UpgradeCommand.php index 4734b99f19247e8763aa29ee0c19f6ae8fdce129..e652bb4d1183481b7c66230eacd7a0013bef3492 100644 --- a/setup/src/Magento/Setup/Console/Command/UpgradeCommand.php +++ b/setup/src/Magento/Setup/Console/Command/UpgradeCommand.php @@ -17,7 +17,7 @@ use Symfony\Component\Console\Output\OutputInterface; class UpgradeCommand extends AbstractSetupCommand { /** - * Option to skip deletion of var/generation directory + * Option to skip deletion of generated/code directory */ const INPUT_KEY_KEEP_GENERATED = 'keep-generated'; diff --git a/setup/src/Magento/Setup/Console/CompilerPreparation.php b/setup/src/Magento/Setup/Console/CompilerPreparation.php index df32f9b018a0f2bbb8103ae9556c8863d17ff286..e986749ee6efb04a26aa73ddbd59fb933cc003a2 100644 --- a/setup/src/Magento/Setup/Console/CompilerPreparation.php +++ b/setup/src/Magento/Setup/Console/CompilerPreparation.php @@ -1,49 +1,62 @@ <?php -/*** +/** * Copyright © 2013-2017 Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - namespace Magento\Setup\Console; - use Magento\Framework\App\Bootstrap; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Console\GenerationDirectoryAccess; +use Magento\Framework\Exception\FileSystemException; use Magento\Framework\Filesystem\Driver\File; +use Magento\Framework\Phrase; use Magento\Setup\Console\Command\DiCompileCommand; use Magento\Setup\Mvc\Bootstrap\InitParamListener; use Symfony\Component\Console\Input\ArgvInput; +use Zend\ServiceManager\ServiceManager; class CompilerPreparation { - /** @var \Zend\ServiceManager\ServiceManager */ + /** + * @var ServiceManager + */ private $serviceManager; - /** @var ArgvInput */ + /** + * @var ArgvInput + */ private $input; - /** @var File */ + /** + * @var File + */ private $filesystemDriver; /** - * @param \Zend\ServiceManager\ServiceManager $serviceManager + * @var GenerationDirectoryAccess + */ + private $generationDirectoryAccess; + + /** + * @param ServiceManager $serviceManager * @param ArgvInput $input * @param File $filesystemDriver */ public function __construct( - \Zend\ServiceManager\ServiceManager $serviceManager, - \Symfony\Component\Console\Input\ArgvInput $input, - \Magento\Framework\Filesystem\Driver\File $filesystemDriver + ServiceManager $serviceManager, + ArgvInput $input, + File $filesystemDriver ) { - $this->serviceManager = $serviceManager; - $this->input = $input; + $this->serviceManager = $serviceManager; + $this->input = $input; $this->filesystemDriver = $filesystemDriver; } /** - * Determine whether a CLI command is for compilation, and if so, clear the directory + * Determine whether a CLI command is for compilation, and if so, clear the directory. * - * @throws \Magento\Framework\Exception\FileSystemException + * @throws FileSystemException if generation directory is read-only * @return void */ public function handleCompilerEnvironment() @@ -63,10 +76,30 @@ class CompilerPreparation $compileDirList[] = $directoryList->getPath(DirectoryList::GENERATION); $compileDirList[] = $directoryList->getPath(DirectoryList::DI); + if (!$this->getGenerationDirectoryAccess()->check()) { + throw new FileSystemException( + new Phrase('Generation directory can not be written.') + ); + } + foreach ($compileDirList as $compileDir) { if ($this->filesystemDriver->isExists($compileDir)) { $this->filesystemDriver->deleteDirectory($compileDir); } } } + + /** + * Retrieves generation directory access checker. + * + * @return GenerationDirectoryAccess the generation directory access checker + */ + private function getGenerationDirectoryAccess() + { + if (null === $this->generationDirectoryAccess) { + $this->generationDirectoryAccess = new GenerationDirectoryAccess($this->serviceManager); + } + + return $this->generationDirectoryAccess; + } } diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index 0918ee66fbb684e5553a857cda7e5807c417d6b8..088b40aa4decbf24fb11ab65dca17c7ca726e445 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -1262,7 +1262,7 @@ class Installer } /** - * Clear var/generation and reset object manager + * Clear generated/code and reset object manager * * @return void */ diff --git a/setup/src/Magento/Setup/Module/Di/Code/Reader/Decorator/Interceptions.php b/setup/src/Magento/Setup/Module/Di/Code/Reader/Decorator/Interceptions.php index 8a415dd65e43f4221abfd90d414dcc44fab617f3..5480a5953ce583fb50b27f6bbcd872acdcfdf0f7 100644 --- a/setup/src/Magento/Setup/Module/Di/Code/Reader/Decorator/Interceptions.php +++ b/setup/src/Magento/Setup/Module/Di/Code/Reader/Decorator/Interceptions.php @@ -6,6 +6,7 @@ namespace Magento\Setup\Module\Di\Code\Reader\Decorator; use Magento\Setup\Module\Di\Compiler\Log\Log; +use Magento\Framework\App\Filesystem\DirectoryList; /** * Class Interceptions @@ -71,7 +72,8 @@ class Interceptions implements \Magento\Setup\Module\Di\Code\Reader\ClassesScann $nameList = []; foreach ($this->classesScanner->getList($path) as $className) { try { - if (!strpos($path, 'generation')) { // validate all classes except classes in var/generation dir + // validate all classes except classes in generated/code dir + if (!strpos($path, DirectoryList::getDefaultConfig()[DirectoryList::GENERATION][DirectoryList::PATH])) { $this->validator->validate($className); } $nameList[] = $className; diff --git a/setup/src/Magento/Setup/Test/Unit/Console/CompilerPreparationTest.php b/setup/src/Magento/Setup/Test/Unit/Console/CompilerPreparationTest.php index 813cb5dccc98f7ac7d34b0fdc28ff7769070bbaf..93118211062eddac065cdfe4b75bcb8f310421f3 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/CompilerPreparationTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/CompilerPreparationTest.php @@ -1,48 +1,69 @@ <?php -/*** +/** * Copyright © 2013-2017 Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - namespace Magento\Setup\Test\Unit\Console; - +use Magento\Framework\Console\GenerationDirectoryAccess; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Setup\Console\Command\DiCompileCommand; use Magento\Setup\Mvc\Bootstrap\InitParamListener; +use Magento\Framework\Filesystem\Driver\File; use Symfony\Component\Console\Input\ArgvInput; +use Zend\ServiceManager\ServiceManager; +use Magento\Setup\Console\CompilerPreparation; +use PHPUnit_Framework_MockObject_MockObject as Mock; class CompilerPreparationTest extends \PHPUnit_Framework_TestCase { - /** @var \Magento\Setup\Console\CompilerPreparation */ + /** + * @var CompilerPreparation|Mock + */ private $model; - /** @var \Zend\ServiceManager\ServiceManager | \PHPUnit_Framework_MockObject_MockObject */ + /** + * @var ServiceManager|Mock + */ private $serviceManagerMock; - /** @var \Symfony\Component\Console\Input\ArgvInput | \PHPUnit_Framework_MockObject_MockObject */ + /** + * @var ArgvInput|Mock + */ private $inputMock; - /** @var \Magento\Framework\Filesystem\Driver\File | \PHPUnit_Framework_MockObject_MockObject */ + /** + * @var File|Mock + */ private $filesystemDriverMock; + /** + * @var GenerationDirectoryAccess|Mock + */ + private $generationDirectoryAccessMock; + public function setUp() { - $this->serviceManagerMock = $this->getMockBuilder(\Zend\ServiceManager\ServiceManager::class) + $this->serviceManagerMock = $this->getMockBuilder(ServiceManager::class) + ->disableOriginalConstructor() + ->getMock(); + $this->inputMock = $this->getMockBuilder(ArgvInput::class) ->disableOriginalConstructor() ->getMock(); - $this->inputMock = $this->getMockBuilder(\Symfony\Component\Console\Input\ArgvInput::class) + $this->filesystemDriverMock = $this->getMockBuilder(File::class) ->disableOriginalConstructor() ->getMock(); - $this->filesystemDriverMock = $this->getMockBuilder(\Magento\Framework\Filesystem\Driver\File::class) + $this->generationDirectoryAccessMock = $this->getMockBuilder(GenerationDirectoryAccess::class) ->disableOriginalConstructor() ->getMock(); + $this->model = (new ObjectManager($this))->getObject( - \Magento\Setup\Console\CompilerPreparation::class, + CompilerPreparation::class, [ 'serviceManager' => $this->serviceManagerMock, 'input' => $this->inputMock, - 'filesystemDriver' => $this->filesystemDriverMock + 'filesystemDriver' => $this->filesystemDriverMock, + 'generationDirectoryAccess' => $this->generationDirectoryAccessMock, ] ); } @@ -56,21 +77,31 @@ class CompilerPreparationTest extends \PHPUnit_Framework_TestCase */ public function testClearGenerationDirWhenNeeded($commandName, $isCompileCommand, $isHelpOption, $dirExists = false) { - $this->inputMock->expects($this->once())->method('getFirstArgument')->willReturn($commandName); + $this->inputMock->expects($this->once()) + ->method('getFirstArgument') + ->willReturn($commandName); $this->inputMock->expects($this->atLeastOnce()) ->method('hasParameterOption') - ->with( - $this->logicalOr('--help', '-h') - )->willReturn($isHelpOption); + ->with($this->logicalOr('--help', '-h')) + ->willReturn($isHelpOption); + if ($isCompileCommand && !$isHelpOption) { $this->filesystemDriverMock->expects($this->exactly(2)) ->method('isExists') ->willReturn($dirExists); - $this->filesystemDriverMock->expects($this->exactly(((int)$dirExists) * 2))->method('deleteDirectory'); + $this->filesystemDriverMock->expects($this->exactly(((int)$dirExists) * 2)) + ->method('deleteDirectory'); } else { - $this->filesystemDriverMock->expects($this->never())->method('isExists'); - $this->filesystemDriverMock->expects($this->never())->method('deleteDirectory'); + $this->filesystemDriverMock->expects($this->never()) + ->method('isExists'); + $this->filesystemDriverMock->expects($this->never()) + ->method('deleteDirectory'); } + + $this->generationDirectoryAccessMock->expects($this->any()) + ->method('check') + ->willReturn(true); + $this->model->handleCompilerEnvironment(); } @@ -108,10 +139,6 @@ class CompilerPreparationTest extends \PHPUnit_Framework_TestCase $customGenerationDirectory = '/custom/generated/code/directory'; $defaultDiDirectory = '/custom/di/directory'; $mageInitParams = ['MAGE_DIRS' => ['generation' => ['path' => $customGenerationDirectory]]]; - - $this->inputMock->expects($this->once()) - ->method('getFirstArgument') - ->willReturn(DiCompileCommand::NAME); $dirValueMap = [ [ $customGenerationDirectory, @@ -122,16 +149,24 @@ class CompilerPreparationTest extends \PHPUnit_Framework_TestCase true ] ]; - // Filesystem mock - $this->filesystemDriverMock->expects($this->exactly(2))->method('isExists')->willReturn(true); + + $this->inputMock->expects($this->once()) + ->method('getFirstArgument') + ->willReturn(DiCompileCommand::NAME); + $this->filesystemDriverMock->expects($this->exactly(2)) + ->method('isExists') + ->willReturn(true); $this->filesystemDriverMock->expects($this->exactly(2)) ->method('deleteDirectory') - ->will($this->returnValueMap($dirValueMap)); - + ->willReturnMap($dirValueMap); $this->serviceManagerMock->expects($this->once()) ->method('get') ->with(InitParamListener::BOOTSTRAP_PARAM) ->willReturn($mageInitParams); + $this->generationDirectoryAccessMock->expects($this->once()) + ->method('check') + ->willReturn(true); + $this->model->handleCompilerEnvironment(); } @@ -139,10 +174,6 @@ class CompilerPreparationTest extends \PHPUnit_Framework_TestCase { $customGenerationDirectory = '/custom/generated/code/directory'; $customDiDirectory = '/custom/di/directory'; - - $this->inputMock->expects($this->once()) - ->method('getFirstArgument') - ->willReturn(DiCompileCommand::NAME); $dirResultMap = [ [ $this->logicalNot($this->equalTo($customGenerationDirectory)), @@ -154,10 +185,18 @@ class CompilerPreparationTest extends \PHPUnit_Framework_TestCase ] ]; - $this->filesystemDriverMock->expects($this->exactly(2))->method('isExists')->willReturn(true); + $this->inputMock->expects($this->once()) + ->method('getFirstArgument') + ->willReturn(DiCompileCommand::NAME); + $this->filesystemDriverMock->expects($this->exactly(2)) + ->method('isExists') + ->willReturn(true); $this->filesystemDriverMock->expects($this->exactly(2)) ->method('deleteDirectory') - ->will($this->returnValueMap($dirResultMap)); + ->willReturnMap($dirResultMap); + $this->generationDirectoryAccessMock->expects($this->once()) + ->method('check') + ->willReturn(true); $this->model->handleCompilerEnvironment(); } diff --git a/setup/src/Magento/Setup/Test/Unit/Module/Di/Code/Reader/InstancesNamesList/DirectoryTest.php b/setup/src/Magento/Setup/Test/Unit/Module/Di/Code/Reader/InstancesNamesList/DirectoryTest.php index b34322ec9992a650f87ad973f94bb07a27c858fb..0ccc4d9f9b35fe82e3775d2934c27dfecb10c382 100644 --- a/setup/src/Magento/Setup/Test/Unit/Module/Di/Code/Reader/InstancesNamesList/DirectoryTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Module/Di/Code/Reader/InstancesNamesList/DirectoryTest.php @@ -66,7 +66,7 @@ class DirectoryTest extends \PHPUnit_Framework_TestCase $this->classReaderMock, $this->classesScanner, $this->validatorMock, - '/var/generation' + '/generated/code' ); } @@ -111,7 +111,7 @@ class DirectoryTest extends \PHPUnit_Framework_TestCase public function testGetListNoValidation() { - $path = '/var/generation'; + $path = '/generated/code'; $classes = ['NameSpace1\ClassName1', 'NameSpace1\ClassName2']; diff --git a/setup/src/Magento/Setup/Test/Unit/Module/Di/Code/Reader/InstancesNamesList/InterceptionsTest.php b/setup/src/Magento/Setup/Test/Unit/Module/Di/Code/Reader/InstancesNamesList/InterceptionsTest.php index 0591b11b9628c0117ede3b88201722ed6d86da2a..733ba0b85866e38d24f17e6b2d031e75bab17ce3 100644 --- a/setup/src/Magento/Setup/Test/Unit/Module/Di/Code/Reader/InstancesNamesList/InterceptionsTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Module/Di/Code/Reader/InstancesNamesList/InterceptionsTest.php @@ -97,7 +97,7 @@ class InterceptionsTest extends \PHPUnit_Framework_TestCase public function testGetListNoValidation() { - $path = '/var/generation'; + $path = '/generated/code'; $classes = ['NameSpace1\ClassName1', 'NameSpace1\ClassName2'];