I’ve just updated an Interactivity API function. Now, it includes a _doing_it_wrong() that will trigger if the directives server processing fails.
However, adding this notice interfered with the existing tests that were already covering that function.

After comparing it with other tests in the Core, I realized it’s necessary to ‘catch’ that function. So, I added the following line to the test:
/** * Array of expected `_doing_it_wrong()` calls. * * @var string[] */protected $expected_doing_it_wrong; /** * Set up. */ public function set_up() { parent::set_up(); $this->interactivity = new WP_Interactivity_API(); $this->expected_doing_it_wrong = array(); } /** * Declares an expected `_doing_it_wrong()` call from within a test. * * @since 4.2.0 * * @param string $doing_it_wrong Name of the function, method, or class that appears in * the first argument of the source `_doing_it_wrong()` call. */ public function setExpectedIncorrectUsage( $doing_it_wrong ) { $this->expected_doing_it_wrong[] = $doing_it_wrong; }
I defined a protected variable with an array of doing_it_wrong calls and a function to add them.
Then, in each test, you have to add that catcher, like this:
public function test_process_directives_does_not_change_inner_html_in_math() { $this->interactivity->state( 'myPlugin', array( 'id' => 'some-id', ) ); $html = ' <header> <math data-wp-bind--id="myPlugin::state.math"> <mrow data-wp-bind--id="myPlugin::state.id" /> <mi>x</mi> <mo>=</mo> <mi>1</mi> </math> </header> '; $processed_html = $this->interactivity->process_directives( $html ); $this->setExpectedIncorrectUsage( 'WP_Interactivity_API::process_directives_args' ); $p = new WP_HTML_Tag_Processor( $processed_html ); $p->next_tag( 'div' ); $this->assertNull( $p->get_attribute( 'id' ) ); }
And voilá, tests back to green.

PD: There seems to be a simpler way, by using PHPDoc annotation – expectedIncorrectUsage.
/** * Tests the `set_content_between_balanced_tags` method with unbalanced tags. * * @covers ::set_content_between_balanced_tags * * @expectedIncorrectUsage WP_Interactivity_API::process_directives_args */public function test_set_content_between_balanced_tags_with_unbalanced_tags() { ....}
Leave a Reply