From 82457142a62007f0b4cb0bac0ed1b8ff6f857bb6 Mon Sep 17 00:00:00 2001 From: Frank Bokdam Date: Mon, 14 Aug 2023 16:21:24 +0200 Subject: [PATCH 1/2] fix integration tests --- .github/workflows/_files/composer.json | 76 +++++++++ .../workflows/_files/install-config-mysql.php | 17 ++ .github/workflows/module_tests.yml | 148 ++++++++++++++++++ composer.json | 3 + 4 files changed, 244 insertions(+) create mode 100644 .github/workflows/_files/composer.json create mode 100644 .github/workflows/_files/install-config-mysql.php create mode 100644 .github/workflows/module_tests.yml diff --git a/.github/workflows/_files/composer.json b/.github/workflows/_files/composer.json new file mode 100644 index 0000000..a634b5d --- /dev/null +++ b/.github/workflows/_files/composer.json @@ -0,0 +1,76 @@ +{ + "name": "magento/project-community-edition", + "description": "eCommerce Platform for Growth (Community Edition)", + "type": "project", + "license": [ + "OSL-3.0", + "AFL-3.0" + ], + "config": { + "preferred-install": "dist", + "sort-packages": true + }, + "require": { + "magento/product-community-edition": "2.4.1" + }, + "require-dev": { + "allure-framework/allure-phpunit": "~1.2.0", + "dealerdirect/phpcodesniffer-composer-installer": "^0.5.0", + "friendsofphp/php-cs-fixer": "~2.16.0", + "lusitanian/oauth": "~0.8.10", + "magento/magento-coding-standard": "*", + "magento/magento2-functional-testing-framework": "^3.0", + "pdepend/pdepend": "~2.7.1", + "phpcompatibility/php-compatibility": "^9.3", + "phpmd/phpmd": "^2.8.0", + "phpstan/phpstan": ">=0.12.3 <=0.12.23", + "phpunit/phpunit": "^9", + "reach-digital/magento2-test-framework": "^1.4", + "sebastian/phpcpd": "~5.0.0", + "squizlabs/php_codesniffer": "~3.5.4", + "tddwizard/magento2-fixtures": "^1.0" + }, + "conflict": { + "gene/bluefoot": "*" + }, + "autoload": { + "psr-4": { + "Magento\\Framework\\": "lib/internal/Magento/Framework/", + "Magento\\Setup\\": "setup/src/Magento/Setup/", + "Magento\\": "app/code/Magento/", + "Zend\\Mvc\\Controller\\": "setup/src/Zend/Mvc/Controller/" + }, + "psr-0": { + "": [ + "app/code/", + "generated/code/" + ] + }, + "files": [ + "app/etc/NonComposerComponentRegistration.php" + ], + "exclude-from-classmap": [ + "**/dev/**", + "**/update/**", + "**/Test/**" + ] + }, + "autoload-dev": { + "psr-4": { + "Magento\\Sniffs\\": "dev/tests/static/framework/Magento/Sniffs/", + "Magento\\Tools\\": "dev/tools/Magento/Tools/", + "Magento\\Tools\\Sanity\\": "dev/build/publication/sanity/Magento/Tools/Sanity/", + "Magento\\TestFramework\\Inspection\\": "dev/tests/static/framework/Magento/TestFramework/Inspection/", + "Magento\\TestFramework\\Utility\\": "dev/tests/static/framework/Magento/TestFramework/Utility/" + } + }, + "version": "2.3.3", + "minimum-stability": "stable", + "repositories": [ + {"type": "composer", "url": "https://repo.packagist.com/vendic/"}, + {"packagist.org": false} + ], + "extra": { + "magento-force": "override" + } +} diff --git a/.github/workflows/_files/install-config-mysql.php b/.github/workflows/_files/install-config-mysql.php new file mode 100644 index 0000000..55cbfe1 --- /dev/null +++ b/.github/workflows/_files/install-config-mysql.php @@ -0,0 +1,17 @@ + '{{mysql-host}}', + 'db-user' => '{{mysql-user}}', + 'db-password' => '{{mysql-password}}', + 'db-name' => '{{mysql-db-name}}', + 'db-prefix' => '', + 'backend-frontname' => 'backend', + 'search-engine' => 'elasticsearch7', + 'elasticsearch-host' => '{{elasticsearch-host}}', + 'elasticsearch-port' => '{{elasticsearch-port}}', + 'admin-user' => \Magento\TestFramework\Bootstrap::ADMIN_NAME, + 'admin-password' => \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD, + 'admin-email' => \Magento\TestFramework\Bootstrap::ADMIN_EMAIL, + 'admin-firstname' => \Magento\TestFramework\Bootstrap::ADMIN_FIRSTNAME, + 'admin-lastname' => \Magento\TestFramework\Bootstrap::ADMIN_LASTNAME +]; diff --git a/.github/workflows/module_tests.yml b/.github/workflows/module_tests.yml new file mode 100644 index 0000000..10fdd7f --- /dev/null +++ b/.github/workflows/module_tests.yml @@ -0,0 +1,148 @@ +name: Tests +env: + COMPOSER_TOKEN: ${{ secrets.COMPOSER_TOKEN }} + PHP_VERSION: ${{ secrets.PHP_VERSION }} + MYSQL_HOST: ${{ secrets.MYSQL_HOST }} + MYSQL_PASSWORD: ${{ secrets.MYSQL_PASSWORD }} + MYSQL_USER: ${{ secrets.MYSQL_USER }} + MYSQL_PORT: ${{ secrets.MYSQL_PORT }} + ELASTIC_HOST: ${{ secrets.ELASTIC_HOST }} + ELASTIC_PORT: 9200 + PACKAGIST_URL: ${{ secrets.PACKAGIST_URL }} + MAGENTO_VERSION: '2.4.2' + MODULE_NAME: 'vendic/magento2-postcode-nl' + +on: + push: + branches: + - '**' + tags-ignore: + - '*.*.*' + +jobs: + phpcs: + name: Code styling + runs-on: self-hosted + steps: + - name: Clean + run: | + if [ -f "/home/runner/.ssh/id_rsa" ]; then rm /home/runner/.ssh/id_rsa; fi + echo "Cleaning up previous run" + rm -rf "${{ github.workspace }}" + rm -rf $HOME/.ssh + mkdir -p "${{ github.workspace }}" + + - uses: actions/checkout@v2 + + - name: Setup PHP with PECL extension + uses: shivammathur/setup-php@v2 + with: + coverage: none + php-version: ${{ env.PHP_VERSION }} + tools: composer:v1, + extensions: gd, bcmath, soap, pdo_mysql, ctype, curl, dom, hash, iconv, intl, mbstring, openssl, simplexml, xsl, sockets, zip + env: + runner: self-hosted + + - name: Create empty folders + run: | + mkdir -p app/etc + touch app/etc/vendor_path.php + + - name: Setup composer repositories + run: | + composer config repositories.private-packagist composer ${{ env.PACKAGIST_URL }} + composer config repositories.packagist.org false + + - name: Install composer dependencies + run: | + composer config --global --auth http-basic.repo.packagist.com token ${{ env.COMPOSER_TOKEN }} + composer install --prefer-dist + + - name: Run phpcs + run: | + vendor/bin/phpcs --config-set installed_paths vendor/magento/magento-coding-standard/ + vendor/bin/phpcs --standard=Magento2 ./ --ignore="*vendor/*" + + integration: + name: Integration tests + runs-on: self-hosted + steps: + + - name: Clean + run: | + if [ -f "/home/runner/.ssh/id_rsa" ]; then rm /home/runner/.ssh/id_rsa; fi + echo "Cleaning up previous run" + rm -rf "${{ github.workspace }}" + rm -rf $HOME/.ssh + mkdir -p "${{ github.workspace }}" + + - uses: actions/checkout@v2 + - uses: FranzDiebold/github-env-vars-action@v2 + + - name: Set DB name + run: | + # DB name + DB_NAME=$(< /dev/urandom tr -dc a-z | head -c9) + echo "DB_NAME=$DB_NAME" >> $GITHUB_ENV + + - name: Setup PHP with PECL extension + uses: shivammathur/setup-php@v2 + with: + coverage: none + php-version: ${{ env.PHP_VERSION }} + tools: composer:v1 + extensions: gd, bcmath, soap, pdo_mysql, ctype, curl, dom, hash, iconv, intl, mbstring, openssl, simplexml, xsl, sockets, zip + env: + runner: self-hosted + + - name: Create folder for Magento 2 + run: | + mkdir magento2 + chmod 775 magento2 + + - name: Setup composer authentication + run: | + composer config --global --auth http-basic.repo.packagist.com token ${{ env.COMPOSER_TOKEN }} + + - name: Copy Magento 2 composer.json + run: | + cp .github/workflows/_files/composer.json magento2/composer.json + + - name: Prepare test database + run: | + echo 'CREATE DATABASE IF NOT EXISTS ${{ env.DB_NAME }};' | mysql -h ${{ env.MYSQL_HOST }} -u${{ env.MYSQL_USER}} -p${{ env.MYSQL_PASSWORD }} --port=${{ env.MYSQL_PORT }} + + - name: Prepare integration test config + run: | + sed -i -e "s/{{mysql-db-name}}/${{ env.DB_NAME }}/g" .github/workflows/_files/install-config-mysql.php + sed -i -e "s/{{mysql-host}}/${{ env.MYSQL_HOST }}:${{ env.MYSQL_PORT }}/g" .github/workflows/_files/install-config-mysql.php + sed -i -e "s/{{mysql-password}}/${{ env.MYSQL_PASSWORD }}/g" .github/workflows/_files/install-config-mysql.php + sed -i -e "s/{{mysql-user}}/${{ env.MYSQL_USER }}/g" .github/workflows/_files/install-config-mysql.php + sed -i -e "s/{{elasticsearch-host}}/${{ env.ELASTIC_HOST }}/g" .github/workflows/_files/install-config-mysql.php + sed -i -e "s/{{elasticsearch-port}}/${{ env.ELASTIC_PORT }}/g" .github/workflows/_files/install-config-mysql.php + mkdir -p magento2/dev/tests/integration/etc + cp .github/workflows/_files/install-config-mysql.php magento2/dev/tests/integration/etc/install-config-mysql.php + cat magento2/dev/tests/integration/etc/install-config-mysql.php + + - name: Setup Magento 2 + run: | + cd magento2 + COMPOSER_MEMORY_LIMIT=-3 composer require magento/product-community-edition ${{ env.MAGENTO_VERSION }} --no-update + COMPOSER_MEMORY_LIMIT=-3 composer update + COMPOSER_MEMORY_LIMIT=-3 composer config minimum-stability dev + + - name: Install module + run: | + cd magento2 + COMPOSER_MEMORY_LIMIT=-3 composer require ${{ env.MODULE_NAME }}:dev-${{ env.CI_REF_NAME }} + + - name: Run integration tests + run: | + cd magento2/dev/tests/integration + ../../../vendor/bin/phpunit -c phpunit.xml.dist ../../../vendor/${{ env.MODULE_NAME }} + + - name: Clean DB + if: ${{ always() }} + run: | + echo 'DROP DATABASE IF EXISTS ${{ env.DB_NAME }};' | mysql -h ${{ env.MYSQL_HOST }} -u${{ env.MYSQL_USER}} -p${{ env.MYSQL_PASSWORD }} --port=${{ env.MYSQL_PORT }} diff --git a/composer.json b/composer.json index 3bde5e5..e332d4d 100644 --- a/composer.json +++ b/composer.json @@ -6,6 +6,9 @@ "tig/postnl-magento2": "1.12.*", "magento/magento-composer-installer": "*" }, + "require-dev": { + "magento/magento-coding-standard": "*" + }, "type": "magento2-module", "autoload": { "files": [ From e8c8e6e3fa3e53317cfb8f25a8c7bbd66d866153 Mon Sep 17 00:00:00 2001 From: Frank Bokdam Date: Mon, 14 Aug 2023 16:31:19 +0200 Subject: [PATCH 2/2] make sure integration test does not crash --- Test/Integration/RequestBuilderTest.php | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/Test/Integration/RequestBuilderTest.php b/Test/Integration/RequestBuilderTest.php index 09cc994..0407f25 100644 --- a/Test/Integration/RequestBuilderTest.php +++ b/Test/Integration/RequestBuilderTest.php @@ -33,24 +33,9 @@ public function testBuildRequestForPickupSave() : void /** @var QuoteAddress $billingAddress */ $billingAddress = $objectManager->create(QuoteAddress::class, ['data' => $billingAddressData]); - $pickupPointData = [ - LocationInterface::NAME => 'Mobile Express', - LocationInterface::COUNTRY => 'BE', - LocationInterface::RETAIL_NETWORK_ID => 'PNPBE-01', - LocationInterface::LOCATION_CODE => '218791', - LocationInterface::FROM => '15:00:00', - LocationInterface::CITY => 'Leuven', - LocationInterface::HOUSE_NR => '93', - LocationInterface::STREET => 'Diestsesteenweg', - LocationInterface::ZIPCODE => '3010' - ]; - - /** @var LocationInterface $postnlPickupLocation */ - $postnlPickupLocation = $objectManager->create(LocationInterface::class, ['data' => $pickupPointData]); - /** @var RequestBuilder $requestBuilder */ $requestBuilder = $objectManager->get(RequestBuilder::class); - $request = $requestBuilder->buildForLocations($billingAddress, $postnlPickupLocation); + $request = $requestBuilder->buildForLocations($billingAddress); var_dump($request->toArray()); }