Skip to content

Add comprehensive unit testing and bug fixes #1

Add comprehensive unit testing and bug fixes

Add comprehensive unit testing and bug fixes #1

name: Pull Request Tests
on:
pull_request:
branches:
- 'master'
- 'v*'
push:
branches:
- 'master'
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
options: >-
--health-cmd="pg_isready -U postgres"
--health-interval=10s
--health-timeout=5s
--health-retries=5
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
extensions: pgsql, pdo_pgsql, dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, xdebug
coverage: xdebug
ini-values: memory_limit=-1
- name: Cache Composer Dependencies
uses: actions/cache@v3
with:
path: ~/.composer/cache
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install Dependencies
run: composer install --no-progress --prefer-dist --optimize-autoloader
- name: Setup Test Environment
run: |
# Wait for PostgreSQL
until pg_isready -h localhost -p 5432 -U postgres; do
echo "Waiting for PostgreSQL to be ready..."
sleep 1
done
# Copy test environment file
cp tests/.env.example tests/.env
# Update environment variables for GitHub Actions
sed -i 's/host=postgres/host=localhost/' tests/.env
- name: Run Unit Tests
env:
DB_DSN: "pgsql:host=localhost;port=5432;dbname=postgres"
DB_USER: "postgres"
DB_PASSWORD: "postgres"
DB_SCHEMA: "public"
DB_TABLE_PREFIX: "craft"
CRAFT_SECURITY_KEY: "3WaPXa5zWQPi3YqkuZpc97JN8rNO-1Ba"
run: vendor/bin/codecept run unit
- name: Run Functional Tests
env:
DB_DSN: "pgsql:host=localhost;port=5432;dbname=postgres"
DB_USER: "postgres"
DB_PASSWORD: "postgres"
DB_SCHEMA: "public"
DB_TABLE_PREFIX: "craft"
CRAFT_SECURITY_KEY: "3WaPXa5zWQPi3YqkuZpc97JN8rNO-1Ba"
run: vendor/bin/codecept run functional
- name: Run Tests with Coverage
env:
DB_DSN: "pgsql:host=localhost;port=5432;dbname=postgres"
DB_USER: "postgres"
DB_PASSWORD: "postgres"
DB_SCHEMA: "public"
DB_TABLE_PREFIX: "craft"
CRAFT_SECURITY_KEY: "3WaPXa5zWQPi3YqkuZpc97JN8rNO-1Ba"
CODECLIMATE_TEST_REPORTER_ID: ${{ secrets.CODECLIMATE_TEST_REPORTER_ID }}
run: |
if [ -n "$CODECLIMATE_TEST_REPORTER_ID" ]; then
vendor/bin/codecept run --coverage --coverage-xml
else
echo "Code Climate token not available, skipping coverage upload"
vendor/bin/codecept run
fi
- name: Upload Coverage to Code Climate
if: env.CODECLIMATE_TEST_REPORTER_ID != ''
env:
CODECLIMATE_TEST_REPORTER_ID: ${{ secrets.CODECLIMATE_TEST_REPORTER_ID }}
run: |
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
./cc-test-reporter before-build
./cc-test-reporter format-coverage --input-type clover tests/_output/coverage.xml
./cc-test-reporter upload-coverage