Skip to content

test: add comprehensive tests for QueryTester, SchemaInspector, and S… #271

test: add comprehensive tests for QueryTester, SchemaInspector, and S…

test: add comprehensive tests for QueryTester, SchemaInspector, and S… #271

Workflow file for this run

name: Tests
on:
push:
pull_request:
jobs:
phpstan:
name: PHPStan Static Analysis
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
extensions: pdo, pdo_mysql, pdo_pgsql, pdo_sqlite
coverage: none
- run: composer install --no-interaction --prefer-dist
- run: composer pdodb:phpstan
mysql:
name: MySQL Tests
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0
env:
MYSQL_DATABASE: testdb
MYSQL_USER: testuser
MYSQL_PASSWORD: testpass
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping -h 127.0.0.1 -uroot -proot"
--health-interval=10s
--health-timeout=5s
--health-retries=3
redis:
image: redis:7-alpine
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
memcached:
image: memcached:1.6-alpine
ports:
- 11211:11211
options: >-
--health-cmd "echo 'stats' | nc localhost 11211"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
extensions: pdo_mysql, simplexml, xmlreader, redis, memcached, apcu
coverage: xdebug
- run: composer install --no-interaction --prefer-dist
- name: Enable MySQL local_infile
run: |
mysql -h 127.0.0.1 -uroot -proot -e "SET GLOBAL local_infile=1;"
- run: |
PDODB_DSN="mysql:host=127.0.0.1;port=3306;dbname=testdb;charset=utf8mb4" \
PDODB_USERNAME="testuser" \
PDODB_PASSWORD="testpass" \
vendor/bin/phpunit --testsuite="MySQL Tests" --coverage-clover coverage-mysql.xml
- name: Test MySQL Examples
run: ./scripts/test-examples.sh --verbose
- name: Upload MySQL coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage-mysql.xml
flags: mysql
name: mysql-coverage
mariadb:
name: MariaDB Tests
runs-on: ubuntu-latest
services:
mariadb:
image: mariadb:11.2
env:
MYSQL_DATABASE: testdb
MYSQL_USER: testuser
MYSQL_PASSWORD: testpass
MYSQL_ROOT_PASSWORD: root
ports:
- 3305:3306
options: >-
--health-cmd="healthcheck.sh --connect --innodb_initialized"
--health-interval=5s
--health-timeout=10s
--health-retries=20
--health-start-period=40s
redis:
image: redis:7-alpine
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
memcached:
image: memcached:1.6-alpine
ports:
- 11211:11211
options: >-
--health-cmd "echo 'stats' | nc localhost 11211"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
extensions: pdo_mysql, simplexml, xmlreader, redis, memcached, apcu
coverage: xdebug
- run: composer install --no-interaction --prefer-dist
- run: |
PDODB_DSN="mariadb:host=127.0.0.1;port=3305;dbname=testdb;charset=utf8mb4" \
PDODB_USERNAME="testuser" \
PDODB_PASSWORD="testpass" \
vendor/bin/phpunit --testsuite="MariaDB Tests" --coverage-clover coverage-mariadb.xml
- name: Test MariaDB Examples
run: |
export PDODB_DRIVER=mariadb
export PDODB_USERNAME="testuser"
export PDODB_PASSWORD="testpass"
export PDODB_HOST="127.0.0.1"
export PDODB_PORT="3305"
export PDODB_DATABASE="testdb"
./scripts/test-examples.sh --verbose
- name: Upload MariaDB coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage-mariadb.xml
flags: mariadb
name: mariadb-coverage
postgres:
name: PostgreSQL Tests
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
env:
POSTGRES_DB: testdb
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- 5433:5432
options: >-
--health-cmd="pg_isready -U postgres -d testdb"
--health-interval=10s
--health-timeout=5s
--health-retries=5
redis:
image: redis:7-alpine
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
memcached:
image: memcached:1.6-alpine
ports:
- 11211:11211
options: >-
--health-cmd "echo 'stats' | nc localhost 11211"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
extensions: pdo_pgsql, simplexml, xmlreader, redis, memcached, apcu
coverage: xdebug
- run: composer install --no-interaction --prefer-dist
- name: Setup PostgreSQL test user
run: |
PGPASSWORD=postgres psql -h localhost -p 5433 -U postgres -d testdb -c "CREATE USER testuser WITH PASSWORD 'testpass';"
PGPASSWORD=postgres psql -h localhost -p 5433 -U postgres -d testdb -c "GRANT ALL PRIVILEGES ON DATABASE testdb TO testuser;"
PGPASSWORD=postgres psql -h localhost -p 5433 -U postgres -d testdb -c "GRANT ALL ON SCHEMA public TO testuser;"
- run: |
PDODB_DSN="pgsql:host=localhost;port=5433;dbname=testdb" \
PDODB_USERNAME="testuser" \
PDODB_PASSWORD="testpass" \
vendor/bin/phpunit --testsuite="PostgreSQL Tests" --coverage-clover coverage-postgres.xml
- name: Test PostgreSQL Examples
run: ./scripts/test-examples.sh --verbose
- name: Upload PostgreSQL coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage-postgres.xml
flags: postgres
name: postgres-coverage
sqlite:
name: SQLite Tests
runs-on: ubuntu-latest
services:
redis:
image: redis:7-alpine
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
memcached:
image: memcached:1.6-alpine
ports:
- 11211:11211
options: >-
--health-cmd "echo 'stats' | nc localhost 11211"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
extensions: pdo_sqlite, redis, memcached, apcu
coverage: xdebug
- run: composer install --no-interaction --prefer-dist
- run: |
PDODB_DSN="sqlite::memory:" \
vendor/bin/phpunit --testsuite="SQLite Tests" --coverage-clover coverage-sqlite.xml
- name: Test SQLite Examples
run: ./scripts/test-examples.sh --verbose
- name: Upload SQLite coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage-sqlite.xml
flags: sqlite
name: sqlite-coverage
mssql:
name: MSSQL Tests
runs-on: ubuntu-latest
services:
mssql:
image: mcr.microsoft.com/mssql/server:2022-latest
env:
ACCEPT_EULA: Y
MSSQL_SA_PASSWORD: Test123!@#
MSSQL_PID: Developer
ports:
- 1433:1433
redis:
image: redis:7-alpine
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
memcached:
image: memcached:1.6-alpine
ports:
- 11211:11211
options: >-
--health-cmd "echo 'stats' | nc localhost 11211"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
extensions: pdo, pdo_odbc, odbc, redis, memcached, apcu
coverage: xdebug
- name: Install Microsoft ODBC Driver and SQL Server Tools
run: |
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18 unixodbc-dev mssql-tools18
echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc
export PATH="$PATH:/opt/mssql-tools18/bin"
- name: Install pdo_sqlsrv extension
run: |
if ! php -m | grep -q pdo_sqlsrv; then
sudo pecl install pdo_sqlsrv-5.11.1 || sudo pecl install -f pdo_sqlsrv-5.11.1
echo "extension=pdo_sqlsrv.so" | sudo tee $(php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||")/conf.d/pdo_sqlsrv.ini
fi
php -m | grep pdo_sqlsrv || echo "Warning: pdo_sqlsrv extension not loaded"
- name: Wait for MSSQL to be ready
run: |
export PATH="$PATH:/opt/mssql-tools18/bin"
echo "Waiting for MSSQL to be ready..."
for i in {1..120}; do
if sqlcmd -S localhost -U sa -P 'Test123!@#' -C -Q 'SELECT 1' -b > /dev/null 2>&1; then
echo "MSSQL is ready!"
sqlcmd -S localhost -U sa -P 'Test123!@#' -C -Q 'SELECT @@VERSION' -b
break
fi
if [ $i -eq 120 ]; then
echo "MSSQL failed to start after 240 seconds"
exit 1
fi
echo "Waiting for MSSQL... ($i/120)"
sleep 2
done
- name: Create database
run: |
export PATH="$PATH:/opt/mssql-tools18/bin"
# Create database (ignore error if exists)
sqlcmd -S localhost -U sa -P 'Test123!@#' -C -Q "IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = 'testdb') CREATE DATABASE testdb;" || true
echo "Database 'testdb' ready"
- run: composer install --no-interaction --prefer-dist
- run: |
PDODB_DSN="sqlsrv:Server=localhost,1433;Database=testdb;TrustServerCertificate=yes" \
PDODB_USERNAME="sa" \
PDODB_PASSWORD="Test123!@#" \
vendor/bin/phpunit --testsuite="MSSQL Tests" --coverage-clover coverage-mssql.xml
- name: Test MSSQL Examples
run: |
export PDODB_DRIVER=sqlsrv
export PDODB_USERNAME="sa"
export PDODB_PASSWORD="Test123!@#"
export PDODB_HOST="localhost"
export PDODB_PORT="1433"
export PDODB_DATABASE="testdb"
./scripts/test-examples.sh --verbose
- name: Upload MSSQL coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage-mssql.xml
flags: mssql
name: mssql-coverage
shared-coverage:
name: Shared Coverage Tests
runs-on: ubuntu-latest
services:
redis:
image: redis:7-alpine
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
memcached:
image: memcached:1.6-alpine
ports:
- 11211:11211
options: >-
--health-cmd "echo 'stats' | nc localhost 11211"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
extensions: pdo_sqlite, redis, memcached, apcu
coverage: xdebug
- run: composer install --no-interaction --prefer-dist
- run: vendor/bin/phpunit --testsuite="Shared Tests" --coverage-clover coverage-shared.xml
- name: Upload Shared coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage-shared.xml
flags: shared
name: shared-coverage