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:
Marcel Berteler
2022-12-19 23:18:32 +02:00
committed by GitHub
parent 9fd59bb21c
commit 5e24bfd390
3 changed files with 74 additions and 2 deletions
+32
View File
@@ -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.