mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-14 15:56:48 +03:00
Fix microsecond rounding error on 32-bit systems
This commit is contained in:
@@ -7,9 +7,15 @@ namespace Ramsey\Uuid\Test;
|
||||
use Brick\Math\BigDecimal;
|
||||
use Brick\Math\RoundingMode;
|
||||
use DateTimeInterface;
|
||||
use Mockery;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Ramsey\Uuid\Builder\DefaultUuidBuilder;
|
||||
use Ramsey\Uuid\Codec\StringCodec;
|
||||
use Ramsey\Uuid\Codec\TimestampFirstCombCodec;
|
||||
use Ramsey\Uuid\Codec\TimestampLastCombCodec;
|
||||
use Ramsey\Uuid\Converter\Number\BigNumberConverter;
|
||||
use Ramsey\Uuid\Converter\TimeConverterInterface;
|
||||
use Ramsey\Uuid\Exception\DateTimeException;
|
||||
use Ramsey\Uuid\Exception\InvalidArgumentException;
|
||||
use Ramsey\Uuid\Exception\InvalidUuidStringException;
|
||||
use Ramsey\Uuid\Exception\UnsupportedOperationException;
|
||||
@@ -1464,6 +1470,33 @@ class UuidTest extends TestCase
|
||||
$this->assertEquals($uuid->getVersion(), Uuid::UUID_TYPE_HASH_SHA1);
|
||||
}
|
||||
|
||||
public function testGetDateTimeThrowsExceptionWhenDateTimeCannotParseDate(): void
|
||||
{
|
||||
$numberConverter = new BigNumberConverter();
|
||||
$timeConverter = Mockery::mock(TimeConverterInterface::class);
|
||||
|
||||
$timeConverter
|
||||
->shouldReceive('convertTime')
|
||||
->once()
|
||||
->andReturn(new Time(1234567890, '1234567'));
|
||||
|
||||
$builder = new DefaultUuidBuilder($numberConverter, $timeConverter);
|
||||
$codec = new StringCodec($builder);
|
||||
|
||||
$factory = new UuidFactory();
|
||||
$factory->setCodec($codec);
|
||||
|
||||
$uuid = $factory->fromString('b1484596-25dc-11ea-978f-2e728ce88125');
|
||||
|
||||
$this->expectException(DateTimeException::class);
|
||||
$this->expectExceptionMessage(
|
||||
'DateTimeImmutable::__construct(): Failed to parse time string '
|
||||
. '(@1234567890.1234567) at position 18 (7): Unexpected character'
|
||||
);
|
||||
|
||||
$uuid->getDateTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string $expectedClass
|
||||
* @param mixed[] $args
|
||||
|
||||
Reference in New Issue
Block a user