Skip to content

add unit test

add unit test #51

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
MYSQL_DATABASE: wordpress_test
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- name: Setup WordPress Test Suite
run: |
mkdir -p /home/runner/wordpress-tests
cd /home/runner/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
sed -i "s/youremptytestdbnamehere/wordpress_test/g" wp-tests-config.php
sed -i "s/yourusernamehere/root/g" wp-tests-config.php
sed -i "s/yourpasswordhere/rootpassword/g" wp-tests-config.php
sed -i "s/localhost/127.0.0.1/g" wp-tests-config.php
env:
WP_TESTS_PATH: /home/runner/wordpress-tests/wordpress-develop/tests/phpunit
- uses: actions/checkout@v2
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
extensions: mbstring, intl, mysqli, zip
tools: composer:v2
- name: Update Composer dependencies
run: |
composer config --no-plugins allow-plugins.composer/installers true
composer config --no-plugins allow-plugins.automattic/jetpack-autoloader true
composer update --no-interaction --no-progress
composer require --dev woocommerce/woocommerce:^5.9.1 --no-interaction --no-progress
echo "Composer installation complete. Listing vendor directory:"
ls -R vendor
echo "Composer autoload files:"
cat vendor/composer/autoload_psr4.php
- name: Install WooCommerce
run: |
mkdir -p wp-content/plugins
wget https://downloads.wordpress.org/plugin/woocommerce.5.9.1.zip
unzip -q -o woocommerce.5.9.1.zip -d wp-content/plugins/
rm woocommerce.5.9.1.zip
echo "WooCommerce installation complete. Listing wp-content/plugins directory:"
ls -R wp-content/plugins
- name: Check WooCommerce installation
run: |
echo "Current directory: $(pwd)"
echo "Listing vendor directory:"
ls -R vendor
if [ -d "wp-content/plugins/woocommerce" ]; then
echo "WooCommerce found in WordPress plugins directory"
ls -l wp-content/plugins/woocommerce
else
echo "WooCommerce not found in WordPress plugins directory"
exit 1
fi
- name: Run PHPUnit tests
env:
COMPOSER_PROCESS_TIMEOUT: 0
COMPOSER_NO_INTERACTION: 1
COMPOSER_NO_AUDIT: 1
WP_TESTS_PATH: /home/runner/wordpress-tests/wordpress-develop/tests/phpunit
WP_PHPUNIT__DIR: /home/runner/wordpress-tests/wordpress-develop/tests/phpunit
DB_NAME: wordpress_test
DB_USER: root
DB_PASSWORD: rootpassword
DB_HOST: 127.0.0.1
run: |
# Wait for MySQL to be ready
while ! mysqladmin ping -h"$DB_HOST" -u"$DB_USER" -p"$DB_PASSWORD" --silent; do
echo "Waiting for MySQL to be ready..."
sleep 2
done
# Set WP_PLUGIN_DIR environment variable
export WP_PLUGIN_DIR=$(pwd)/wp-content/plugins
# Copy WooCommerce to WordPress test environment
mkdir -p /home/runner/wordpress-tests/wordpress-develop/src/wp-content/plugins
cp -r wp-content/plugins/woocommerce /home/runner/wordpress-tests/wordpress-develop/src/wp-content/plugins/
# Run PHPUnit tests
vendor/bin/phpunit --bootstrap tests/bootstrap.php --debug