From b48ba13f8663d11b87a1b4d08269eca0d8e116a6 Mon Sep 17 00:00:00 2001 From: David Callizaya Date: Tue, 25 Jun 2024 21:34:13 -0400 Subject: [PATCH] Add tests to github action --- .circleci/config.yml | 14 +++++++---- .github/workflows/sonarqube.yml | 42 +++++++++++++++++++++++++++++---- check_coverage.php | 1 + composer.json | 2 +- phpunit.xml | 17 ++++++++++--- sonar-project.properties | 3 +++ 6 files changed, 65 insertions(+), 14 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c3d14393..e948b8fe 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,10 +3,15 @@ version: 2 jobs: build: docker: - - image: circleci/php:7.1-node-browsers + - image: php:8.2.0-fpm steps: - checkout - - run: sudo composer self-update + - run: apt-get update && apt-get install -y git unzip + - run: pecl install xdebug && docker-php-ext-enable xdebug + - run: curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer + - run: | + echo "error_reporting = E_ALL & ~E_DEPRECATED" > /usr/local/etc/php/conf.d/error_reporting.ini + - run: composer self-update - restore_cache: keys: - composer-v1-{{ checksum "composer.json" }} @@ -16,8 +21,7 @@ jobs: key: composer-v1-{{ checksum "composer.json" }} paths: - vendor - - run: sudo docker-php-ext-enable xdebug - - run: ./vendor/bin/phpunit -d memory_limit=-1 --coverage-html coverage + - run: composer coverage - run: ./check_coverage.php - store_artifacts: - path: coverage + path: coverage \ No newline at end of file diff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.yml index 3980790a..64775419 100644 --- a/.github/workflows/sonarqube.yml +++ b/.github/workflows/sonarqube.yml @@ -4,17 +4,49 @@ on: push: branches: - develop + - next pull_request: - types: [opened, synchronize, reopened] + types: [opened, synchronize, reopened, edited] jobs: - build: - name: Scan + test: runs-on: ubuntu-latest + steps: - - uses: actions/checkout@v2 + - name: Checkout code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Update Composer + run: sudo composer self-update + + - name: Cache Composer dependencies + id: composer-cache + uses: actions/cache@v2 + with: + path: vendor + key: composer-v1-${{ hashFiles('composer.json') }} + restore-keys: | + composer-v1- + + - name: Setup PHP + uses: shivammathur/setup-php@v2 with: - fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + php-version: "8.2" + extensions: xdebug + coverage: xdebug + ini-values: xdebug.mode=coverage + + - name: Install Composer dependencies + run: composer install -n --prefer-dist + + - name: Run PHPUnit tests + run: ./vendor/bin/phpunit -d memory_limit=-1 + + - name: List coverage files + run: ls -l coverage + - uses: sonarsource/sonarqube-scan-action@master env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/check_coverage.php b/check_coverage.php index 881e495d..78c4b082 100755 --- a/check_coverage.php +++ b/check_coverage.php @@ -1,5 +1,6 @@ #!/usr/bin/env php loadHTMLFile('coverage/index.html', LIBXML_NOERROR); $xpath = new DOMXpath($coverage); diff --git a/composer.json b/composer.json index 18b16d41..c010bdbb 100755 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ }, "scripts": { "test": "phpunit", - "coverage": "phpunit -d memory_limit=-1 --coverage-html coverage" + "coverage": "@php -d zend_extension=xdebug.so -d xdebug.mode=coverage -d xdebug.start_with_request=no vendor/bin/phpunit" }, "require-dev": { "phpunit/phpunit": "^9.5" diff --git a/phpunit.xml b/phpunit.xml index 5c977b2d..06204f27 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,13 +1,24 @@ - - + + + + + + + - ./src + src + tests/Feature + + tests/unit diff --git a/sonar-project.properties b/sonar-project.properties index 48a651e5..f6d6d464 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1 +1,4 @@ sonar.projectKey=ProcessMaker_nayra_AYq58Vs2xYvY_isvKv_4 +sonar.php.coverage.reportPaths=./coverage/clover.xml +sonar.sources=src +sonar.tests=tests