[wp-trac] [WordPress Trac] #28535: WP Unit Tests should reset hooks after each test

WordPress Trac noreply at wordpress.org
Sat Jun 14 05:54:59 UTC 2014


#28535: WP Unit Tests should reset hooks after each test
------------------------------+-----------------------------
 Reporter:  mnelson4          |      Owner:
     Type:  enhancement       |     Status:  new
 Priority:  normal            |  Milestone:  Awaiting Review
Component:  Build/Test Tools  |    Version:  trunk
 Severity:  normal            |   Keywords:
  Focuses:                    |
------------------------------+-----------------------------
 After each unit test method is ran (Eg
 TEsts_Actions_Callbacks::test_callback_representations() ), the actions
 and filters set during that unit test preserved. This means that any
 filters added during one unit test will affect subsequent tests (which is
 troublesome because you can then have tests that fail because a hook was
 set on a previous test, but if you only run the unit test that failed
 (without the previous test that added the hook), it may pass.)

 I'm thinking the fix would be:
 add a global called something like $saved_wp_actions; During
 WP_UnitTestCase::setUp() copy the contents of $wp_actions to it. Then
 during WP_UnitTestCase::tearDown() restore $wp_actions to its previous
 state from before the test by assigning it to be equal to
 $saved_wp_actions.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/28535>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list