Skip to content

Commit

Permalink
Remove duplicate code from 83 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sivaram7 committed Nov 11, 2024
1 parent 10d3f76 commit 417b303
Show file tree
Hide file tree
Showing 13 changed files with 0 additions and 1,249 deletions.
274 changes: 0 additions & 274 deletions src/Test/Functional/Acceptance/Acceptance83Cest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,278 +28,4 @@ class Acceptance83Cest extends AcceptanceCest
* @var string
*/
protected $magentoCloudTemplate = '2.4.7';

/**
* @param CliTester $I
*
* @throws TaskException
*/
public function _before(CliTester $I): void
{
parent::_before($I);

$I->copyFileToWorkDir('files/debug_logging/.magento.env.yaml', '.magento.env.yaml');
}

/**
* @param CliTester $I
* @param Example $data
*
* @throws TaskException
*
* @dataProvider defaultDataProvider
*/
public function testDefault(\CliTester $I, \Codeception\Example $data): void
{
$I->generateDockerCompose(
sprintf(
'--mode=production --env-vars="%s"',
$this->convertEnvFromArrayToJson($data['variables'])
)
);
$I->runDockerComposeCommand('run build cloud-build');
$I->startEnvironment();
$I->runDockerComposeCommand('run deploy cloud-deploy');
$I->amOnPage('/');
$I->see('Home page');
$I->see('CMS homepage content goes here.');

$destination = sys_get_temp_dir() . '/app/etc/env.php';
$I->assertTrue($I->downloadFromContainer('/app/etc/env.php', $destination, Docker::DEPLOY_CONTAINER));
$config = require $destination;
$this->checkArraySubset($data['expectedConfig'], $config, $I);

$I->assertTrue($I->runDockerComposeCommand('run deploy ece-command config:dump'));
$destination = sys_get_temp_dir() . '/app/etc/config.php';
$I->assertTrue($I->downloadFromContainer('/app/etc/config.php', $destination, Docker::DEPLOY_CONTAINER));
$config = require $destination;
$flattenKeysConfig = implode(array_keys($this->getArrayManager()->flatten($config, '#')));

$I->assertStringContainsString('#modules', $flattenKeysConfig);
$I->assertStringContainsString('#scopes', $flattenKeysConfig);
$I->assertStringContainsString('#system/default/general/locale/code', $flattenKeysConfig);
$I->assertStringContainsString('#system/default/dev/static/sign', $flattenKeysConfig);
$I->assertStringContainsString('#system/default/dev/front_end_development_workflow', $flattenKeysConfig);
$I->assertStringContainsString('#system/default/dev/template', $flattenKeysConfig);
$I->assertStringContainsString('#system/default/dev/js', $flattenKeysConfig);
$I->assertStringContainsString('#system/default/dev/css', $flattenKeysConfig);
$I->assertStringContainsString('#system/stores', $flattenKeysConfig);
$I->assertStringContainsString('#system/websites', $flattenKeysConfig);
$I->assertStringContainsString('#admin_user/locale/code', $flattenKeysConfig);

$I->amOnPage('/');
$I->see('Home page');
$I->see('CMS homepage content goes here.');

$log = $I->grabFileContent('/var/log/cloud.log');
$I->assertStringContainsString('--admin-password=\'******\'', $log);
if (strpos($log, '--db-password') !== false) {
$I->assertStringContainsString('--db-password=\'******\'', $log);
}
}

/**
* @return array
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function defaultDataProvider(): array
{
return [
'default configuration' => [
'variables' => [
'MAGENTO_CLOUD_VARIABLES' => [
'ADMIN_EMAIL' => '[email protected]',
],
],
'expectedConfig' => [
'cron_consumers_runner' => [
'cron_run' => false,
'max_messages' => 10000,
'consumers' => [],
],
'directories' => [
'document_root_is_pub' => true,
],
'lock' => [
'provider' => 'db',
],
],
],
'test cron_consumers_runner with array and there is MAGENTO_CLOUD_LOCKS_DIR' => [
'variables' => [
'MAGENTO_CLOUD_VARIABLES' => [
'ADMIN_EMAIL' => '[email protected]',
'CRON_CONSUMERS_RUNNER' => [
'cron_run' => true,
'max_messages' => 5000,
'consumers' => ['test'],
],
],
'MAGENTO_CLOUD_LOCKS_DIR' => '/tmp/locks',
],
'expectedConfig' => [
'cron_consumers_runner' => [
'cron_run' => true,
'max_messages' => 5000,
'consumers' => ['test'],
],
'directories' => [
'document_root_is_pub' => true,
],
'lock' => [
'provider' => 'file',
'config' => [
'path' => '/tmp/locks',
],
],
],
],
'test cron_consumers_runner with wrong array, there is MAGENTO_CLOUD_LOCKS_DIR, LOCK_PROVIDER is db' => [
'variables' => [
'MAGENTO_CLOUD_VARIABLES' => [
'ADMIN_EMAIL' => '[email protected]',
'LOCK_PROVIDER' => 'db',
'CRON_CONSUMERS_RUNNER' => [
'cron_run' => 'true',
'max_messages' => 5000,
'consumers' => ['test'],
],
],
'MAGENTO_CLOUD_LOCKS_DIR' => '/tmp/locks',
],
'expectedConfig' => [
'cron_consumers_runner' => [
'cron_run' => false,
'max_messages' => 5000,
'consumers' => ['test'],
],
'directories' => [
'document_root_is_pub' => true,
],
'lock' => [
'provider' => 'db',
],
],
],
'test cron_consumers_runner with string' => [
'variables' => [
'MAGENTO_CLOUD_VARIABLES' => [
'ADMIN_EMAIL' => '[email protected]',
'CRON_CONSUMERS_RUNNER' => '{"cron_run":true, "max_messages":100, "consumers":["test2"]}',
],
],
'expectedConfig' => [
'cron_consumers_runner' => [
'cron_run' => true,
'max_messages' => 100,
'consumers' => ['test2'],
],
'directories' => [
'document_root_is_pub' => true,
],
],
],
'test cron_consumers_runner with wrong string' => [
'variables' => [
'MAGENTO_CLOUD_VARIABLES' => [
'ADMIN_EMAIL' => '[email protected]',
'CRON_CONSUMERS_RUNNER' => '{"cron_run":"true", "max_messages":100, "consumers":["test2"]}',
],
],
'expectedConfig' => [
'cron_consumers_runner' => [
'cron_run' => false,
'max_messages' => 100,
'consumers' => ['test2'],
],
'directories' => [
'document_root_is_pub' => true,
],
],
],
'disabled static content symlinks 3 jobs' => [
'variables' => [
'MAGENTO_CLOUD_VARIABLES' => [
'ADMIN_EMAIL' => '[email protected]',
'STATIC_CONTENT_SYMLINK' => 'disabled',
'STATIC_CONTENT_THREADS' => 3,
],
],
'expectedConfig' => [
'cron_consumers_runner' => [
'cron_run' => false,
'max_messages' => 10000,
'consumers' => [],
],
'directories' => [
'document_root_is_pub' => true,
],
],
],
];
}

/**
* @param CliTester $I
* @throws TaskException
*/
public function testWithOldNonSplitBuildCommand(\CliTester $I): void
{
$config = $I->readAppMagentoYaml();
$config['hooks']['build'] = 'set -e' . PHP_EOL . 'php ./vendor/bin/ece-tools build' . PHP_EOL;
$I->writeAppMagentoYaml($config);

$I->generateDockerCompose('--mode=production');
$I->runDockerComposeCommand('run build cloud-build');
$I->startEnvironment();
$I->runDockerComposeCommand('run deploy cloud-deploy');
$I->amOnPage('/');
$I->see('Home page');
$I->see('CMS homepage content goes here.');
}

/**
* @param CliTester $I
*
* @throws TaskException
*/
public function testDeployInBuild(\CliTester $I): void
{
$tmpConfig = sys_get_temp_dir() . '/app/etc/config.php';
$I->generateDockerCompose('--mode=production');
$I->runDockerComposeCommand('run build cloud-build');
$I->startEnvironment();
$I->runDockerComposeCommand('run deploy cloud-deploy');
$I->amOnPage('/');
$I->see('Home page');
$I->see('CMS homepage content goes here.');
$I->runDockerComposeCommand('run deploy ece-command config:dump');
$I->assertStringNotContainsString(
'Static content deployment was performed during the build phase or disabled. '
. 'Skipping deploy phase static content compression.',
$I->grabFileContent('/var/log/cloud.log')
);
$I->amOnPage('/');
$I->see('Home page');
$I->see('CMS homepage content goes here.');
$I->assertTrue(
$I->downloadFromContainer('/app/etc/config.php', $tmpConfig, Docker::DEPLOY_CONTAINER),
'Cannot download config.php from Docker'
);

$I->assertTrue($I->stopEnvironment());
$I->assertTrue($I->copyFileToWorkDir($tmpConfig, 'app/etc/config.php'));
$I->runDockerComposeCommand('run build cloud-build');
$I->startEnvironment();
$I->runDockerComposeCommand('run deploy cloud-deploy');
$I->assertStringContainsString(
'Static content deployment was performed during the build phase or disabled. '
. 'Skipping deploy phase static content compression.',
$I->grabFileContent('/var/log/cloud.log')
);
$I->amOnPage('/');
$I->see('Home page');
$I->see('CMS homepage content goes here.');
}
}
Loading

0 comments on commit 417b303

Please sign in to comment.