Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#33867 closed enhancement (fixed)

Unit tests to protect against breaking pluggable function changes

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

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 11 years ago.
33867.2.patch​ (5.5 KB ) - added by adamsilverstein 11 years ago.
add @group pluggable

Download all attachments as: .zip

Change History (11)

#1 follow-up: @johnbillion
11 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
11 years ago

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

@adamsilverstein
11 years ago

add @group pluggable

#3 in reply to: ↑ 1 @adamsilverstein
11 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
11 years ago

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

#5 @johnbillion
11 years ago

  • Owner set to johnbillion
  • Resolution → fixed
  • Status new → 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
11 years ago

In 34607:

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

See #33867

#7 @johnbillion
11 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
11 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
11 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.