From 102cb95559eb54cb9b1ed25bef6134e5acc5ffe3 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 9 Dec 2019 10:39:39 +0000 Subject: [PATCH] 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 --- .../includes/factory/class-wp-unittest-factory-for-thing.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/includes/factory/class-wp-unittest-factory-for-thing.php b/tests/phpunit/includes/factory/class-wp-unittest-factory-for-thing.php index 2ae24a1f95..0fa45059d4 100644 --- a/tests/phpunit/includes/factory/class-wp-unittest-factory-for-thing.php +++ b/tests/phpunit/includes/factory/class-wp-unittest-factory-for-thing.php @@ -130,8 +130,9 @@ abstract class WP_UnitTest_Factory_For_Thing { } // Use the same incrementor for all fields belonging to this object. - $gen = new WP_UnitTest_Generator_Sequence(); - $incr = $gen->get_incr(); + $gen = new WP_UnitTest_Generator_Sequence(); + // 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 ) { if ( ! isset( $args[ $field_name ] ) ) {