Skip to content

Commit d13162b

Browse files
MAGECLOUD-3275: Rewrite ConfigDumpTest to use Cloud Docker (#431)
1 parent ca83af1 commit d13162b

File tree

7 files changed

+95
-129
lines changed

7 files changed

+95
-129
lines changed

src/Docker/IntegrationV2Builder.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function build(Repository $repository): array
6161
'db',
6262
],
6363
'volumes' => [
64-
$this->getMagentoVolume(false)
64+
$this->getMagentoVolume(true)
6565
],
6666
'volumes_from' => [
6767
'appdata',
@@ -100,7 +100,7 @@ public function build(Repository $repository): array
100100
'db',
101101
],
102102
'volumes' => [
103-
$this->getMagentoVolume(false)
103+
$this->getMagentoVolume(true)
104104
],
105105
'volumes_from' => [
106106
'appdata',
@@ -119,18 +119,21 @@ public function build(Repository $repository): array
119119

120120
$services['services']['build'] = $this->getCliService(
121121
$phpVersion,
122+
'build',
122123
false,
123124
['db'],
124125
'build.magento2.docker'
125126
);
126127
$services['services']['deploy'] = $this->getCliService(
127128
$phpVersion,
129+
'deploy',
128130
false,
129131
['db'],
130132
'deploy.magento2.docker'
131133
);
132134
$services['services']['cron'] = $this->getCliService(
133135
$phpVersion,
136+
'cron',
134137
false,
135138
['db'],
136139
'cron.magento2.docker',
@@ -152,6 +155,7 @@ public function build(Repository $repository): array
152155

153156
/**
154157
* @param string $version
158+
* @param string $name
155159
* @param bool $isReadOnly
156160
* @param array $depends
157161
* @param string $hostname
@@ -161,6 +165,7 @@ public function build(Repository $repository): array
161165
*/
162166
private function getCliService(
163167
string $version,
168+
string $name,
164169
bool $isReadOnly,
165170
array $depends,
166171
string $hostname,
@@ -175,6 +180,7 @@ private function getCliService(
175180
$version,
176181
[
177182
'hostname' => $hostname,
183+
'container_name' => $name,
178184
'depends_on' => $depends,
179185
'volumes' => [
180186
$composeCacheDirectory . ':/root/.composer/cache',
@@ -205,9 +211,7 @@ private function getMagentoVolume(bool $isReadOnly): string
205211
{
206212
$volume = 'magento:/var/www/magento';
207213

208-
return $isReadOnly
209-
? $volume . ':ro'
210-
: $volume . ':rw';
214+
return $isReadOnly ? $volume . ':ro' : $volume . ':rw';
211215
}
212216

213217
/**

src/Test/DockerIntegration/AcceptanceTest.php

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,21 @@
66
namespace Magento\MagentoCloud\Test\DockerIntegration;
77

88
use Magento\MagentoCloud\Test\DockerIntegration\Process;
9+
use Magento\MagentoCloud\Util\ArrayManager;
910

1011
/**
1112
* @inheritdoc
1213
*
1314
* @php 7.2
15+
*
16+
* 1. Test successful deploy
17+
* 2. Test content presence
18+
* 3. Test config dump
19+
* 4. Test content presence
1420
*/
1521
class AcceptanceTest extends AbstractTest
1622
{
17-
public function testDefault()
23+
public function test()
1824
{
1925
(new Process\GitClone('master'))
2026
->setTimeout(null)
@@ -41,11 +47,44 @@ public function testDefault()
4147

4248
$this->assertSame(0, $code);
4349

44-
$process = new Process\Curl();
45-
$process->setTimeout(null)
50+
$assertContentPresence = function () {
51+
$process = new Process\Curl();
52+
$process->setTimeout(null)
53+
->run();
54+
55+
$this->assertSame(0, $process->getExitCode());
56+
$this->assertContains('Home page', $process->getOutput());
57+
};
58+
59+
$assertContentPresence();
60+
61+
$code = (new Process\Ece('config:dump', Config::CONTAINER_DEPLOY))
4662
->run();
4763

48-
$this->assertSame(0, $process->getExitCode());
49-
$this->assertContains('Home page', $process->getOutput());
64+
$this->assertSame(0, $code);
65+
66+
$to = sys_get_temp_dir() . '/app/etc/config.php';
67+
68+
$read = new Process\Copy('/app/etc/config.php', $to);
69+
$read->mustRun();
70+
71+
$config = require $to;
72+
73+
$arrayManager = new ArrayManager();
74+
$flattenKeysConfig = implode(array_keys($arrayManager->flatten($config, '#')));
75+
76+
$this->assertContains('#modules', $flattenKeysConfig);
77+
$this->assertContains('#scopes', $flattenKeysConfig);
78+
$this->assertContains('#system/default/general/locale/code', $flattenKeysConfig);
79+
$this->assertContains('#system/default/dev/static/sign', $flattenKeysConfig);
80+
$this->assertContains('#system/default/dev/front_end_development_workflow', $flattenKeysConfig);
81+
$this->assertContains('#system/default/dev/template', $flattenKeysConfig);
82+
$this->assertContains('#system/default/dev/js', $flattenKeysConfig);
83+
$this->assertContains('#system/default/dev/css', $flattenKeysConfig);
84+
$this->assertContains('#system/stores', $flattenKeysConfig);
85+
$this->assertContains('#system/websites', $flattenKeysConfig);
86+
$this->assertContains('#admin_user/locale/code', $flattenKeysConfig);
87+
88+
$assertContentPresence();
5089
}
5190
}

src/Test/DockerIntegration/Upgrade21Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Upgrade21Test extends UpgradeTest
1515
/**
1616
* @return array
1717
*/
18-
public function defaultDataProvider(): array
18+
public function testDataProvider(): array
1919
{
2020
return [
2121
['2.1.12', '2.2.0']

src/Test/DockerIntegration/Upgrade22Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Upgrade22Test extends UpgradeTest
1515
/**
1616
* @return array
1717
*/
18-
public function defaultDataProvider(): array
18+
public function testDataProvider(): array
1919
{
2020
return [
2121
['2.2.0', '2.2.*']

src/Test/DockerIntegration/UpgradeTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ class UpgradeTest extends AbstractTest
1717
/**
1818
* @param string $updateFrom
1919
* @param string $updateTo
20-
* @dataProvider defaultDataProvider
20+
* @dataProvider testDataProvider
2121
*/
22-
public function testDefault(string $updateFrom, string $updateTo)
22+
public function test(string $updateFrom, string $updateTo)
2323
{
2424
$assert = function () {
2525
$code = (new Process\Ece('build', Config::DEFAULT_CONTAINER))
@@ -40,9 +40,9 @@ public function testDefault(string $updateFrom, string $updateTo)
4040

4141
$this->assertSame(0, $code);
4242

43-
$config = new Config();
44-
$process = new Process\Process(sprintf('curl %s | grep Home', $config->get('env.url.base')));
45-
$process->run();
43+
$process = new Process\Curl();
44+
$process->setTimeout(null)
45+
->run();
4646

4747
$this->assertSame(0, $process->getExitCode());
4848
$this->assertContains('Home page', $process->getOutput());
@@ -67,7 +67,7 @@ public function testDefault(string $updateFrom, string $updateTo)
6767
/**
6868
* @return array
6969
*/
70-
public function defaultDataProvider(): array
70+
public function testDataProvider(): array
7171
{
7272
return [
7373
['2.3.0', '2.3.*']

src/Test/Integration/CommandDumpTest.php

Lines changed: 0 additions & 111 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\MagentoCloud\Test\DockerIntegration\Process;
7+
8+
use Magento\MagentoCloud\Test\DockerIntegration\Config;
9+
10+
class Copy extends Process
11+
{
12+
/**
13+
* @param string $file
14+
* @param string $to
15+
*/
16+
public function __construct(string $file, string $to)
17+
{
18+
$config = new Config();
19+
$dir = pathinfo($to, PATHINFO_DIRNAME);
20+
21+
if (!is_dir($dir)) {
22+
mkdir(pathinfo($to, PATHINFO_DIRNAME), 0755, true);
23+
}
24+
25+
parent::__construct(
26+
sprintf(
27+
'docker cp %s:%s %s',
28+
Config::CONTAINER_DEPLOY,
29+
$config->get('system.magento_dir') . $file,
30+
$to
31+
)
32+
);
33+
}
34+
}

0 commit comments

Comments
 (0)