From fad946f0f0e2cedbd0a5c0cbed592fc4177c754b Mon Sep 17 00:00:00 2001 From: Bohdan Korablov Date: Mon, 6 Jul 2020 15:29:26 -0500 Subject: [PATCH 1/3] MCLOUD-6338: Adopt CI acceptance functional build from magento/magento-cloud-patches for magento/quality-patches repository --- .travis.yaml | 53 ++++++++++++++ codeception.dist.yml | 37 ++++++++++ composer.json | 19 +++-- src/Test/Functional/Acceptance.suite.dist.yml | 7 ++ .../Functional/Acceptance/AbstractCest.php | 69 +++++++++++++++++++ .../Acceptance/Acceptance71CeCest.php | 19 +++++ .../Acceptance/Acceptance71Cest.php | 38 ++++++++++ .../Acceptance/Acceptance72CeCest.php | 19 +++++ .../Acceptance/Acceptance72Cest.php | 26 +++++++ .../Acceptance/AcceptanceCeCest.php | 19 +++++ .../Functional/Acceptance/AcceptanceCest.php | 57 +++++++++++++++ .../Acceptance/PatchApplierCest.php | 64 +++++++++++++++++ tests/functional/_data/.gitkeep | 0 .../files/debug_logging/.magento.env.yaml | 9 +++ .../_data/files/patches/patch.patch | 7 ++ .../_data/files/patches/target_file.md | 1 + .../patches/target_file_applied_patch.md | 3 + tests/functional/_output/.gitignore | 2 + tests/travis/functional-ce.sh | 19 +++++ tests/travis/functional-ee.sh | 19 +++++ 20 files changed, 477 insertions(+), 10 deletions(-) create mode 100644 .travis.yaml create mode 100644 codeception.dist.yml create mode 100644 src/Test/Functional/Acceptance.suite.dist.yml create mode 100644 src/Test/Functional/Acceptance/AbstractCest.php create mode 100644 src/Test/Functional/Acceptance/Acceptance71CeCest.php create mode 100644 src/Test/Functional/Acceptance/Acceptance71Cest.php create mode 100644 src/Test/Functional/Acceptance/Acceptance72CeCest.php create mode 100644 src/Test/Functional/Acceptance/Acceptance72Cest.php create mode 100644 src/Test/Functional/Acceptance/AcceptanceCeCest.php create mode 100644 src/Test/Functional/Acceptance/AcceptanceCest.php create mode 100644 src/Test/Functional/Acceptance/PatchApplierCest.php create mode 100644 tests/functional/_data/.gitkeep create mode 100644 tests/functional/_data/files/debug_logging/.magento.env.yaml create mode 100644 tests/functional/_data/files/patches/patch.patch create mode 100644 tests/functional/_data/files/patches/target_file.md create mode 100644 tests/functional/_data/files/patches/target_file_applied_patch.md create mode 100644 tests/functional/_output/.gitignore create mode 100755 tests/travis/functional-ce.sh create mode 100755 tests/travis/functional-ee.sh diff --git a/.travis.yaml b/.travis.yaml new file mode 100644 index 00000000..0d7da23f --- /dev/null +++ b/.travis.yaml @@ -0,0 +1,53 @@ +dist: xenial + +git: + depth: false + +addons: + hosts: + - magento2.docker + +services: + - docker + +language: php + +stages: + - test + +jobs: + include: + - stage: test + php: '7.1' + env: + - TEST_SUITE=functional-ee + - php: '7.2' + env: + - TEST_SUITE=functional-ee + - php: '7.3' + env: + - TEST_SUITE=functional-ee + - php: '7.1' + env: + - TEST_SUITE=functional-ce + - php: '7.2' + env: + - TEST_SUITE=functional-ce + - php: '7.3' + env: + - TEST_SUITE=functional-ce + +install: + - composer config http-basic.repo.magento.com ${REPO_USERNAME_CE} ${REPO_PASSWORD_CE} + - composer config github-oauth.github.com ${GITHUB_TOKEN} + - if [ -n "${MCD_VERSION}" ] && [ $TRAVIS_PHP_VERSION != "7.0" ]; then composer config repositories.mcd git git@github.com:magento/magento-cloud-docker.git && composer require "magento/magento-cloud-docker:${MCD_VERSION}" --no-update; fi; + - if [ -n "${MCP_VERSION}" ] && [ $TRAVIS_PHP_VERSION != "7.0" ]; then composer config repositories.mcp git git@github.com:magento-mpi/magento-cloud-patches.git && composer require "magento/magento-cloud-patches:${MCP_VERSION}" --no-update; fi; + - composer update -n --no-suggest + +before_script: + - sudo sysctl -w vm.max_map_count=262144 + - 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 [ $TRAVIS_SECURE_ENV_VARS == "true" ] && [ $TEST_SUITE == "functional-ee" ]; then ./tests/travis/functional-ee.sh; fi; + - if [ $TEST_SUITE == "functional-ce" ]; then ./tests/travis/functional-ce.sh; fi; diff --git a/codeception.dist.yml b/codeception.dist.yml new file mode 100644 index 00000000..710cb349 --- /dev/null +++ b/codeception.dist.yml @@ -0,0 +1,37 @@ +paths: + tests: src/Test/Functional + output: tests/functional/_output + data: tests/functional/_data + support: vendor/magento/magento-cloud-docker/tests/functional/_support +actor_suffix: Tester +settings: + colors: true +extensions: + enabled: + - Codeception\Extension\RunFailed + - Codeception\Extension\FailedInfo +params: + - vendor/magento/magento-cloud-docker/tests/functional/configuration.dist.yml + - env +modules: + config: + 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%" + printOutput: false + PhpBrowser: + url: "%Magento.docker.settings.env.url.base%" + 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 f0a0e1d9..27a84ebd 100644 --- a/composer.json +++ b/composer.json @@ -6,21 +6,20 @@ "license": "OSL-3.0", "require": { "php": "^7.0", - "ext-json": "*", - "magento/magento-cloud-patches": "dev-MC-34580" + "ext-json": "*" + }, + "require-dev": { + "codeception/codeception": "^2.5.3", + "consolidation/robo": "^1.2", + "phpunit/phpunit": "^6.2" }, "autoload": { "psr-4": { - "Magento\\QualityPatches\\": "src/" + "Magento\\QualityPatches\\": "src/", + "Magento\\QualityPatches\\Test\\Functional\\": "tests/functional/" } }, "config": { "sort-packages": true - }, - "repositories": [ - { - "type": "vcs", - "url": "https://github.com/magento-mpi/magento-cloud-patches.git" - } - ] + } } diff --git a/src/Test/Functional/Acceptance.suite.dist.yml b/src/Test/Functional/Acceptance.suite.dist.yml new file mode 100644 index 00000000..cf284341 --- /dev/null +++ b/src/Test/Functional/Acceptance.suite.dist.yml @@ -0,0 +1,7 @@ +actor: CliTester +modules: + enabled: + - Magento\CloudDocker\Test\Functional\Codeception\TestInfrastructure + - Magento\CloudDocker\Test\Functional\Codeception\Docker + - PhpBrowser + - Asserts diff --git a/src/Test/Functional/Acceptance/AbstractCest.php b/src/Test/Functional/Acceptance/AbstractCest.php new file mode 100644 index 00000000..4ea4e134 --- /dev/null +++ b/src/Test/Functional/Acceptance/AbstractCest.php @@ -0,0 +1,69 @@ +cleanupWorkDir(); + } + + /** + * @param \CliTester $I + * @param string $templateVersion + */ + protected function prepareTemplate(\CliTester $I, string $templateVersion): void + { + $I->cloneTemplateToWorkDir($templateVersion); + $I->createAuthJson(); + $I->createArtifactsDir(); + $I->createArtifactCurrentTestedCode('patches', '1.0.99'); + $I->addArtifactsRepoToComposer(); + $I->addEceDockerGitRepoToComposer(); + $I->addCloudPatchesGitRepoToComposer(); + $I->addDependencyToComposer('magento/quality-patches', '1.0.99'); + $I->addDependencyToComposer( + 'magento/magento-cloud-patches', + $I->getDependencyVersion('magento/magento-cloud-patches') + ); + $I->addDependencyToComposer( + 'magento/magento-cloud-docker', + $I->getDependencyVersion('magento/magento-cloud-docker') + ); + + if ($this->edition === 'CE') { + $version = $this->getVersionRangeForMagento($I); + $I->removeDependencyFromComposer('magento/magento-cloud-metapackage'); + $I->addDependencyToComposer('magento/ece-tools', '^2002.1.0'); + $I->addDependencyToComposer('magento/product-community-edition', $version); + } + + $I->composerUpdate(); + } + + /** + * @param \CliTester $I + */ + public function _after(\CliTester $I): void + { + $I->stopEnvironment(); + $I->removeWorkDir(); + } +} diff --git a/src/Test/Functional/Acceptance/Acceptance71CeCest.php b/src/Test/Functional/Acceptance/Acceptance71CeCest.php new file mode 100644 index 00000000..f2e0260b --- /dev/null +++ b/src/Test/Functional/Acceptance/Acceptance71CeCest.php @@ -0,0 +1,19 @@ + '2.1.16'], + ['templateVersion' => '2.1.17'], + ['templateVersion' => '2.1.18'], + ['templateVersion' => '2.2.0'], + ['templateVersion' => '2.2.1'], + ['templateVersion' => '2.2.2'], + ['templateVersion' => '2.2.3'], + ['templateVersion' => '2.2.4'], + ['templateVersion' => '2.2.5'], + ['templateVersion' => '2.2.6'], + ['templateVersion' => '2.2.7'], + ['templateVersion' => '2.2.8'], + ['templateVersion' => '2.2.9'], + ['templateVersion' => '2.2.10'], + ['templateVersion' => '2.2.11'], + ]; + } +} diff --git a/src/Test/Functional/Acceptance/Acceptance72CeCest.php b/src/Test/Functional/Acceptance/Acceptance72CeCest.php new file mode 100644 index 00000000..076fa3c2 --- /dev/null +++ b/src/Test/Functional/Acceptance/Acceptance72CeCest.php @@ -0,0 +1,19 @@ + '2.3.0'], + ['templateVersion' => '2.3.1'], + ['templateVersion' => '2.3.2'], + ]; + } +} diff --git a/src/Test/Functional/Acceptance/AcceptanceCeCest.php b/src/Test/Functional/Acceptance/AcceptanceCeCest.php new file mode 100644 index 00000000..5cdd0aad --- /dev/null +++ b/src/Test/Functional/Acceptance/AcceptanceCeCest.php @@ -0,0 +1,19 @@ +getWorkDirPath() . '/composer.json'), true); + + return $composer['require']['magento/magento-cloud-metapackage'] ?? ''; + } + + /** + * @param \CliTester $I + * @param \Codeception\Example $data + * @throws \Robo\Exception\TaskException + * @dataProvider patchesDataProvider + */ + public function testPatches(\CliTester $I, \Codeception\Example $data): void + { + $this->prepareTemplate($I, $data['templateVersion']); + $I->assertTrue($I->runEceDockerCommand('build:compose --mode=production')); + $I->assertTrue($I->runDockerComposeCommand('run build cloud-build')); + $I->assertTrue($I->startEnvironment()); + $I->assertTrue($I->runDockerComposeCommand('run deploy cloud-deploy')); + $I->assertTrue($I->runDockerComposeCommand('run deploy cloud-post-deploy')); + $I->amOnPage('/'); + $I->see('Home page'); + $I->see('CMS homepage content goes here.'); + } + + /** + * @return array + */ + protected function patchesDataProvider(): array + { + return [ + ['templateVersion' => '2.3.3'], + ['templateVersion' => '2.3.4'], + ['templateVersion' => '2.3.5'], + ['templateVersion' => 'master'], + ]; + } +} diff --git a/src/Test/Functional/Acceptance/PatchApplierCest.php b/src/Test/Functional/Acceptance/PatchApplierCest.php new file mode 100644 index 00000000..96bf6af2 --- /dev/null +++ b/src/Test/Functional/Acceptance/PatchApplierCest.php @@ -0,0 +1,64 @@ +prepareTemplate($I, 'master'); + $I->copyFileToWorkDir('files/debug_logging/.magento.env.yaml', '.magento.env.yaml'); + $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->runDockerComposeCommand('run build cloud-build'); + $I->startEnvironment(); + + $targetFile = $I->grabFileContent('/target_file.md', Docker::BUILD_CONTAINER); + $I->assertContains('# Hello Magento', $targetFile); + $I->assertContains('## Additional Info', $targetFile); + $log = $I->grabFileContent('/var/log/cloud.log', Docker::BUILD_CONTAINER); + $I->assertContains('Patch "/app/m2-hotfixes/patch.patch" applied', $log); + } + + /** + * @param \CliTester $I + * @throws \Robo\Exception\TaskException + */ +// public function testApplyingExistingPatch(\CliTester $I): void +// { +// $this->prepareTemplate($I, 'master'); +// $I->copyFileToWorkDir('files/debug_logging/.magento.env.yaml', '.magento.env.yaml'); +// $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->runDockerComposeCommand('run build cloud-build'); +// $I->startEnvironment(); +// +// $targetFile = $I->grabFileContent('/target_file.md', Docker::BUILD_CONTAINER); +// $I->assertContains('# Hello Magento', $targetFile); +// $I->assertContains('## Additional Info', $targetFile); +// $I->assertContains( +// 'Patch "/app/m2-hotfixes/patch.patch" was already applied', +// $I->grabFileContent('/var/log/cloud.log', Docker::BUILD_CONTAINER) +// ); +// } +} diff --git a/tests/functional/_data/.gitkeep b/tests/functional/_data/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/tests/functional/_data/files/debug_logging/.magento.env.yaml b/tests/functional/_data/files/debug_logging/.magento.env.yaml new file mode 100644 index 00000000..f9b165be --- /dev/null +++ b/tests/functional/_data/files/debug_logging/.magento.env.yaml @@ -0,0 +1,9 @@ +stage: + global: + MIN_LOGGING_LEVEL: debug + +log: + file: + min_level: "debug" + stream: + min_level: "debug" diff --git a/tests/functional/_data/files/patches/patch.patch b/tests/functional/_data/files/patches/patch.patch new file mode 100644 index 00000000..f83b5cd2 --- /dev/null +++ b/tests/functional/_data/files/patches/patch.patch @@ -0,0 +1,7 @@ +--- target_file.md 2018-01-26 16:04:11.000000000 -0600 ++++ target_file.md 2018-01-26 16:04:45.000000000 -0600 +@@ -1 +1,3 @@ +-# Hello World ++# Hello Magento ++ ++## Additional Info diff --git a/tests/functional/_data/files/patches/target_file.md b/tests/functional/_data/files/patches/target_file.md new file mode 100644 index 00000000..29658341 --- /dev/null +++ b/tests/functional/_data/files/patches/target_file.md @@ -0,0 +1 @@ +# Hello World diff --git a/tests/functional/_data/files/patches/target_file_applied_patch.md b/tests/functional/_data/files/patches/target_file_applied_patch.md new file mode 100644 index 00000000..8beae785 --- /dev/null +++ b/tests/functional/_data/files/patches/target_file_applied_patch.md @@ -0,0 +1,3 @@ +# Hello Magento + +## Additional Info diff --git a/tests/functional/_output/.gitignore b/tests/functional/_output/.gitignore new file mode 100644 index 00000000..d6b7ef32 --- /dev/null +++ b/tests/functional/_output/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/tests/travis/functional-ce.sh b/tests/travis/functional-ce.sh new file mode 100755 index 00000000..6eedc70a --- /dev/null +++ b/tests/travis/functional-ce.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Copyright © Magento, Inc. All rights reserved. +# See COPYING.txt for license details. + +set -e +trap '>&2 echo Error: Command \`$BASH_COMMAND\` on line $LINENO failed with exit code $?' ERR + +case $TRAVIS_PHP_VERSION in + 7.1) + ./vendor/bin/codecept run -g php71ce --steps + ;; + 7.2) + ./vendor/bin/codecept run -g php72ce --steps + ;; + 7.3) + ./vendor/bin/codecept run -g php73ce --steps + ;; +esac diff --git a/tests/travis/functional-ee.sh b/tests/travis/functional-ee.sh new file mode 100755 index 00000000..a0d12a11 --- /dev/null +++ b/tests/travis/functional-ee.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Copyright © Magento, Inc. All rights reserved. +# See COPYING.txt for license details. + +set -e +trap '>&2 echo Error: Command \`$BASH_COMMAND\` on line $LINENO failed with exit code $?' ERR + +case $TRAVIS_PHP_VERSION in + 7.1) + ./vendor/bin/codecept run -g php71 --steps + ;; + 7.2) + ./vendor/bin/codecept run -g php72 --steps + ;; + 7.3) + ./vendor/bin/codecept run -g php73 --steps + ;; +esac From 2853d7bfc926500b18c7c622629504373bf07fcb Mon Sep 17 00:00:00 2001 From: Bohdan Korablov Date: Tue, 7 Jul 2020 10:16:54 -0500 Subject: [PATCH 2/3] MCLOUD-6338: Adopt CI acceptance functional build from magento/magento-cloud-patches for magento/quality-patches repository --- .travis.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yaml b/.travis.yaml index 0d7da23f..b245cc9f 100644 --- a/.travis.yaml +++ b/.travis.yaml @@ -46,7 +46,9 @@ install: before_script: - sudo sysctl -w vm.max_map_count=262144 - - 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; + - cp codeception.dist.yml codeception.yml + - sed -i "s/https:\/\/github.com\/magento\/magento-cloud-patches.git/https:\/\/github.com\/magento-mpi\/magento-cloud-patches.git/" codeception.yml + - if [ $TEST_SUITE == "functional-ce" ]; then sed -i "s/REPO_USERNAME/REPO_USERNAME_CE/" codeception.yml && sed -i "s/REPO_PASSWORD/REPO_PASSWORD_CE/" codeception.yml; fi; script: - if [ $TRAVIS_SECURE_ENV_VARS == "true" ] && [ $TEST_SUITE == "functional-ee" ]; then ./tests/travis/functional-ee.sh; fi; From 1e98ef323395a8e73221b4304864d9b7e171a9e2 Mon Sep 17 00:00:00 2001 From: Bohdan Korablov Date: Tue, 7 Jul 2020 10:42:13 -0500 Subject: [PATCH 3/3] MCLOUD-6338: Adopt CI acceptance functional build from magento/magento-cloud-patches for magento/quality-patches repository --- .travis.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yaml b/.travis.yaml index b245cc9f..6c72242e 100644 --- a/.travis.yaml +++ b/.travis.yaml @@ -40,8 +40,8 @@ jobs: install: - composer config http-basic.repo.magento.com ${REPO_USERNAME_CE} ${REPO_PASSWORD_CE} - composer config github-oauth.github.com ${GITHUB_TOKEN} - - if [ -n "${MCD_VERSION}" ] && [ $TRAVIS_PHP_VERSION != "7.0" ]; then composer config repositories.mcd git git@github.com:magento/magento-cloud-docker.git && composer require "magento/magento-cloud-docker:${MCD_VERSION}" --no-update; fi; - - if [ -n "${MCP_VERSION}" ] && [ $TRAVIS_PHP_VERSION != "7.0" ]; then composer config repositories.mcp git git@github.com:magento-mpi/magento-cloud-patches.git && composer require "magento/magento-cloud-patches:${MCP_VERSION}" --no-update; fi; + - if [ -n "${MCD_VERSION}" ]; then composer config repositories.mcd git git@github.com:magento/magento-cloud-docker.git && composer require "magento/magento-cloud-docker:${MCD_VERSION}" --no-update; fi; + - if [ -n "${MCP_VERSION}" ]; then composer config repositories.mcp git git@github.com:magento-mpi/magento-cloud-patches.git && composer require "magento/magento-cloud-patches:${MCP_VERSION}" --no-update; fi; - composer update -n --no-suggest before_script: