mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-14 15:56:48 +03:00
feat: add Uuid:fromHexadecimal() (#309)
Co-authored-by: mberteler <marcel.berteler@capetown.gov.za> Co-authored-by: Ben Ramsey <ben@benramsey.com>
This commit is contained in:
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Ramsey\Uuid\Test;
|
||||
|
||||
use BadMethodCallException;
|
||||
use Brick\Math\BigDecimal;
|
||||
use Brick\Math\RoundingMode;
|
||||
use DateTimeImmutable;
|
||||
@@ -73,6 +74,37 @@ class UuidTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testFromHexadecimal(): void
|
||||
{
|
||||
$hex = new Hexadecimal('0x1EA78DEB37CE625E8F1A025041000001');
|
||||
$uuid = Uuid::fromHexadecimal($hex);
|
||||
$this->assertInstanceOf(Uuid::class, $uuid);
|
||||
$this->assertEquals('1ea78deb-37ce-625e-8f1a-025041000001', $uuid->toString());
|
||||
}
|
||||
|
||||
public function testFromHexadecimalShort(): void
|
||||
{
|
||||
$hex = new Hexadecimal('0x1EA78DEB37CE625E8F1A0250410000');
|
||||
|
||||
$this->expectException(InvalidUuidStringException::class);
|
||||
$this->expectExceptionMessage('Invalid UUID string:');
|
||||
|
||||
Uuid::fromHexadecimal($hex);
|
||||
}
|
||||
|
||||
public function testFromHexadecimalThrowsWhenMethodDoesNotExist(): void
|
||||
{
|
||||
$factory = Mockery::mock(UuidFactoryInterface::class);
|
||||
Uuid::setFactory($factory);
|
||||
|
||||
$hex = new Hexadecimal('0x1EA78DEB37CE625E8F1A025041000001');
|
||||
|
||||
$this->expectException(BadMethodCallException::class);
|
||||
$this->expectExceptionMessage('The method fromHexadecimal() does not exist on the provided factory');
|
||||
|
||||
Uuid::fromHexadecimal($hex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that UUID and GUID's have the same textual representation but not
|
||||
* the same binary representation.
|
||||
|
||||
Reference in New Issue
Block a user