X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Futils%2FUIDGeneratorTest.php;h=d746ea1459364d4f6418f37b121074a7b39c020f;hb=3b7f4539639b3899e246e245df481882f81f9340;hp=6d7325dee1a5824d8b2570211cb8c13180628fe4;hpb=663d41c91c7ad8b559fa6eddab7a3202c029e010;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/utils/UIDGeneratorTest.php b/tests/phpunit/includes/utils/UIDGeneratorTest.php index 6d7325dee1..230c9354b9 100644 --- a/tests/phpunit/includes/utils/UIDGeneratorTest.php +++ b/tests/phpunit/includes/utils/UIDGeneratorTest.php @@ -2,6 +2,8 @@ class UIDGeneratorTest extends PHPUnit_Framework_TestCase { + use MediaWikiCoversValidator; + protected function tearDown() { // Bug: 44850 UIDGenerator::unitTestTearDown(); @@ -9,6 +11,8 @@ class UIDGeneratorTest extends PHPUnit_Framework_TestCase { } /** + * Test that generated UIDs have the expected properties + * * @dataProvider provider_testTimestampedUID * @covers UIDGenerator::newTimestampedUID128 * @covers UIDGenerator::newTimestampedUID88 @@ -31,19 +35,29 @@ class UIDGeneratorTest extends PHPUnit_Framework_TestCase { $this->assertSame( array_unique( $ids ), $ids, "All generated IDs are unique." ); foreach ( $ids as $id ) { - $id_bin = Wikimedia\base_convert( $id, 10, 2 ); - $lastId_bin = Wikimedia\base_convert( $lastId, 10, 2 ); + // Convert string to binary and pad to full length so we can + // extract segments + $id_bin = Wikimedia\base_convert( $id, 10, 2, $bits ); + $lastId_bin = Wikimedia\base_convert( $lastId, 10, 2, $bits ); + + $timestamp_bin = substr( $id_bin, 0, $tbits ); + $last_timestamp_bin = substr( $lastId_bin, 0, $tbits ); $this->assertGreaterThanOrEqual( - substr( $lastId_bin, 0, $tbits ), - substr( $id_bin, 0, $tbits ), - "New ID timestamp ($id_bin) >= prior one ($lastId_bin)." ); + $last_timestamp_bin, + $timestamp_bin, + "timestamp ($timestamp_bin) of current ID ($id_bin) >= timestamp ($last_timestamp_bin) " . + "of prior one ($lastId_bin)" ); + + $hostbits_bin = substr( $id_bin, -$hostbits ); + $last_hostbits_bin = substr( $lastId_bin, -$hostbits ); if ( $hostbits ) { $this->assertEquals( - substr( $id_bin, -$hostbits ), - substr( $lastId_bin, -$hostbits ), - "Host ID of ($id_bin) is same as prior one ($lastId_bin)." ); + $hostbits_bin, + $last_hostbits_bin, + "Host ID ($hostbits_bin) of current ID ($id_bin) is same as host ID ($last_hostbits_bin) " . + "of prior one ($lastId_bin)." ); } $lastId = $id;