Test Driven Development with WordPress. Sample codes derived from notes in this StackOverflow question.
WordPress Testing framework developed by Nikolay Bachiyski. His framework is a wrapper around PHPUnit and is now being integrated as the defacto test runner in WordPress Unit Tests for the WordPress Core.
-
Clone this Git Repository
$ git clone git://github.com/miccheng/WordPress-TDD.git
-
Initialize Git submodule for WordPress-Tests.
$ git submodule init $ git submodule update
-
Copy
my-plugin
folder into your current WordPress installation. -
Enable the MyPlugin module.
-
Copy
WordPress-Tests
folder to the same folder level as your WordPress installation. -
Copy
unittests-config-sample.php
tounittests-config.php
. Edit the new file and update the database, path setting. -
In console/terminal,
cd
to themy-plugin
folder. -
Type:
phpunit
.
- Refer to my slides on SpeakerDeck (TDD for PHP -https://speakerdeck.com/u/miccheng/p/test-drive-development-with-php) for basics of TDD with PHPUnit.
- Look inside
my-plugin/tests/
folder for sample of how to write tests for WordPress.