Merge pull request #86 from abbasudo/feature/mariadb #290
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: PHPUnit Tests | |
on: | |
push: | |
branches: [ "**" ] | |
pull_request: | |
branches: [ "**" ] | |
permissions: | |
contents: read | |
jobs: | |
test: | |
runs-on: ubuntu-24.04 | |
strategy: | |
matrix: | |
db: [ sqlite, mysql, pgsql ] | |
php: [ 8.2, 8.3 ] | |
prefer: [ lowest, stable ] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup PHP | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: ${{ matrix.php }} | |
- name: Validate composer.json and composer.lock | |
run: composer validate --strict | |
- name: Cache Composer packages | |
id: composer-cache | |
uses: actions/cache@v3 | |
with: | |
path: vendor | |
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} | |
restore-keys: | | |
${{ runner.os }}-php- | |
- name: Install dependencies | |
run: composer update --prefer-dist --no-progress --prefer-${{ matrix.prefer }} | |
- name: Configure MySQL | |
if: matrix.db == 'mysql' | |
run: | | |
sudo systemctl start mysql.service | |
sudo mysql --password=root --user=root -e "CREATE DATABASE IF NOT EXISTS test_db;" | |
- name: Configure PostgreSQL | |
if: matrix.db == 'pgsql' | |
run: | | |
sudo systemctl start postgresql.service | |
sudo -u postgres psql -c "CREATE DATABASE test_db;" | |
sudo -u postgres psql -c "CREATE USER test_user WITH PASSWORD 'passw0rd!';" | |
sudo -u postgres psql -c "ALTER DATABASE test_db OWNER TO test_user;" | |
# - name: Configure MariaDB | |
# if: matrix.db == 'mariadb' | |
# uses: getong/mariadb-action@v1.11 | |
# with: | |
# host port: 3800 | |
# container port: 3307 | |
# character set server: 'utf8' | |
# collation server: 'utf8_general_ci' | |
# mariadb version: '10.4.10' | |
# mysql database: 'test_db' | |
# mysql root password: 'root' | |
- name: Run PHPUnit tests | |
env: | |
DB_CONNECTION: ${{ matrix.db }} | |
DB_HOST: ${{ matrix.db == 'sqlite' && '' || (matrix.db == 'mysql' && '127.0.0.1') || (matrix.db == 'pgsql' && '127.0.0.1') || (matrix.db == 'mariadb' && '127.0.0.1') }} | |
DB_PORT: ${{ matrix.db == 'sqlite' && '' || (matrix.db == 'mysql' && '3306') || (matrix.db == 'pgsql' && '5432') || (matrix.db == 'mariadb' && '3800') }} | |
DB_DATABASE: ${{ matrix.db == 'sqlite' && ':memory:' || (matrix.db == 'mysql' && 'test_db') || (matrix.db == 'pgsql' && 'test_db') || (matrix.db == 'mariadb' && 'test_db') }} | |
DB_USERNAME: ${{ matrix.db == 'sqlite' && '' || (matrix.db == 'mysql' && 'root') || (matrix.db == 'pgsql' && 'test_user') || (matrix.db == 'mariadb' && 'root') }} | |
DB_PASSWORD: ${{ matrix.db == 'sqlite' && '' || (matrix.db == 'mysql' && 'root') || (matrix.db == 'pgsql' && 'passw0rd!') || (matrix.db == 'mariadb' && 'root') }} | |
run: vendor/bin/phpunit |