From d8a7f3e08c5b161b45e3673654dd0f5f5523e5df Mon Sep 17 00:00:00 2001
From: Alejandro Celaya <alejandro@alejandrocelaya.com>
Date: Sun, 13 Dec 2020 13:11:41 +0100
Subject: [PATCH] Added mutation-tests step in ci workflow

---
 .github/workflows/ci.yml | 35 +++++++++++++++++++++++++++++++++++
 composer.json            |  3 ++-
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index d96e5ce5..652a66d4 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -67,6 +67,7 @@ jobs:
         run: composer install --no-interaction --prefer-dist
       - run: composer test:unit:ci
       - uses: actions/upload-artifact@v2
+        if: ${{ matrix.php-version == '7.4' }}
         with:
           name: coverage-unit
           path: |
@@ -95,6 +96,7 @@ jobs:
         run: composer install --no-interaction --prefer-dist
       - run: composer test:db:sqlite:ci
       - uses: actions/upload-artifact@v2
+        if: ${{ matrix.php-version == '7.4' }}
         with:
           name: coverage-db
           path: |
@@ -222,8 +224,41 @@ jobs:
         run: composer install --no-interaction --prefer-dist
       - run: bin/test/run-api-tests.sh
       - uses: actions/upload-artifact@v2
+        if: ${{ matrix.php-version == '7.4' }}
         with:
           name: coverage-api
           path: |
             build/coverage-api
             build/coverage-api.cov
+
+  mutation-tests:
+    needs:
+      - unit-tests
+      - db-tests-sqlite
+      - api-tests
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        php-version: ['7.4']
+    steps:
+      - name: Checkout code
+        uses: actions/checkout@v2
+      - name: Start database server
+        run: docker-compose -f docker-compose.yml -f docker-compose.ci.yml up -d shlink_db
+      - name: Use PHP
+        uses: shivammathur/setup-php@v2
+        with:
+          php-version: ${{ matrix.php-version }}
+          tools: composer
+          extensions: swoole-4.5.9
+          coverage: pcov
+          ini-values: pcov.directory=module
+      - if: ${{ matrix.php-version == '8.0' }}
+        run: composer install --no-interaction --prefer-dist --ignore-platform-req=php
+      - if: ${{ matrix.php-version != '8.0' }}
+        run: composer install --no-interaction --prefer-dist
+      - uses: actions/download-artifact@v2
+        with:
+          path: build
+      - run: ls -l build
+      - run: composer infect:ci
diff --git a/composer.json b/composer.json
index b89d3e63..19c4097e 100644
--- a/composer.json
+++ b/composer.json
@@ -115,7 +115,8 @@
         ],
         "test:ci": [
             "@test:unit:ci",
-            "@test:db"
+            "@test:db",
+            "@test:api"
         ],
         "test:unit": "@php vendor/bin/phpunit --order-by=random --colors=always --coverage-php build/coverage-unit.cov --testdox",
         "test:unit:ci": "@test:unit --coverage-xml=build/coverage-unit/coverage-xml --log-junit=build/coverage-unit/junit.xml",