how to set context in WordPress for unit testing

If you have phpUnit configured for testing a WP plugin, you can use a test case like this:

In your plugin-directory/tests/Some_Test_Case.php:

class Plugin_Test extends WP_UnitTestCase {
    /**
     * @dataProvider post_IDs_and_expected_results
     */
    public function test_something( $post_id, $expected_result ) {
        global $post;
        $post = get_post( $post_id );
        $plugin_content = call_plugin_function(); // Your function name here
        $this->assertEquals( $expected_result, $plugin_content, "Content OK for post $post_id" );
    }
    public function post_IDs_and_expected_results() {
        return array(
            array( 1, 'expected result for post_id = 1' ),
            array( 2, 'expected result for post_id = 2' )
        );
    }

}

Command line in your plugin’s directory: phpunit ./tests/Some_Test_Case.php