Skip to content

Commit f8a750d

Browse files
Merge pull request #157 from magento-commerce/MCLOUD-12854
MCLOUD-12854 Codeception v5 DataProvider issue fix
2 parents 24ac0bf + c8f3570 commit f8a750d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2057
-547
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
/auth.json
99
/codeception.yml
1010
/_workdir
11+
/_workdir_cache
1112
/*.code-workspace
1213
**/.phpunit.result.cache
Lines changed: 305 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,305 @@
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\Test\Functional\Acceptance;
9+
10+
use CliTester;
11+
use Robo\Exception\TaskException;
12+
use Codeception\Example;
13+
use Magento\CloudDocker\Test\Functional\Codeception\Docker;
14+
15+
/**
16+
* This test runs on the latest version of PHP
17+
*
18+
* 1. Test successful deploy
19+
* 2. Test content presence
20+
* 3. Test config dump
21+
* 4. Test content presence
22+
*
23+
* @group php83
24+
*/
25+
class Acceptance83Cest extends AcceptanceCest
26+
{
27+
/**
28+
* @var string
29+
*/
30+
protected $magentoCloudTemplate = '2.4.7';
31+
32+
/**
33+
* @param CliTester $I
34+
*
35+
* @throws TaskException
36+
*/
37+
public function _before(CliTester $I): void
38+
{
39+
parent::_before($I);
40+
41+
$I->copyFileToWorkDir('files/debug_logging/.magento.env.yaml', '.magento.env.yaml');
42+
}
43+
44+
/**
45+
* @param CliTester $I
46+
* @param Example $data
47+
*
48+
* @throws TaskException
49+
*
50+
* @dataProvider defaultDataProvider
51+
*/
52+
public function testDefault(\CliTester $I, \Codeception\Example $data): void
53+
{
54+
$I->generateDockerCompose(
55+
sprintf(
56+
'--mode=production --env-vars="%s"',
57+
$this->convertEnvFromArrayToJson($data['variables'])
58+
)
59+
);
60+
$I->runDockerComposeCommand('run build cloud-build');
61+
$I->startEnvironment();
62+
$I->runDockerComposeCommand('run deploy cloud-deploy');
63+
$I->amOnPage('/');
64+
$I->see('Home page');
65+
$I->see('CMS homepage content goes here.');
66+
67+
$destination = sys_get_temp_dir() . '/app/etc/env.php';
68+
$I->assertTrue($I->downloadFromContainer('/app/etc/env.php', $destination, Docker::DEPLOY_CONTAINER));
69+
$config = require $destination;
70+
$this->checkArraySubset($data['expectedConfig'], $config, $I);
71+
72+
$I->assertTrue($I->runDockerComposeCommand('run deploy ece-command config:dump'));
73+
$destination = sys_get_temp_dir() . '/app/etc/config.php';
74+
$I->assertTrue($I->downloadFromContainer('/app/etc/config.php', $destination, Docker::DEPLOY_CONTAINER));
75+
$config = require $destination;
76+
$flattenKeysConfig = implode(array_keys($this->getArrayManager()->flatten($config, '#')));
77+
78+
$I->assertStringContainsString('#modules', $flattenKeysConfig);
79+
$I->assertStringContainsString('#scopes', $flattenKeysConfig);
80+
$I->assertStringContainsString('#system/default/general/locale/code', $flattenKeysConfig);
81+
$I->assertStringContainsString('#system/default/dev/static/sign', $flattenKeysConfig);
82+
$I->assertStringContainsString('#system/default/dev/front_end_development_workflow', $flattenKeysConfig);
83+
$I->assertStringContainsString('#system/default/dev/template', $flattenKeysConfig);
84+
$I->assertStringContainsString('#system/default/dev/js', $flattenKeysConfig);
85+
$I->assertStringContainsString('#system/default/dev/css', $flattenKeysConfig);
86+
$I->assertStringContainsString('#system/stores', $flattenKeysConfig);
87+
$I->assertStringContainsString('#system/websites', $flattenKeysConfig);
88+
$I->assertStringContainsString('#admin_user/locale/code', $flattenKeysConfig);
89+
90+
$I->amOnPage('/');
91+
$I->see('Home page');
92+
$I->see('CMS homepage content goes here.');
93+
94+
$log = $I->grabFileContent('/var/log/cloud.log');
95+
$I->assertStringContainsString('--admin-password=\'******\'', $log);
96+
if (strpos($log, '--db-password') !== false) {
97+
$I->assertStringContainsString('--db-password=\'******\'', $log);
98+
}
99+
}
100+
101+
/**
102+
* @return array
103+
*
104+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
105+
*/
106+
protected function defaultDataProvider(): array
107+
{
108+
return [
109+
'default configuration' => [
110+
'variables' => [
111+
'MAGENTO_CLOUD_VARIABLES' => [
112+
'ADMIN_EMAIL' => 'admin@example.com',
113+
],
114+
],
115+
'expectedConfig' => [
116+
'cron_consumers_runner' => [
117+
'cron_run' => false,
118+
'max_messages' => 10000,
119+
'consumers' => [],
120+
],
121+
'directories' => [
122+
'document_root_is_pub' => true,
123+
],
124+
'lock' => [
125+
'provider' => 'db',
126+
],
127+
],
128+
],
129+
'test cron_consumers_runner with array and there is MAGENTO_CLOUD_LOCKS_DIR' => [
130+
'variables' => [
131+
'MAGENTO_CLOUD_VARIABLES' => [
132+
'ADMIN_EMAIL' => 'admin@example.com',
133+
'CRON_CONSUMERS_RUNNER' => [
134+
'cron_run' => true,
135+
'max_messages' => 5000,
136+
'consumers' => ['test'],
137+
],
138+
],
139+
'MAGENTO_CLOUD_LOCKS_DIR' => '/tmp/locks',
140+
],
141+
'expectedConfig' => [
142+
'cron_consumers_runner' => [
143+
'cron_run' => true,
144+
'max_messages' => 5000,
145+
'consumers' => ['test'],
146+
],
147+
'directories' => [
148+
'document_root_is_pub' => true,
149+
],
150+
'lock' => [
151+
'provider' => 'file',
152+
'config' => [
153+
'path' => '/tmp/locks',
154+
],
155+
],
156+
],
157+
],
158+
'test cron_consumers_runner with wrong array, there is MAGENTO_CLOUD_LOCKS_DIR, LOCK_PROVIDER is db' => [
159+
'variables' => [
160+
'MAGENTO_CLOUD_VARIABLES' => [
161+
'ADMIN_EMAIL' => 'admin@example.com',
162+
'LOCK_PROVIDER' => 'db',
163+
'CRON_CONSUMERS_RUNNER' => [
164+
'cron_run' => 'true',
165+
'max_messages' => 5000,
166+
'consumers' => ['test'],
167+
],
168+
],
169+
'MAGENTO_CLOUD_LOCKS_DIR' => '/tmp/locks',
170+
],
171+
'expectedConfig' => [
172+
'cron_consumers_runner' => [
173+
'cron_run' => false,
174+
'max_messages' => 5000,
175+
'consumers' => ['test'],
176+
],
177+
'directories' => [
178+
'document_root_is_pub' => true,
179+
],
180+
'lock' => [
181+
'provider' => 'db',
182+
],
183+
],
184+
],
185+
'test cron_consumers_runner with string' => [
186+
'variables' => [
187+
'MAGENTO_CLOUD_VARIABLES' => [
188+
'ADMIN_EMAIL' => 'admin@example.com',
189+
'CRON_CONSUMERS_RUNNER' => '{"cron_run":true, "max_messages":100, "consumers":["test2"]}',
190+
],
191+
],
192+
'expectedConfig' => [
193+
'cron_consumers_runner' => [
194+
'cron_run' => true,
195+
'max_messages' => 100,
196+
'consumers' => ['test2'],
197+
],
198+
'directories' => [
199+
'document_root_is_pub' => true,
200+
],
201+
],
202+
],
203+
'test cron_consumers_runner with wrong string' => [
204+
'variables' => [
205+
'MAGENTO_CLOUD_VARIABLES' => [
206+
'ADMIN_EMAIL' => 'admin@example.com',
207+
'CRON_CONSUMERS_RUNNER' => '{"cron_run":"true", "max_messages":100, "consumers":["test2"]}',
208+
],
209+
],
210+
'expectedConfig' => [
211+
'cron_consumers_runner' => [
212+
'cron_run' => false,
213+
'max_messages' => 100,
214+
'consumers' => ['test2'],
215+
],
216+
'directories' => [
217+
'document_root_is_pub' => true,
218+
],
219+
],
220+
],
221+
'disabled static content symlinks 3 jobs' => [
222+
'variables' => [
223+
'MAGENTO_CLOUD_VARIABLES' => [
224+
'ADMIN_EMAIL' => 'admin@example.com',
225+
'STATIC_CONTENT_SYMLINK' => 'disabled',
226+
'STATIC_CONTENT_THREADS' => 3,
227+
],
228+
],
229+
'expectedConfig' => [
230+
'cron_consumers_runner' => [
231+
'cron_run' => false,
232+
'max_messages' => 10000,
233+
'consumers' => [],
234+
],
235+
'directories' => [
236+
'document_root_is_pub' => true,
237+
],
238+
],
239+
],
240+
];
241+
}
242+
243+
/**
244+
* @param CliTester $I
245+
* @throws TaskException
246+
*/
247+
public function testWithOldNonSplitBuildCommand(\CliTester $I): void
248+
{
249+
$config = $I->readAppMagentoYaml();
250+
$config['hooks']['build'] = 'set -e' . PHP_EOL . 'php ./vendor/bin/ece-tools build' . PHP_EOL;
251+
$I->writeAppMagentoYaml($config);
252+
253+
$I->generateDockerCompose('--mode=production');
254+
$I->runDockerComposeCommand('run build cloud-build');
255+
$I->startEnvironment();
256+
$I->runDockerComposeCommand('run deploy cloud-deploy');
257+
$I->amOnPage('/');
258+
$I->see('Home page');
259+
$I->see('CMS homepage content goes here.');
260+
}
261+
262+
/**
263+
* @param CliTester $I
264+
*
265+
* @throws TaskException
266+
*/
267+
public function testDeployInBuild(\CliTester $I): void
268+
{
269+
$tmpConfig = sys_get_temp_dir() . '/app/etc/config.php';
270+
$I->generateDockerCompose('--mode=production');
271+
$I->runDockerComposeCommand('run build cloud-build');
272+
$I->startEnvironment();
273+
$I->runDockerComposeCommand('run deploy cloud-deploy');
274+
$I->amOnPage('/');
275+
$I->see('Home page');
276+
$I->see('CMS homepage content goes here.');
277+
$I->runDockerComposeCommand('run deploy ece-command config:dump');
278+
$I->assertStringNotContainsString(
279+
'Static content deployment was performed during the build phase or disabled. '
280+
. 'Skipping deploy phase static content compression.',
281+
$I->grabFileContent('/var/log/cloud.log')
282+
);
283+
$I->amOnPage('/');
284+
$I->see('Home page');
285+
$I->see('CMS homepage content goes here.');
286+
$I->assertTrue(
287+
$I->downloadFromContainer('/app/etc/config.php', $tmpConfig, Docker::DEPLOY_CONTAINER),
288+
'Cannot download config.php from Docker'
289+
);
290+
291+
$I->assertTrue($I->stopEnvironment());
292+
$I->assertTrue($I->copyFileToWorkDir($tmpConfig, 'app/etc/config.php'));
293+
$I->runDockerComposeCommand('run build cloud-build');
294+
$I->startEnvironment();
295+
$I->runDockerComposeCommand('run deploy cloud-deploy');
296+
$I->assertStringContainsString(
297+
'Static content deployment was performed during the build phase or disabled. '
298+
. 'Skipping deploy phase static content compression.',
299+
$I->grabFileContent('/var/log/cloud.log')
300+
);
301+
$I->amOnPage('/');
302+
$I->see('Home page');
303+
$I->see('CMS homepage content goes here.');
304+
}
305+
}

0 commit comments

Comments
 (0)