Skip to content

Commit c8a3411

Browse files
authored
MCLOUD-5532: Add Versioning to Env Variable Schema (magento#714)
1 parent ad741c8 commit c8a3411

File tree

11 files changed

+717
-714
lines changed

11 files changed

+717
-714
lines changed

config/schema.yaml

Lines changed: 699 additions & 698 deletions
Large diffs are not rendered by default.

src/Command/GenerateSchema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function execute(InputInterface $input, OutputInterface $output)
8282
{
8383
$output->writeln('Starting schema dist file generation');
8484

85-
$data = $this->schema->getSchema();
85+
$data = $this->schema->getVariables();
8686

8787
$this->file->filePutContents(
8888
$this->fileList->getEnvDistConfig(),

src/Config/Schema.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function getDefaults(string $stage): array
7878
return $this->defaults[$stage];
7979
}
8080

81-
foreach ($this->getSchema() as $itemName => $itemOptions) {
81+
foreach ($this->getVariables() as $itemName => $itemOptions) {
8282
if (array_key_exists($stage, $itemOptions[self::SCHEMA_DEFAULT_VALUE])) {
8383
$this->defaults[$stage][$itemName] = $itemOptions[self::SCHEMA_DEFAULT_VALUE][$stage];
8484
}
@@ -88,7 +88,7 @@ public function getDefaults(string $stage): array
8888
}
8989

9090
/**
91-
* Returns configuration schema.
91+
* Returns variables configuration.
9292
*
9393
* Each configuration item can have next options:
9494
* 'type' - possible types (string, integer, array, etc..)
@@ -99,11 +99,13 @@ public function getDefaults(string $stage): array
9999
* @return array
100100
* @throws \Magento\MagentoCloud\Filesystem\FileSystemException
101101
*/
102-
public function getSchema(): array
102+
public function getVariables(): array
103103
{
104-
return $this->parser->parse(
104+
$schema = $this->parser->parse(
105105
$this->file->fileGetContents($this->systemList->getConfig() . '/schema.yaml'),
106106
Yaml::PARSE_CONSTANT
107107
);
108+
109+
return $schema['variables'] ?? [];
108110
}
109111
}

src/Config/Schema/Validator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function __construct(
6161
*/
6262
public function validate(string $key, string $stage, $value): ResultInterface
6363
{
64-
$schema = $this->schema->getSchema();
64+
$schema = $this->schema->getVariables();
6565
if (!isset($schema[$key])) {
6666
return $this->resultFactory->error(sprintf(
6767
'The %s variable is not allowed in configuration.',

src/Config/Stage/Deploy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function get(string $name)
6868

6969
$value = $decodedValue !== null && json_last_error() === JSON_ERROR_NONE ? $decodedValue : $value;
7070

71-
$schemaDetails = $this->schema->getSchema()[$name];
71+
$schemaDetails = $this->schema->getVariables()[$name];
7272

7373
if ($schemaDetails[Schema::SCHEMA_TYPE] === ['array'] && !is_array($value)) {
7474
$value = $schemaDetails[Schema::SCHEMA_DEFAULT_VALUE][StageConfigInterface::STAGE_DEPLOY];

src/Config/Validator/Deploy/JsonFormatVariable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function validate(): Validator\ResultInterface
5858
try {
5959
$errors = [];
6060

61-
foreach ($this->schema->getSchema() as $optionName => $optionConfig) {
61+
foreach ($this->schema->getVariables() as $optionName => $optionConfig) {
6262
if ($optionConfig[Schema::SCHEMA_TYPE] !== ['array'] ||
6363
!in_array(StageConfigInterface::STAGE_DEPLOY, $optionConfig[Schema::SCHEMA_STAGES]) ||
6464
!is_string($this->mergedConfig->get()[$optionName])

src/Test/Unit/Command/GenerateSchemaTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function testExecute(): void
7373
$output->expects($this->exactly(2))
7474
->method('writeln');
7575

76-
$this->schemaMock->method('getSchema')
76+
$this->schemaMock->method('getVariables')
7777
->willReturn(['some' => 'schema']);
7878
$this->fileListMock->method('getEnvDistConfig')
7979
->willReturn('.magento.env.md');

src/Test/Unit/Config/Schema/ValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function testValidate(
120120
->with('ErrorValidator', ['value1', 'value2'])
121121
->willReturn($mockValidatorError);
122122
$this->schemaMock->expects($this->once())
123-
->method('getSchema')
123+
->method('getVariables')
124124
->willReturn($schema);
125125

126126
$this->assertEquals(

src/Test/Unit/Config/SchemaTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public function testGetSchemaItemsExists(): void
208208
];
209209

210210
foreach ($requiredItems as $item) {
211-
$this->assertArrayHasKey($item, $this->schema->getSchema());
211+
$this->assertArrayHasKey($item, $this->schema->getVariables());
212212
}
213213
}
214214
}

src/Test/Unit/Config/Stage/DeployTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ public function testGet(string $name, $expectedValue, array $mergedConfig, array
6666

6767
if ($schema !== null) {
6868
$this->schemaMock->expects($this->once())
69-
->method('getSchema')
69+
->method('getVariables')
7070
->willReturn($schema);
7171
} else {
7272
$this->schemaMock->expects($this->never())
73-
->method('getSchema');
73+
->method('getVariables');
7474
}
7575

7676
$this->assertEquals($expectedValue, $this->deployConfig->get($name));

0 commit comments

Comments
 (0)