Skip to content

Commit 5d91400

Browse files
committed
Merge remote-tracking branch 'origin/2.3-develop-pr6' into 2.3-develop-pr2
2 parents 3365516 + 36ce88d commit 5d91400

File tree

3 files changed

+200
-0
lines changed
  • dev/tests/integration/testsuite/Magento/Framework/Console
  • lib/internal/Magento/Framework/Console

3 files changed

+200
-0
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Console;
9+
10+
use Magento\Framework\App\DeploymentConfig;
11+
use Magento\Framework\App\DeploymentConfig\FileReader;
12+
use Magento\Framework\App\DeploymentConfig\Writer;
13+
use Magento\Framework\App\Filesystem\DirectoryList;
14+
use Magento\Framework\Config\File\ConfigFilePool;
15+
use Magento\Framework\Filesystem;
16+
use Magento\Framework\ObjectManagerInterface;
17+
use Magento\TestFramework\Helper\Bootstrap;
18+
19+
class CliTest extends \PHPUnit\Framework\TestCase
20+
{
21+
/**
22+
* @var ObjectManagerInterface
23+
*/
24+
private $objectManager;
25+
26+
/**
27+
* @var Filesystem
28+
*/
29+
private $filesystem;
30+
31+
/**
32+
* @var ConfigFilePool
33+
*/
34+
private $configFilePool;
35+
36+
/**
37+
* @var FileReader
38+
*/
39+
private $reader;
40+
41+
/**
42+
* @var Writer
43+
*/
44+
private $writer;
45+
46+
/**
47+
* @var array
48+
*/
49+
private $envConfig;
50+
51+
/**
52+
* @inheritdoc
53+
*/
54+
protected function setUp()
55+
{
56+
$this->objectManager = Bootstrap::getObjectManager();
57+
$this->configFilePool = $this->objectManager->get(ConfigFilePool::class);
58+
$this->filesystem = $this->objectManager->get(Filesystem::class);
59+
$this->reader = $this->objectManager->get(FileReader::class);
60+
$this->writer = $this->objectManager->get(Writer::class);
61+
62+
$this->envConfig = $this->reader->load(ConfigFilePool::APP_ENV);
63+
}
64+
65+
/**
66+
* @inheritdoc
67+
*/
68+
protected function tearDown()
69+
{
70+
$this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->writeFile(
71+
$this->configFilePool->getPath(ConfigFilePool::APP_ENV),
72+
"<?php\n return array();\n"
73+
);
74+
75+
$this->writer->saveConfig([ConfigFilePool::APP_ENV => $this->envConfig], true);
76+
}
77+
78+
/**
79+
* Checks that settings from env.php config file are applied
80+
* to created application instance.
81+
*
82+
* @param bool $isPub
83+
* @param array $params
84+
* @dataProvider documentRootIsPubProvider
85+
*/
86+
public function testDocumentRootIsPublic($isPub, $params)
87+
{
88+
$config = include __DIR__ . '/_files/env.php';
89+
$config['directories']['document_root_is_pub'] = $isPub;
90+
$this->writer->saveConfig([ConfigFilePool::APP_ENV => $config], true);
91+
92+
$cli = new Cli();
93+
$cliReflection = new \ReflectionClass($cli);
94+
95+
$serviceManagerProperty = $cliReflection->getProperty('serviceManager');
96+
$serviceManagerProperty->setAccessible(true);
97+
$serviceManager = $serviceManagerProperty->getValue($cli);
98+
$deploymentConfig = $this->objectManager->get(DeploymentConfig::class);
99+
$serviceManager->setAllowOverride(true);
100+
$serviceManager->setService(DeploymentConfig::class, $deploymentConfig);
101+
$serviceManagerProperty->setAccessible(false);
102+
103+
$documentRootResolver = $cliReflection->getMethod('documentRootResolver');
104+
$documentRootResolver->setAccessible(true);
105+
106+
self::assertEquals($params, $documentRootResolver->invoke($cli));
107+
}
108+
109+
/**
110+
* Provides document root setting and expecting
111+
* properties for object manager creation.
112+
*
113+
* @return array
114+
*/
115+
public function documentRootIsPubProvider(): array
116+
{
117+
return [
118+
[true, [
119+
'MAGE_DIRS' => [
120+
'pub' => ['uri' => ''],
121+
'media' => ['uri' => 'media'],
122+
'static' => ['uri' => 'static'],
123+
'upload' => ['uri' => 'media/upload']
124+
]
125+
]],
126+
[false, []]
127+
];
128+
}
129+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
return [
9+
'backend' => [
10+
'frontName' => 'admin',
11+
],
12+
'crypt' => [
13+
'key' => 'some_key',
14+
],
15+
'session' => [
16+
'save' => 'files',
17+
],
18+
'db' => [
19+
'table_prefix' => '',
20+
'connection' => [],
21+
],
22+
'resource' => [],
23+
'x-frame-options' => 'SAMEORIGIN',
24+
'MAGE_MODE' => 'default',
25+
'cache_types' => [
26+
'config' => 1,
27+
'layout' => 1,
28+
'block_html' => 1,
29+
'collections' => 1,
30+
'reflection' => 1,
31+
'db_ddl' => 1,
32+
'eav' => 1,
33+
'customer_notification' => 1,
34+
'config_integration' => 1,
35+
'config_integration_api' => 1,
36+
'full_page' => 1,
37+
'translate' => 1,
38+
'config_webservice' => 1,
39+
],
40+
'install' => [
41+
'date' => 'Thu, 09 Feb 2017 14:28:00 +0000',
42+
],
43+
'directories' => [
44+
'document_root_is_pub' => true
45+
]
46+
];

lib/internal/Magento/Framework/Console/Cli.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Magento\Setup\Console\CompilerPreparation;
2020
use Magento\Setup\Model\ObjectManagerProvider;
2121
use Symfony\Component\Console;
22+
use Magento\Framework\Config\ConfigOptionsListConstants;
2223

2324
/**
2425
* Magento 2 CLI Application.
@@ -157,6 +158,7 @@ private function initObjectManager()
157158
{
158159
$params = (new ComplexParameter(self::INPUT_KEY_BOOTSTRAP))->mergeFromArgv($_SERVER, $_SERVER);
159160
$params[Bootstrap::PARAM_REQUIRE_MAINTENANCE] = null;
161+
$params = $this->documentRootResolver($params);
160162
$requestParams = $this->serviceManager->get('magento-init-params');
161163
$appBootstrapKey = Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS;
162164

@@ -242,4 +244,27 @@ protected function getVendorCommands($objectManager)
242244

243245
return $commands;
244246
}
247+
248+
/**
249+
* Provides updated configuration in
250+
* accordance to document root settings.
251+
*
252+
* @param array $config
253+
* @return array
254+
*/
255+
private function documentRootResolver(array $config = []): array
256+
{
257+
$params = [];
258+
$deploymentConfig = $this->serviceManager->get(DeploymentConfig::class);
259+
if ((bool)$deploymentConfig->get(ConfigOptionsListConstants::CONFIG_PATH_DOCUMENT_ROOT_IS_PUB)) {
260+
$params[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] = [
261+
DirectoryList::PUB => [DirectoryList::URL_PATH => ''],
262+
DirectoryList::MEDIA => [DirectoryList::URL_PATH => 'media'],
263+
DirectoryList::STATIC_VIEW => [DirectoryList::URL_PATH => 'static'],
264+
DirectoryList::UPLOAD => [DirectoryList::URL_PATH => 'media/upload'],
265+
];
266+
}
267+
268+
return array_merge_recursive($config, $params);
269+
}
245270
}

0 commit comments

Comments
 (0)