diff --git a/.github/ci-files/local.config.php b/.github/ci-files/local.config.php index d9213085..c69ba12c 100644 --- a/.github/ci-files/local.config.php +++ b/.github/ci-files/local.config.php @@ -52,10 +52,10 @@ 'version' => 'OAuth1a', // Required for OAuth1a and OAuth2 - 'baseUrl' => 'http://localhost/index_dev.php', + 'baseUrl' => 'http://localhost/', // Required for All tests - 'apiUrl' => 'http://localhost/index_dev.php/api/', + 'apiUrl' => 'http://localhost/api/', // Required for EmailsTest 'testEmail' => 'notexisting@email.com', diff --git a/.github/ci-files/local.php b/.github/ci-files/local.php deleted file mode 100644 index 0fc13904..00000000 --- a/.github/ci-files/local.php +++ /dev/null @@ -1,17 +0,0 @@ - true, - 'api_enable_basic_auth' => true, - 'db_driver' => 'pdo_mysql', - 'db_host' => '127.0.0.1', - 'db_table_prefix' => null, - 'db_port' => getenv('DB_PORT'), - 'db_name' => 'mautictest', - 'db_user' => 'root', - 'db_password' => '', - 'admin_email' => 'github-actions@mautic.org', - 'admin_password' => 'mautic', -]; diff --git a/.github/ci-files/prepare_mautic.sh b/.github/ci-files/prepare_mautic.sh new file mode 100644 index 00000000..5b2e2296 --- /dev/null +++ b/.github/ci-files/prepare_mautic.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +set -e + +apt-get update && apt-get install default-mysql-client -y + +cd /var/www + +cat << 'EOF' > docroot/app/config/parameters_local.php + true, + 'api_enable_basic_auth' => true, +]; +EOF + +cat << 'EOF2' > docroot/app/config/security_local.php +import('security.php'); + +// Support HTTP basic auth for test logins +$container->loadFromExtension('security', + [ + 'firewalls' => [ + 'main' => [ + // Support HTTP basic auth for test logins + 'http_basic' => true, + ], + ], + 'encoders' => [ + 'Symfony\Component\Security\Core\User\User' => [ + 'algorithm' => 'md5', + 'encode_as_base64' => false, + 'iterations' => 0, + ], + 'Mautic\UserBundle\Entity\User' => [ + 'algorithm' => 'md5', + 'encode_as_base64' => false, + 'iterations' => 0, + ], + ], + ] +); +EOF2 + +php bin/console cache:clear --no-warmup + +php bin/console mautic:install http://localhost/ --force --mailer_from_name="GitHub Actions" --mailer_from_email="github-actions@mautic.org" --mailer_transport="smtp" --mailer_host="mailhog" --mailer_port="1025" --admin_username=admin --admin_password=mautic --admin_email="bla@bla.be" + +mysql -uroot -proot -hmysql mautictest -e "INSERT INTO plugin_integration_settings (plugin_id, name, is_published, supported_features, api_keys, feature_settings) VALUES (NULL, 'Twilio', 1, 'a:0:{}', 'a:2:{s:8:\"username\";s:169:\"bzFmNlIydWRSZXlIN2lQVkdpanJ4aTQ2NUh6RVdDbHlLRVhsWGZ4b0kyZVNxLzYrQ1J6V1RvMnlhVEp0c245TEp6eStQekx5ZVhLWjB1YVdoR3RnR2dHQ3k1emVVdGt5NzZKUmtjUnJ3c1E9|L8tbZRIYhwatT7Mq+HAdYA==\";s:8:\"password\";s:169:\"T2d2cFpXQWE5YVZnNFFianJSYURRYUtGRHBNZGZjM1VETXg2Wm5Va3NheW43MjVWUlJhTVlCL2pYMDBpbElONStiVVBNbEM3M3BaeGJMNkFKNUFEN1pTNldSRjc4bUM4SDh1SE9OY1k5MTg9|TeuSvfx4XSUOvp0O7T49Cg==\";}', 'a:4:{s:20:\"sending_phone_number\";N;s:22:\"disable_trackable_urls\";i:0;s:16:\"frequency_number\";N;s:14:\"frequency_time\";N;}');" +php bin/console mautic:plugins:reload + +cp -rp docroot/app/assets/images/* docroot/media/images/ + +chown -R www-data:www-data /var/www diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8e5a4bb1..063e8d4c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -18,116 +18,93 @@ on: jobs: phpunit: runs-on: ubuntu-20.04 - name: PHPUnit tests + name: PHPUnit ${{ matrix.php_version }} ${{ matrix.mautic_version }} + strategy: + matrix: + mautic_version: ["5.x-dev", "4.x-dev"] + php_version: ["7.4", "8.0", "8.1"] services: mysql: image: mysql:5.7 env: - MYSQL_ALLOW_EMPTY_PASSWORD: yes + MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: mautictest ports: - - 3306 - options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + - 3306:3306 + options: >- + --shm-size=2gb + --name=mysql + --tmpfs=/var/lib/mysql + --health-cmd="mysqladmin ping" + --health-interval=10s + --health-timeout=5s + --health-retries=3 mailhog: image: mailhog/mailhog:latest ports: - 1025:1025 - - redis: - image: redis:6 - ports: - - 6379:6379 + mautic: + image: ghcr.io/mollux/docker-mautic:${{ matrix.mautic_version }} + env: + MAUTIC_DB_HOST: mysql + MAUTIC_DB_USER: root + MAUTIC_DB_PASSWORD: root + MAUTIC_DB_NAME: mautictest + MAUTIC_RUN_CRON_JOBS: "false" + ports: + - 80:80 + options: + --health-cmd="curl --fail http://localhost || exit 1" + --health-interval=10s + --health-timeout=5s + --health-retries=10 + --name=mautic steps: - uses: actions/checkout@v3 + - name: Prepare Mautic installation + run: | + sudo docker cp .github/ci-files/prepare_mautic.sh mautic:/tmp/prepare_mautic.sh + sudo docker exec mautic chmod 755 /tmp/prepare_mautic.sh + sudo docker exec mautic /tmp/prepare_mautic.sh + - name: Copy our API library config into the tests/ folder run: cp -a ./.github/ci-files/local.config.php tests/local.config.php - name: Setup PHP, with composer and extensions uses: shivammathur/setup-php@v2 with: - php-version: 8.0 - ini-values: session.save_handler=redis, session.save_path="tcp://127.0.0.1:6379" - extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, mysql, pdo_mysql + php-version: ${{ matrix.php_version }} coverage: pcov - name: Set SYMFONY_ENV to test run: echo "SYMFONY_ENV=test" >> $GITHUB_ENV - - name: Install Apache - # We need the sed command at the bottom to set the PHP session save path to a directory that's writable for PHP - # NOTE: update the PHP version below as well if you're updating PHP! - run: | - sudo add-apt-repository ppa:ondrej/php -y - sudo add-apt-repository ppa:ondrej/apache2 -y - sudo apt-get install apache2 libapache2-mod-php8.0 - sudo a2enmod rewrite - sudo sed -i 's,^session.save_handler =.*$,session.save_handler = redis,' /etc/php/8.0/apache2/php.ini - sudo sed -i 's,^;session.save_path =.*$,session.save_path = "tcp://127.0.0.1:6379",' /etc/php/8.0/apache2/php.ini - sudo service apache2 restart - cat /etc/php/8.0/apache2/php.ini | grep session - - name: Install dependencies run: | composer validate --strict composer install --prefer-dist --no-progress - - name: Clone Mautic main branch or specific PR from GitHub - run: | - gh repo clone mautic/mautic -- --single-branch --depth 1 - if [[ "${{ github.event.inputs.pr }}" != "" ]]; then - pushd mautic - gh pr checkout ${{ github.event.inputs.pr }} - popd - fi - env: - GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} - - - name: Move files to web root - run: | - shopt -s dotglob - sudo chmod -R 777 /var/www/html - sudo chown -R www-data:www-data /var/www/html - rm -rf /var/www/html/* - mv $GITHUB_WORKSPACE/mautic/* /var/www/html/ - - - name: Install Mautic - env: - DB_PORT: ${{ job.services.mysql.ports[3306] }} - run: | - composer install --prefer-dist --no-progress - cp $GITHUB_WORKSPACE/.github/ci-files/local.php ./app/config/local.php - php bin/console mautic:install http://localhost/ \ - --force --mailer_from_name="GitHub Actions" --mailer_from_email="github-actions@mautic.org" \ - --mailer_transport="smtp" --mailer_host="localhost" --mailer_port="1025" --env=dev - php bin/console cache:warmup --no-interaction --env=dev - working-directory: /var/www/html/ - - # Enable Twilio plugin with random credentials (needed for MessagesTest to function, doesn't actually contact Twilio API). - - name: Enable Twilio plugin - run: | - mysql -uroot -P${{ job.services.mysql.ports[3306] }} -h127.0.0.1 -e "USE mautictest; INSERT INTO plugin_integration_settings (plugin_id, name, is_published, supported_features, api_keys, feature_settings) VALUES (NULL, 'Twilio', 1, 'a:0:{}', 'a:2:{s:8:\"username\";s:169:\"bzFmNlIydWRSZXlIN2lQVkdpanJ4aTQ2NUh6RVdDbHlLRVhsWGZ4b0kyZVNxLzYrQ1J6V1RvMnlhVEp0c245TEp6eStQekx5ZVhLWjB1YVdoR3RnR2dHQ3k1emVVdGt5NzZKUmtjUnJ3c1E9|L8tbZRIYhwatT7Mq+HAdYA==\";s:8:\"password\";s:169:\"T2d2cFpXQWE5YVZnNFFianJSYURRYUtGRHBNZGZjM1VETXg2Wm5Va3NheW43MjVWUlJhTVlCL2pYMDBpbElONStiVVBNbEM3M3BaeGJMNkFKNUFEN1pTNldSRjc4bUM4SDh1SE9OY1k5MTg9|TeuSvfx4XSUOvp0O7T49Cg==\";}', 'a:4:{s:20:\"sending_phone_number\";N;s:22:\"disable_trackable_urls\";i:0;s:16:\"frequency_number\";N;s:14:\"frequency_time\";N;}');" - php bin/console mautic:plugins:reload --env=dev - working-directory: /var/www/html - - - name: Set correct ownership so Apache can access the files - run: sudo chown -R www-data:www-data /var/www/html - - name: Run tests - run: vendor/bin/paratest -p 3 --coverage-clover coverage.xml + run: vendor/bin/phpunit --coverage-clover coverage.xml - name: Upload code coverage run: bash <(curl -s https://codecov.io/bash) - + + - name: gather logs + if: always() + run: | + sudo docker cp mautic:/var/www/docroot/var/logs/ /tmp/logs + - name: Upload logs as artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 if: always() with: - name: mautic-logs - path: /var/www/html/var/logs/ + name: mautic-logs-${{ matrix.mautic_version }} + path: /tmp/logs/ - name: Slack Notification if tests fail uses: rtCamp/action-slack-notify@v2 @@ -139,6 +116,9 @@ jobs: cs: runs-on: ubuntu-20.04 name: CS tests + strategy: + matrix: + php_version: ["7.4", "8.0"] steps: - uses: actions/checkout@v3 @@ -146,8 +126,7 @@ jobs: - name: Setup PHP, with composer and extensions uses: shivammathur/setup-php@v2 with: - php-version: 8.0 - extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, mysql, pdo_mysql + php-version: ${{ matrix.php_version }} - name: Install dependencies run: | diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 64811a6b..4b65860a 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,18 @@ - + lib