PHP Development With WordPress Plugin
WordPress Plugin Template
Josh's WordPress plugin starter
| Name |
|---|
| Getting Started |
| PHP |
| JavaScript |
| Local Development |
| CI/ CD |
PHP code goes in the directory “php” or “tests”. The psr-4 standard is used for file and class naming. Composer is used for an autoloader and for dev dependencies.
The php tests are separated into two genres: unit – located in /tests/Unit – and integration – located in /tests/Integration.
Unit Tests
Unit Testing Classes That Call Functions From WordPress core
These tests do NOT run with WordPress and MySQL and are run with phpunit.
- Install for development
composer install
- Run unit tests
composer test
The following unit testing tools are installed:
- Yoast/yoast-test-helper - Provides assertions from nwer versions of phpunit so we can use a WordPress-compatible version.
- Mockery - For mocking classes.
- Brain Monkey - For monkey-patching functions.
Integration Tests
-
These tests are dependent on WordPress and MySQL and are run with phpunit.
-
Run WordPress Integration Tests
- If supplying your own test setup and database:
composer test:wordpress
- Using supplied docker-compose:
docker-compose run phpunit- This puts you inside phpunit container with database setup.
composer install# install for development inside of the container.composer:test:wordpress
- Using futureys/phpunit-wordpress-plugin
- If supplying your own test setup and database: