A minimal WordPress plugin showcasing unit and integration testing setup.
- PHP 7.4+
- WordPress 5.0+
- Composer
- Node.js & npm
- Docker (for integration tests)
- Clone the repository into your
wp-content/pluginsdirectory:
git clone https://github.com/your-username/my-awesome-plugin.git
cd my-awesome-plugin- Install PHP dependencies:
composer install- Install Node.js dependencies:
npm installThis plugin uses @wordpress/env for local development and integration testing.
Start the local environment:
npm run wp-env startStop the environment:
npm run wp-env stopThis plugin demonstrates a complete testing setup with both unit tests (using Brain Monkey) and integration tests (using the WordPress test environment).
Unit tests run without WordPress loaded, using Brain Monkey to mock WordPress functions.
npm run test:unitIntegration tests run with a full WordPress environment inside Docker containers via wp-env.
npm run test:integrationNote: Make sure Docker is running and
wp-envis started before running integration tests.
my-awesome-plugin/
├── src/ # Plugin source code
│ └── Helpers.php # Helper utilities
├── tests/
│ ├── bootstrap.php # Integration tests bootstrap
│ ├── integration/ # Integration test files
│ └── unit/
│ ├── bootstrap.php # Unit tests bootstrap
│ └── *.php # Unit test files
├── .wp-env.json # wp-env configuration
├── composer.json # PHP dependencies
├── package.json # Node.js dependencies
├── phpunit.unit.xml # PHPUnit config for unit tests
├── phpunit.xml.dist # PHPUnit config for integration tests
└── my-awesome-plugin.php # Main plugin file
GPL v2 or later