[Uid] make Uuid::equals()
accept any types of argument for more flexibility
This commit is contained in:
parent
14c95a9d8c
commit
46721c19f9
@ -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 = [];
|
||||
|
@ -42,7 +42,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
|
||||
@ -85,8 +85,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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user