Skip to content

Commit 25d6cc5

Browse files
oshmyheliukBohdan Korablov
authored andcommitted
MAGECLOUD-1493: URL Update Flow is Working not as Expected (#138)
1 parent 11d3b5f commit 25d6cc5

File tree

2 files changed

+42
-27
lines changed

2 files changed

+42
-27
lines changed

src/Config/Environment.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ class Environment
1818
const MAGENTO_PRODUCTION_MODE = 'production';
1919
const MAGENTO_DEVELOPER_MODE = 'developer';
2020

21-
const GIT_MASTER_BRANCH_RE = '/^master(?:-[a-z0-9]+)?$/i';
21+
/**
22+
* Regex pattern for detecting main branch.
23+
* The name of the main branch must be started from one of three prefixes:
24+
* master - is for integration environment;
25+
* production and staging are for production and staging environments respectively.
26+
*/
27+
const GIT_MASTER_BRANCH_RE = '/^(master|production|staging)(?:-[a-z0-9]+)?$/i';
2228

2329
const CLOUD_MODE_ENTERPRISE = 'enterprise';
2430

@@ -278,6 +284,9 @@ public function getDefaultCurrency(): string
278284
}
279285

280286
/**
287+
* Checks that environment uses the main branch depending on environment variable MAGENTO_CLOUD_ENVIRONMENT
288+
* which contains the name of the git branch.
289+
*
281290
* @return bool
282291
*/
283292
public function isMasterBranch(): bool

src/Test/Unit/Config/EnvironmentTest.php

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -161,37 +161,43 @@ public function testGetDefaultCurrency()
161161
);
162162
}
163163

164+
/**
165+
* @param bool $expectedResult
166+
* @param string $branchName
167+
* @dataProvider isMasterBranchDataProvider
168+
*/
169+
public function testIsMasterBranch(bool $expectedResult, string $branchName)
170+
{
171+
$_ENV['MAGENTO_CLOUD_ENVIRONMENT'] = $branchName;
172+
173+
$this->assertSame(
174+
$expectedResult,
175+
$this->environment->isMasterBranch()
176+
);
177+
}
178+
164179
/**
165180
* @return array
166181
*/
167-
public function getCronConsumersRunnerDataProvider(): array
182+
public function isMasterBranchDataProvider(): array
168183
{
169184
return [
170-
['variables' => [], 'expectedResult' => []],
171-
[
172-
'variables' => [
173-
'CRON_CONSUMERS_RUNNER' => [
174-
'cron_run' => 'false',
175-
'max_messages' => '100',
176-
'consumers' => ['test'],
177-
],
178-
],
179-
'expectedResult' => [
180-
'cron_run' => 'false',
181-
'max_messages' => '100',
182-
'consumers' => ['test'],
183-
],
184-
],
185-
[
186-
'variables' => [
187-
'CRON_CONSUMERS_RUNNER' => '{"cron_run":"false", "max_messages":"100", "consumers":["test"]}',
188-
],
189-
'expectedResult' => [
190-
'cron_run' => 'false',
191-
'max_messages' => '100',
192-
'consumers' => ['test'],
193-
],
194-
],
185+
[false, 'branch213'],
186+
[false, 'prod-branch'],
187+
[false, 'stage'],
188+
[false, 'branch-production-lad13m'],
189+
[false, 'branch-staging-lad13m'],
190+
[false, 'branch-master-lad13m'],
191+
[false, 'branch-production'],
192+
[false, 'branch-staging'],
193+
[false, 'branch-master'],
194+
[false, 'product'],
195+
[true, 'staging'],
196+
[true, 'staging-ba3ma'],
197+
[true, 'master'],
198+
[true, 'master-ad123m'],
199+
[true, 'production'],
200+
[true, 'production-lad13m'],
195201
];
196202
}
197203
}

0 commit comments

Comments
 (0)