Running WordPress tests with PHPUnit
-
Has anyone ever gotten the wordpress test suite () to run using PHPUnit from the command line, instead of running “php wp-test.php”?
I would like to integrate testing into a continuous integration environment, and I am having trouble translating wp-test.php into a PHPUnit bootstrap file. I would like to run the WordPress test suite like this:
phpunit --bootstrap bootstrap.php --log-junit phpunit.xml wp-testcase/test_actions.php
I created a bootstrap.php file that is heavily based on wp-test.php, and I when I run it, I get this error:
Fatal error: Call to undefined method stdClass::set_prefix() in C:\wamp\www\wordpress\trunk\src\wp-settings.php on line 286
Line 286 of wp-settings.php is this:
$prefix = $wpdb->set_prefix($table_prefix); // set up global tables
It appears that $wpdb is not being defined properly by this point in the execution, but when I run “php wp-test.php”, which is almost the same execution steps, it works. It leads me to believe that there is some issue with the way PHPUnit bootstrap files allow or don’t play nice with all of WordPress’ global variables, like $wpdb. I cannot change the WordPress source code to make it bootstrappable, so I thought I’d check here first and see if there’s a setting or flag I’m missing when running PHPUnit.
Any help would be greatly appreciated. Thanks,
Dave Morris
- The topic ‘Running WordPress tests with PHPUnit’ is closed to new replies.