Skip to content

Commit

Permalink
Merge pull request #166 from magento-commerce/abstract-method-fix
Browse files Browse the repository at this point in the history
MCLOUD-12755  - Stabilize functional  tests for ece-tools
  • Loading branch information
andriyShevtsov authored Dec 5, 2024
2 parents 8ca4db7 + 5f3cb8c commit 12dfdc8
Show file tree
Hide file tree
Showing 27 changed files with 280 additions and 1,305 deletions.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/App/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* @inheritdoc
*/
class Logger extends \Monolog\Logger
class Logger extends \Monolog\Logger // @phpstan-ignore-line
{
/**
* @var File
Expand Down
2 changes: 1 addition & 1 deletion src/App/Logger/Formatter/JsonErrorFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function format(\Monolog\LogRecord|array $record): string
if (isset($loggedErrors[$record['context']['errorCode']])) {
return '';
}

/** @phpstan-ignore-next-line */
return parent::format($this->formatLog($record));
} catch (\Exception $exception) {
return '';
Expand Down
7 changes: 3 additions & 4 deletions src/Step/ValidateConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,9 @@ private function collectErrors(): array

/* @var $validators ValidatorInterface[] */
foreach ($this->validators as $level => $validators) {
/** @phpstan-ignore-next-line */
$level = Logger::toMonologLevel($level);
if (!is_int($level)) {
$level = $level->value;
$level = Logger::toMonologLevel($level); // @phpstan-ignore-line
if (!is_int($level)) { // @phpstan-ignore-line
$level = $level->value; // @phpstan-ignore-line
}
foreach ($validators as $name => $validator) {
if (!$validator instanceof ValidatorInterface) {
Expand Down
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 12dfdc8

Please sign in to comment.