Skip to content

PHPUnit

PHPUnit #532

Workflow file for this run

name: PHPUnit
on:
# Run automatically every Monday on midnight.
schedule:
- cron: '0 0 * * 1'
workflow_call:
# Allow manually triggering the workflow.
workflow_dispatch:
jobs:
unit-tests:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: ['7.4', '8.3']
mysql-version: ['5.7', '8.0']
services:
mysql:
image: mysql:${{ matrix.mysql-version }}
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: db
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- name: Validate mysql service
run: |
echo "Checking mysql service"
sudo apt-get install -y mysql-client
mysql --host 127.0.0.1 --port ${{ job.services.mysql.ports['3306'] }} -uroot -proot -e "SHOW DATABASES"
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: pcov #optional, setup coverage driver
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v4
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install dependencies
run: composer install --prefer-dist --no-progress --ignore-platform-req=ext-*
- name: Install OpenMage
run: |
php -f install.php -- \
--license_agreement_accepted 'yes' \
--locale 'en_US' \
--timezone 'America/New_York' \
--db_host '127.0.0.1' \
--db_name 'db' \
--db_user 'root' \
--db_pass 'root' \
--db_prefix '' \
--url 'http://openmage.local' \
--use_rewrites 'yes' \
--use_secure 'yes' \
--secure_base_url 'http://openmage.local' \
--use_secure_admin 'yes' \
--admin_username 'admin' \
--admin_lastname 'Administrator' \
--admin_firstname 'OpenMage' \
--admin_email '[email protected]' \
--admin_password 'veryl0ngpassw0rd' \
--session_save 'files' \
--admin_frontname 'admin' \
--backend_frontname 'admin' \
--default_currency 'USD' \
--enable_charts 'yes' \
--skip_url_validation 'yes'
- name: Run phpUnit
run: php -f vendor/bin/phpunit
- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
files: tests/logging/*.xml
- name: prepare SonarCloud Scan Data
if: ${{ (matrix.php-versions == '7.4') && (matrix.mysql-version == '5.7') }}
run: |
head tests/coverage/clover.xml
sed -i 's@'$GITHUB_WORKSPACE'/@/github/workspace/@g' tests/logging/junit.xml
sed -i 's@'$GITHUB_WORKSPACE'/@/github/workspace/@g' tests/coverage/clover.xml
head ./tests/coverage/clover.xml
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
continue-on-error: true
if: ${{ (matrix.php-versions == '7.4') && (matrix.mysql-version == '5.7') }} && SONAR_TOKEN
with:
args: >
-Dproject.settings=tests/sonar-project.properties
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}