Tests: Pad incrementors used in factories with leading zeros to make sure MySQL sorting works as expected.

Previously, tests could create sequential objects with names like `Term 99`, `Term 100`, which by default would be returned in reverse order when sorted by name alphabetically, causing seemingly random test failures that are extremely hard to debug.

See #48145.

git-svn-id: https://develop.svn.wordpress.org/trunk@46830 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2019-12-09 10:39:39 +00:00
parent 0660804327
commit 102cb95559
1 changed files with 3 additions and 2 deletions

View File

@ -131,7 +131,8 @@ abstract class WP_UnitTest_Factory_For_Thing {
// Use the same incrementor for all fields belonging to this object. // Use the same incrementor for all fields belonging to this object.
$gen = new WP_UnitTest_Generator_Sequence(); $gen = new WP_UnitTest_Generator_Sequence();
$incr = $gen->get_incr(); // Add leading zeros to make sure MySQL sorting works as expected.
$incr = zeroise( $gen->get_incr(), 7 );
foreach ( array_keys( $generation_definitions ) as $field_name ) { foreach ( array_keys( $generation_definitions ) as $field_name ) {
if ( ! isset( $args[ $field_name ] ) ) { if ( ! isset( $args[ $field_name ] ) ) {