Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#33867 closed enhancement (fixed)

Unit tests to protect against breaking pluggable function changes

Reported by: johnbillion's profile johnbillion Owned by: johnbillion's profile johnbillion
Milestone: 4.4 Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords: has-patch
Focuses: Cc:

Description

In [33023] and [33620], the parameters of the pluggable wp_new_user_notification() function were changed, which caused breakage. See #33654.

We can introduce unit tests which protect us against this by using reflection to compare the functions in pluggable.php against an array of expected signatures (well, parameter names and default values at least). That way, if a pluggable function's parameters are changed, the unit tests will fail.

It's not fool-proof (a parameter can be re-purposed without having its name or default value changed), but it gets us a long way.

Attachments (2)

33867.patch (5.5 KB) - added by johnbillion 9 years ago.
33867.2.patch (5.5 KB) - added by adamsilverstein 9 years ago.
add @group pluggable

Download all attachments as: .zip

Change History (11)

@johnbillion
9 years ago

#1 follow-up: @johnbillion
9 years ago

  • Keywords has-patch added

Any of the following changes will cause the tests in 33867.patch to fail:

  • Renaming a pluggable function parameter.
  • Changing, adding, or removing the default value of a pluggable function parameter.
  • Deleting a pluggable function, or moving it outside of pluggable.php.
  • Adding a new pluggable function.

#2 @johnbillion
9 years ago

  • Summary changed from Unit tests to protected against breaking pluggable function changes to Unit tests to protect against breaking pluggable function changes

@adamsilverstein
9 years ago

add @group pluggable

#3 in reply to: ↑ 1 @adamsilverstein
9 years ago

This is a great idea John, thanks!.

I tested locally and verified the test fail when i changed a pluggable function parameter signature.

What do you think about adding @group pluggable to the header? I added this to help me run just these tests and notice we already have some tests in this group. Added in 33867.2.patch.

Replying to johnbillion:

Any of the following changes will cause the tests in 33867.patch to fail:

  • Renaming a pluggable function parameter.
  • Changing, adding, or removing the default value of a pluggable function parameter.
  • Deleting a pluggable function, or moving it outside of pluggable.php.
  • Adding a new pluggable function.

#4 @boonebgorges
9 years ago

Good idea, and clever implementation. +1 from me.

#5 @johnbillion
9 years ago

  • Owner set to johnbillion
  • Resolution set to fixed
  • Status changed from new to closed

In 34126:

Implement unit tests which use reflection to test functions in pluggable.php. This means any changes to these functions will need explicit changes to their corresponding tests, which helps prevent unintentional breakage.

Fixes #33867

#6 @johnbillion
9 years ago

In 34607:

Add function signature tests for the pluggable functions in wp-includes/cache.php.

See #33867

#7 @johnbillion
9 years ago

In 34608:

Add function signature tests for the pluggable functions in wp-admin/includes/schema.php and wp-admin/includes/upgrade.php.

See #33867

#8 @johnbillion
9 years ago

In 35145:

Remove wp_cache_reset() from the pluggable functions signature tests, as the function is deprecated and no longer used.

See #31491, #33867

#9 @ocean90
9 years ago

In 35148:

Improve [35146] to only skip pluggable function signature tests for wp-includes/cache.php when an external object cache is in use.

See #31491, #33867.

Note: See TracTickets for help on using tickets.