Skip to content

Commit 2d48eac

Browse files
MAGECLOUD-4127: Build fails with empty config.php (magento#651)
1 parent 5f05f4e commit 2d48eac

File tree

23 files changed

+501
-348
lines changed

23 files changed

+501
-348
lines changed

composer.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,19 @@
6868
}
6969
},
7070
"scripts": {
71-
"test": [
72-
"@phpstan",
73-
"@phpcs",
74-
"@phpmd",
75-
"@phpunit",
76-
"@coverage"
71+
"test:all": [
72+
"@test:phpstan",
73+
"@test:phpcs",
74+
"@test:phpmd",
75+
"@test:phpunit",
76+
"@test:coverage"
7777
],
78-
"phpstan": "phpstan analyse -c tests/static/phpstan.neon",
79-
"phpcs": "phpcs src --standard=tests/static/phpcs-ruleset.xml -p -n",
80-
"phpmd": "phpmd src xml tests/static/phpmd-ruleset.xml",
81-
"phpunit": "phpunit --configuration tests/unit",
82-
"coverage": "phpunit --configuration tests/unit --coverage-clover tests/unit/tmp/clover.xml && php tests/unit/code-coverage.php tests/unit/tmp/clover.xml",
83-
"coverage-generate": "phpunit --configuration tests/unit --coverage-html tests/unit/tmp/coverage",
78+
"test:phpstan": "phpstan analyse -c tests/static/phpstan.neon",
79+
"test:phpcs": "phpcs src --standard=tests/static/phpcs-ruleset.xml -p -n",
80+
"test:phpmd": "phpmd src xml tests/static/phpmd-ruleset.xml",
81+
"test:phpunit": "phpunit --configuration tests/unit",
82+
"test:coverage": "phpunit --configuration tests/unit --coverage-clover tests/unit/tmp/clover.xml && php tests/unit/code-coverage.php tests/unit/tmp/clover.xml",
83+
"test:coverage-generate": "phpunit --configuration tests/unit --coverage-html tests/unit/tmp/coverage",
8484
"pre-autoload-dump": [
8585
"Magento\\MagentoCloud\\Composer\\ClearAutoload::preAutoloadDump"
8686
]

src/Command/ConfigDump/Generate.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Magento\MagentoCloud\DB\ConnectionInterface;
1111
use Magento\MagentoCloud\Filesystem\Driver\File;
1212
use Magento\MagentoCloud\Filesystem\FileSystemException;
13-
use Magento\MagentoCloud\Filesystem\Resolver\SharedConfig;
13+
use Magento\MagentoCloud\Config\Magento\Shared\Resolver;
1414
use Magento\MagentoCloud\Package\MagentoVersion;
1515
use Magento\MagentoCloud\Package\UndefinedPackageException;
1616
use Magento\MagentoCloud\Util\ArrayManager;
@@ -53,9 +53,9 @@ class Generate
5353
private $arrayManager;
5454

5555
/**
56-
* @var SharedConfig
56+
* @var Resolver
5757
*/
58-
private $sharedConfig;
58+
private $resolver;
5959

6060
/**
6161
* @var MagentoVersion
@@ -72,21 +72,21 @@ class Generate
7272
* @param File $file
7373
* @param ArrayManager $arrayManager
7474
* @param MagentoVersion $magentoVersion
75-
* @param SharedConfig $sharedConfig
75+
* @param Resolver $resolver
7676
* @param PhpFormatter $phpFormatter
7777
*/
7878
public function __construct(
7979
ConnectionInterface $connection,
8080
File $file,
8181
ArrayManager $arrayManager,
8282
MagentoVersion $magentoVersion,
83-
SharedConfig $sharedConfig,
83+
Resolver $resolver,
8484
PhpFormatter $phpFormatter
8585
) {
8686
$this->connection = $connection;
8787
$this->file = $file;
8888
$this->arrayManager = $arrayManager;
89-
$this->sharedConfig = $sharedConfig;
89+
$this->resolver = $resolver;
9090
$this->magentoVersion = $magentoVersion;
9191
$this->phpFormatter = $phpFormatter;
9292
}
@@ -97,14 +97,15 @@ public function __construct(
9797
* @throws UndefinedPackageException
9898
* @throws FileSystemException
9999
*/
100-
public function execute()
100+
public function execute(): void
101101
{
102102
if ($this->magentoVersion->isGreaterOrEqual('2.2')) {
103103
$this->configKeys[] = 'modules';
104104
}
105105

106-
$configFile = $this->sharedConfig->resolve();
107-
$oldConfig = require $configFile;
106+
$configFile = $this->resolver->getPath();
107+
$oldConfig = $this->resolver->read();
108+
108109
$newConfig = [];
109110

110111
foreach ($this->configKeys as $requiredConfigKey) {
@@ -165,7 +166,7 @@ public function execute()
165166
* @param string $scope Name of scope: websites or stores
166167
* @return array Result of config data after filtering
167168
*/
168-
private function filterSystemData($config, $scope)
169+
private function filterSystemData($config, $scope): array
169170
{
170171
$scopeCodes = isset($config['system'][$scope])
171172
? array_keys($config['system'][$scope])

src/Config/Environment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Environment
2626
/**
2727
* The environment variable for controlling the directory nesting level for error reporting
2828
*/
29-
private const ENV_MAGE_ERROR_REPORT_DIR_NESTING_LEVEL = 'MAGE_ERROR_REPORT_DIR_NESTING_LEVEL';
29+
public const ENV_MAGE_ERROR_REPORT_DIR_NESTING_LEVEL = 'MAGE_ERROR_REPORT_DIR_NESTING_LEVEL';
3030

3131
/**
3232
* @var EnvironmentDataInterface

src/Config/Magento/Shared/Reader.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public function read(): array
4646
return [];
4747
}
4848

49-
return require $configPath;
49+
$content = $this->file->requireFile($configPath);
50+
51+
return is_array($content) ? $content : [];
5052
}
5153
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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\MagentoCloud\Config\Magento\Shared;
9+
10+
use Magento\MagentoCloud\Filesystem\ConfigFileList;
11+
use Magento\MagentoCloud\Filesystem\Driver\File;
12+
use Magento\MagentoCloud\Package\MagentoVersion;
13+
use Magento\MagentoCloud\Package\UndefinedPackageException;
14+
15+
/**
16+
* Resolves the correct config file depending on Magento version
17+
*
18+
* Possible files: app/etc/config.php or app/etc/config.php.local
19+
*
20+
* @deprecated should be removed with dropping Magento 2.1 support
21+
*/
22+
class Resolver
23+
{
24+
/**
25+
* @var ConfigFileList
26+
*/
27+
private $configFileList;
28+
29+
/**
30+
* @var MagentoVersion
31+
*/
32+
private $magentoVersion;
33+
34+
/**
35+
* @var File
36+
*/
37+
private $file;
38+
39+
/**
40+
* @param ConfigFileList $configFileList
41+
* @param MagentoVersion $magentoVersion
42+
* @param File $file
43+
*/
44+
public function __construct(ConfigFileList $configFileList, MagentoVersion $magentoVersion, File $file)
45+
{
46+
$this->configFileList = $configFileList;
47+
$this->magentoVersion = $magentoVersion;
48+
$this->file = $file;
49+
}
50+
51+
/**
52+
* Get the resolved config path according to Magento version
53+
*
54+
* @throws UndefinedPackageException
55+
*/
56+
public function getPath(): string
57+
{
58+
return $this->magentoVersion->isGreaterOrEqual('2.2')
59+
? $this->configFileList->getConfig()
60+
: $this->configFileList->getConfigLocal();
61+
}
62+
63+
/**
64+
* Read the contents of resolved config according to Magento version
65+
*
66+
* @return array
67+
* @throws UndefinedPackageException
68+
*/
69+
public function read(): array
70+
{
71+
$configPath = $this->getPath();
72+
73+
if (!$this->file->isExists($configPath)) {
74+
return [];
75+
}
76+
77+
$content = $this->file->requireFile($configPath);
78+
79+
return is_array($content) ? $content : [];
80+
}
81+
}

src/Config/Module.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ public function __construct(ReaderInterface $reader, WriterInterface $writer, Sh
5555
*/
5656
public function refresh(): array
5757
{
58+
// Update initial config file to avoid broken file error.
59+
$this->writer->update(['modules' => []]);
60+
5861
$moduleConfig = $this->reader->read()['modules'] ?? [];
5962

6063
$this->magentoShell->execute('module:enable --all');

src/Config/Validator/Build/ConfigFileStructure.php

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
use Magento\MagentoCloud\Config\Validator;
1111
use Magento\MagentoCloud\Config\ValidatorInterface;
12-
use Magento\MagentoCloud\Filesystem\Driver\File;
13-
use Magento\MagentoCloud\Filesystem\Resolver\SharedConfig;
12+
use Magento\MagentoCloud\Config\Magento\Shared\Resolver;
13+
use Magento\MagentoCloud\Package\UndefinedPackageException;
1414
use Magento\MagentoCloud\Util\ArrayManager;
1515

1616
/**
@@ -26,47 +26,42 @@ class ConfigFileStructure implements ValidatorInterface
2626
*/
2727
private $arrayManager;
2828

29-
/**
30-
* @var File
31-
*/
32-
private $file;
33-
3429
/**
3530
* @var Validator\ResultFactory
3631
*/
3732
private $resultFactory;
3833

3934
/**
40-
* @var SharedConfig
35+
* @var Resolver
4136
*/
42-
private $configResolver;
37+
private $resolver;
4338

4439
/**
4540
* @param ArrayManager $arrayManager
46-
* @param File $file
4741
* @param Validator\ResultFactory $resultFactory
48-
* @param SharedConfig $configResolver
42+
* @param Resolver $resolver
4943
*/
5044
public function __construct(
5145
ArrayManager $arrayManager,
52-
File $file,
5346
Validator\ResultFactory $resultFactory,
54-
SharedConfig $configResolver
47+
Resolver $resolver
5548
) {
5649
$this->arrayManager = $arrayManager;
57-
$this->file = $file;
5850
$this->resultFactory = $resultFactory;
59-
$this->configResolver = $configResolver;
51+
$this->resolver = $resolver;
6052
}
6153

6254
/**
63-
* @inheritdoc
55+
* {@inheritdoc}
56+
*
57+
* @throws UndefinedPackageException
6458
*/
6559
public function validate(): Validator\ResultInterface
6660
{
67-
$configFile = $this->configResolver->resolve();
61+
$configFile = $this->resolver->getPath();
62+
$config = $this->resolver->read();
63+
6864
$configFileName = basename($configFile);
69-
$config = $this->file->isExists($configFile) ? $this->file->requireFile($configFile) : [];
7065

7166
$flattenedConfig = $this->arrayManager->flatten($config);
7267
$websites = $this->arrayManager->filter($flattenedConfig, 'scopes/websites', false);

src/Filesystem/Resolver/ConfigResolverInterface.php

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/Filesystem/Resolver/SharedConfig.php

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)