This document explains how to set up and run tests for the Tour Operator Plugin.
The plugin includes two types of tests:
- Located in:
tests/php/TestSimpleFunctions.php - These tests verify basic PHP functionality and plugin logic without requiring WordPress
- Can be run immediately after installing Composer dependencies
- Located in:
tests/php/test-basic.phpandtests/php/utils/ - These tests require a full WordPress testing environment
- Test plugin functionality within WordPress context
composer install# Run basic tests (no WordPress environment needed)
composer test:simple
# OR directly:
./vendor/bin/phpunit --no-configuration tests/php/TestSimpleFunctions.phpFirst, set up the environment:
# Set up WordPress test environment (one-time setup)
./bin/install-wp-tests.sh
# Set environment variables
export WP_TESTS_DIR='/tmp/wordpress-tests-lib'
export WP_CORE_DIR='/tmp/wordpress/'
export WP_TESTS_DB_NAME='tour_operator_test'
export WP_TESTS_DB_USER='root'
export WP_TESTS_DB_PASSWORD=''
export WP_TESTS_DB_HOST='localhost'
# Run WordPress integration tests
composer test:wpThe following NPM and Composer scripts are available:
# PHP Tests
npm run test:php # Run PHP tests (simple by default)
composer test # Run simple tests
composer test:simple # Run tests that don't need WordPress
composer test:wp # Run WordPress integration tests (requires setup)
composer test:coverage # Run tests with coverage report
# E2E Tests
npm run test:e2e # Run Playwright E2E tests
npm run test:e2e:ui # Run E2E tests with UI
npm run test:e2e:debug # Run E2E tests in debug mode
# All Tests
npm test # Run both PHP and E2E testsTo run the full WordPress integration tests, you need to set up the WordPress test environment:
# Create a directory for WordPress tests
mkdir -p /tmp/wordpress-tests-lib
# Download and set up WordPress test suite
# (This is a simplified example - actual setup may vary)
svn co https://develop.svn.wordpress.org/trunk/tests/phpunit/includes/ /tmp/wordpress-tests-lib/includes
svn co https://develop.svn.wordpress.org/trunk/tests/phpunit/data/ /tmp/wordpress-tests-lib/dataexport WP_TESTS_DIR="/tmp/wordpress-tests-lib"
export WP_TESTS_DB_NAME="tour_operator_test"
export WP_TESTS_DB_USER="root"
export WP_TESTS_DB_PASSWORD=""
export WP_TESTS_DB_HOST="localhost"mysql -u root -p -e "CREATE DATABASE tour_operator_test;"composer test:wpphpunit.xml- Full WordPress integration test configurationphpunit-simple.xml- Simple tests configuration (no WordPress)tests/php/bootstrap.php- WordPress test environment bootstrap
tests/php/TestSimpleFunctions.php- Simple unit teststests/php/test-basic.php- WordPress integration teststests/php/utils/- Test utilities and helper classestests/e2e/- Playwright E2E tests
Tour_Operator_Test_Case- Base test case with helper methodsTour_Operator_Factory- Factory for creating test data
Coverage reports are generated in the tests/coverage/ directory when running:
composer test:coverageThe test suite is designed to work with GitHub Actions and other CI systems. The E2E tests require a running WordPress environment, while the simple unit tests can run in any PHP environment.
This error occurs when trying to run WordPress integration tests without the proper environment setup. Either:
- Set up the WordPress test environment as described above, or
- Run only the simple tests:
composer test:simple
This usually means PHPUnit couldn't find the test files. Ensure:
- Test files are named correctly (e.g.,
TestSimpleFunctions.php) - Test classes extend
PHPUnit\Framework\TestCaseorTour_Operator_Test_Case - Test methods are named with
test_prefix
Make sure the class name matches the filename and follows PSR-4 naming conventions.
When adding new tests:
- Simple functionality tests should go in separate files like
TestSimpleFunctions.php - WordPress integration tests should extend
Tour_Operator_Test_Case - E2E tests should be added to the
tests/e2e/directory - Always run the test suite before submitting changes