Skip to content

Commit

Permalink
Merge 65cc76f into 67fc99a
Browse files Browse the repository at this point in the history
  • Loading branch information
jmauerhan committed Oct 2, 2016
2 parents 67fc99a + 65cc76f commit 6735fc6
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 23 deletions.
1 change: 1 addition & 0 deletions src/UuidFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public function fromBytes($bytes)

public function fromString($uuid)
{
$uuid = strtolower($uuid);
return $this->codec->decode($uuid);
}

Expand Down
11 changes: 11 additions & 0 deletions tests/UuidFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,15 @@ public function testParsesGuidCorrectly()

$this->assertEquals('ff6f8cb0-c57d-11e1-9b21-0800200c9a66', $uuid->toString());
}

public function testFromStringParsesUuidInLowercase()
{
$uuidString = 'ff6f8cb0-c57d-11e1-9b21-0800200c9a66';
$uuidUpper = strtoupper($uuidString);
$factory = new UuidFactory(new FeatureSet(true));

$uuid = $factory->fromString($uuidUpper);

$this->assertEquals($uuidString, $uuid->toString());
}
}
67 changes: 44 additions & 23 deletions tests/UuidTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ public function testUuid3WithKnownUuids()
$this->assertEquals(Uuid::RFC_4122, $uobj->getVariant());
$this->assertEquals(3, $uobj->getVersion());
$this->assertEquals(Uuid::fromString($ustr), $uobj);
$this->assertEquals((string) $uobj, $ustr);
$this->assertEquals((string)$uobj, $ustr);
}
}

Expand All @@ -815,7 +815,7 @@ public function testUuid4TimestampLastComb()
->method('generate')
->willReturnCallback(function ($length) {

// Makes first fields of UUIDs equal
// Makes first fields of UUIDs equal
return str_pad('', $length, '0');
});

Expand All @@ -827,7 +827,7 @@ public function testUuid4TimestampLastComb()

$previous = $factory->uuid4();

for ($i = 0; $i < 1000; $i ++) {
for ($i = 0; $i < 1000; $i++) {
usleep(10);
$uuid = $factory->uuid4();
$this->assertGreaterThan($previous->toString(), $uuid->toString());
Expand Down Expand Up @@ -859,7 +859,7 @@ public function testUuid4TimestampFirstComb()

$previous = $factory->uuid4();

for ($i = 0; $i < 1000; $i ++) {
for ($i = 0; $i < 1000; $i++) {
usleep(10);
$uuid = $factory->uuid4();
$this->assertGreaterThan($previous->toString(), $uuid->toString());
Expand Down Expand Up @@ -935,7 +935,7 @@ public function testUuid5WithKnownUuids()
$this->assertEquals(Uuid::RFC_4122, $uobj->getVariant());
$this->assertEquals(5, $uobj->getVersion());
$this->assertEquals(Uuid::fromString($ustr), $uobj);
$this->assertEquals((string) $uobj, $ustr);
$this->assertEquals((string)$uobj, $ustr);
}
}

Expand Down Expand Up @@ -967,6 +967,28 @@ public function testCompareTo()
$this->assertEquals(1, $uuid3->compareto($uuid5));
}

public function testCompareToReturnsZeroWhenDifferentCases()
{
$uuidString = 'ff6f8cb0-c57d-11e1-9b21-0800200c9a66';
// $uuid1 and $uuid2 are identical
$uuid1 = Uuid::fromString($uuidString);
$uuid2 = Uuid::fromString(strtoupper($uuidString));

$this->assertEquals(0, $uuid1->compareTo($uuid2));
$this->assertEquals(0, $uuid2->compareTo($uuid1));
}

public function testEqualsReturnsTrueWhenDifferentCases()
{
$uuidString = 'ff6f8cb0-c57d-11e1-9b21-0800200c9a66';
// $uuid1 and $uuid2 are identical
$uuid1 = Uuid::fromString($uuidString);
$uuid2 = Uuid::fromString(strtoupper($uuidString));

$this->assertTrue($uuid1->equals($uuid2));
$this->assertTrue($uuid2->equals($uuid1));
}

/**
*/
public function testEquals()
Expand Down Expand Up @@ -999,7 +1021,7 @@ public function testCalculateUuidTime()
Uuid::setFactory(new UuidFactory($featureSet));
$uuidA = Uuid::uuid1(0x00007ffffffe, 0x1669);

$this->assertEquals('c4dbe7e2-097f-11e2-9669-00007ffffffe', (string) $uuidA);
$this->assertEquals('c4dbe7e2-097f-11e2-9669-00007ffffffe', (string)$uuidA);
$this->assertEquals('c4dbe7e2', $uuidA->getTimeLowHex());
$this->assertEquals('097f', $uuidA->getTimeMidHex());
$this->assertEquals('11e2', $uuidA->getTimeHiAndVersionHex());
Expand All @@ -1008,7 +1030,7 @@ public function testCalculateUuidTime()
$timeOfDay->setUsec(0);
$uuidB = Uuid::uuid1(0x00007ffffffe, 0x1669);

$this->assertEquals('c4b18100-097f-11e2-9669-00007ffffffe', (string) $uuidB);
$this->assertEquals('c4b18100-097f-11e2-9669-00007ffffffe', (string)$uuidB);
$this->assertEquals('c4b18100', $uuidB->getTimeLowHex());
$this->assertEquals('097f', $uuidB->getTimeMidHex());
$this->assertEquals('11e2', $uuidB->getTimeHiAndVersionHex());
Expand All @@ -1017,7 +1039,7 @@ public function testCalculateUuidTime()
$timeOfDay->setUsec(999999);
$uuidC = Uuid::uuid1(0x00007ffffffe, 0x1669);

$this->assertEquals('c54a1776-097f-11e2-9669-00007ffffffe', (string) $uuidC);
$this->assertEquals('c54a1776-097f-11e2-9669-00007ffffffe', (string)$uuidC);
$this->assertEquals('c54a1776', $uuidC->getTimeLowHex());
$this->assertEquals('097f', $uuidC->getTimeMidHex());
$this->assertEquals('11e2', $uuidC->getTimeHiAndVersionHex());
Expand All @@ -1044,7 +1066,7 @@ public function testCalculateUuidTimeForce32BitPath()
// For usec = 277885
$uuidA = Uuid::uuid1(0x00007ffffffe, 0x1669);

$this->assertEquals('c4dbe7e2-097f-11e2-9669-00007ffffffe', (string) $uuidA);
$this->assertEquals('c4dbe7e2-097f-11e2-9669-00007ffffffe', (string)$uuidA);
$this->assertEquals('c4dbe7e2', $uuidA->getTimeLowHex());
$this->assertEquals('097f', $uuidA->getTimeMidHex());
$this->assertEquals('11e2', $uuidA->getTimeHiAndVersionHex());
Expand All @@ -1053,7 +1075,7 @@ public function testCalculateUuidTimeForce32BitPath()
$timeOfDay->setUsec(0);
$uuidB = Uuid::uuid1(0x00007ffffffe, 0x1669);

$this->assertEquals('c4b18100-097f-11e2-9669-00007ffffffe', (string) $uuidB);
$this->assertEquals('c4b18100-097f-11e2-9669-00007ffffffe', (string)$uuidB);
$this->assertEquals('c4b18100', $uuidB->getTimeLowHex());
$this->assertEquals('097f', $uuidB->getTimeMidHex());
$this->assertEquals('11e2', $uuidB->getTimeHiAndVersionHex());
Expand All @@ -1062,7 +1084,7 @@ public function testCalculateUuidTimeForce32BitPath()
$timeOfDay->setUsec(999999);
$uuidC = Uuid::uuid1(0x00007ffffffe, 0x1669);

$this->assertEquals('c54a1776-097f-11e2-9669-00007ffffffe', (string) $uuidC);
$this->assertEquals('c54a1776-097f-11e2-9669-00007ffffffe', (string)$uuidC);
$this->assertEquals('c54a1776', $uuidC->getTimeLowHex());
$this->assertEquals('097f', $uuidC->getTimeMidHex());
$this->assertEquals('11e2', $uuidC->getTimeHiAndVersionHex());
Expand All @@ -1088,7 +1110,7 @@ public function testCalculateUuidTimeUpperLowerBounds64Bit()
Uuid::setFactory(new UuidFactory($featureSet));
$uuidA = Uuid::uuid1(0x00007ffffffe, 0x1669);

$this->assertEquals('ff9785f6-ffff-1fff-9669-00007ffffffe', (string) $uuidA);
$this->assertEquals('ff9785f6-ffff-1fff-9669-00007ffffffe', (string)$uuidA);
$this->assertEquals('ff9785f6', $uuidA->getTimeLowHex());
$this->assertEquals('ffff', $uuidA->getTimeMidHex());
$this->assertEquals('1fff', $uuidA->getTimeHiAndVersionHex());
Expand All @@ -1106,7 +1128,7 @@ public function testCalculateUuidTimeUpperLowerBounds64Bit()
Uuid::setFactory(new UuidFactory($featureSet));
$uuidB = Uuid::uuid1(0x00007ffffffe, 0x1669);

$this->assertEquals('00000000-0000-1000-9669-00007ffffffe', (string) $uuidB);
$this->assertEquals('00000000-0000-1000-9669-00007ffffffe', (string)$uuidB);
$this->assertEquals('00000000', $uuidB->getTimeLowHex());
$this->assertEquals('0000', $uuidB->getTimeMidHex());
$this->assertEquals('1000', $uuidB->getTimeHiAndVersionHex());
Expand Down Expand Up @@ -1138,7 +1160,7 @@ public function testCalculateUuidTimeUpperLowerBounds64BitThrough32BitPath()

$uuidA = Uuid::uuid1(0x00007ffffffe, 0x1669);

$this->assertEquals('ff9785f6-ffff-1fff-9669-00007ffffffe', (string) $uuidA);
$this->assertEquals('ff9785f6-ffff-1fff-9669-00007ffffffe', (string)$uuidA);
$this->assertEquals('ff9785f6', $uuidA->getTimeLowHex());
$this->assertEquals('ffff', $uuidA->getTimeMidHex());
$this->assertEquals('1fff', $uuidA->getTimeHiAndVersionHex());
Expand All @@ -1157,7 +1179,7 @@ public function testCalculateUuidTimeUpperLowerBounds64BitThrough32BitPath()

$uuidB = Uuid::uuid1(0x00007ffffffe, 0x1669);

$this->assertEquals('00000000-0000-1000-9669-00007ffffffe', (string) $uuidB);
$this->assertEquals('00000000-0000-1000-9669-00007ffffffe', (string)$uuidB);
$this->assertEquals('00000000', $uuidB->getTimeLowHex());
$this->assertEquals('0000', $uuidB->getTimeMidHex());
$this->assertEquals('1000', $uuidB->getTimeHiAndVersionHex());
Expand All @@ -1184,7 +1206,7 @@ public function testCalculateUuidTimeUpperLowerBounds32Bit()

$uuidA = Uuid::uuid1(0x00007ffffffe, 0x1669);

$this->assertEquals('13813ff6-6912-11fe-9669-00007ffffffe', (string) $uuidA);
$this->assertEquals('13813ff6-6912-11fe-9669-00007ffffffe', (string)$uuidA);
$this->assertEquals('13813ff6', $uuidA->getTimeLowHex());
$this->assertEquals('6912', $uuidA->getTimeMidHex());
$this->assertEquals('11fe', $uuidA->getTimeHiAndVersionHex());
Expand All @@ -1203,7 +1225,7 @@ public function testCalculateUuidTimeUpperLowerBounds32Bit()

$uuidB = Uuid::uuid1(0x00007ffffffe, 0x1669);

$this->assertEquals('1419d680-d292-1165-9669-00007ffffffe', (string) $uuidB);
$this->assertEquals('1419d680-d292-1165-9669-00007ffffffe', (string)$uuidB);
$this->assertEquals('1419d680', $uuidB->getTimeLowHex());
$this->assertEquals('d292', $uuidB->getTimeMidHex());
$this->assertEquals('1165', $uuidB->getTimeHiAndVersionHex());
Expand Down Expand Up @@ -1233,7 +1255,7 @@ public function testCalculateUuidTimeUpperLowerBounds32BitThrough64BitPath()

$uuidA = Uuid::uuid1(0x00007ffffffe, 0x1669);

$this->assertEquals('13813ff6-6912-11fe-9669-00007ffffffe', (string) $uuidA);
$this->assertEquals('13813ff6-6912-11fe-9669-00007ffffffe', (string)$uuidA);
$this->assertEquals('13813ff6', $uuidA->getTimeLowHex());
$this->assertEquals('6912', $uuidA->getTimeMidHex());
$this->assertEquals('11fe', $uuidA->getTimeHiAndVersionHex());
Expand All @@ -1249,10 +1271,9 @@ public function testCalculateUuidTimeUpperLowerBounds32BitThrough64BitPath()
$featureSet->setTimeProvider($timeOfDay);

Uuid::setFactory(new UuidFactory($featureSet));
;
$uuidB = Uuid::uuid1(0x00007ffffffe, 0x1669);

$this->assertEquals('1419d680-d292-1165-9669-00007ffffffe', (string) $uuidB);
$this->assertEquals('1419d680-d292-1165-9669-00007ffffffe', (string)$uuidB);
$this->assertEquals('1419d680', $uuidB->getTimeLowHex());
$this->assertEquals('d292', $uuidB->getTimeMidHex());
$this->assertEquals('1165', $uuidB->getTimeHiAndVersionHex());
Expand Down Expand Up @@ -1298,7 +1319,7 @@ public function test32BitMatch64BitForOneHourPeriod()
$this->assertTrue(
$uuid32->equals($uuid64),
'Breaks at ' . gmdate('r', $currentTime)
. "; 32-bit: {$uuid32->toString()}, 64-bit: {$uuid64->toString()}"
. "; 32-bit: {$uuid32->toString()}, 64-bit: {$uuid64->toString()}"
);

// Assert that the time matches
Expand Down Expand Up @@ -1821,11 +1842,11 @@ public function testUuidPassesPythonTests()
Uuid::fromInteger($test['int']),
);
foreach ($uuids as $uuid) {
$this->assertEquals($test['string'], (string) $uuid);
$this->assertEquals($test['string'], (string)$uuid);
$this->assertEquals($test['hex'], $uuid->getHex());
$this->assertEquals(base64_decode($test['bytes']), $uuid->getBytes());
if ($this->hasMoontoastMath()) {
$this->assertEquals($test['int'], (string) $uuid->getInteger());
$this->assertEquals($test['int'], (string)$uuid->getInteger());
}
$this->assertEquals($test['fields'], $uuid->getFieldsHex());
$this->assertEquals($test['fields']['time_low'], $uuid->getTimeLowHex());
Expand Down

0 comments on commit 6735fc6

Please sign in to comment.