Skip to content

Commit be14a3d

Browse files
authored
MCLOUD-5535: Add service modification/validation tests (#173)
1 parent fde5777 commit be14a3d

File tree

22 files changed

+564
-80
lines changed

22 files changed

+564
-80
lines changed

.travis.yml

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
os: linux
12
dist: bionic
23

34
git:
@@ -12,13 +13,6 @@ services:
1213
- docker
1314

1415
language: php
15-
php:
16-
- '7.1'
17-
- '7.2'
18-
- '7.3'
19-
20-
env:
21-
- TEST_SUITE=functional
2216

2317
stages:
2418
- static-unit
@@ -28,6 +22,7 @@ stages:
2822
jobs:
2923
include:
3024
- stage: static-unit
25+
php: '7.1'
3126
script: ./tests/travis/static-unit.sh;
3227
env:
3328
- TEST_SUITE=static-unit
@@ -41,6 +36,7 @@ jobs:
4136
- TEST_SUITE=static-unit
4237
- stage: integration
4338
script: ./vendor/bin/phpunit --configuration ./tests/integration;
39+
php: '7.1'
4440
env:
4541
- TEST_SUITE=integration
4642
- script: ./vendor/bin/phpunit --configuration ./tests/integration;
@@ -51,9 +47,23 @@ jobs:
5147
php: '7.3'
5248
env:
5349
- TEST_SUITE=integration
50+
- stage: test
51+
php: '7.1'
52+
dist: xenial
53+
env:
54+
- TEST_SUITE=functional
55+
- php: '7.2'
56+
dist: xenial
57+
env:
58+
- TEST_SUITE=functional
59+
- php: '7.3'
60+
env:
61+
- TEST_SUITE=functional
5462

5563
install: composer update
5664

65+
before_script:
66+
- sudo sysctl -w vm.max_map_count=262144
67+
5768
script:
5869
- if [ $TRAVIS_SECURE_ENV_VARS == "true" ] && [ $TEST_SUITE == "functional" ]; then ./tests/travis/functional.sh; fi;
59-

src/Compose/ProductionBuilder.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,18 @@ public function build(Config $config): Manager
155155
$hasSelenium = $config->hasSelenium();
156156
$hasTmpMounts = $config->hasTmpMounts();
157157

158+
$hasGenerated = !version_compare($config->getMagentoVersion(), '2.2.0', '<');
159+
158160
if ($hasTmpMounts) {
159161
$volumes[self::VOLUME_DOCKER_MNT] = $this->getVolumeConfig('/.docker/mnt');
160162
}
161163

162-
foreach ($this->volumeResolver->getMagentoVolumes($mounts, false, $hasSelenium) as $volumeName => $volume) {
164+
foreach ($this->volumeResolver->getMagentoVolumes(
165+
$mounts,
166+
false,
167+
$hasSelenium,
168+
$hasGenerated
169+
) as $volumeName => $volume) {
163170
$syncConfig = [];
164171

165172
if (!empty($volume['volume']) && $config->getSyncEngine() === self::SYNC_ENGINE_NATIVE) {
@@ -175,15 +182,15 @@ public function build(Config $config): Manager
175182
$manager->setVolumes($volumes);
176183

177184
$volumesBuild = $this->volumeResolver->normalize(array_merge(
178-
$this->volumeResolver->getDefaultMagentoVolumes(false),
185+
$this->volumeResolver->getDefaultMagentoVolumes(false, $hasGenerated),
179186
$this->volumeResolver->getComposerVolumes()
180187
));
181188
$volumesRo = $this->volumeResolver->normalize(array_merge(
182-
$this->volumeResolver->getMagentoVolumes($mounts, true, $hasSelenium),
189+
$this->volumeResolver->getMagentoVolumes($mounts, true, $hasSelenium, $hasGenerated),
183190
$this->volumeResolver->getMountVolumes($hasTmpMounts)
184191
));
185192
$volumesRw = $this->volumeResolver->normalize(array_merge(
186-
$this->volumeResolver->getMagentoVolumes($mounts, false, $hasSelenium),
193+
$this->volumeResolver->getMagentoVolumes($mounts, false, $hasSelenium, $hasGenerated),
187194
$this->volumeResolver->getMountVolumes($hasTmpMounts),
188195
$this->volumeResolver->getComposerVolumes()
189196
));

src/Compose/ProductionBuilder/VolumeResolver.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ class VolumeResolver
1616
{
1717
/**
1818
* @param bool $isReadOnly
19+
* @param bool $hasGenerated
1920
* @return array
2021
*/
21-
public function getDefaultMagentoVolumes(bool $isReadOnly): array
22+
public function getDefaultMagentoVolumes(bool $isReadOnly, bool $hasGenerated = true): array
2223
{
2324
$mode = $isReadOnly ? 'ro' : 'rw';
2425

25-
return [
26+
$volumes = [
2627
BuilderInterface::VOLUME_MAGENTO => [
2728
'path' => BuilderInterface::DIR_MAGENTO,
2829
'volume' => '/',
@@ -32,24 +33,34 @@ public function getDefaultMagentoVolumes(bool $isReadOnly): array
3233
'path' => BuilderInterface::DIR_MAGENTO . '/vendor',
3334
'volume' => '/vendor',
3435
'mode' => $mode,
35-
],
36-
BuilderInterface::VOLUME_MAGENTO_GENERATED => [
36+
]
37+
];
38+
39+
if ($hasGenerated) {
40+
$volumes[BuilderInterface::VOLUME_MAGENTO_GENERATED] = [
3741
'path' => BuilderInterface::DIR_MAGENTO . '/generated',
3842
'volume' => '/generated',
3943
'mode' => $mode
40-
]
41-
];
44+
];
45+
}
46+
47+
return $volumes;
4248
}
4349

4450
/**
4551
* @param array $mounts
4652
* @param bool $isReadOnly
4753
* @param bool $hasSelenium
54+
* @param bool $hasGenerated
4855
* @return array
4956
*/
50-
public function getMagentoVolumes(array $mounts, bool $isReadOnly, bool $hasSelenium): array
51-
{
52-
$volumes = $this->getDefaultMagentoVolumes($isReadOnly);
57+
public function getMagentoVolumes(
58+
array $mounts,
59+
bool $isReadOnly,
60+
bool $hasSelenium,
61+
bool $hasGenerated = true
62+
): array {
63+
$volumes = $this->getDefaultMagentoVolumes($isReadOnly, $hasGenerated);
5364

5465
foreach ($mounts as $volumeData) {
5566
$path = $volumeData['path'];

src/Config/Config.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ public function getVariables(): array
316316
* Returns host value or default if host not set
317317
*
318318
* @return string
319+
* @throws ConfigurationMismatchException
319320
*/
320321
public function getHost(): string
321322
{
@@ -326,6 +327,7 @@ public function getHost(): string
326327
* Returns port value or default if port not set
327328
*
328329
* @return string
330+
* @throws ConfigurationMismatchException
329331
*/
330332
public function getPort(): string
331333
{
@@ -336,8 +338,17 @@ public function getPort(): string
336338
* @return String
337339
* @throws ConfigurationMismatchException
338340
*/
339-
public function getName(): String
341+
public function getName(): string
340342
{
341343
return $this->all()->get(SourceInterface::NAME);
342344
}
345+
346+
/**
347+
* @return string|null
348+
* @throws ConfigurationMismatchException
349+
*/
350+
public function getMagentoVersion(): ?string
351+
{
352+
return $this->all()->get(SourceInterface::MAGENTO_VERSION);
353+
}
343354
}

src/Config/Source/BaseSource.php

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77

88
namespace Magento\CloudDocker\Config\Source;
99

10+
use Composer\IO\NullIO;
11+
use Composer\Factory;
1012
use Illuminate\Config\Repository;
1113
use Magento\CloudDocker\Compose\BuilderFactory;
14+
use Magento\CloudDocker\Filesystem\Filesystem;
15+
use Magento\CloudDocker\Filesystem\FileList;
1216
use Magento\CloudDocker\Filesystem\FilesystemException;
1317
use Magento\CloudDocker\Config\Environment\Shared\Reader as EnvReader;
1418

@@ -28,12 +32,29 @@ class BaseSource implements SourceInterface
2832
*/
2933
private $envReader;
3034

35+
/**
36+
* @var FileList
37+
*/
38+
private $fileList;
39+
40+
/**
41+
* @var Filesystem
42+
*/
43+
private $filesystem;
44+
3145
/**
3246
* @param EnvReader $envReader
47+
* @param Filesystem $filesystem
48+
* @param FileList $fileList
3349
*/
34-
public function __construct(EnvReader $envReader)
35-
{
50+
public function __construct(
51+
EnvReader $envReader,
52+
Filesystem $filesystem,
53+
FileList $fileList
54+
) {
3655
$this->envReader = $envReader;
56+
$this->filesystem = $filesystem;
57+
$this->fileList = $fileList;
3758
}
3859

3960
/**
@@ -49,7 +70,8 @@ public function read(): Repository
4970
self::CRON_ENABLED => false,
5071
self::CONFIG_PORT => self::DEFAULT_PORT,
5172
self::CONFIG_HOST => self::DEFAULT_HOST,
52-
self::INSTALLATION_TYPE => self::INSTALLATION_TYPE_COMPOSER
73+
self::INSTALLATION_TYPE => self::INSTALLATION_TYPE_COMPOSER,
74+
self::MAGENTO_VERSION => $this->getMagentoVersion()
5375
]);
5476

5577
try {
@@ -62,4 +84,22 @@ public function read(): Repository
6284

6385
return $config;
6486
}
87+
88+
/**
89+
* Gets Magento version from composer.json
90+
*
91+
* @return string|null
92+
*/
93+
private function getMagentoVersion(): ?string
94+
{
95+
$composer = $this->fileList->getComposer();
96+
97+
if ($this->filesystem->exists($composer)) {
98+
return Factory::create(new NullIO(), $this->fileList->getMagentoComposer())
99+
->getPackage()
100+
->getVersion();
101+
}
102+
103+
return null;
104+
}
65105
}

src/Config/Source/SourceInterface.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ interface SourceInterface
105105
public const PHP_DISABLED_EXTENSIONS = self::PHP . '.extensions.disabled';
106106

107107
public const INSTALLATION_TYPE = 'install.type';
108+
109+
public const MAGENTO_VERSION = 'magento.version';
110+
108111
/**
109112
* Config
110113
*/

src/Filesystem/FileList.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ public function getComposer(): string
6565
return $this->directoryList->getRoot() . '/composer.json';
6666
}
6767

68+
/**
69+
* @return string
70+
*/
71+
public function getMagentoComposer(): string
72+
{
73+
return $this->directoryList->getMagentoRoot() . '/composer.json';
74+
}
75+
6876
/**
6977
* @return string
7078
*/

src/Test/Functional/Acceptance/AbstractAcceptanceCest.php renamed to src/Test/Functional/Acceptance/AbstractCest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
namespace Magento\CloudDocker\Test\Functional\Acceptance;
99

1010
/**
11-
* Abstract class for AcceptanceCest
11+
* General Cest
1212
*/
13-
abstract class AbstractAcceptanceCest
13+
abstract class AbstractCest
1414
{
1515
/**
1616
* Template version for testing
@@ -42,7 +42,6 @@ public function _before(\CliTester $I): void
4242
public function _after(\CliTester $I): void
4343
{
4444
$I->stopEnvironment();
45-
$I->removeDockerCompose();
4645
$I->removeWorkDir();
4746
}
4847
}

src/Test/Functional/Acceptance/AcceptanceCest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/**
1313
* @group php73
1414
*/
15-
class AcceptanceCest extends AbstractAcceptanceCest
15+
class AcceptanceCest extends AbstractCest
1616
{
1717
/**
1818
* @param \CliTester $I
@@ -32,7 +32,9 @@ public function testProductionMode(\CliTester $I): void
3232

3333
/**
3434
* @param \CliTester $I
35-
* @throws \Robo\Exception\TaskException
35+
* @throws TaskException
36+
* @throws \Codeception\Exception\ModuleConfigException
37+
* @throws \Codeception\Exception\ModuleException
3638
*/
3739
public function testCustomHost(\CliTester $I): void
3840
{
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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\CloudDocker\Test\Functional\Acceptance;
9+
10+
use CliTester;
11+
use Codeception\Example;
12+
use Robo\Exception\TaskException;
13+
14+
/**
15+
* @group php72
16+
*/
17+
class Elasticsearch72Cest extends ElasticsearchCest
18+
{
19+
/**
20+
* Template version for testing
21+
*/
22+
protected const TEMPLATE_VERSION = '2.3.0';
23+
24+
/**
25+
* @return array
26+
*/
27+
protected function dataProvider(): array
28+
{
29+
return [
30+
[
31+
'version' => '1.7',
32+
'xms' => '512m',
33+
'xmx' => '512m',
34+
],
35+
[
36+
'version' => '2.4',
37+
'xms' => '514m',
38+
'xmx' => '514m',
39+
],
40+
[
41+
'version' => '5.2',
42+
'xms' => '516m',
43+
'xmx' => '516m',
44+
'param' => [
45+
'key' => 'index.store.type',
46+
'value' => 'fs',
47+
'needle' => '"index":{"store":{"type":"fs"}}',
48+
]
49+
],
50+
];
51+
}
52+
}

0 commit comments

Comments
 (0)