From 38f71a3766d4b50f99148280f30b124059f1f40c Mon Sep 17 00:00:00 2001 From: DevDavido <997605+DevDavido@users.noreply.github.com> Date: Wed, 20 Dec 2023 12:22:38 +0100 Subject: [PATCH] build: Update tests workflow --- .github/workflows/tests.yml | 78 ++++++------------- tests/Integration/ApiTest.php | 9 +-- .../PerformanceAuditIntegrationTest.php | 5 +- tests/Unit/Metric/PercentTest.php | 7 +- tests/Unit/Metric/SecondsTest.php | 2 +- 5 files changed, 35 insertions(+), 66 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f3b7b291..12965265 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -5,67 +5,39 @@ on: paths-ignore: - '*.md' -env: - PLUGIN_NAME: PerformanceAudit - TEST_SUITE: PluginTests - MYSQL_ADAPTER: PDO_MYSQL - jobs: - phpunit: + tests: strategy: + fail-fast: false matrix: - php-versions: ['7.1'] - #php-versions: ['7.1', '7.2', '7.3', '7.4', '8.0'] - matomo-versions: ['3.12.0', '3.14.0'] - node-version: [12.x] - #node-version: [10.x, 12.x] + #php: ['7.2', '7.4', '8.0', '8.2', '8.3'] + php: ['7.2'] + matomo-target: ['minimum_required_matomo', 'maximum_supported_matomo'] + #node: ['12.x', '20.x'] + node: ['12.x'] runs-on: ubuntu-latest - name: PHPUnit with PHP ${{ matrix.php-versions }}, Node.js ${{ matrix.node-version }} and Matomo ${{ matrix.matomo-versions }} + permissions: + checks: write + pull-requests: write + contents: read - steps: - - uses: actions/checkout@v2 + name: Tests with PHP '${{ matrix.php }}', Node.js '${{ matrix.node }}' and Matomo target '${{ matrix.matomo-target }}' - - name: Setup PHP - uses: shivammathur/setup-php@v2 + steps: + - name: Checkout repository + uses: actions/checkout@v4 with: - php-version: ${{ matrix.php-versions }} - extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, intl, gd, iconv - coverage: none - tools: composer, phpunit:7.5.20 + lfs: true + persist-credentials: false - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 + - name: Run plugin tests + uses: matomo-org/github-action-tests@main with: - node-version: ${{ matrix.node-version }} - - - name: Create database - run: | - sudo /etc/init.d/mysql start - mysql -u root -proot -e 'CREATE DATABASE IF NOT EXISTS matomo_tests;' - - - name: Clone Matomo and run plugin Tests - # TODO - run: | - shopt -s extglob - mkdir ${{ env.PLUGIN_NAME }} - cp -R !(${{ env.PLUGIN_NAME }}) ${{ env.PLUGIN_NAME }} - cp -R .git/ ${{ env.PLUGIN_NAME }}/ - - git clone --config filter.lfs.smudge=true -q https://github.com/matomo-org/matomo.git matomo - cd matomo - git fetch --all - git submodule update - git checkout -f -q tags/${{ matrix.matomo-versions }} - [ -d ./tests/travis/.git ] || sh -c "rm -rf ./tests/travis && git clone https://github.com/matomo-org/travis-scripts.git ./tests/travis" - cd ./tests/travis - git checkout master - cd ../.. - [ ! -f ./tests/travis/check_plugin_compatible_with_piwik.php ] || php ./tests/travis/check_plugin_compatible_with_piwik.php "${{ env.PLUGIN_NAME }}" - composer install --no-dev --no-progress - rm -rf plugins/${{ env.PLUGIN_NAME }} - mv ../${{ env.PLUGIN_NAME }} plugins - echo './console tests:run PerformanceAudit' - env: - DB_PASSWORD: root + plugin-name: 'PerformanceAudit' + test-type: 'PluginTests' + php-version: ${{ matrix.php }} + matomo-test-branch: ${{ matrix.matomo-target }} + node-version: ${{ matrix.node }} + mysql-service: true diff --git a/tests/Integration/ApiTest.php b/tests/Integration/ApiTest.php index d718612d..53e79e87 100644 --- a/tests/Integration/ApiTest.php +++ b/tests/Integration/ApiTest.php @@ -9,7 +9,7 @@ use Piwik\ArchiveProcessor\Rules; use Piwik\DataTable; use Piwik\Date; -use Piwik\Translate; +use Piwik\Tests\Framework\Fixture; /** * @group ApiTest @@ -29,15 +29,14 @@ public function setUp(): void $this->date = Date::factory('2020-06-15'); - Translate::loadAllTranslations(); + Fixture::loadAllTranslations(); Rules::setBrowserTriggerArchiving(true); } - public function tearDown() + public function tearDown(): void { + Fixture::resetTranslations(); parent::tearDown(); - - //Translate::reset(); } // Site 1 diff --git a/tests/Integration/PerformanceAuditIntegrationTest.php b/tests/Integration/PerformanceAuditIntegrationTest.php index f69ff8f5..e8357f49 100644 --- a/tests/Integration/PerformanceAuditIntegrationTest.php +++ b/tests/Integration/PerformanceAuditIntegrationTest.php @@ -43,9 +43,10 @@ public function setUp(): void // Create user $this->addPreexistingSuperUser(); - $this->superUserTokenAuth = UsersManagerAPI::getInstance()->getTokenAuth( + $this->superUserTokenAuth = UsersManagerAPI::getInstance()->createAppSpecificTokenAuth( self::TEST_SUPERUSER_LOGIN, - md5(self::TEST_SUPERUSER_PASS) + self::TEST_SUPERUSER_PASS, + "app-specific-pwd-description" ); // Create sites diff --git a/tests/Unit/Metric/PercentTest.php b/tests/Unit/Metric/PercentTest.php index c4ece8f5..2c89e520 100644 --- a/tests/Unit/Metric/PercentTest.php +++ b/tests/Unit/Metric/PercentTest.php @@ -5,7 +5,6 @@ require PIWIK_INCLUDE_PATH . '/plugins/PerformanceAudit/vendor/autoload.php'; use PHPUnit\Framework\TestCase; -use PHPUnit_Framework_Error_Warning; use Piwik\Metrics\Formatter; use Piwik\Plugins\PerformanceAudit\Columns\Metrics\MaxPercent; use Piwik\Plugins\PerformanceAudit\Columns\Metrics\MedianPercent; @@ -22,7 +21,7 @@ class PercentTest extends TestCase /** @var Formatter */ private $formatter; - public function setUp() + public function setUp(): void { parent::setUp(); @@ -45,11 +44,9 @@ public function test_max_median_min_percent_format_as_expected() } } - /** - * @expectedException PHPUnit_Framework_Error_Warning - */ public function test_max_median_min_percent_format_with_warning() { + $this->expectWarning(); $objs = [ new MaxPercent(), new MedianPercent(), diff --git a/tests/Unit/Metric/SecondsTest.php b/tests/Unit/Metric/SecondsTest.php index 0291621e..d0ff3b50 100644 --- a/tests/Unit/Metric/SecondsTest.php +++ b/tests/Unit/Metric/SecondsTest.php @@ -21,7 +21,7 @@ class SecondsTest extends TestCase /** @var Formatter */ private $formatter; - public function setUp() + public function setUp(): void { parent::setUp();