From ee744a6fd570222938ffdbed4b626ea6aa552240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Fri, 25 Feb 2022 13:29:21 -0300 Subject: [PATCH 1/2] Improve mutation tests workflow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Runs only if has changes in `'*/classes/**.php'` files. - Runs full test for `push`. - Runs only for changed files for `pull_request`. - Adds GitHub Annotations for pull requests - Removes the unnecessary checks for [ci skip]. Signed-off-by: MaurĂ­cio Meneghini Fauth --- .github/workflows/mutation-tests.yml | 61 ++++++++++++++-------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/.github/workflows/mutation-tests.yml b/.github/workflows/mutation-tests.yml index 17d0da682d..ad08a5ca87 100644 --- a/.github/workflows/mutation-tests.yml +++ b/.github/workflows/mutation-tests.yml @@ -1,34 +1,38 @@ +# https://docs.github.com/en/actions + name: Mutation tests on: push: - branches: [master] + branches: + - master + paths: + - '*/classes/**.php' pull_request: - branches: [master] + branches: + - master + paths: + - '*/classes/**.php' permissions: contents: read jobs: - tests: - name: Mutation tests with PHP ${{ matrix.php-version }} + infection: + name: Infection runs-on: ${{ matrix.operating-system }} strategy: matrix: - php-version: ["8.0"] - operating-system: [ubuntu-latest] + php-version: + - "8.1" + operating-system: + - ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v3 - - name: Fetch github.base_ref (for diffing) - if: ${{ github.base_ref != '' }} - run: | - git fetch --depth=1 origin +refs/heads/${{ github.base_ref }}:refs/remotes/origin/${{ github.base_ref }} - - name: Install Gettext - run: | - sudo apt-get install -y gettext + run: sudo apt-get install -y gettext - name: Generate mo files run: ./scripts/generate-mo --quiet @@ -43,31 +47,26 @@ jobs: - name: Install Infection # The GPG key can be found at https://infection.github.io/guide/installation.html - run: | - phive --no-progress install --target ./build/tools --trust-gpg-keys C5095986493B4AA0 infection + run: phive --no-progress install --target ./build/tools --trust-gpg-keys C5095986493B4AA0 infection - name: Install Composer dependencies - uses: ramsey/composer-install@v1 + uses: ramsey/composer-install@v2 with: dependency-versions: highest - name: Collect coverage report - run: | - composer run phpunit -- --testsuite unit --stop-on-failure + run: composer run phpunit -- --testsuite unit --stop-on-failure - - name: Infection - if: ${{ github.base_ref != '' }} + - name: Run Infection for changed files only + if: github.event_name == 'pull_request' run: | - CHANGED_FILES=$(git diff origin/$GITHUB_BASE_REF --diff-filter=AM --name-only | grep libraries/classes/ | paste -sd "," -); - ./build/tools/infection -j$(nproc) --skip-initial-tests --no-interaction --no-progress --coverage=build/logs \ - --ignore-msi-with-no-mutations \ - --filter=$CHANGED_FILES - env: - INFECTION_BADGE_API_KEY: ${{ secrets.INFECTION_BADGE_API_KEY }} - - - name: Infection - if: ${{ github.base_ref == '' }} - run: | - ./build/tools/infection -j$(nproc) --skip-initial-tests --no-interaction --no-progress --coverage=build/logs + git fetch --depth=1 origin $GITHUB_BASE_REF + ./build/tools/infection -j$(nproc) --git-diff-lines --git-diff-base=origin/$GITHUB_BASE_REF \ + --logger-github --ignore-msi-with-no-mutations --only-covered \ + --skip-initial-tests --coverage=build/logs --no-interaction --no-progress + + - name: Run Infection + if: github.event_name == 'push' env: INFECTION_BADGE_API_KEY: ${{ secrets.INFECTION_BADGE_API_KEY }} + run: ./build/tools/infection -j$(nproc) --skip-initial-tests --coverage=build/logs --no-interaction --no-progress From 38564b5477c36c29eebb282eb56fce088ca3e4ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Fri, 25 Feb 2022 14:11:43 -0300 Subject: [PATCH 2/2] Check if db and table are strings in RecentFavoriteController MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- .../Controllers/Table/RecentFavoriteController.php | 8 ++++++-- psalm-baseline.xml | 6 ------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/libraries/classes/Controllers/Table/RecentFavoriteController.php b/libraries/classes/Controllers/Table/RecentFavoriteController.php index 3cb915b618..61f97bf810 100644 --- a/libraries/classes/Controllers/Table/RecentFavoriteController.php +++ b/libraries/classes/Controllers/Table/RecentFavoriteController.php @@ -8,6 +8,8 @@ use PhpMyAdmin\Controllers\AbstractController; use PhpMyAdmin\Controllers\Sql\SqlController; use PhpMyAdmin\RecentFavoriteTable; +use function is_string; + /** * Browse recent and favorite tables chosen from navigation. */ @@ -17,9 +19,11 @@ class RecentFavoriteController extends AbstractController { $GLOBALS['containerBuilder'] = $GLOBALS['containerBuilder'] ?? null; - RecentFavoriteTable::getInstance('recent')->removeIfInvalid($_REQUEST['db'], $_REQUEST['table']); + $db = isset($_REQUEST['db']) && is_string($_REQUEST['db']) ? $_REQUEST['db'] : ''; + $table = isset($_REQUEST['table']) && is_string($_REQUEST['table']) ? $_REQUEST['table'] : ''; - RecentFavoriteTable::getInstance('favorite')->removeIfInvalid($_REQUEST['db'], $_REQUEST['table']); + RecentFavoriteTable::getInstance('recent')->removeIfInvalid($db, $table); + RecentFavoriteTable::getInstance('favorite')->removeIfInvalid($db, $table); /** @var SqlController $controller */ $controller = $GLOBALS['containerBuilder']->get(SqlController::class); diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 19d34b1304..3528e6a840 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -3556,12 +3556,6 @@ - - $_REQUEST['db'] - $_REQUEST['db'] - $_REQUEST['table'] - $_REQUEST['table'] - get