WordPress setup: Installed WordPress using VVV.
PHPUnit setup:
I have setup the testing suite as mentioned in Pippin’s blog. And accessing PHPUnit after logging into the box machine by using vagrant ssh
.
Test case: I’m writing my test cases inside the /tests/
folder in the test-{my-plugin-filename}.php
file.
function test_my_plugin_method() {
$links = plugin_method();
}
Where I’m stuck?
When I run PHPUnit
, I’m getting the following error.
Error: Call to undefined function plugin_method()
I have added the following line.
require_once( dirname( dirname( __FILE__ ) ) . '/plugin-file.php' );
But I believe I’m missing something. Any help would be much appreciated.
Edit 1:
I executed wp scaffold plugin-tests
and then the following line as mentioned in Pippin’s blog (refer above for link).
bash bin/install-wp-tests.sh wordpress_test root '' localhost latest
Finally I executed phpunit
.
bootstrap.php
I haven’t changed anything in the bootstrap.php file.
<?php
$_tests_dir = getenv( 'WP_TESTS_DIR' );
if ( ! $_tests_dir ) {
$_tests_dir="/tmp/wordpress-tests-lib";
}
require_once $_tests_dir . '/includes/functions.php';
function _manually_load_plugin() {
require dirname( dirname( __FILE__ ) ) . '/my-plugin.php';
}
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
require $_tests_dir . '/includes/bootstrap.php';