By default WordPress has many non-mockable functions such as register_taxonomy(). By implementing this wrapper you can create tests that use mocks instead of a real WordPress installation.
- Go to the root directory of your theme/plugin.
- Run the following command:
composer require mrkoopie/wp_wrapper
- Include the composer autoloader in your script (for a theme the functions.php).
require_once('vendor/autoload.php');
Simply include this in the top of your file:
use MrKoopie/WP_wrapper/WP_wrapper;
Now you can run any command (including any PHP command) via the wrapper:
echo WP_wrapper::print_r('Y',1);
Simply use this code to make the class available without the namespace. Do note that this may cause conflicts when an other class exists with the name WP_wrapper.
require_once('vendor/autoload.php');
class WP_wrapper extends MrKoopie/WP_wrapper/WP_Wrapper {};