diff --git a/.gitignore b/.gitignore index a3b63ba..b02912e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ /composer.phar /composer.lock /auth.json +/codeception.yml +/_workdir diff --git a/.travis.yml b/.travis.yml index 1104c7c..062e400 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,16 +3,50 @@ dist: xenial git: depth: false +addons: + hosts: + - magento2.docker + +services: + - docker + language: php php: - - '7.0' - '7.1' - '7.2' - '7.3' -install: composer update +env: + - TEST_SUITE=functional + +stages: + - static-unit + - test + +jobs: + include: + - stage: static-unit + script: ./tests/travis/static-unit.sh; + php: '7.0' + env: + - TEST_SUITE=static-unit + - script: ./tests/travis/static-unit.sh; + php: '7.1' + env: + - TEST_SUITE=static-unit + - script: ./tests/travis/static-unit.sh; + php: '7.2' + env: + - TEST_SUITE=static-unit + - script: ./tests/travis/static-unit.sh; + php: '7.3' + env: + - TEST_SUITE=static-unit + +install: + - 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; + - composer update -n --no-suggest script: - - ./vendor/bin/phpcs ./src --standard=./tests/static/phpcs-ruleset.xml -p -n - - ./vendor/bin/phpmd ./src xml ./tests/static/phpmd-ruleset.xml - - ./vendor/bin/phpunit --configuration ./tests/unit + - if [ $TRAVIS_SECURE_ENV_VARS == "true" ] && [ $TEST_SUITE == "functional" ]; then ./tests/travis/functional.sh; fi; diff --git a/codeception.dist.yml b/codeception.dist.yml new file mode 100644 index 0000000..710cb34 --- /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 84c3baf..61fc678 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,8 @@ "symfony/process": "^2.1||^4.1" }, "require-dev": { + "codeception/codeception": "^2.5.3", + "consolidation/robo": "^1.2", "phpmd/phpmd": "@stable", "phpunit/phpunit": "^6.2", "squizlabs/php_codesniffer": "^3.0" @@ -24,7 +26,8 @@ ], "autoload": { "psr-4": { - "Magento\\CloudPatches\\": "src/" + "Magento\\CloudPatches\\": "src/", + "Magento\\CloudPatches\\Test\\Functional\\": "tests/functional/" } }, "scripts": { diff --git a/src/Test/Functional/Acceptance.suite.dist.yml b/src/Test/Functional/Acceptance.suite.dist.yml new file mode 100644 index 0000000..cf28434 --- /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/Acceptance71Cest.php b/src/Test/Functional/Acceptance/Acceptance71Cest.php new file mode 100644 index 0000000..57294c0 --- /dev/null +++ b/src/Test/Functional/Acceptance/Acceptance71Cest.php @@ -0,0 +1,27 @@ + '2.1.16'], + ['magentoVersion' => '2.1.18'], + ['magentoVersion' => '2.2.0'], + ['magentoVersion' => '2.2.11'], + ]; + } +} diff --git a/src/Test/Functional/Acceptance/Acceptance72Cest.php b/src/Test/Functional/Acceptance/Acceptance72Cest.php new file mode 100644 index 0000000..3c2bd10 --- /dev/null +++ b/src/Test/Functional/Acceptance/Acceptance72Cest.php @@ -0,0 +1,25 @@ + '2.3.0'], + ['magentoVersion' => '2.3.2'], + ]; + } +} diff --git a/src/Test/Functional/Acceptance/AcceptanceCest.php b/src/Test/Functional/Acceptance/AcceptanceCest.php new file mode 100644 index 0000000..5bd219f --- /dev/null +++ b/src/Test/Functional/Acceptance/AcceptanceCest.php @@ -0,0 +1,99 @@ +cleanupWorkDir(); + } + + /** + * @param \CliTester $I + * @param string $magentoVersion + */ + protected function prepareTemplate(\CliTester $I, string $magentoVersion): void + { + $I->cloneTemplateToWorkDir($magentoVersion); + $I->createAuthJson(); + $I->createArtifactsDir(); + $I->createArtifactCurrentTestedCode('patches', '1.0.99'); + $I->addArtifactsRepoToComposer(); + $I->addEceDockerGitRepoToComposer(); + $I->addDependencyToComposer('magento/magento-cloud-patches', '1.0.99'); + $I->addDependencyToComposer( + 'magento/magento-cloud-docker', + $I->getDependencyVersion('magento/magento-cloud-docker') + ); + $I->composerUpdate(); + } + + /** + * @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['magentoVersion']); + $this->removeESIfExists($I); + $I->runEceDockerCommand('build:compose --mode=production'); + $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.'); + } + + /** + * @param \CliTester $I + */ + protected function removeESIfExists(\CliTester $I): void + { + $services = $I->readServicesYaml(); + + if (isset($services['elasticsearch'])) { + unset($services['elasticsearch']); + $I->writeServicesYaml($services); + + $app = $I->readAppMagentoYaml(); + unset($app['relationships']['elasticsearch']); + $I->writeAppMagentoYaml($app); + } + } + + /** + * @return array + */ + protected function patchesDataProvider(): array + { + return [ + ['magentoVersion' => '2.3.3'], + ['magentoVersion' => 'master'], + ]; + } + + /** + * @param \CliTester $I + */ + public function _after(\CliTester $I): void + { + $I->stopEnvironment(); + $I->removeWorkDir(); + } +} diff --git a/tests/functional/_data/.gitkeep b/tests/functional/_data/.gitkeep new file mode 100644 index 0000000..e69de29 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 0000000..f9b165b --- /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/_output/.gitignore b/tests/functional/_output/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/tests/functional/_output/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/tests/travis/functional.sh b/tests/travis/functional.sh new file mode 100755 index 0000000..a0d12a1 --- /dev/null +++ b/tests/travis/functional.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 diff --git a/tests/travis/static-unit.sh b/tests/travis/static-unit.sh new file mode 100755 index 0000000..dc99e6a --- /dev/null +++ b/tests/travis/static-unit.sh @@ -0,0 +1,11 @@ +#!/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 + +./vendor/bin/phpcs ./src --standard=./tests/static/phpcs-ruleset.xml -p -n +./vendor/bin/phpmd ./src xml ./tests/static/phpmd-ruleset.xml +./vendor/bin/phpunit --configuration ./tests/unit