diff --git a/src/Symfony/Component/Uid/Tests/UuidTest.php b/src/Symfony/Component/Uid/Tests/UuidTest.php index fb431e0089..e43275230e 100644 --- a/src/Symfony/Component/Uid/Tests/UuidTest.php +++ b/src/Symfony/Component/Uid/Tests/UuidTest.php @@ -94,6 +94,22 @@ class UuidTest extends TestCase $this->assertFalse($uuid1->equals($uuid2)); } + /** + * @dataProvider provideInvalidEqualType + */ + public function testEqualsAgainstOtherType($other) + { + $this->assertFalse((new Uuid(self::A_UUID_V4))->equals($other)); + } + + public function provideInvalidEqualType() + { + yield [null]; + yield [self::A_UUID_V1]; + yield [self::A_UUID_V4]; + yield [new \stdClass()]; + } + public function testCompare() { $uuids = []; diff --git a/src/Symfony/Component/Uid/Uuid.php b/src/Symfony/Component/Uid/Uuid.php index a6dd3536f3..1da54e7190 100644 --- a/src/Symfony/Component/Uid/Uuid.php +++ b/src/Symfony/Component/Uid/Uuid.php @@ -48,7 +48,7 @@ class Uuid implements \JsonSerializable throw new \InvalidArgumentException(sprintf('Invalid UUID: "%s".', $uuid)); } - $this->uuid = $uuid; + $this->uuid = strtr($uuid, 'ABCDEF', 'abcdef'); } public static function v1(): self @@ -91,8 +91,15 @@ class Uuid implements \JsonSerializable return uuid_is_null($this->uuid); } - public function equals(self $other): bool + /** + * Returns whether the argument is of class Uuid and contains the same value as the current instance. + */ + public function equals($other): bool { + if (!$other instanceof self) { + return false; + } + return 0 === uuid_compare($this->uuid, $other->uuid); }