Unit Testing action hook
I found out why. here is the solution: you have to activate the plugin in the tests / bootstrap.php file: $GLOBALS[ ‘wp_tests_options’ ] = array( ‘active_plugins’ => array( ‘YOUR-PLUGIN/YOUR-PLUGIN.php’ ) )
I found out why. here is the solution: you have to activate the plugin in the tests / bootstrap.php file: $GLOBALS[ ‘wp_tests_options’ ] = array( ‘active_plugins’ => array( ‘YOUR-PLUGIN/YOUR-PLUGIN.php’ ) )
return defined(‘WC_VERSION’); should fix since defined() accepts a string as parameter. https://www.php.net/manual/en/function.defined.php If you use: require_once($_SERVER[‘DOCUMENT_ROOT’].’/wp-load.php’); adjusting your path if the installation is in a subrdir you load all the WP environment including active plugins etc
In order of preference: composer require wp-phpunit/wp-phpunit –dev. Depending on the IDE you use you might need to mark the package in vendor/ as a source directory. Each IDE allows you to add definitions from external libraries. In PHPStorm it’s Settings → Languages & Frameworks → PHP → Include Path. Just copy the files over … Read more
So I am using PEST as my testing framework, and if I just define my mocks in the helpers, they won’t be called correctly, because the WPCLI will probably be autoloaded after that on each test. So I added beforeEach(function () { $wpCliMock = \Mockery::mock(‘alias:WP_CLI’); $wpCliMock ->shouldReceive(‘success’) ->andReturnArg(0); $wpCliMock ->shouldReceive(‘error’) ->andReturnArg(0); }); Inside my tests, … Read more
How do I unit test a plugin with forms?
no_rest_route in Unit Testing for REST endpoint for CPT registered via show_in_rest
I don’t know of a library, but you could probably build one using TracTickets as a guide and using GitHub’s API. I’m actually answering to say don’t do this. WordPress actually no longer uses this method of skipping tests. See ticket #30284. I quote from there: Our previous convention was to write unit tests to … Read more
That seems to be an old repo, you should use https://core.trac.wordpress.org/browser/trunk/tests. Obviously trunk should be used if you want to use the tests with 4.6. Not sure how much difference there is in the infrastructure between the version (in other words, it is unlikely that you care how core does a specific test, therefor the … Read more
There are basically three options: Load that file with the admin-side code on-the-fly in setUp() or setUpBeforeClass(), so it will be loaded when those tests run. Load that file before the test suite is loaded and run, like in a bootstrap.php file or something, so it will be loaded for all the tests. Separate your … Read more
The error is telling you that the code tried to output a HTTP response header with the header() function after the response body has already begun to be sent. As you noted, line 68 of bootstrap.php is calling that script that outputs Installing…. So after that output has already been sent, you can’t send a … Read more