From 1e13ec3829c3de8c43d319fa6fe4b4dac6bf6c8a Mon Sep 17 00:00:00 2001 From: Oleg Posyniak Date: Thu, 5 Mar 2020 17:08:23 -0600 Subject: [PATCH] MAGECLOUD-4486: Docker functional tests and CI with ece-tools test framework (#656) --- .gitignore | 1 + .travis.yml | 7 +- codeception.dist.yml | 33 +- composer.json | 6 + config/schema.yaml | 16 +- src/Config/Schema.php | 22 +- src/Test/Functional/Acceptance.suite.dist.yml | 5 +- .../Functional/Acceptance/AbstractCest.php | 77 +- .../Acceptance/AbstractInstallCest.php | 31 - .../Acceptance/AcceptanceCeCest.php | 20 +- .../Functional/Acceptance/AcceptanceCest.php | 89 ++- .../Acceptance/AdminCredentialCest.php | 54 +- src/Test/Functional/Acceptance/Cron21Cest.php | 2 +- src/Test/Functional/Acceptance/CronCest.php | 49 +- .../Functional/Acceptance/CronUnlockCest.php | 32 +- .../DataTypesOptionValidationCest.php | 34 +- .../Acceptance/DatabaseConfigurationCest.php | 38 +- .../Acceptance/ElasticSearch22Cest.php | 17 +- .../Acceptance/ElasticSearch23Php72Cest.php | 17 +- .../Acceptance/ElasticSearchCest.php | 60 +- .../Acceptance/ErrorMessageCest.php | 18 +- .../Acceptance/PatchApplierCest.php | 30 +- .../Functional/Acceptance/PostDeployCest.php | 58 +- .../Acceptance/ReportDirNestingLevelCest.php | 118 +-- .../Functional/Acceptance/ScdMatrixCest.php | 25 +- .../Functional/Acceptance/ScdStrategyCest.php | 26 +- .../Acceptance/ScenarioExtensibilityCest.php | 41 +- .../Acceptance/SessionConfigurationCest.php | 36 +- .../Functional/Acceptance/Upgrade21Cest.php | 4 +- .../Functional/Acceptance/Upgrade22Cest.php | 2 +- .../Functional/Acceptance/UpgradeCest.php | 37 +- .../Functional/Acceptance/WizardScdCest.php | 35 +- src/Test/Unit/Config/SchemaTest.php | 10 +- tests/functional/Codeception/Docker.php | 687 ------------------ tests/functional/Codeception/MagentoDb.php | 103 --- tests/functional/Robo/Tasks.php | 98 --- tests/functional/Robo/Tasks/Bash.php | 15 - .../functional/Robo/Tasks/CopyFromDocker.php | 111 --- tests/functional/Robo/Tasks/CopyToDocker.php | 108 --- .../Robo/Tasks/DockerCompose/Run.php | 132 ---- tests/functional/Robo/Tasks/EnvCleanUp.php | 65 -- tests/functional/Robo/Tasks/EnvDown.php | 37 - tests/functional/Robo/Tasks/EnvUp.php | 37 - .../Robo/Tasks/GenerateDockerCompose.php | 61 -- .../Robo/Tasks/RemoveDockerCompose.php | 37 - tests/functional/_support/.gitignore | 1 - tests/functional/_support/CliTester.php | 16 - tests/functional/_support/FailedInfo.php | 36 - tests/functional/bootstrap.php | 30 - tests/functional/configuration.dist.yml | 19 - tests/travis/functional_ee.sh | 6 +- 51 files changed, 525 insertions(+), 2124 deletions(-) delete mode 100644 src/Test/Functional/Acceptance/AbstractInstallCest.php delete mode 100644 tests/functional/Codeception/Docker.php delete mode 100644 tests/functional/Codeception/MagentoDb.php delete mode 100644 tests/functional/Robo/Tasks.php delete mode 100644 tests/functional/Robo/Tasks/Bash.php delete mode 100644 tests/functional/Robo/Tasks/CopyFromDocker.php delete mode 100644 tests/functional/Robo/Tasks/CopyToDocker.php delete mode 100644 tests/functional/Robo/Tasks/DockerCompose/Run.php delete mode 100644 tests/functional/Robo/Tasks/EnvCleanUp.php delete mode 100644 tests/functional/Robo/Tasks/EnvDown.php delete mode 100644 tests/functional/Robo/Tasks/EnvUp.php delete mode 100644 tests/functional/Robo/Tasks/GenerateDockerCompose.php delete mode 100644 tests/functional/Robo/Tasks/RemoveDockerCompose.php delete mode 100644 tests/functional/_support/.gitignore delete mode 100644 tests/functional/_support/CliTester.php delete mode 100644 tests/functional/_support/FailedInfo.php delete mode 100644 tests/functional/bootstrap.php delete mode 100644 tests/functional/configuration.dist.yml diff --git a/.gitignore b/.gitignore index bc383d9e94..a317184a3d 100755 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ /docker-compose.yml /auth.json /codeception.yml +/_workdir diff --git a/.travis.yml b/.travis.yml index 316064083d..726f873e01 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -dist: xenial +dist: bionic addons: hosts: @@ -86,10 +86,7 @@ install: - composer update -n --no-suggest before_script: - - if [ $TEST_SUITE == "functional-ce" ]; then echo "COMPOSER_MAGENTO_USERNAME=${REPO_USERNAME_CE}" >> ./.docker/composer.env && echo "COMPOSER_MAGENTO_PASSWORD=${REPO_PASSWORD_CE}" >> ./.docker/composer.env; fi; - - if [ $TEST_SUITE == "functional-ee" ]; then echo "COMPOSER_MAGENTO_USERNAME=${REPO_USERNAME}" >> ./.docker/composer.env && echo "COMPOSER_MAGENTO_PASSWORD=${REPO_PASSWORD}" >> ./.docker/composer.env; fi; - - echo "COMPOSER_GITHUB_TOKEN=${GITHUB_TOKEN}" >> ./.docker/composer.env - - if [ $XDEBUG == "true" ]; then echo "PHP_ENABLE_XDEBUG=true" >> ./.docker/global.env; fi; + - if [ $TEST_SUITE == "functional-ce" ]; then cp codeception.dist.yml codeception.yml && sed -i "s/REPO_USERNAME/REPO_USERNAME_CE/" codeception.yml && sed -i "s/REPO_PASSWORD/REPO_PASSWORD_CE/" codeception.yml; fi; script: - if [ $TEST_SUITE == "functional-ce" ]; then ./tests/travis/functional_ce.sh; fi; diff --git a/codeception.dist.yml b/codeception.dist.yml index d7c0d24f30..710cb3498a 100644 --- a/codeception.dist.yml +++ b/codeception.dist.yml @@ -2,8 +2,7 @@ paths: tests: src/Test/Functional output: tests/functional/_output data: tests/functional/_data - support: tests/functional/_support - envs: tests/functional/_envs + support: vendor/magento/magento-cloud-docker/tests/functional/_support actor_suffix: Tester settings: colors: true @@ -12,27 +11,27 @@ extensions: - Codeception\Extension\RunFailed - Codeception\Extension\FailedInfo params: - - tests/functional/configuration.dist.yml + - vendor/magento/magento-cloud-docker/tests/functional/configuration.dist.yml + - env modules: config: - Magento\MagentoCloud\Test\Functional\Codeception\Docker: - db_host: "%Magento.docker.settings.db.host%" - db_port: "%Magento.docker.settings.db.port%" - db_username: "%Magento.docker.settings.db.username%" - db_password: "%Magento.docker.settings.db.password%" - db_path: "%Magento.docker.settings.db.path%" - repo_url: "%Magento.docker.settings.repo.url%" - repo_branch: "%Magento.docker.settings.repo.branch%" - system_ece_tools_dir: "%Magento.docker.settings.system.ece_dir%" + Magento\CloudDocker\Test\Functional\Codeception\TestInfrastructure: + template_repo: "https://github.com/magento/magento-cloud.git" + mcd_repo: "https://github.com/magento/magento-cloud-docker.git" + mcc_repo: "https://github.com/magento/magento-cloud-components.git" + mcp_repo: "https://github.com/magento/magento-cloud-patches.git" + composer_magento_username: "%REPO_USERNAME%" + composer_magento_password: "%REPO_PASSWORD%" + composer_github_token: "%GITHUB_TOKEN%" + printOutput: false + Magento\CloudDocker\Test\Functional\Codeception\Docker: system_magento_dir: "%Magento.docker.settings.system.magento_dir%" - env_base_url: "%Magento.docker.settings.env.url.base%" - env_secure_base_url: "%Magento.docker.settings.env.url.secure_base%" - volumes: [] printOutput: false PhpBrowser: url: "%Magento.docker.settings.env.url.base%" - Magento\MagentoCloud\Test\Functional\Codeception\MagentoDb: - dsn: "mysql:host=127.0.0.1;port=3306;dbname=%Magento.docker.settings.db.path%" + Magento\CloudDocker\Test\Functional\Codeception\MagentoDb: + dsn: "mysql:host=%Magento.docker.settings.db.host%;port=%Magento.docker.settings.db.port%;dbname=%Magento.docker.settings.db.path%" user: "%Magento.docker.settings.db.username%" password: "%Magento.docker.settings.db.password%" + exposed_port: "%Magento.docker.settings.db.port%" reconnect: true diff --git a/composer.json b/composer.json index 1f6bef2972..8e001d62f0 100755 --- a/composer.json +++ b/composer.json @@ -93,6 +93,12 @@ }, "prefer-stable": true, "extra": { + "map": [ + [ + "dist/.magento.env.yaml", + ".magento.env.yaml.dist" + ] + ], "include_files": [ "vendor/codeception/phpunit-wrapper/src/phpunit7-interfaces.php" ] diff --git a/config/schema.yaml b/config/schema.yaml index 1fbb6889bf..f14ff471ed 100644 --- a/config/schema.yaml +++ b/config/schema.yaml @@ -195,14 +195,14 @@ MIN_LOGGING_LEVEL: type: string allowed: - '' - - !php/const Magento\MagentoCloud\Config\Log::LEVEL_DEBUG - - !php/const Magento\MagentoCloud\Config\Log::LEVEL_INFO - - !php/const Magento\MagentoCloud\Config\Log::LEVEL_NOTICE - - !php/const Magento\MagentoCloud\Config\Log::LEVEL_WARNING - - !php/const Magento\MagentoCloud\Config\Log::LEVEL_ERROR - - !php/const Magento\MagentoCloud\Config\Log::LEVEL_CRITICAL - - !php/const Magento\MagentoCloud\Config\Log::LEVEL_ALERT - - !php/const Magento\MagentoCloud\Config\Log::LEVEL_EMERGENCY + - 'debug' + - 'info' + - 'notice' + - 'warning' + - 'error' + - 'critical' + - 'alert' + - 'emergency' stages: - global default: diff --git a/src/Config/Schema.php b/src/Config/Schema.php index 3db31308c2..9b0d08d2d6 100644 --- a/src/Config/Schema.php +++ b/src/Config/Schema.php @@ -8,6 +8,7 @@ namespace Magento\MagentoCloud\Config; use Magento\MagentoCloud\Filesystem\SystemList; +use Magento\MagentoCloud\Filesystem\Driver\File; use Symfony\Component\Yaml\Parser; use Symfony\Component\Yaml\Yaml; @@ -39,6 +40,11 @@ class Schema */ private $parser; + /** + * @var File + */ + private $file; + /** * @var array */ @@ -47,11 +53,16 @@ class Schema /** * @param SystemList $systemList * @param Parser $parser + * @param File $file */ - public function __construct(SystemList $systemList, Parser $parser) - { + public function __construct( + SystemList $systemList, + Parser $parser, + File $file + ) { $this->systemList = $systemList; $this->parser = $parser; + $this->file = $file; } /** @@ -59,6 +70,7 @@ public function __construct(SystemList $systemList, Parser $parser) * * @param string $stage * @return array + * @throws \Magento\MagentoCloud\Filesystem\FileSystemException */ public function getDefaults(string $stage): array { @@ -85,12 +97,12 @@ public function getDefaults(string $stage): array * 'default_values' - array of default values * * @return array - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + * @throws \Magento\MagentoCloud\Filesystem\FileSystemException */ public function getSchema(): array { - return $this->parser->parseFile( - $this->systemList->getConfig() . '/schema.yaml', + return $this->parser->parse( + $this->file->fileGetContents($this->systemList->getConfig() . '/schema.yaml'), Yaml::PARSE_CONSTANT ); } diff --git a/src/Test/Functional/Acceptance.suite.dist.yml b/src/Test/Functional/Acceptance.suite.dist.yml index c90c278209..b8a860d563 100644 --- a/src/Test/Functional/Acceptance.suite.dist.yml +++ b/src/Test/Functional/Acceptance.suite.dist.yml @@ -1,7 +1,8 @@ actor: CliTester modules: enabled: - - Magento\MagentoCloud\Test\Functional\Codeception\Docker - - Magento\MagentoCloud\Test\Functional\Codeception\MagentoDb + - Magento\CloudDocker\Test\Functional\Codeception\TestInfrastructure + - Magento\CloudDocker\Test\Functional\Codeception\Docker + - Magento\CloudDocker\Test\Functional\Codeception\MagentoDb - PhpBrowser - Asserts diff --git a/src/Test/Functional/Acceptance/AbstractCest.php b/src/Test/Functional/Acceptance/AbstractCest.php index 0dedfdd50b..67cc17e688 100644 --- a/src/Test/Functional/Acceptance/AbstractCest.php +++ b/src/Test/Functional/Acceptance/AbstractCest.php @@ -13,13 +13,22 @@ */ abstract class AbstractCest { + /** + * @var boolean + */ + protected $removeEs = true; + + /** + * @var string + */ + protected $magentoCloudTemplate = 'master'; + /** * @param \CliTester $I */ - public function _before(\CliTester $I) + public function _before(\CliTester $I): void { - $I->generateDockerCompose(); - $I->cleanUpEnvironment(); + $this->prepareWorkplace($I, $this->magentoCloudTemplate); } /** @@ -28,6 +37,66 @@ public function _before(\CliTester $I) public function _after(\CliTester $I): void { $I->stopEnvironment(); - $I->removeDockerCompose(); + $I->removeWorkDir(); + } + + /** + * @param array $data + * @return string + */ + protected function convertEnvFromArrayToJson(array $data): string + { + return addslashes(json_encode($data)); + } + + /** + * @param \CliTester $I + * @param string $version + */ + protected function prepareWorkplace(\CliTester $I, string $version): void + { + $I->cleanupWorkDir(); + $I->cloneTemplateToWorkDir($version); + $I->createAuthJson(); + $I->createArtifactsDir(); + $I->createArtifactCurrentTestedCode('ece-tools', '2002.1.99'); + $I->addArtifactsRepoToComposer(); + $I->addDependencyToComposer('magento/ece-tools', '2002.1.99'); + $I->addEceDockerGitRepoToComposer(); + $I->addCloudComponentsGitRepoToComposer(); + $I->addCloudPatchesGitRepoToComposer(); + $I->addDependencyToComposer( + 'magento/magento-cloud-docker', + $I->getDependencyVersion('magento/magento-cloud-docker') + ); + $I->addDependencyToComposer( + 'magento/magento-cloud-components', + $I->getDependencyVersion('magento/magento-cloud-components') + ); + $I->addDependencyToComposer( + 'magento/magento-cloud-patches', + $I->getDependencyVersion('magento/magento-cloud-patches') + ); + $I->composerUpdate(); + $this->removeESIfExists($I); + } + + /** + * @param \CliTester $I + */ + protected function removeESIfExists(\CliTester $I): void + { + if ($this->removeEs) { + $services = $I->readServicesYaml(); + + if (isset($services['elasticsearch'])) { + unset($services['elasticsearch']); + $I->writeServicesYaml($services); + + $app = $I->readAppMagentoYaml(); + unset($app['relationships']['elasticsearch']); + $I->writeAppMagentoYaml($app); + } + } } } diff --git a/src/Test/Functional/Acceptance/AbstractInstallCest.php b/src/Test/Functional/Acceptance/AbstractInstallCest.php deleted file mode 100644 index 4a09f7a91f..0000000000 --- a/src/Test/Functional/Acceptance/AbstractInstallCest.php +++ /dev/null @@ -1,31 +0,0 @@ -cloneTemplate(null, static::EDITION); - $I->addEceComposerRepo(); - } -} diff --git a/src/Test/Functional/Acceptance/AcceptanceCeCest.php b/src/Test/Functional/Acceptance/AcceptanceCeCest.php index eada7aa2d3..ad1f28b616 100644 --- a/src/Test/Functional/Acceptance/AcceptanceCeCest.php +++ b/src/Test/Functional/Acceptance/AcceptanceCeCest.php @@ -7,7 +7,7 @@ namespace Magento\MagentoCloud\Test\Functional\Acceptance; -use Magento\MagentoCloud\Test\Functional\Codeception\Docker; +use Magento\CloudDocker\Test\Functional\Codeception\Docker; use Robo\Exception\TaskException; use CliTester; @@ -16,9 +16,16 @@ * * @group edition-ce */ -class AcceptanceCeCest extends AbstractInstallCest +class AcceptanceCeCest extends AbstractCest { - public const EDITION = 'CE'; + public function _before(\CliTester $I): void + { + parent::_before($I); + + $I->removeDependencyFromComposer('magento/magento-cloud-metapackage'); + $I->addDependencyToComposer('magento/product-community-edition', '@stable'); + $I->composerUpdate(); + } /** * @param CliTester $I @@ -27,11 +34,10 @@ class AcceptanceCeCest extends AbstractInstallCest */ public function testWithSplitBuildCommand(\CliTester $I): void { - $I->assertTrue($I->runEceToolsCommand('build:generate', Docker::BUILD_CONTAINER)); - $I->assertTrue($I->runEceToolsCommand('build:transfer', Docker::BUILD_CONTAINER)); + $I->runEceDockerCommand('build:compose --mode=production'); $I->startEnvironment(); - $I->assertTrue($I->runEceToolsCommand('deploy', Docker::DEPLOY_CONTAINER)); - $I->assertTrue($I->runEceToolsCommand('post-deploy', Docker::DEPLOY_CONTAINER)); + $I->runDockerComposeCommand('run build cloud-build'); + $I->runDockerComposeCommand('run deploy cloud-deploy'); $I->amOnPage('/'); $I->see('Home page'); $I->see('CMS homepage content goes here.'); diff --git a/src/Test/Functional/Acceptance/AcceptanceCest.php b/src/Test/Functional/Acceptance/AcceptanceCest.php index d2749922eb..74fb8922f1 100644 --- a/src/Test/Functional/Acceptance/AcceptanceCest.php +++ b/src/Test/Functional/Acceptance/AcceptanceCest.php @@ -10,7 +10,7 @@ use CliTester; use Robo\Exception\TaskException; use Codeception\Example; -use Magento\MagentoCloud\Test\Functional\Codeception\Docker; +use Magento\CloudDocker\Test\Functional\Codeception\Docker; use Magento\MagentoCloud\Util\ArrayManager; /** @@ -21,7 +21,7 @@ * 3. Test config dump * 4. Test content presence */ -class AcceptanceCest extends AbstractInstallCest +class AcceptanceCest extends AbstractCest { /** * @param CliTester $I @@ -32,7 +32,7 @@ public function _before(CliTester $I): void { parent::_before($I); - $I->uploadToContainer('files/debug_logging/.magento.env.yaml', '/.magento.env.yaml', Docker::BUILD_CONTAINER); + $I->copyFileToWorkDir('files/debug_logging/.magento.env.yaml', '.magento.env.yaml'); } /** @@ -45,25 +45,25 @@ public function _before(CliTester $I): void */ public function testDefault(\CliTester $I, \Codeception\Example $data): void { - $I->assertTrue($I->runEceToolsCommand('build', Docker::BUILD_CONTAINER)); + $I->runEceDockerCommand( + sprintf( + 'build:compose --mode=production --env-vars="%s"', + $this->convertEnvFromArrayToJson($data['variables']) + ) + ); + $I->runDockerComposeCommand('run build cloud-build'); $I->startEnvironment(); - $I->assertTrue($I->runEceToolsCommand( - 'deploy', - Docker::DEPLOY_CONTAINER, - $data['cloudVariables'], - $data['rawVariables'] - )); - $I->assertTrue($I->runEceToolsCommand('post-deploy', Docker::DEPLOY_CONTAINER)); - + $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; $I->assertArraySubset($data['expectedConfig'], $config); - $I->assertTrue($I->runEceToolsCommand('config:dump', Docker::DEPLOY_CONTAINER)); + $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; @@ -85,6 +85,7 @@ public function testDefault(\CliTester $I, \Codeception\Example $data): void $I->amOnPage('/'); $I->see('Home page'); + $I->see('CMS homepage content goes here.'); $log = $I->grabFileContent('/var/log/cloud.log'); $I->assertContains('--admin-password=\'******\'', $log); @@ -102,12 +103,11 @@ protected function defaultDataProvider(): array { return [ 'default configuration' => [ - 'cloudVariables' => [ + 'variables' => [ 'MAGENTO_CLOUD_VARIABLES' => [ 'ADMIN_EMAIL' => 'admin@example.com', ], ], - 'rawVariables' => [], 'expectedConfig' => [ 'cron_consumers_runner' => [ 'cron_run' => false, @@ -126,7 +126,7 @@ protected function defaultDataProvider(): array ], ], 'test cron_consumers_runner with array and there is MAGENTO_CLOUD_LOCKS_DIR' => [ - 'cloudVariables' => [ + 'variables' => [ 'MAGENTO_CLOUD_VARIABLES' => [ 'ADMIN_EMAIL' => 'admin@example.com', 'CRON_CONSUMERS_RUNNER' => [ @@ -135,8 +135,6 @@ protected function defaultDataProvider(): array 'consumers' => ['test'], ], ], - ], - 'rawVariables' => [ 'MAGENTO_CLOUD_LOCKS_DIR' => '/tmp/locks', ], 'expectedConfig' => [ @@ -157,7 +155,7 @@ protected function defaultDataProvider(): array ], ], 'test cron_consumers_runner with wrong array, there is MAGENTO_CLOUD_LOCKS_DIR, LOCK_PROVIDER is db' => [ - 'cloudVariables' => [ + 'variables' => [ 'MAGENTO_CLOUD_VARIABLES' => [ 'ADMIN_EMAIL' => 'admin@example.com', 'LOCK_PROVIDER' => 'db', @@ -167,8 +165,6 @@ protected function defaultDataProvider(): array 'consumers' => ['test'], ], ], - ], - 'rawVariables' => [ 'MAGENTO_CLOUD_LOCKS_DIR' => '/tmp/locks', ], 'expectedConfig' => [ @@ -189,13 +185,12 @@ protected function defaultDataProvider(): array ], ], 'test cron_consumers_runner with string' => [ - 'cloudVariables' => [ + 'variables' => [ 'MAGENTO_CLOUD_VARIABLES' => [ 'ADMIN_EMAIL' => 'admin@example.com', 'CRON_CONSUMERS_RUNNER' => '{"cron_run":true, "max_messages":100, "consumers":["test2"]}', ], ], - 'rawVariables' => [], 'expectedConfig' => [ 'cron_consumers_runner' => [ 'cron_run' => true, @@ -208,13 +203,12 @@ protected function defaultDataProvider(): array ], ], 'test cron_consumers_runner with wrong string' => [ - 'cloudVariables' => [ + 'variables' => [ 'MAGENTO_CLOUD_VARIABLES' => [ 'ADMIN_EMAIL' => 'admin@example.com', 'CRON_CONSUMERS_RUNNER' => '{"cron_run":"true", "max_messages":100, "consumers":["test2"]}', ], ], - 'rawVariables' => [], 'expectedConfig' => [ 'cron_consumers_runner' => [ 'cron_run' => false, @@ -227,14 +221,13 @@ protected function defaultDataProvider(): array ], ], 'disabled static content symlinks 3 jobs' => [ - 'cloudVariables' => [ + 'variables' => [ 'MAGENTO_CLOUD_VARIABLES' => [ 'ADMIN_EMAIL' => 'admin@example.com', 'STATIC_CONTENT_SYMLINK' => 'disabled', 'STATIC_CONTENT_THREADS' => 3, ], ], - 'rawVariables' => [], 'expectedConfig' => [ 'cron_consumers_runner' => [ 'cron_run' => false, @@ -251,16 +244,18 @@ protected function defaultDataProvider(): array /** * @param CliTester $I - * * @throws TaskException */ - public function testWithSplitBuildCommand(\CliTester $I): void + public function testWithOldNonSplitBuildCommand(\CliTester $I): void { - $I->assertTrue($I->runEceToolsCommand('build:generate', Docker::BUILD_CONTAINER)); - $I->assertTrue($I->runEceToolsCommand('build:transfer', Docker::BUILD_CONTAINER)); + $config = $I->readAppMagentoYaml(); + $config['hooks']['build'] = 'set -e' . PHP_EOL . 'php ./vendor/bin/ece-tools build' . PHP_EOL; + $I->writeAppMagentoYaml($config); + + $I->runEceDockerCommand('build:compose --mode=production'); + $I->runDockerComposeCommand('run build cloud-build'); $I->startEnvironment(); - $I->assertTrue($I->runEceToolsCommand('deploy', Docker::DEPLOY_CONTAINER)); - $I->assertTrue($I->runEceToolsCommand('post-deploy', Docker::DEPLOY_CONTAINER)); + $I->runDockerComposeCommand('run deploy cloud-deploy'); $I->amOnPage('/'); $I->see('Home page'); $I->see('CMS homepage content goes here.'); @@ -274,11 +269,14 @@ public function testWithSplitBuildCommand(\CliTester $I): void public function testDeployInBuild(\CliTester $I): void { $tmpConfig = sys_get_temp_dir() . '/app/etc/config.php'; + $I->runEceDockerCommand('build:compose --mode=production'); + $I->runDockerComposeCommand('run build cloud-build'); $I->startEnvironment(); - $I->assertTrue($I->runEceToolsCommand('build', Docker::BUILD_CONTAINER)); - $I->assertTrue($I->runEceToolsCommand('deploy', Docker::DEPLOY_CONTAINER)); - $I->assertTrue($I->runEceToolsCommand('post-deploy', Docker::DEPLOY_CONTAINER)); - $I->assertTrue($I->runEceToolsCommand('config:dump', Docker::DEPLOY_CONTAINER)); + $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->assertNotContains( 'Static content deployment was performed during the build phase or disabled. ' . 'Skipping deploy phase static content compression.', @@ -287,17 +285,16 @@ public function testDeployInBuild(\CliTester $I): void $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)); - - $I->assertTrue($I->cleanUpEnvironment()); + $I->assertTrue( + $I->downloadFromContainer('/app/etc/config.php', $tmpConfig, Docker::DEPLOY_CONTAINER), + 'Cannot download config.php from Docker' + ); - $I->assertTrue($I->cloneTemplate()); - $I->assertTrue($I->addEceComposerRepo()); - $I->assertTrue($I->uploadToContainer($tmpConfig, '/app/etc/config.php', Docker::BUILD_CONTAINER)); - $I->assertTrue($I->runEceToolsCommand('build', Docker::BUILD_CONTAINER)); - $I->assertTrue($I->runEceToolsCommand('deploy', Docker::DEPLOY_CONTAINER)); - $I->assertTrue($I->runEceToolsCommand('post-deploy', Docker::DEPLOY_CONTAINER)); + $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->assertContains( 'Static content deployment was performed during the build phase or disabled. ' . 'Skipping deploy phase static content compression.', diff --git a/src/Test/Functional/Acceptance/AdminCredentialCest.php b/src/Test/Functional/Acceptance/AdminCredentialCest.php index 271ce87885..212a62db89 100644 --- a/src/Test/Functional/Acceptance/AdminCredentialCest.php +++ b/src/Test/Functional/Acceptance/AdminCredentialCest.php @@ -7,28 +7,19 @@ namespace Magento\MagentoCloud\Test\Functional\Acceptance; -use Magento\MagentoCloud\Test\Functional\Codeception\Docker; - /** * This test runs on the latest version of PHP */ class AdminCredentialCest extends AbstractCest { - /** - * @var string - */ - protected $magentoCloudTemplate = 'master'; - /** * @param \CliTester $I - * @throws \Robo\Exception\TaskException */ - public function _before(\CliTester $I) + public function _before(\CliTester $I): void { parent::_before($I); - $I->cloneTemplate($this->magentoCloudTemplate); - $I->addEceComposerRepo(); - $I->uploadToContainer('files/debug_logging/.magento.env.yaml', '/.magento.env.yaml', Docker::BUILD_CONTAINER); + + $I->copyFileToWorkDir('files/debug_logging/.magento.env.yaml', '.magento.env.yaml'); } /** @@ -37,12 +28,21 @@ public function _before(\CliTester $I) * @throws \Robo\Exception\TaskException * @dataProvider installWithoutAdminEmailDataProvider */ - public function testInstallWithoutAdminEmail(\CliTester $I, \Codeception\Example $data) + public function testInstallWithoutAdminEmail(\CliTester $I, \Codeception\Example $data): void { - $I->assertTrue($I->runEceToolsCommand('build', Docker::BUILD_CONTAINER, $data['variables'])); + $I->runEceDockerCommand( + sprintf( + 'build:compose --mode=production --env-vars="%s"', + $this->convertEnvFromArrayToJson($data['variables']) + ) + ); + $I->runDockerComposeCommand('run build cloud-build'); $I->startEnvironment(); - $I->assertTrue($I->runEceToolsCommand('deploy', Docker::DEPLOY_CONTAINER, $data['variables'])); - $I->assertTrue($I->runEceToolsCommand('post-deploy', Docker::DEPLOY_CONTAINER, $data['variables'])); + $I->runDockerComposeCommand('run build cloud-build'); + $I->runDockerComposeCommand('run deploy cloud-deploy'); + $I->amOnPage('/'); + $I->see('Home page'); + $I->see('CMS homepage content goes here.'); $log = $I->grabFileContent('/var/log/cloud.log'); $I->assertContains($data['installMessage'], $log); @@ -53,8 +53,7 @@ public function testInstallWithoutAdminEmail(\CliTester $I, \Codeception\Example $I->assertNotContains('--admin-password', $log); // Upgrade - $I->assertTrue($I->runEceToolsCommand('deploy', Docker::DEPLOY_CONTAINER, $data['variables'])); - $I->assertTrue($I->runEceToolsCommand('post-deploy', Docker::DEPLOY_CONTAINER, $data['variables'])); + $I->runDockerComposeCommand('run deploy cloud-deploy'); $I->assertContains($data['upgradeMessage'], $I->grabFileContent('/var/log/cloud.log')); } @@ -62,7 +61,7 @@ public function testInstallWithoutAdminEmail(\CliTester $I, \Codeception\Example /** * @return array */ - protected function installWithoutAdminEmailDataProvider() + protected function installWithoutAdminEmailDataProvider(): array { return [ [ @@ -88,10 +87,18 @@ protected function installWithoutAdminEmailDataProvider() */ public function testInstallWithDifferentVariables(\CliTester $I, \Codeception\Example $data) { - $I->assertTrue($I->runEceToolsCommand('build', Docker::BUILD_CONTAINER, $data['variables'])); + $I->runEceDockerCommand( + sprintf( + 'build:compose --mode=production --env-vars="%s"', + $this->convertEnvFromArrayToJson($data['variables']) + ) + ); + $I->runDockerComposeCommand('run build cloud-build'); $I->startEnvironment(); - $I->assertTrue($I->runEceToolsCommand('deploy', Docker::DEPLOY_CONTAINER, $data['variables'])); - $I->assertTrue($I->runEceToolsCommand('post-deploy', Docker::DEPLOY_CONTAINER, $data['variables'])); + $I->runDockerComposeCommand('run deploy cloud-deploy'); + $I->amOnPage('/'); + $I->see('Home page'); + $I->see('CMS homepage content goes here.'); $credentialsEmail = $I->grabFileContent('/var/credentials_email.txt'); $I->assertContains($data['expectedAdminEmail'], $credentialsEmail); @@ -110,8 +117,7 @@ public function testInstallWithDifferentVariables(\CliTester $I, \Codeception\Ex ); // Upgrade - $I->assertTrue($I->runEceToolsCommand('deploy', Docker::DEPLOY_CONTAINER, $data['variables'])); - $I->assertTrue($I->runEceToolsCommand('post-deploy', Docker::DEPLOY_CONTAINER, $data['variables'])); + $I->runDockerComposeCommand('run deploy cloud-deploy'); $I->assertNotContains( 'The following admin data is required to create an admin user during initial installation only' diff --git a/src/Test/Functional/Acceptance/Cron21Cest.php b/src/Test/Functional/Acceptance/Cron21Cest.php index d2d4faf67e..25c1c561a1 100644 --- a/src/Test/Functional/Acceptance/Cron21Cest.php +++ b/src/Test/Functional/Acceptance/Cron21Cest.php @@ -19,7 +19,7 @@ protected function cronDataProvider(): array { return [ [ - 'version' => '2.1.16', + 'version' => '2.1.17', 'variables' => [ 'MAGENTO_CLOUD_VARIABLES' => [ 'ADMIN_EMAIL' => 'admin@example.com', diff --git a/src/Test/Functional/Acceptance/CronCest.php b/src/Test/Functional/Acceptance/CronCest.php index 6f08e1680a..97c252905d 100644 --- a/src/Test/Functional/Acceptance/CronCest.php +++ b/src/Test/Functional/Acceptance/CronCest.php @@ -7,13 +7,19 @@ namespace Magento\MagentoCloud\Test\Functional\Acceptance; -use Magento\MagentoCloud\Test\Functional\Codeception\Docker; - /** * This test runs on the latest version of PHP */ class CronCest extends AbstractCest { + /** + * @inheritdoc + */ + public function _before(\CliTester $I): void + { + //Do nothing... + } + /** * @param \CliTester $I * @param \Codeception\Example $data @@ -21,19 +27,21 @@ class CronCest extends AbstractCest * @throws \Robo\Exception\TaskException * @dataProvider cronDataProvider */ - public function testCron(\CliTester $I, \Codeception\Example $data) + public function testCron(\CliTester $I, \Codeception\Example $data): void { - $I->assertTrue($I->cloneTemplate($data['version'])); - $I->assertTrue($I->addEceComposerRepo()); - $I->createDirectory('/app/code/Magento/CronTest', Docker::BUILD_CONTAINER); - $I->uploadToContainer('modules/Magento/CronTest/.', '/app/code/Magento/CronTest', Docker::BUILD_CONTAINER); - $I->assertTrue($I->runEceToolsCommand('build', Docker::BUILD_CONTAINER, $data['variables'])); + $this->prepareWorkplace($I, $data['version']); + $I->runEceDockerCommand(sprintf( + 'build:compose --mode=production --expose-db-port=%s --env-vars="%s"', + $I->getExposedPort(), + $this->convertEnvFromArrayToJson($data['variables']) + )); + $I->copyDirToWorkDir('modules/Magento/CronTest', 'app/code/Magento/CronTest'); + $I->runDockerComposeCommand('run build cloud-build'); $I->startEnvironment(); - $I->assertTrue($I->runEceToolsCommand('deploy', Docker::DEPLOY_CONTAINER, $data['variables'])); - $I->assertTrue($I->runEceToolsCommand('post-deploy', Docker::DEPLOY_CONTAINER, $data['variables'])); + $I->runDockerComposeCommand('run deploy cloud-deploy'); $I->deleteFromDatabase('cron_schedule'); - $I->assertTrue($I->runBinMagentoCommand('cron:run', Docker::DEPLOY_CONTAINER)); - $I->assertTrue($I->runBinMagentoCommand('cron:run', Docker::DEPLOY_CONTAINER)); + $I->runDockerComposeCommand('run deploy magento-command cron:run'); + $I->runDockerComposeCommand('run deploy magento-command cron:run'); $this->checkCronJobForLocale($I, 'cron_test_job_timeformat', 5); $this->checkCronJobForLocale($I, 'cron_test_job_timeformat_six', 6); @@ -51,8 +59,8 @@ public function testCron(\CliTester $I, \Codeception\Example $data) $I->updateInDatabase('cron_schedule', ['scheduled_at' => date('Y-m-d H:i:s')], ['status' => 'pending']); - $I->assertTrue($I->runBinMagentoCommand('cron:run', Docker::DEPLOY_CONTAINER)); - $I->assertTrue($I->runBinMagentoCommand('cron:run', Docker::DEPLOY_CONTAINER)); + $I->runDockerComposeCommand('run deploy magento-command cron:run'); + $I->runDockerComposeCommand('run deploy magento-command cron:run'); $successfulJobs2 = $I->grabNumRecords('cron_schedule', ['job_code' => 'cron_test_job', 'status' => 'success']); @@ -78,7 +86,7 @@ public function testCron(\CliTester $I, \Codeception\Example $data) ['job_code' => 'cron_test_job', 'status' => 'pending'] ); - $I->assertTrue($I->runBinMagentoCommand('cron:run', Docker::DEPLOY_CONTAINER)); + $I->runDockerComposeCommand('run deploy magento-command cron:run'); $successfulJobs3 = $I->grabNumRecords('cron_schedule', ['job_code' => 'cron_test_job', 'status' => 'success']); $I->assertGreaterThan( @@ -94,7 +102,7 @@ public function testCron(\CliTester $I, \Codeception\Example $data) * @param int $timeInterval * @throws \Exception */ - private function checkCronJobForLocale(\CliTester $I, string $jobCode, int $timeInterval) + private function checkCronJobForLocale(\CliTester $I, string $jobCode, int $timeInterval): void { $schedule = $I->grabColumnFromDatabase( 'cron_schedule', @@ -122,6 +130,15 @@ private function checkCronJobForLocale(\CliTester $I, string $jobCode, int $time protected function cronDataProvider(): array { return [ + [ + 'version' => '2.3.4', + 'variables' => [ + 'MAGENTO_CLOUD_VARIABLES' => [ + 'ADMIN_EMAIL' => 'admin@example.com', + 'ADMIN_LOCALE' => 'fr_FR' + ], + ], + ], [ 'version' => '2.3.3', 'variables' => [ diff --git a/src/Test/Functional/Acceptance/CronUnlockCest.php b/src/Test/Functional/Acceptance/CronUnlockCest.php index 75ebc48c36..326f90b5c9 100644 --- a/src/Test/Functional/Acceptance/CronUnlockCest.php +++ b/src/Test/Functional/Acceptance/CronUnlockCest.php @@ -7,8 +7,6 @@ namespace Magento\MagentoCloud\Test\Functional\Acceptance; -use Magento\MagentoCloud\Test\Functional\Codeception\Docker; - /** * Test for cron:unlock. */ @@ -18,23 +16,12 @@ class CronUnlockCest extends AbstractCest * @param \CliTester $I * @throws \Robo\Exception\TaskException */ - public function _before(\CliTester $I) - { - parent::_before($I); - $I->cloneTemplate(); - $I->addEceComposerRepo(); - } - - /** - * @param \CliTester $I - * @throws \Robo\Exception\TaskException - */ - public function testCronUnlock(\CliTester $I) + public function testCronUnlock(\CliTester $I): void { - $I->assertTrue($I->runEceToolsCommand('build', Docker::BUILD_CONTAINER)); + $I->runEceDockerCommand(sprintf('build:compose --mode=production --expose-db-port=%s', $I->getExposedPort())); + $I->runDockerComposeCommand('run build cloud-build'); $I->startEnvironment(); - $I->assertTrue($I->runEceToolsCommand('deploy', Docker::DEPLOY_CONTAINER)); - $I->assertTrue($I->runEceToolsCommand('post-deploy', Docker::DEPLOY_CONTAINER)); + $I->runDockerComposeCommand('run deploy cloud-deploy'); $sampleData = $this->getSampleData(); $scheduleIds = []; @@ -49,7 +36,7 @@ public function testCronUnlock(\CliTester $I) } $I->seeInDatabase('cron_schedule', ['status' => 'running']); - $I->assertTrue($I->runEceToolsCommand('cron:unlock', Docker::DEPLOY_CONTAINER)); + $I->assertTrue($I->runDockerComposeCommand('run deploy ece-command cron:unlock')); $I->seeInDatabase('cron_schedule', ['status' => 'error']); foreach (array_slice($scheduleIds, 0, 3) as $scheduleId) { $I->seeInDatabase('cron_schedule', ['schedule_id' => $scheduleId, 'status' => 'error']); @@ -61,13 +48,12 @@ public function testCronUnlock(\CliTester $I) $I->seeInDatabase('cron_schedule', ['status' => 'running']); $I->assertTrue( - $I->runEceToolsCommand( + $I->runDockerComposeCommand( sprintf( - 'cron:unlock --job-code=%s --job-code=%s', + 'run deploy ece-command cron:unlock --job-code=%s --job-code=%s', 'catalog_product_frontend_actions_flush', 'catalog_product_outdated_price_values_cleanup' - ), - Docker::DEPLOY_CONTAINER + ) ) ); @@ -81,7 +67,7 @@ public function testCronUnlock(\CliTester $I) * @param $scheduleId * @param $status */ - private function updateScheduleInDb(\CLITester $I, $scheduleId, $status) + private function updateScheduleInDb(\CLITester $I, $scheduleId, $status): void { $I->updateInDatabase( 'cron_schedule', diff --git a/src/Test/Functional/Acceptance/DataTypesOptionValidationCest.php b/src/Test/Functional/Acceptance/DataTypesOptionValidationCest.php index fd8c5e41df..960ec088af 100644 --- a/src/Test/Functional/Acceptance/DataTypesOptionValidationCest.php +++ b/src/Test/Functional/Acceptance/DataTypesOptionValidationCest.php @@ -7,39 +7,29 @@ namespace Magento\MagentoCloud\Test\Functional\Acceptance; -use Magento\MagentoCloud\Test\Functional\Codeception\Docker; - /** * This test runs on the latest version of PHP */ class DataTypesOptionValidationCest extends AbstractCest { - /** - * @param \CliTester $I - * @throws \Robo\Exception\TaskException - */ - public function _before(\CliTester $I) - { - parent::_before($I); - $I->cloneTemplate(); - $I->addEceComposerRepo(); - } - /** * @param \CliTester $I * @param \Codeception\Example $data * @throws \Robo\Exception\TaskException * @dataProvider dataTypesDataProvider */ - public function dataTypesValidationOnDeploy(\CliTester $I, \Codeception\Example $data) + public function dataTypesValidationOnDeploy(\CliTester $I, \Codeception\Example $data): void { - $I->assertTrue($I->runEceToolsCommand('build', Docker::BUILD_CONTAINER)); + $I->runEceDockerCommand( + sprintf( + 'build:compose --mode=production --env-vars="%s"', + $this->convertEnvFromArrayToJson($data['variables']) + ) + ); + $I->runDockerComposeCommand('run build cloud-build'); $I->startEnvironment(); - $I->assertTrue($I->runEceToolsCommand( - 'deploy', - Docker::DEPLOY_CONTAINER, - $data['cloudVariables'] - )); + $I->runDockerComposeCommand('run deploy cloud-deploy'); + $log = $I->grabFileContent('/var/log/cloud.log'); $I->assertContains($data['expectedError'], $log); } @@ -51,7 +41,7 @@ protected function dataTypesDataProvider(): array { return [ 'string_instead_integer' => [ - 'cloudVariables' => [ + 'variables' => [ 'MAGENTO_CLOUD_VARIABLES' => [ 'SCD_THREADS' => 'one', ], @@ -59,7 +49,7 @@ protected function dataTypesDataProvider(): array 'expectedError' => 'SCD_THREADS has wrong value', ], 'integer_instead_boolean' => [ - 'cloudVariables' => [ + 'variables' => [ 'MAGENTO_CLOUD_VARIABLES' => [ 'CLEAN_STATIC_FILES' => 1, ], diff --git a/src/Test/Functional/Acceptance/DatabaseConfigurationCest.php b/src/Test/Functional/Acceptance/DatabaseConfigurationCest.php index 779de75d3b..8d80a09fae 100644 --- a/src/Test/Functional/Acceptance/DatabaseConfigurationCest.php +++ b/src/Test/Functional/Acceptance/DatabaseConfigurationCest.php @@ -7,39 +7,29 @@ namespace Magento\MagentoCloud\Test\Functional\Acceptance; -use Magento\MagentoCloud\Test\Functional\Codeception\Docker; - /** * This test runs on the latest version of PHP */ class DatabaseConfigurationCest extends AbstractCest { - /** - * @param \CliTester $I - * @throws \Robo\Exception\TaskException - */ - public function _before(\CliTester $I) - { - parent::_before($I); - $I->cloneTemplate(); - $I->addEceComposerRepo(); - } - /** * @param \CliTester $I * @param \Codeception\Example $data * @throws \Robo\Exception\TaskException * @dataProvider databaseConfigurationDataProvider */ - public function databaseConfiguration(\CliTester $I, \Codeception\Example $data) + public function databaseConfiguration(\CliTester $I, \Codeception\Example $data): void { - $I->assertTrue($I->runEceToolsCommand('build', Docker::BUILD_CONTAINER)); + $I->runEceDockerCommand( + sprintf( + 'build:compose --mode=production --env-vars="%s"', + $this->convertEnvFromArrayToJson($data['variables']) + ) + ); + $I->runDockerComposeCommand('run build cloud-build'); $I->startEnvironment(); - $I->assertTrue($I->runEceToolsCommand( - 'deploy', - Docker::DEPLOY_CONTAINER, - $data['cloudVariables'] - )); + $I->runDockerComposeCommand('run deploy cloud-deploy'); + $file = $I->grabFileContent('/app/etc/env.php'); $I->assertContains($data['mergedConfig'], $file); $I->assertContains($data['defaultConfig'], $file); @@ -52,16 +42,16 @@ protected function databaseConfigurationDataProvider(): array { return [ 'singleConfig' => [ - 'cloudVariables' => [ + 'variables' => [ 'MAGENTO_CLOUD_VARIABLES' => [ 'DATABASE_CONFIGURATION'=>['some_config' => 'value', '_merge' => true], ], ], 'mergedConfig' => 'some_config', - 'defaultConfig' => 'db.magento2.docker', + 'defaultConfig' => 'db', ], 'multiConfig' => [ - 'cloudVariables' => [ + 'variables' => [ 'MAGENTO_CLOUD_VARIABLES' => [ 'DATABASE_CONFIGURATION'=>[ 'connection' => [ @@ -84,7 +74,7 @@ protected function databaseConfigurationDataProvider(): array ], ], 'mergedConfig' => '1001', - 'defaultConfig' => 'db.magento2.docker', + 'defaultConfig' => 'db', ], ]; } diff --git a/src/Test/Functional/Acceptance/ElasticSearch22Cest.php b/src/Test/Functional/Acceptance/ElasticSearch22Cest.php index 59879afb60..6e930c6f3b 100644 --- a/src/Test/Functional/Acceptance/ElasticSearch22Cest.php +++ b/src/Test/Functional/Acceptance/ElasticSearch22Cest.php @@ -12,6 +12,17 @@ */ class ElasticSearch22Cest extends ElasticSearchCest { + /** + * @param \CliTester $I + * @param \Codeception\Example $data + * @throws \Robo\Exception\TaskException + * @skip Skip Need to fix ElasticSearch containers + */ + public function testElastic(\CliTester $I, \Codeception\Example $data): void + { + parent::testElastic($I, $data); // TODO: Change the autogenerated stub + } + /** * @return array */ @@ -20,14 +31,14 @@ protected function elasticDataProvider(): array return [ [ 'magento' => '2.2.8', - 'services' => [], + 'removeES' => true, 'expectedResult' => ['engine' => 'mysql'], ], [ 'magento' => '2.2.8', - 'services' => ['es' => '2.4'], + 'removeES' => false, 'expectedResult' => [ - 'engine' => 'elasticsearch', + 'engine' => 'elasticsearch6', 'elasticsearch_server_hostname' => 'elasticsearch', 'elasticsearch_server_port' => '9200' ], diff --git a/src/Test/Functional/Acceptance/ElasticSearch23Php72Cest.php b/src/Test/Functional/Acceptance/ElasticSearch23Php72Cest.php index 4f6ff42ae5..00fa8491a7 100644 --- a/src/Test/Functional/Acceptance/ElasticSearch23Php72Cest.php +++ b/src/Test/Functional/Acceptance/ElasticSearch23Php72Cest.php @@ -12,6 +12,17 @@ */ class ElasticSearch23Php72Cest extends ElasticSearchCest { + /** + * @param \CliTester $I + * @param \Codeception\Example $data + * @throws \Robo\Exception\TaskException + * @skip Skip Need to fix ElasticSearch containers + */ + public function testElastic(\CliTester $I, \Codeception\Example $data): void + { + parent::testElastic($I, $data); // TODO: Change the autogenerated stub + } + /** * @return array */ @@ -20,12 +31,12 @@ protected function elasticDataProvider(): array return [ [ 'magento' => '2.3.0', - 'services' => [], + 'removeES' => true, 'expectedResult' => ['engine' => 'mysql'], ], [ 'magento' => '2.3.0', - 'services' => ['es' => '5.2'], + 'removeES' => false, 'expectedResult' => [ 'engine' => 'elasticsearch5', 'elasticsearch5_server_hostname' => 'elasticsearch', @@ -34,7 +45,7 @@ protected function elasticDataProvider(): array ], [ 'magento' => '2.3.2', - 'services' => ['es' => '6.5'], + 'removeES' => false, 'expectedResult' => [ 'engine' => 'elasticsearch6', 'elasticsearch6_server_hostname' => 'elasticsearch', diff --git a/src/Test/Functional/Acceptance/ElasticSearchCest.php b/src/Test/Functional/Acceptance/ElasticSearchCest.php index ab87d754fb..dc59cdde79 100644 --- a/src/Test/Functional/Acceptance/ElasticSearchCest.php +++ b/src/Test/Functional/Acceptance/ElasticSearchCest.php @@ -7,17 +7,22 @@ namespace Magento\MagentoCloud\Test\Functional\Acceptance; -use Magento\MagentoCloud\Test\Functional\Codeception\Docker; +use Magento\CloudDocker\Test\Functional\Codeception\Docker; /** * This test runs on the latest version of PHP */ class ElasticSearchCest extends AbstractCest { + /** + * @var boolean + */ + protected $removeEs = false; + /** * @param \CliTester $I */ - public function _before(\CliTester $I) + public function _before(\CliTester $I): void { // Do nothing } @@ -27,19 +32,23 @@ public function _before(\CliTester $I) * @param \Codeception\Example $data * @throws \Robo\Exception\TaskException * @dataProvider elasticDataProvider + * @skip Skip Need to fix ElasticSearch containers */ - public function testElastic(\CliTester $I, \Codeception\Example $data) + public function testElastic(\CliTester $I, \Codeception\Example $data): void { - $I->generateDockerCompose($data['services']); - $I->cleanUpEnvironment(); - $I->cloneTemplate($data['magento']); - $I->addEceComposerRepo(); - $I->assertTrue($I->runEceToolsCommand('build', Docker::BUILD_CONTAINER)); + $this->removeEs = $data['removeES']; + + $this->prepareWorkplace($I, $data['magento']); + + $I->runEceDockerCommand('build:compose --mode=production'); + + $I->runDockerComposeCommand('run build cloud-build'); $I->startEnvironment(); - $I->assertTrue($I->runEceToolsCommand('deploy', Docker::DEPLOY_CONTAINER)); - $I->assertTrue($I->runEceToolsCommand('post-deploy', Docker::DEPLOY_CONTAINER)); + $I->runDockerComposeCommand('run deploy cloud-deploy'); - $I->runBinMagentoCommand('config:set general/region/state_required US --lock-env', Docker::DEPLOY_CONTAINER); + $I->runDockerComposeCommand( + 'run deploy magento-command config:set general/region/state_required US --lock-env' + ); $this->checkConfigurationIsNotRemoved($I); $I->amOnPage('/'); @@ -52,19 +61,16 @@ public function testElastic(\CliTester $I, \Codeception\Example $data) ); $I->assertTrue($I->cleanDirectories(['/vendor/*', '/setup/*'])); + $I->stopEnvironment(true); + $this->removeEs = true; + $this->removeESIfExists($I); - $relationships = [ - 'MAGENTO_CLOUD_RELATIONSHIPS' => [ - 'database' => [ - $I->getDbCredential(), - ], - ], - ]; + $I->runEceDockerCommand('build:compose --mode=production'); + + $I->runDockerComposeCommand('run build cloud-build'); + $I->startEnvironment(); + $I->runDockerComposeCommand('run deploy cloud-deploy'); - $I->composerInstall(); - $I->assertTrue($I->runEceToolsCommand('build', Docker::BUILD_CONTAINER)); - $I->assertTrue($I->runEceToolsCommand('deploy', Docker::DEPLOY_CONTAINER, $relationships)); - $I->assertTrue($I->runEceToolsCommand('post-deploy', Docker::DEPLOY_CONTAINER, $relationships)); $this->checkConfigurationIsNotRemoved($I); $I->amOnPage('/'); @@ -92,7 +98,7 @@ private function getConfig(\CliTester $I): array * @param \CliTester $I * @return array */ - private function checkConfigurationIsNotRemoved(\CliTester $I) + private function checkConfigurationIsNotRemoved(\CliTester $I): void { $config = $this->getConfig($I); @@ -109,13 +115,13 @@ protected function elasticDataProvider(): array { return [ [ - 'magento' => '2.3.3', - 'services' => [], + 'magento' => '2.3.4', + 'removeES' => true, 'expectedResult' => ['engine' => 'mysql'], ], [ - 'magento' => '2.3.3', - 'services' => ['es' => '6.5'], + 'magento' => '2.3.4', + 'removeES' => false, 'expectedResult' => [ 'engine' => 'elasticsearch6', 'elasticsearch6_server_hostname' => 'elasticsearch', diff --git a/src/Test/Functional/Acceptance/ErrorMessageCest.php b/src/Test/Functional/Acceptance/ErrorMessageCest.php index bd116b18c3..483059da51 100644 --- a/src/Test/Functional/Acceptance/ErrorMessageCest.php +++ b/src/Test/Functional/Acceptance/ErrorMessageCest.php @@ -8,7 +8,6 @@ namespace Magento\MagentoCloud\Test\Functional\Acceptance; use CliTester; -use Magento\MagentoCloud\Test\Functional\Codeception\Docker; /** * This test runs on the latest version of PHP @@ -19,21 +18,12 @@ class ErrorMessageCest extends AbstractCest * @param CliTester $I * @throws \Robo\Exception\TaskException */ - public function _before(CliTester $I) - { - parent::_before($I); - $I->cloneTemplate(); - $I->addEceComposerRepo(); - } - - /** - * @param CliTester $I - * @throws \Robo\Exception\TaskException - */ - public function testShellErrorMessage(CliTester $I) + public function testShellErrorMessage(CliTester $I): void { + $I->runEceDockerCommand('build:compose --mode=production'); + $I->runDockerComposeCommand('run build cloud-build'); $I->cleanDirectories(['/bin/*']); - $I->assertFalse($I->runEceToolsCommand('build', Docker::BUILD_CONTAINER)); + $I->assertFalse($I->runDockerComposeCommand('run build ece-command build')); $I->seeInOutput('Could not open input file: ./bin/magento'); } } diff --git a/src/Test/Functional/Acceptance/PatchApplierCest.php b/src/Test/Functional/Acceptance/PatchApplierCest.php index 77d94b9909..4d49bca7e8 100644 --- a/src/Test/Functional/Acceptance/PatchApplierCest.php +++ b/src/Test/Functional/Acceptance/PatchApplierCest.php @@ -7,7 +7,7 @@ namespace Magento\MagentoCloud\Test\Functional\Acceptance; -use Magento\MagentoCloud\Test\Functional\Codeception\Docker; +use Magento\CloudDocker\Test\Functional\Codeception\Docker; /** * This test runs on the latest version of PHP @@ -16,27 +16,27 @@ class PatchApplierCest extends AbstractCest { /** * @param \CliTester $I - * @throws \Robo\Exception\TaskException */ - public function _before(\CliTester $I) + public function _before(\CliTester $I): void { parent::_before($I); - $I->cloneTemplate(); - $I->addEceComposerRepo(); - $I->uploadToContainer('files/debug_logging/.magento.env.yaml', '/.magento.env.yaml', Docker::BUILD_CONTAINER); + + $I->copyFileToWorkDir('files/debug_logging/.magento.env.yaml', '.magento.env.yaml'); } /** * @param \CliTester $I * @throws \Robo\Exception\TaskException */ - public function testApplyingPatch(\CliTester $I) + public function testApplyingPatch(\CliTester $I): void { - $I->uploadToContainer('files/patches/target_file.md', '/target_file.md', Docker::BUILD_CONTAINER); - $I->uploadToContainer('files/patches/patch.patch', '/m2-hotfixes/patch.patch', Docker::BUILD_CONTAINER); + $I->runEceDockerCommand('build:compose --mode=production'); + $I->copyFileToWorkDir('files/patches/target_file.md', 'target_file.md'); + $I->copyFileToWorkDir('files/patches/patch.patch', 'm2-hotfixes/patch.patch'); // For this test, only the build phase is enough - $I->assertTrue($I->runEceToolsCommand('build', Docker::BUILD_CONTAINER)); + $I->runDockerComposeCommand('run build cloud-build'); + $I->startEnvironment(); $targetFile = $I->grabFileContent('/target_file.md', Docker::BUILD_CONTAINER); $I->assertContains('# Hello Magento', $targetFile); @@ -49,13 +49,15 @@ public function testApplyingPatch(\CliTester $I) * @param \CliTester $I * @throws \Robo\Exception\TaskException */ - public function testApplyingExistingPatch(\CliTester $I) + public function testApplyingExistingPatch(\CliTester $I): void { - $I->uploadToContainer('files/patches/target_file_applied_patch.md', '/target_file.md', Docker::BUILD_CONTAINER); - $I->uploadToContainer('files/patches/patch.patch', '/m2-hotfixes/patch.patch', Docker::BUILD_CONTAINER); + $I->runEceDockerCommand('build:compose --mode=production'); + $I->copyFileToWorkDir('files/patches/target_file_applied_patch.md', 'target_file.md'); + $I->copyFileToWorkDir('files/patches/patch.patch', 'm2-hotfixes/patch.patch'); // For this test, only the build phase is enough - $I->assertTrue($I->runEceToolsCommand('build', Docker::BUILD_CONTAINER)); + $I->runDockerComposeCommand('run build cloud-build'); + $I->startEnvironment(); $targetFile = $I->grabFileContent('/target_file.md', Docker::BUILD_CONTAINER); $I->assertContains('# Hello Magento', $targetFile); diff --git a/src/Test/Functional/Acceptance/PostDeployCest.php b/src/Test/Functional/Acceptance/PostDeployCest.php index 678b6ad374..b993a568b3 100644 --- a/src/Test/Functional/Acceptance/PostDeployCest.php +++ b/src/Test/Functional/Acceptance/PostDeployCest.php @@ -7,37 +7,32 @@ namespace Magento\MagentoCloud\Test\Functional\Acceptance; -use Magento\MagentoCloud\Test\Functional\Codeception\Docker; - /** * This test runs on the latest version of PHP */ class PostDeployCest extends AbstractCest { - /** - * @param \CliTester $I - * @throws \Robo\Exception\TaskException - */ - public function _before(\CliTester $I) - { - parent::_before($I); - $I->cloneTemplate(); - $I->addEceComposerRepo(); - } - /** * @param \CliTester $I * @param \Codeception\Example $data * @throws \Robo\Exception\TaskException * @dataProvider postDeployDataProvider */ - public function testPostDeploy(\CliTester $I, \Codeception\Example $data) + public function testPostDeploy(\CliTester $I, \Codeception\Example $data): void { - $I->uploadToContainer('files/scdondemand/.magento.env.yaml', '/.magento.env.yaml', Docker::BUILD_CONTAINER); - $I->assertTrue($I->runEceToolsCommand('build', Docker::BUILD_CONTAINER, $data['variables'])); + $I->runEceDockerCommand( + sprintf( + 'build:compose --mode=production --env-vars="%s"', + $this->convertEnvFromArrayToJson($data['variables']) + ) + ); + + $I->copyFileToWorkDir('files/scdondemand/.magento.env.yaml', '.magento.env.yaml'); + + $I->runDockerComposeCommand('run build cloud-build'); $I->startEnvironment(); - $I->assertTrue($I->runEceToolsCommand('deploy', Docker::DEPLOY_CONTAINER, $data['variables'])); - $I->assertTrue($I->runEceToolsCommand('post-deploy', Docker::DEPLOY_CONTAINER, $data['variables'])); + $I->runDockerComposeCommand('run deploy cloud-deploy'); + $I->runDockerComposeCommand('run deploy cloud-post-deploy'); $log = $I->grabFileContent('/var/log/cloud.log'); $I->assertContains('INFO: Starting scenario(s): scenario/post-deploy.xml', $log); @@ -55,8 +50,14 @@ public function testPostDeploy(\CliTester $I, \Codeception\Example $data) protected function postDeployDataProvider(): array { return [ - ['variables' => ['ADMIN_EMAIL' => 'admin@example.com']], - ['variables' => []], + [ + 'variables' => [ + 'MAGENTO_CLOUD_VARIABLES' => ['ADMIN_EMAIL' => 'admin@example.com'] + ], + ], + [ + 'variables' => ['MAGENTO_CLOUD_VARIABLES' => []] + ], ]; } @@ -64,18 +65,17 @@ protected function postDeployDataProvider(): array * @param \CliTester $I * @throws \Robo\Exception\TaskException */ - public function testPostDeployIsNotRun(\CliTester $I) + public function testPostDeployIsNotRun(\CliTester $I): void { - $I->uploadToContainer( - 'files/wrong_db_configuration/.magento.env.yaml', - '/.magento.env.yaml', - Docker::BUILD_CONTAINER - ); - $I->assertTrue($I->runEceToolsCommand('build', Docker::BUILD_CONTAINER)); + $I->runEceDockerCommand('build:compose --mode=production'); + $I->copyFileToWorkDir('files/wrong_db_configuration/.magento.env.yaml', '.magento.env.yaml'); + + $I->runDockerComposeCommand('run build cloud-build'); $I->startEnvironment(); - $I->assertFalse($I->runEceToolsCommand('deploy', Docker::DEPLOY_CONTAINER)); + $I->assertFalse($I->runDockerComposeCommand('run deploy cloud-deploy')); $I->seeInOutput('Variable DATABASE_CONFIGURATION is not configured properly'); - $I->assertFalse($I->runEceToolsCommand('post-deploy', Docker::DEPLOY_CONTAINER)); + $I->runDockerComposeCommand('run deploy cloud-post-deploy'); + $log = $I->grabFileContent('/var/log/cloud.log'); $I->assertContains('Fix configuration with given suggestions', $log); $I->assertContains('Post-deploy is skipped because deploy was failed.', $log); diff --git a/src/Test/Functional/Acceptance/ReportDirNestingLevelCest.php b/src/Test/Functional/Acceptance/ReportDirNestingLevelCest.php index e2fee50263..7349342584 100644 --- a/src/Test/Functional/Acceptance/ReportDirNestingLevelCest.php +++ b/src/Test/Functional/Acceptance/ReportDirNestingLevelCest.php @@ -7,9 +7,7 @@ namespace Magento\MagentoCloud\Test\Functional\Acceptance; -use Magento\MagentoCloud\Config\Environment; use Magento\MagentoCloud\Config\Stage\BuildInterface; -use Magento\MagentoCloud\Test\Functional\Codeception\Docker; /** * This test runs on the latest version of PHP @@ -21,17 +19,6 @@ class ReportDirNestingLevelCest extends AbstractCest */ private $expectedPathLocalXml = '/app/pub/errors/local.xml'; - /** - * @param \CliTester $I - * @throws \Robo\Exception\TaskException - */ - public function _before(\CliTester $I) - { - parent::_before($I); - $I->cloneTemplate(); - $I->addEceComposerRepo(); - } - /** * The case when the property ERROR_REPORT_DIR_NESTING_LEVEL not set in .magento.env.yaml file * and the file /errors/local.xml not exist on build phase @@ -40,11 +27,12 @@ public function _before(\CliTester $I) * @param \CliTester $I * @throws \Robo\Exception\TaskException */ - public function testDefault(\CliTester $I) + public function testDefault(\CliTester $I): void { - $I->assertTrue($I->runEceToolsCommand('build', Docker::BUILD_CONTAINER)); + $I->runEceDockerCommand('build:compose --mode=production'); + $I->runDockerComposeCommand('run build cloud-build'); $I->startEnvironment(); - $I->assertTrue($I->runEceToolsCommand('deploy', Docker::DEPLOY_CONTAINER)); + $I->runDockerComposeCommand('run deploy cloud-deploy'); $I->assertContains( $this->getTemplateLocalXm(1), $I->grabFileContent('/pub/errors/local.xml') @@ -67,16 +55,13 @@ public function testDefault(\CliTester $I) * @param \CliTester $I * @throws \Robo\Exception\TaskException */ - public function testWithPropertyInMagentoEnvFile(\CliTester $I) + public function testWithPropertyInMagentoEnvFile(\CliTester $I): void { - $I->uploadToContainer( - 'files/report_dir_nesting_level/.magento.env.yaml', - '/.magento.env.yaml', - Docker::BUILD_CONTAINER - ); - $I->assertTrue($I->runEceToolsCommand('build', Docker::BUILD_CONTAINER)); + $I->copyFileToWorkDir('files/report_dir_nesting_level/.magento.env.yaml', '.magento.env.yaml'); + $I->runEceDockerCommand('build:compose --mode=production'); + $I->runDockerComposeCommand('run build cloud-build'); $I->startEnvironment(); - $I->assertTrue($I->runEceToolsCommand('deploy', Docker::DEPLOY_CONTAINER)); + $I->runDockerComposeCommand('run deploy cloud-deploy'); $I->assertContains( $this->getTemplateLocalXm(3), $I->grabFileContent('/pub/errors/local.xml') @@ -99,21 +84,14 @@ public function testWithPropertyInMagentoEnvFile(\CliTester $I) * @param \CliTester $I * @throws \Robo\Exception\TaskException */ - public function testWithPropertyInLocalXmlFile(\CliTester $I) + public function testWithPropertyInLocalXmlFile(\CliTester $I): void { - $I->uploadToContainer( - 'files/report_dir_nesting_level/.magento.env.yaml', - '/.magento.env.yaml', - Docker::BUILD_CONTAINER - ); - $I->uploadToContainer( - 'files/report_dir_nesting_level/local_with_property.xml', - '/pub/errors/local.xml', - Docker::BUILD_CONTAINER - ); - $I->assertTrue($I->runEceToolsCommand('build', Docker::BUILD_CONTAINER)); + $I->copyFileToWorkDir('files/report_dir_nesting_level/.magento.env.yaml', '.magento.env.yaml'); + $I->copyFileToWorkDir('files/report_dir_nesting_level/local_with_property.xml', 'pub/errors/local.xml'); + $I->runEceDockerCommand('build:compose --mode=production'); + $I->runDockerComposeCommand('run build cloud-build'); $I->startEnvironment(); - $I->assertTrue($I->runEceToolsCommand('deploy', Docker::DEPLOY_CONTAINER)); + $I->runDockerComposeCommand('run deploy cloud-deploy'); $log = $I->grabFileContent('/var/log/cloud.log'); $I->assertContains( sprintf( @@ -134,26 +112,18 @@ public function testWithPropertyInLocalXmlFile(\CliTester $I) * @param \CliTester $I * @throws \Robo\Exception\TaskException */ - public function testWhenSetEnvVar(\CliTester $I) + public function testWhenSetEnvVar(\CliTester $I): void { - $I->uploadToContainer( - 'files/report_dir_nesting_level/.magento.env.yaml', - '/.magento.env.yaml', - Docker::BUILD_CONTAINER - ); - $I->uploadToContainer( - 'files/report_dir_nesting_level/local_with_property.xml', - '/pub/errors/local.xml', - Docker::BUILD_CONTAINER - ); - $I->assertTrue($I->runEceToolsCommand('build', Docker::BUILD_CONTAINER)); - $I->startEnvironment(); - $I->assertTrue($I->runEceToolsCommand( - 'deploy', - Docker::DEPLOY_CONTAINER, - [], - ['MAGE_ERROR_REPORT_DIR_NESTING_LEVEL' => 7] + $I->copyFileToWorkDir('files/report_dir_nesting_level/.magento.env.yaml', '.magento.env.yaml'); + $I->copyFileToWorkDir('files/report_dir_nesting_level/local_with_property.xml', 'pub/errors/local.xml'); + $I->runEceDockerCommand(sprintf( + 'build:compose --mode=production --env-vars="%s"', + $this->convertEnvFromArrayToJson(['MAGE_ERROR_REPORT_DIR_NESTING_LEVEL' => 7]) )); + $I->runDockerComposeCommand('run build cloud-build'); + $I->startEnvironment(); + $I->runDockerComposeCommand('run deploy cloud-deploy'); + $log = $I->grabFileContent('/var/log/cloud.log'); $I->assertContains( sprintf( @@ -174,21 +144,14 @@ public function testWhenSetEnvVar(\CliTester $I) * @param \CliTester $I * @throws \Robo\Exception\TaskException */ - public function testErrorReportDirNestingLevelNotSet(\CliTester $I) + public function testErrorReportDirNestingLevelNotSet(\CliTester $I): void { - $I->uploadToContainer( - 'files/report_dir_nesting_level/.magento.env.yaml', - '/.magento.env.yaml', - Docker::BUILD_CONTAINER - ); - $I->uploadToContainer( - 'files/report_dir_nesting_level/local_without_property.xml', - '/pub/errors/local.xml', - Docker::BUILD_CONTAINER - ); - $I->assertTrue($I->runEceToolsCommand('build', Docker::BUILD_CONTAINER)); + $I->copyFileToWorkDir('files/report_dir_nesting_level/.magento.env.yaml', '.magento.env.yaml'); + $I->copyFileToWorkDir('files/report_dir_nesting_level/local_without_property.xml', 'pub/errors/local.xml'); + $I->runEceDockerCommand('build:compose --mode=production'); + $I->runDockerComposeCommand('run build cloud-build'); $I->startEnvironment(); - $I->assertTrue($I->runEceToolsCommand('deploy', Docker::DEPLOY_CONTAINER)); + $I->runDockerComposeCommand('run deploy cloud-deploy'); $log = $I->grabFileContent('/var/log/cloud.log'); $I->assertContains( sprintf( @@ -218,21 +181,14 @@ public function testErrorReportDirNestingLevelNotSet(\CliTester $I) * @param \CliTester $I * @throws \Robo\Exception\TaskException */ - public function testWithInvalidLocalXmlFile(\CliTester $I) + public function testWithInvalidLocalXmlFile(\CliTester $I): void { - $I->uploadToContainer( - 'files/report_dir_nesting_level/.magento.env.yaml', - '/.magento.env.yaml', - Docker::BUILD_CONTAINER - ); - $I->uploadToContainer( - 'files/report_dir_nesting_level/invalid_local.xml', - '/pub/errors/local.xml', - Docker::BUILD_CONTAINER - ); - $I->assertTrue($I->runEceToolsCommand('build', Docker::BUILD_CONTAINER)); + $I->copyFileToWorkDir('files/report_dir_nesting_level/.magento.env.yaml', '.magento.env.yaml'); + $I->copyFileToWorkDir('files/report_dir_nesting_level/invalid_local.xml', 'pub/errors/local.xml'); + $I->runEceDockerCommand('build:compose --mode=production'); + $I->runDockerComposeCommand('run build cloud-build'); $I->startEnvironment(); - $I->assertTrue($I->runEceToolsCommand('deploy', Docker::DEPLOY_CONTAINER)); + $I->runDockerComposeCommand('run deploy cloud-deploy'); $log = $I->grabFileContent('/var/log/cloud.log'); $I->assertContains( sprintf( diff --git a/src/Test/Functional/Acceptance/ScdMatrixCest.php b/src/Test/Functional/Acceptance/ScdMatrixCest.php index 589cf31413..aaea6effec 100644 --- a/src/Test/Functional/Acceptance/ScdMatrixCest.php +++ b/src/Test/Functional/Acceptance/ScdMatrixCest.php @@ -7,37 +7,26 @@ namespace Magento\MagentoCloud\Test\Functional\Acceptance; -use Magento\MagentoCloud\Test\Functional\Codeception\Docker; - /** * This test runs on the latest version of PHP */ class ScdMatrixCest extends AbstractCest { - /** - * @param \CliTester $I - * @throws \Robo\Exception\TaskException - */ - public function _before(\CliTester $I) - { - parent::_before($I); - $I->cloneTemplate(); - $I->addEceComposerRepo(); - } - /** * @param \CliTester $I * @param \Codeception\Example $data * @throws \Robo\Exception\TaskException * @dataProvider scdOnDeployDataProvider */ - public function testScdOnDeploy(\CliTester $I, \Codeception\Example $data) + public function testScdOnDeploy(\CliTester $I, \Codeception\Example $data): void { - $I->assertTrue($I->uploadToContainer($data['env_yaml'], '/.magento.env.yaml', Docker::BUILD_CONTAINER)); - $I->assertTrue($I->runEceToolsCommand('build', Docker::BUILD_CONTAINER)); + $I->copyFileToWorkDir($data['env_yaml'], 'magento.env.yaml'); + $I->runEceDockerCommand('build:compose --mode=production'); + $I->runDockerComposeCommand('run build cloud-build'); $I->startEnvironment(); - $I->assertTrue($I->runEceToolsCommand('deploy', Docker::DEPLOY_CONTAINER)); - $I->assertTrue($I->runEceToolsCommand('post-deploy', Docker::DEPLOY_CONTAINER)); + $I->runDockerComposeCommand('run deploy cloud-deploy'); + $I->runDockerComposeCommand('run deploy cloud-post-deploy'); + $I->amOnPage('/'); $I->see('Home page'); $I->see('CMS homepage content goes here.'); diff --git a/src/Test/Functional/Acceptance/ScdStrategyCest.php b/src/Test/Functional/Acceptance/ScdStrategyCest.php index b947f255ec..5bdb2dea5b 100644 --- a/src/Test/Functional/Acceptance/ScdStrategyCest.php +++ b/src/Test/Functional/Acceptance/ScdStrategyCest.php @@ -7,37 +7,26 @@ namespace Magento\MagentoCloud\Test\Functional\Acceptance; -use Magento\MagentoCloud\Test\Functional\Codeception\Docker; - /** * This test runs on the latest version of PHP */ class ScdStrategyCest extends AbstractCest { - /** - * @param \CliTester $I - * @throws \Robo\Exception\TaskException - */ - public function _before(\CliTester $I) - { - parent::_before($I); - $I->cloneTemplate(); - $I->addEceComposerRepo(); - } - /** * @param \CliTester $I * @param \Codeception\Example $data * @throws \Robo\Exception\TaskException * @dataProvider scdStrategyDataProvider */ - public function testScdStrategyOnDeploy(\CliTester $I, \Codeception\Example $data) + public function testScdStrategyOnDeploy(\CliTester $I, \Codeception\Example $data): void { - $I->assertTrue($I->uploadToContainer($data['env_yaml'], '/.magento.env.yaml', Docker::BUILD_CONTAINER)); - $I->assertTrue($I->runEceToolsCommand('build', Docker::BUILD_CONTAINER)); + $I->copyFileToWorkDir($data['env_yaml'], '.magento.env.yaml'); + $I->runEceDockerCommand('build:compose --mode=production'); + $I->runDockerComposeCommand('run build cloud-build'); $I->startEnvironment(); - $I->assertTrue($I->runEceToolsCommand('deploy', Docker::DEPLOY_CONTAINER)); - $I->assertTrue($I->runEceToolsCommand('post-deploy', Docker::DEPLOY_CONTAINER)); + $I->runDockerComposeCommand('run deploy cloud-deploy'); + $I->runDockerComposeCommand('run deploy cloud-post-deploy'); + $I->amOnPage('/'); $I->see('Home page'); $I->see('CMS homepage content goes here.'); @@ -55,7 +44,6 @@ protected function scdStrategyDataProvider(): array 'env_yaml' => 'files/scd/scd-strategy-quick.yaml', 'strategy' => 'quick' ], - [ 'env_yaml' => 'files/scd/scd-strategy-standard.yaml', 'strategy' => 'standard' diff --git a/src/Test/Functional/Acceptance/ScenarioExtensibilityCest.php b/src/Test/Functional/Acceptance/ScenarioExtensibilityCest.php index 319170a798..9573f97ff9 100644 --- a/src/Test/Functional/Acceptance/ScenarioExtensibilityCest.php +++ b/src/Test/Functional/Acceptance/ScenarioExtensibilityCest.php @@ -7,7 +7,7 @@ namespace Magento\MagentoCloud\Test\Functional\Acceptance; -use Magento\MagentoCloud\Test\Functional\Codeception\Docker; +use Magento\CloudDocker\Test\Functional\Codeception\Docker; /** * Tests extensibility base deployment scenarios @@ -16,39 +16,34 @@ class ScenarioExtensibilityCest extends AbstractCest { /** * @param \CliTester $I - * @throws \Robo\Exception\TaskException */ - public function _before(\CliTester $I) + public function _before(\CliTester $I): void { parent::_before($I); - $I->cloneTemplate(); - $I->addEceComposerRepo(); - $I->addEceExtendComposerRepo(); - $I->uploadToContainer('files/debug_logging/.magento.env.yaml', '/.magento.env.yaml', Docker::BUILD_CONTAINER); + + $I->copyFileToWorkDir('files/debug_logging/.magento.env.yaml', '.magento.env.yaml'); + $I->createArtifact('ece-tools-extend', 'packages/ece-tools-extend'); + $I->addDependencyToComposer('magento/ece-tools-extend', '*'); + $I->composerUpdate(); } /** * @param \CliTester $I * @throws \Robo\Exception\TaskException */ - public function testScenarioExtensibilityAndPriority(\CliTester $I) + public function testScenarioExtensibilityAndPriority(\CliTester $I): void { - $generateScenarios = [ - './vendor/magento/ece-tools/scenario/build/generate.xml', - './vendor/magento/ece-tools-extend/scenario/extend-build-generate.xml', - './vendor/magento/ece-tools-extend/scenario/extend-build-generate-skip-di.xml', - ]; - $transferScenarios = [ - './vendor/magento/ece-tools/scenario/build/transfer.xml', - './vendor/magento/ece-tools-extend/scenario/extend-build-transfer.xml', - ]; + $app = $I->readAppMagentoYaml(); + $app['hooks']['build'] = 'set -e' . PHP_EOL + . 'php ./vendor/bin/ece-tools run ./vendor/magento/ece-tools/scenario/build/generate.xml' + . ' ./vendor/magento/ece-tools-extend/scenario/extend-build-generate.xml' + . ' ./vendor/magento/ece-tools-extend/scenario/extend-build-generate-skip-di.xml' . PHP_EOL + . 'php ./vendor/bin/ece-tools run ./vendor/magento/ece-tools/scenario/build/transfer.xml' + . ' ./vendor/magento/ece-tools-extend/scenario/extend-build-transfer.xml'; + $I->writeAppMagentoYaml($app); - $I->assertTrue( - $I->runEceToolsCommand(sprintf('run %s', implode(' ', $generateScenarios)), Docker::BUILD_CONTAINER) - ); - $I->assertTrue( - $I->runEceToolsCommand(sprintf('run %s', implode(' ', $transferScenarios)), Docker::BUILD_CONTAINER) - ); + $I->runEceDockerCommand('build:compose --mode=production'); + $I->runDockerComposeCommand('run build cloud-build'); $I->startEnvironment(); $cloudLog = $I->grabFileContent('/var/log/cloud.log', Docker::BUILD_CONTAINER); diff --git a/src/Test/Functional/Acceptance/SessionConfigurationCest.php b/src/Test/Functional/Acceptance/SessionConfigurationCest.php index 778832448e..9bf788d0ae 100644 --- a/src/Test/Functional/Acceptance/SessionConfigurationCest.php +++ b/src/Test/Functional/Acceptance/SessionConfigurationCest.php @@ -7,42 +7,30 @@ namespace Magento\MagentoCloud\Test\Functional\Acceptance; -use Magento\MagentoCloud\Test\Functional\Codeception\Docker; - /** * This scenario checks that session can be configured through environment variable SESSION_CONFIGURATION * Zephyr ID MAGECLOUD-46 */ class SessionConfigurationCest extends AbstractCest { - /** - * @param \CliTester $I - * @throws \Robo\Exception\TaskException - */ - public function _before(\CliTester $I) - { - // Do nothing - } - /** * @param \CliTester $I * @param \Codeception\Example $data * @throws \Robo\Exception\TaskException * @dataProvider sessionConfigurationDataProvider */ - public function sessionConfiguration(\CliTester $I, \Codeception\Example $data) + public function sessionConfiguration(\CliTester $I, \Codeception\Example $data): void { - $I->generateDockerCompose(['redis' => '5.0']); - $I->cleanUpEnvironment(); - $I->cloneTemplate(); - $I->addEceComposerRepo(); - $I->assertTrue($I->runEceToolsCommand('build', Docker::BUILD_CONTAINER)); + $I->runEceDockerCommand( + sprintf( + 'build:compose --mode=production --env-vars="%s"', + $this->convertEnvFromArrayToJson($data['variables']) + ) + ); + $I->runDockerComposeCommand('run build cloud-build'); $I->startEnvironment(); - $I->assertTrue($I->runEceToolsCommand( - 'deploy', - Docker::DEPLOY_CONTAINER, - $data['cloudVariables'] - )); + $I->runDockerComposeCommand('run deploy cloud-deploy'); + $file = $I->grabFileContent('/app/etc/env.php'); $I->assertContains($data['mergedConfig'], $file); $I->assertContains($data['defaultConfig'], $file); @@ -55,7 +43,7 @@ protected function sessionConfigurationDataProvider(): array { return [ 'singleConfig' => [ - 'cloudVariables' => [ + 'variables' => [ 'MAGENTO_CLOUD_VARIABLES' => [ 'SESSION_CONFIGURATION'=>['max_concurrency' => '10', '_merge' => true], ], @@ -64,7 +52,7 @@ protected function sessionConfigurationDataProvider(): array 'defaultConfig' => 'redis', ], 'withoutMerge' => [ - 'cloudVariables' => [ + 'variables' => [ 'MAGENTO_CLOUD_VARIABLES' => [ 'SESSION_CONFIGURATION'=>[ 'save' => 'redis', diff --git a/src/Test/Functional/Acceptance/Upgrade21Cest.php b/src/Test/Functional/Acceptance/Upgrade21Cest.php index 28e3e7760b..6bbcbaad3c 100644 --- a/src/Test/Functional/Acceptance/Upgrade21Cest.php +++ b/src/Test/Functional/Acceptance/Upgrade21Cest.php @@ -15,10 +15,10 @@ class Upgrade21Cest extends UpgradeCest /** * @return array */ - protected function testProvider() + protected function testProvider(): array { return [ - ['from' => '2.1.16', 'to' => '2.2.0'] + ['from' => '2.1.16', 'to' => '>=2.2.0 <2.2.1'] ]; } } diff --git a/src/Test/Functional/Acceptance/Upgrade22Cest.php b/src/Test/Functional/Acceptance/Upgrade22Cest.php index dfbbf51e5f..1a1913e742 100644 --- a/src/Test/Functional/Acceptance/Upgrade22Cest.php +++ b/src/Test/Functional/Acceptance/Upgrade22Cest.php @@ -15,7 +15,7 @@ class Upgrade22Cest extends UpgradeCest /** * @return array */ - protected function testProvider() + protected function testProvider(): array { return [ ['from' => '2.2.0', 'to' => '2.2.*'] diff --git a/src/Test/Functional/Acceptance/UpgradeCest.php b/src/Test/Functional/Acceptance/UpgradeCest.php index 8a83e6a253..77b9b746fb 100644 --- a/src/Test/Functional/Acceptance/UpgradeCest.php +++ b/src/Test/Functional/Acceptance/UpgradeCest.php @@ -7,8 +7,6 @@ namespace Magento\MagentoCloud\Test\Functional\Acceptance; -use Magento\MagentoCloud\Test\Functional\Codeception\Docker; - /** * This test runs on the latest version of PHP * @@ -16,20 +14,29 @@ */ class UpgradeCest extends AbstractCest { + /** + * @param \CliTester $I + */ + public function _before(\CliTester $I): void + { + // Do nothing... + } + /** * @param \CliTester $I * @param \Codeception\Example $data * @throws \Robo\Exception\TaskException * @dataProvider testProvider */ - public function test(\CliTester $I, \Codeception\Example $data) + public function test(\CliTester $I, \Codeception\Example $data): void { - $I->startEnvironment(); - $I->assertTrue($I->cloneTemplate($data['from'])); - $I->assertTrue($I->addEceComposerRepo()); + $this->prepareWorkplace($I, $data['from']); + $I->runEceDockerCommand('build:compose --mode=production'); $this->assert($I); $I->assertTrue($I->cleanDirectories(['/vendor/*', '/setup/*'])); - $I->assertTrue($I->composerRequireMagentoCloud($data['to'])); + $I->stopEnvironment(true); + $I->addDependencyToComposer('magento/magento-cloud-metapackage', $data['to']); + $I->composerUpdate(); $this->assert($I); } @@ -37,25 +44,29 @@ public function test(\CliTester $I, \Codeception\Example $data) * @param \CliTester $I * @throws \Robo\Exception\TaskException */ - protected function assert(\CliTester $I) + protected function assert(\CliTester $I): void { - $I->assertTrue($I->runEceToolsCommand('build', Docker::BUILD_CONTAINER)); - $I->assertTrue($I->runEceToolsCommand('deploy', Docker::DEPLOY_CONTAINER)); - $I->assertTrue($I->runEceToolsCommand('post-deploy', Docker::DEPLOY_CONTAINER)); + + $I->runDockerComposeCommand('run build cloud-build'); + $I->startEnvironment(); + $I->runDockerComposeCommand('run deploy cloud-deploy'); + $I->runDockerComposeCommand('run deploy cloud-post-deploy'); $I->amOnPage('/'); $I->see('Home page'); + $I->see('CMS homepage content goes here.'); } /** * @return array */ - protected function testProvider() + protected function testProvider(): array { // @TODO change version to 2.3.* after fix in magento core. // https://magento2.atlassian.net/browse/MAGECLOUD-3725 return [ - ['from' => '2.3.0', 'to' => '2.3.1'] + ['from' => '2.3.0', 'to' => '>=2.3.1 <2.3.2'], + ['from' => '2.3.3', 'to' => '>=2.3.4 <2.3.5'], ]; } } diff --git a/src/Test/Functional/Acceptance/WizardScdCest.php b/src/Test/Functional/Acceptance/WizardScdCest.php index 258f291c45..29afae5ca3 100644 --- a/src/Test/Functional/Acceptance/WizardScdCest.php +++ b/src/Test/Functional/Acceptance/WizardScdCest.php @@ -7,31 +7,26 @@ namespace Magento\MagentoCloud\Test\Functional\Acceptance; -use Magento\MagentoCloud\Test\Functional\Codeception\Docker; - /** * This test runs on the latest version of PHP */ class WizardScdCest extends AbstractCest { - /** - * @param \CliTester $I - * @throws \Robo\Exception\TaskException - */ - public function _before(\CliTester $I) + public function _before(\CliTester $I): void { parent::_before($I); - $I->assertTrue($I->cloneTemplate()); - $I->assertTrue($I->addEceComposerRepo()); + + $I->runEceDockerCommand('build:compose --mode=production'); } /** * @param \CliTester $I * @throws \Robo\Exception\TaskException */ - public function testDefault(\CliTester $I) + public function testDefault(\CliTester $I): void { - $I->assertFalse($I->runEceToolsCommand('wizard:scd-on-build', Docker::BUILD_CONTAINER)); + $I->runDockerComposeCommand('run build cloud-build'); + $I->assertFalse($I->runDockerComposeCommand('run build ece-command wizard:scd-on-build')); $I->seeInOutput(' - No stores/website/locales found in'); $I->seeInOutput('SCD on build is disabled'); } @@ -40,14 +35,11 @@ public function testDefault(\CliTester $I) * @param \CliTester $I * @throws \Robo\Exception\TaskException */ - public function testScdInBuildIsEnabled(\CliTester $I) + public function testScdInBuildIsEnabled(\CliTester $I): void { - $I->assertTrue($I->uploadToContainer( - 'files/scdinbuild/config.php', - '/app/etc/config.php', - Docker::BUILD_CONTAINER - )); - $I->assertTrue($I->runEceToolsCommand('wizard:scd-on-build', Docker::BUILD_CONTAINER)); + $I->copyFileToWorkDir('files/scdinbuild/config.php', 'app/etc/config.php'); + $I->runDockerComposeCommand('run build cloud-build'); + $I->assertTrue($I->runDockerComposeCommand('run build ece-command wizard:scd-on-build')); $I->seeInOutput('SCD on build is enabled'); } @@ -55,10 +47,11 @@ public function testScdInBuildIsEnabled(\CliTester $I) * @param \CliTester $I * @throws \Robo\Exception\TaskException */ - public function testScdOnDemandIsEnabled(\CliTester $I) + public function testScdOnDemandIsEnabled(\CliTester $I): void { - $I->uploadToContainer('files/scdondemand/.magento.env.yaml', '/.magento.env.yaml', Docker::BUILD_CONTAINER); - $I->assertTrue($I->runEceToolsCommand('wizard:scd-on-demand', Docker::BUILD_CONTAINER)); + $I->copyFileToWorkDir('files/scdondemand/.magento.env.yaml', '.magento.env.yaml'); + $I->runDockerComposeCommand('run build cloud-build'); + $I->assertTrue($I->runDockerComposeCommand('run build ece-command wizard:scd-on-demand')); $I->seeInOutput('SCD on demand is enabled'); } } diff --git a/src/Test/Unit/Config/SchemaTest.php b/src/Test/Unit/Config/SchemaTest.php index 0e46dc3b84..92c450d919 100644 --- a/src/Test/Unit/Config/SchemaTest.php +++ b/src/Test/Unit/Config/SchemaTest.php @@ -14,6 +14,7 @@ use Magento\MagentoCloud\Config\StageConfigInterface; use Magento\MagentoCloud\Config\SystemConfigInterface; use Magento\MagentoCloud\Filesystem\SystemList; +use Magento\MagentoCloud\Filesystem\Driver\File; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Yaml\Parser; @@ -38,6 +39,11 @@ class SchemaTest extends TestCase */ private $parserMock; + /** + * @var File|MockObject + */ + private $fileMock; + /** * @inheritdoc */ @@ -45,13 +51,15 @@ protected function setUp() { $this->systemListMock = $this->createMock(SystemList::class); $this->parserMock = $this->createTestProxy(Parser::class); + $this->fileMock = $this->createTestProxy(File::class); $this->systemListMock->method('getConfig') ->willReturn(ECE_BP . '/config'); $this->schema = new Schema( $this->systemListMock, - $this->parserMock + $this->parserMock, + $this->fileMock ); } diff --git a/tests/functional/Codeception/Docker.php b/tests/functional/Codeception/Docker.php deleted file mode 100644 index 60ea8af5ef..0000000000 --- a/tests/functional/Codeception/Docker.php +++ /dev/null @@ -1,687 +0,0 @@ - '', - 'db_port' => '3306', - 'db_username' => '', - 'db_password' => '', - 'db_path' => '', - 'repo_url' => '', - 'repo_branch' => '', - 'system_ece_tools_dir' => '', - 'system_magento_dir' => '', - 'env_base_url' => '', - 'env_secure_base_url' => '', - 'volumes' => [], - 'printOutput' => false, - ]; - - /** - * @var string - */ - protected $output = ''; - - /** - * @var array - */ - protected $services = []; - - /** - * @inheritdoc - */ - public function _initialize() - { - $container = require Configuration::projectDir() . 'tests/functional/bootstrap.php'; - $builder = CollectionBuilder::create($container, $this); - - $this->setContainer($container); - $this->setBuilder($builder); - } - - /** - * Stops Docker env - * - * @return bool - */ - public function stopEnvironment(): bool - { - return $this->taskEnvDown() - ->printOutput($this->_getConfig('printOutput')) - ->interactive(false) - ->run() - ->stopOnFail() - ->wasSuccessful(); - } - - /** - * Start Docker env - * - * @return bool - */ - public function startEnvironment(): bool - { - return $this->taskEnvUp() - ->printOutput($this->_getConfig('printOutput')) - ->interactive(false) - ->run() - ->stopOnFail() - ->wasSuccessful(); - } - - /** - * Removes docker-compose.yml - * - * @return bool - */ - public function removeDockerCompose(): bool - { - return $this->taskRemoveDockerCompose() - ->printOutput($this->_getConfig('printOutput')) - ->interactive(false) - ->run() - ->stopOnFail() - ->wasSuccessful(); - } - - /** - * Generates docker-compose.yml - * - * @param array $services - * @return bool - */ - public function generateDockerCompose(array $services = []): bool - { - $this->services = $services; - /** @var Result $result */ - $result = $this->taskGenerateDockerCompose($services) - ->printOutput($this->_getConfig('printOutput')) - ->interactive(false) - ->run() - ->stopOnFail(); - - $this->output = $result->getMessage(); - - return $result->wasSuccessful(); - } - - /** - * Clean up Docker env - * - * @return bool - */ - public function cleanUpEnvironment(): bool - { - /** @var Result $result */ - $result = $this->taskEnvCleanUp($this->_getConfig('volumes')) - ->printOutput($this->_getConfig('printOutput')) - ->interactive(false) - ->run() - ->stopOnFail(); - - $this->output = $result->getMessage(); - - return $result->wasSuccessful(); - } - - /** - * Clones magento cloud template from git - * - * @param string|null $version - * @param string|null $edition - * @return bool - * - * @throws TaskException - */ - public function cloneTemplate(string $version = null, string $edition = null): bool - { - $tasks = []; - $tasks[] = $this->taskGitStack() - ->exec('git init') - ->exec(sprintf('git remote add origin %s', $this->_getConfig('repo_url'))) - ->exec('git fetch') - ->checkout($version ?: $this->_getConfig('repo_branch')) - ->getCommand(); - - if ($edition === 'CE') { - $tasks[] = $this->taskComposerRemove('composer') - ->arg('magento/magento-cloud-metapackage') - ->workingDir($this->_getConfig('system_magento_dir')) - ->noInteraction() - ->option('--no-update') - ->getCommand(); - $tasks[] = $this->taskComposerRequire('composer') - ->dependency('magento/product-community-edition', $version ?? '@stable') - ->workingDir($this->_getConfig('system_magento_dir')) - ->noInteraction() - ->option('--no-update') - ->getCommand(); - $tasks[] = $this->taskComposerUpdate('composer') - ->option('--quiet') - ->getCommand(); - } - - /** @var Result $result */ - $result = $this->taskBash(self::BUILD_CONTAINER) - ->printOutput($this->_getConfig('printOutput')) - ->interactive(false) - ->exec(implode(' && ', $tasks)) - ->run(); - - $this->output = $result->getMessage(); - - return $result->wasSuccessful(); - } - - /** - * Runs composer require command - * - * @param string $version - * @return bool - * - * @throws TaskException - */ - public function composerRequireMagentoCloud(string $version): bool - { - $composerRequireTask = $this->taskComposerRequire('composer') - ->dependency('magento/magento-cloud-metapackage', $version) - ->workingDir($this->_getConfig('system_magento_dir')) - ->noInteraction() - ->option('--no-update'); - $composerUpdateTask = $this->taskComposerUpdate('composer'); - - $tasks = [ - $composerRequireTask->getCommand(), - $composerUpdateTask->getCommand() - ]; - - /** @var Result $result */ - $result = $this->taskBash(self::BUILD_CONTAINER) - ->printOutput($this->_getConfig('printOutput')) - ->interactive(false) - ->exec(implode(' && ', $tasks)) - ->run(); - - $this->output = $result->getMessage(); - - return $result->wasSuccessful(); - } - - /** - * Runs composer install command - * - * @return bool - * @throws TaskException - */ - public function composerInstall(): bool - { - $composerTask = $this->taskComposerInstall('composer') - ->noDev() - ->noInteraction() - ->workingDir($this->_getConfig('system_magento_dir')); - - /** @var Result $result */ - $result = $this->taskBash(self::BUILD_CONTAINER) - ->printOutput($this->_getConfig('printOutput')) - ->interactive(false) - ->exec($composerTask) - ->run(); - - $this->output = $result->getMessage(); - - return $result->wasSuccessful(); - } - - /** - * Add local checkout of ECE Tools to composer repositories. - * - * @return bool - * @throws TaskException - */ - public function addEceComposerRepo(): bool - { - $eceToolsVersion = '2002.0.999'; - - $commands = [ - $this->taskComposerConfig('composer') - ->set('repositories.ece-tools', addslashes(json_encode( - [ - 'type' => 'package', - 'package' => [ - 'name' => 'magento/ece-tools', - 'version' => $eceToolsVersion, - 'source' => [ - 'type' => 'git', - 'url' => $this->_getConfig('system_ece_tools_dir'), - 'reference' => exec('git rev-parse HEAD'), - ], - ], - ], - JSON_UNESCAPED_SLASHES - )))->noInteraction() - ->getCommand(), - $this->taskComposerRequire('composer') - ->dependency('magento/ece-tools', $eceToolsVersion) - ->noInteraction() - ->getCommand() - ]; - $customDeps = [ - 'mcp' => [ - 'name' => 'magento/magento-cloud-patches', - 'repo' => [ - 'type' => 'vcs', - 'url' => 'git@github.com:magento/magento-cloud-patches.git' - ] - ], - 'mcc' => [ - 'name' => 'magento/magento-cloud-components', - 'repo' => [ - 'type' => 'vcs', - 'url' => 'git@github.com:magento/magento-cloud-components.git' - ] - ] - ]; - $config = json_decode( - file_get_contents(__DIR__ . '/../../../composer.json'), - true - ); - - foreach ($customDeps as $depName => $extra) { - if (isset($config['require'][$extra['name']])) { - if (!empty($extra['repo'])) { - $commands[] = $this->taskComposerConfig('composer') - ->set( - 'repositories.' . $depName, addslashes(json_encode($extra['repo'], JSON_UNESCAPED_SLASHES)) - ) - ->noInteraction() - ->getCommand(); - } - - $commands[] = $this->taskComposerRequire('composer') - ->dependency($extra['name'], $config['require'][$extra['name']]) - ->noInteraction() - ->option('--no-update') - ->getCommand(); - } - } - - $commands[] = $this->taskComposerUpdate('composer') - ->getCommand(); - - $result = $this->taskBash(self::BUILD_CONTAINER) - ->workingDir((string)$this->_getConfig('system_magento_dir')) - ->printOutput($this->_getConfig('printOutput')) - ->interactive(false) - ->exec(implode(' && ', $commands)) - ->run(); - - $this->output = $result->getMessage(); - - return $result->wasSuccessful(); - } - - /** - * Add ece-tools extend package - * - * @return bool - * - * @throws TaskException - */ - public function addEceExtendComposerRepo(): bool - { - $commands = []; - $repoConfig = [ - 'type' => 'path', - 'url' => $this->_getConfig('system_ece_tools_dir') . '/tests/functional/_data/packages/ece-tools-extend' - ]; - - $commands[] = $this->taskComposerConfig('composer') - ->set('repositories.ece-tools-extend', addslashes(json_encode($repoConfig, JSON_UNESCAPED_SLASHES))) - ->noInteraction() - ->getCommand(); - $commands[] = $this->taskComposerRequire('composer') - ->dependency('magento/ece-tools-extend', '*') - ->noInteraction() - ->getCommand(); - - $result = $this->taskBash(self::BUILD_CONTAINER) - ->workingDir((string)$this->_getConfig('system_ece_tools_dir')) - ->printOutput($this->_getConfig('printOutput')) - ->interactive(false) - ->exec(implode(' && ', $commands)) - ->run(); - - $this->output = $result->getMessage(); - - return $result->wasSuccessful(); - } - - /** - * Cleans directories - * - * @param string|array $path - * @param string $container - * @return bool - * - * @throws TaskException - */ - public function cleanDirectories($path, string $container = self::BUILD_CONTAINER): bool - { - $magentoRoot = $this->_getConfig('system_magento_dir'); - - if (is_array($path)) { - $path = array_map( - static function ($val) use ($magentoRoot) { - return $magentoRoot . $val; - }, - $path - ); - $pathsToCleanup = implode(' ', $path); - } else { - $pathsToCleanup = $magentoRoot . $path; - } - - /** @var Result $result */ - $result = $this->taskBash($container) - ->printOutput($this->_getConfig('printOutput')) - ->interactive(false) - ->exec('rm -rf ' . $pathsToCleanup) - ->run(); - - $this->output = $result->getMessage(); - - return $result->wasSuccessful(); - } - - /** - * Downloads files from Docker container - * - * @param string $source - * @param string $destination - * @param string $container - * @return bool - */ - public function downloadFromContainer(string $source, string $destination, string $container): bool - { - /** @var Result $result */ - $result = $this->taskCopyFromDocker($container) - ->printOutput($this->_getConfig('printOutput')) - ->interactive(false) - ->source($this->_getConfig('system_magento_dir') . $source) - ->destination($destination) - ->run(); - - $this->output = $result->getMessage(); - - return $result->wasSuccessful(); - } - - /** - * Creates folder on Docker - * - * @param string $path - * @param string $container - * @return bool - * @throws TaskException - */ - public function createDirectory(string $path, string $container): bool - { - /** @var Result $result */ - $result = $this->taskBash($container) - ->printOutput($this->_getConfig('printOutput')) - ->interactive(false) - ->exec(sprintf('mkdir -p %s', $this->_getConfig('system_magento_dir') . $path)) - ->run(); - - $this->output = $result->getMessage(); - - return $result->wasSuccessful(); - } - - /** - * Uploads files to Docker container - * - * Relative paths for $source will be expanded from Codeception's data directory. - * - * @param string $source - * @param string $destination - * @param string $container - * @return bool - */ - public function uploadToContainer(string $source, string $destination, string $container): bool - { - if (strpos($source, '/') !== 0) { - $source = Configuration::dataDir() . $source; - } - - /** @var Result $result */ - $result = $this->taskCopyToDocker($container) - ->printOutput($this->_getConfig('printOutput')) - ->interactive(false) - ->source($source) - ->destination($this->_getConfig('system_magento_dir') . $destination) - ->run(); - - $this->output = $result->getMessage(); - - return $result->wasSuccessful(); - } - - /** - * Returns file contents - * - * @param string $source - * @param string $container - * @return string|false - */ - public function grabFileContent(string $source, string $container = self::DEPLOY_CONTAINER) - { - $tmpFile = tempnam(sys_get_temp_dir(), md5($source)); - $this->downloadFromContainer($source, $tmpFile, $container); - - return file_get_contents($tmpFile); - } - - /** - * Runs ece-tools command on Docker container - * - * @param string $command - * @param string $container - * @param array $cloudVariables - * @param array $rawVariables - * @return bool - * @throws \Robo\Exception\TaskException - */ - public function runEceToolsCommand( - string $command, - string $container, - array $cloudVariables = [], - array $rawVariables = [] - ): bool { - /** @var Result $result */ - $result = $this->taskBash($container) - ->printOutput($this->_getConfig('printOutput')) - ->interactive(false) - ->envVars($this->prepareVariables($cloudVariables)) - ->envVars($rawVariables) - ->exec(sprintf('php %s/bin/ece-tools %s', $this->_getConfig('system_ece_tools_dir'), $command)) - ->run(); - - $this->output = $result->getMessage(); - - return $result->wasSuccessful(); - } - - /** - * Checks that output contains $text - * - * @param string $text - */ - public function seeInOutput(string $text) - { - Assert::assertContains($text, $this->output); - } - - /** - * Runs bin/magento command on Docker container - * - * @param string $command - * @param string $container - * @param array $cloudVariables - * @param array $rawVariables - * @return bool - * - * @throws TaskException - */ - public function runBinMagentoCommand( - string $command, - string $container, - array $cloudVariables = [], - array $rawVariables = [] - ): bool { - /** @var Result $result */ - $result = $this->taskBash($container) - ->printOutput($this->_getConfig('printOutput')) - ->interactive(false) - ->envVars($this->prepareVariables($cloudVariables)) - ->envVars($rawVariables) - ->exec(sprintf('php %s/bin/magento %s', $this->_getConfig('system_magento_dir'), $command)) - ->run(); - - $this->output = $result->getMessage(); - - return $result->wasSuccessful(); - } - - /** - * Returns DB credential - * - * @return array - */ - public function getDbCredential(): array - { - return [ - 'host' => $this->_getConfig('db_host'), - 'path' => $this->_getConfig('db_path'), - 'password' => $this->_getConfig('db_password'), - 'username' => $this->_getConfig('db_username'), - 'port' => $this->_getConfig('db_port'), - ]; - } - - /** - * Prepares environment variables - * - * @param array $variables - * @return array - */ - private function prepareVariables(array $variables): array - { - $variables = array_replace($this->getDefaultVariables(), $variables); - - foreach ($variables as $varName => $varValue) { - $variables[$varName] = base64_encode(json_encode($varValue)); - } - - return $variables; - } - - /** - * Returns default environment variables - * - * @return array - */ - private function getDefaultVariables(): array - { - $variables = [ - 'MAGENTO_CLOUD_RELATIONSHIPS' => [ - 'database' => [ - $this->getDbCredential(), - ], - ], - 'MAGENTO_CLOUD_ROUTES' => [ - $this->_getConfig('env_base_url') => [ - 'type' => 'upstream', - 'original_url' => 'http://{default}', - ], - $this->_getConfig('env_secure_base_url') => [ - 'type' => 'upstream', - 'original_url' => 'https://{default}', - ] - ], - 'MAGENTO_CLOUD_VARIABLES' => [ - 'ADMIN_EMAIL' => 'admin@example.com', - ], - ]; - - if (isset($this->services['es'])) { - $variables['MAGENTO_CLOUD_RELATIONSHIPS']['elasticsearch'] = [ - [ - 'host' => 'elasticsearch', - 'port' => '9200', - ], - ]; - } - - if (isset($this->services['redis'])) { - $variables['MAGENTO_CLOUD_RELATIONSHIPS']['redis'] = [ - [ - 'host' => 'redis', - 'port' => '6379', - ], - ]; - } - - if (isset($this->services['rmq'])) { - $variables['MAGENTO_CLOUD_RELATIONSHIPS']['rabbitmq'] = [ - [ - 'host' => 'rabbitmq', - 'port' => '5672', - 'username' => 'guest', - 'password' => 'guest', - ], - ]; - } - - return $variables; - } -} diff --git a/tests/functional/Codeception/MagentoDb.php b/tests/functional/Codeception/MagentoDb.php deleted file mode 100644 index 25db2b8cde..0000000000 --- a/tests/functional/Codeception/MagentoDb.php +++ /dev/null @@ -1,103 +0,0 @@ -_getDriver() - ->deleteQueryByCriteria($table, $criteria); - } - - /** - * @param $table - * @param $columns - * @param array $criteria - * @return array - * @throws \Exception - */ - public function grabColumnsFromDatabase($table, $columns, array $criteria = []) - { - $query = $this->_getDriver()->select($columns, $table, $criteria); - $parameters = array_values($criteria); - $this->debugSection('Query', $query); - $this->debugSection('Parameters', $parameters); - $sth = $this->_getDriver()->executeQuery($query, $parameters); - - return $sth->fetchAll(\PDO::FETCH_ASSOC); - } - - /** - * Checks if there is a connection and reconnects if there is no connection - * - * @param Step $step - * @throws \ReflectionException - */ - public function _beforeStep(Step $step) - { - if (!isset($this->reflection)) { - $this->reflection = new \ReflectionClass($this); - } - - if (!$this->reflection->hasMethod($step->getAction())) { - return; - } - - $class = $this->reflection->getMethod($step->getAction())->getDeclaringClass(); - - if ($class != $this->reflection && $class != $this->reflection->getParentClass()) { - return; - } - - if (!isset($this->drivers[self::DEFAULT_DATABASE]) || !isset($this->drivers[self::DEFAULT_DATABASE])) { - $this->reconnectDatabases(); - } - } - - /** - * @inheritdoc - */ - public function _after(TestInterface $test) - { - $this->disconnectDatabases(); - } - - /** - * This method is overridden to avoid connection attempts before running Docker - * {@inheritdoc} - */ - public function _initialize() {} - - /** - * This method is overridden to avoid connection attempts before running Docker - * {@inheritdoc} - */ - public function _beforeSuite($settings = []) {} - - /** - * This method is overridden to avoid connection attempts before running Docker - * {@inheritdoc} - */ - public function _before(TestInterface $test) {} -} diff --git a/tests/functional/Robo/Tasks.php b/tests/functional/Robo/Tasks.php deleted file mode 100644 index 4d1a4c8369..0000000000 --- a/tests/functional/Robo/Tasks.php +++ /dev/null @@ -1,98 +0,0 @@ -task(Tasks\EnvCleanUp::class, $volumes); - } - - /** - * @param array $volumes - * @return Tasks\EnvUp|CollectionBuilder - */ - protected function taskEnvUp(): CollectionBuilder - { - return $this->task(Tasks\EnvUp::class); - } - - /** - * @return Tasks\EnvDown|CollectionBuilder - */ - protected function taskEnvDown(): CollectionBuilder - { - return $this->task(Tasks\EnvDown::class); - } - - /** - * @param string $container - * @return Tasks\Bash|CollectionBuilder - */ - protected function taskBash(string $container): CollectionBuilder - { - return $this->task(Tasks\Bash::class, $container); - } - - /** - * @param string $container - * @return Tasks\DockerCompose\Run|CollectionBuilder - */ - protected function taskDockerComposeRun(string $container): CollectionBuilder - { - return $this->task(Tasks\DockerCompose\Run::class, $container); - } - - /** - * @param string $container - * @return Tasks\CopyFromDocker|CollectionBuilder - */ - protected function taskCopyFromDocker(string $container): CollectionBuilder - { - return $this->task(Tasks\CopyFromDocker::class, $container); - } - - /** - * @param string $container - * @return Tasks\CopyToDocker|CollectionBuilder - */ - protected function taskCopyToDocker(string $container): CollectionBuilder - { - return $this->task(Tasks\CopyToDocker::class, $container); - } - - /** - * @param array $services - * @return Tasks\GenerateDockerCompose|CollectionBuilder - */ - protected function taskGenerateDockerCompose(array $services = []): CollectionBuilder - { - return $this->task(Tasks\GenerateDockerCompose::class, $services); - } - - /** - * @return Tasks\RemoveDockerCompose|CollectionBuilder - */ - protected function taskRemoveDockerCompose(): CollectionBuilder - { - return $this->task(Tasks\RemoveDockerCompose::class); - } -} diff --git a/tests/functional/Robo/Tasks/Bash.php b/tests/functional/Robo/Tasks/Bash.php deleted file mode 100644 index c60a7665d4..0000000000 --- a/tests/functional/Robo/Tasks/Bash.php +++ /dev/null @@ -1,15 +0,0 @@ -container = $container; - } - - /** - * Sets the source path on the Docker - * - * @param string $source - * @return self - */ - public function source(string $source): self - { - $this->source = $source; - - return $this; - } - - /** - * Sets the destination path on the local machine - * - * @param string $destination - * @return self - */ - public function destination(string $destination): self - { - $this->destination = $destination; - - return $this; - } - - /** - * @inheritdoc - */ - public function getCommand(): string - { - return sprintf( - 'docker cp "$(docker-compose ps -q %s)":%s %s', - $this->container, - $this->source, - $this->destination - ); - } - - /** - * @inheritdoc - */ - public function run(): Result - { - if (!$this->destination) { - throw new \RuntimeException('The destination path is empty'); - } - - if (!$this->source) { - throw new \RuntimeException('The source path is empty'); - } - - $dir = pathinfo($this->destination, PATHINFO_DIRNAME); - - if (!is_dir($dir)) { - mkdir(pathinfo($this->destination, PATHINFO_DIRNAME), 0755, true); - } - - return $this->executeCommand($this->getCommand()); - } -} diff --git a/tests/functional/Robo/Tasks/CopyToDocker.php b/tests/functional/Robo/Tasks/CopyToDocker.php deleted file mode 100644 index f21f8b65f2..0000000000 --- a/tests/functional/Robo/Tasks/CopyToDocker.php +++ /dev/null @@ -1,108 +0,0 @@ -container = $container; - } - - /** - * Sets the source path on the local machine - * - * @param string $source - * @return self - */ - public function source(string $source): self - { - $this->source = $source; - - return $this; - } - - /** - * Sets the destination path on the Docker - * - * @param string $destination - * @return self - */ - public function destination(string $destination): self - { - $this->destination = $destination; - - return $this; - } - - /** - * @inheritdoc - */ - public function getCommand(): string - { - $command = 'docker cp [source] "$(docker-compose ps -q [container])":[destination]'; - return strtr( - $command, - [ - '[source]' => $this->source, - '[container]' => $this->container, - '[destination]' => $this->destination - ] - ); - } - - /** - * @inheritdoc - */ - public function run(): Result - { - if (!file_exists($this->source)) { - throw new \RuntimeException(sprintf('The path "%s" does not exist', $this->source)); - } - - if (!$this->destination) { - throw new \RuntimeException('The destination path is empty'); - } - - return $this->executeCommand($this->getCommand()); - } -} diff --git a/tests/functional/Robo/Tasks/DockerCompose/Run.php b/tests/functional/Robo/Tasks/DockerCompose/Run.php deleted file mode 100644 index 408427c99b..0000000000 --- a/tests/functional/Robo/Tasks/DockerCompose/Run.php +++ /dev/null @@ -1,132 +0,0 @@ -container = $container; - } - - /** - * @inheritdoc - */ - public function getCommand() - { - return trim(sprintf( - 'docker-compose run -w %s %s %s ' . $this->runWrapper, - escapeshellarg($this->workingDir), - $this->arguments, - escapeshellarg($this->container), - $this->run - )); - } - - /** - * @inheritdoc - */ - public function run(): Result - { - return $this->executeCommand($this->getCommand()); - } - - /** - * Sets the command to run - * - * @param string|\Robo\Contract\CommandInterface $run - * @return $this - * @throws \Robo\Exception\TaskException - */ - public function exec($run) - { - $this->run = $this->receiveCommand($run); - return $this; - } - - /** - * Set the command working directory. - * - * @param string - * @return $this - */ - public function workingDir(string $dir): self - { - $this->workingDir = $dir; - return $this; - } - - /** - * Sets environment variables - * - * @param array $env - * @return $this - */ - public function envVars(array $env) - { - foreach ($env as $variable => $value) { - $this->setDockerEnv($variable, $value); - } - return $this; - } - - /** - * @param string $variable - * @param null|string $value - * - * @return $this - */ - protected function setDockerEnv($variable, $value = null) - { - $env = $value ? sprintf('%s=%s', $variable, $value) : $variable; - return $this->option('-e', $env); - } -} diff --git a/tests/functional/Robo/Tasks/EnvCleanUp.php b/tests/functional/Robo/Tasks/EnvCleanUp.php deleted file mode 100644 index 5703140fa8..0000000000 --- a/tests/functional/Robo/Tasks/EnvCleanUp.php +++ /dev/null @@ -1,65 +0,0 @@ -volumes = $volumes; - } - - /** - * @inheritdoc - */ - public function getCommand(): string - { - $commands = [ - 'docker-compose down -v --remove-orphans', - ]; - - foreach ($this->volumes as $volume) { - $commands[] = sprintf( - 'docker-compose run %s bash -c "mkdir -p %s"', - Docker::BUILD_CONTAINER, - $volume - ); - } - - $commands[] = 'docker-compose up -d build'; - - return implode(' && ', $commands); - } - - /** - * @inheritdoc - */ - public function run(): Result - { - return $this->executeCommand($this->getCommand()); - } -} diff --git a/tests/functional/Robo/Tasks/EnvDown.php b/tests/functional/Robo/Tasks/EnvDown.php deleted file mode 100644 index 5be6730934..0000000000 --- a/tests/functional/Robo/Tasks/EnvDown.php +++ /dev/null @@ -1,37 +0,0 @@ -executeCommand($this->getCommand()); - } -} diff --git a/tests/functional/Robo/Tasks/EnvUp.php b/tests/functional/Robo/Tasks/EnvUp.php deleted file mode 100644 index aa4c0daa16..0000000000 --- a/tests/functional/Robo/Tasks/EnvUp.php +++ /dev/null @@ -1,37 +0,0 @@ -executeCommand($this->getCommand()); - } -} diff --git a/tests/functional/Robo/Tasks/GenerateDockerCompose.php b/tests/functional/Robo/Tasks/GenerateDockerCompose.php deleted file mode 100644 index 485e1a136e..0000000000 --- a/tests/functional/Robo/Tasks/GenerateDockerCompose.php +++ /dev/null @@ -1,61 +0,0 @@ -services = $services; - } - - /** - * @inheritdoc - */ - public function getCommand(): string - { - $command = './vendor/bin/ece-docker build:compose --mode=functional'; - - foreach ($this->services as $service => $version) { - $command .= sprintf(' --%s=%s', $service, $version); - } - - return $command; - } - - /** - * @inheritdoc - */ - public function run(): Result - { - return $this->executeCommand($this->getCommand()); - } -} diff --git a/tests/functional/Robo/Tasks/RemoveDockerCompose.php b/tests/functional/Robo/Tasks/RemoveDockerCompose.php deleted file mode 100644 index 8f230d22f2..0000000000 --- a/tests/functional/Robo/Tasks/RemoveDockerCompose.php +++ /dev/null @@ -1,37 +0,0 @@ -executeCommand($this->getCommand()); - } -} diff --git a/tests/functional/_support/.gitignore b/tests/functional/_support/.gitignore deleted file mode 100644 index 68958b461f..0000000000 --- a/tests/functional/_support/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/_generated diff --git a/tests/functional/_support/CliTester.php b/tests/functional/_support/CliTester.php deleted file mode 100644 index 40dc407d49..0000000000 --- a/tests/functional/_support/CliTester.php +++ /dev/null @@ -1,16 +0,0 @@ - 'testFailed' - ]; - - /** - * Method to handle failed tests. - * @param \Codeception\Event\FailEvent $e - */ - public function testFailed(FailEvent $e) { - $failure = $e->getFail(); - $this->writeln('------------------------------------'); - $this->writeln('Message: ' . $failure->getMessage()); - $this->writeln('------------------------------------'); - $this->writeln('Stack Trace: '); - $this->writeln($failure->getTraceAsString()); - $this->writeln('------------------------------------'); - } -} diff --git a/tests/functional/bootstrap.php b/tests/functional/bootstrap.php deleted file mode 100644 index c21553bd28..0000000000 --- a/tests/functional/bootstrap.php +++ /dev/null @@ -1,30 +0,0 @@ -delegate(new League\Container\ReflectionContainer()); - -$container->inflector( - BuilderAwareInterface::class, - function (BuilderAwareInterface $commandClass) use ($container) { - $builder = CollectionBuilder::create($container, $commandClass); - $commandClass->setBuilder($builder); - } -); - -Robo\Robo::setContainer($container); - -return $container; diff --git a/tests/functional/configuration.dist.yml b/tests/functional/configuration.dist.yml deleted file mode 100644 index 4e10e830aa..0000000000 --- a/tests/functional/configuration.dist.yml +++ /dev/null @@ -1,19 +0,0 @@ -Magento: - docker: - settings: - db: - host: 'db.magento2.docker' - port: '3306' - username: 'magento2' - password: 'magento2' - path: 'magento2' - repo: - url: 'https://github.com/magento/magento-cloud' - branch: 'master' - system: - magento_dir: '/app' - ece_dir: '/ece-tools' - env: - url: - base: 'http://magento2.docker/' - secure_base: 'https://magento2.docker/' diff --git a/tests/travis/functional_ee.sh b/tests/travis/functional_ee.sh index 1aac461c77..f5547bd58c 100755 --- a/tests/travis/functional_ee.sh +++ b/tests/travis/functional_ee.sh @@ -8,12 +8,12 @@ trap '>&2 echo Error: Command \`$BASH_COMMAND\` on line $LINENO failed with exit case $TRAVIS_PHP_VERSION in 7.1) - ./vendor/bin/codecept run -g php71 --steps + ./vendor/bin/codecept run -g php71 -x edition-ce --steps ;; 7.2) - ./vendor/bin/codecept run -g parallel_"$FUNCTIONAL_INDEX" --steps + ./vendor/bin/codecept run -g parallel_"$FUNCTIONAL_INDEX" -x edition-ce --steps ;; 7.3) - ./vendor/bin/codecept run -g parallel_"$FUNCTIONAL_INDEX" -x php72 --steps + ./vendor/bin/codecept run -g parallel_"$FUNCTIONAL_INDEX" -x php72 -x edition-ce --steps ;; esac