Skip to content

add unit test

add unit test #9

Workflow file for this run

name: PHPUnit Tests
on:
pull_request:
push:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: rootpassword
ports:
- 3306
options: --health-cmd="mysqladmin ping -h mysql" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- name: Setup WordPress Test Suite and MySQL
run: |
# Wait for MySQL to be ready
until mysqladmin ping -hmysql -uroot -prootpassword; do
echo "Waiting for MySQL to be ready..."
sleep 5
done
mkdir -p ~/wordpress-tests
cd ~/wordpress-tests
git clone --depth=1 https://github.com/WordPress/wordpress-develop.git
cd wordpress-develop
composer install
cp wp-tests-config-sample.php wp-tests-config.php
# Update wp-tests-config.php with your database details
sed -i "s/database_name_here/wordpress_test/g" wp-tests-config.php
sed -i "s/username_here/root/g" wp-tests-config.php
sed -i "s/password_here/rootpassword/g" wp-tests-config.php
# Create the test database
mysql -hmysql -uroot -prootpassword -e "CREATE DATABASE wordpress_test;"
- uses: actions/checkout@v2
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: mbstring, intl, mysqli, zip
tools: composer:v2
- name: Install dependencies
run: composer install --
- name: Run PHPUnit tests
run: vendor/bin/phpunit