Fix microsecond rounding error on 32-bit systems

This commit is contained in:
Ben Ramsey
2020-02-21 02:51:31 -06:00
parent 1396eaf756
commit a7cf07a2d8
5 changed files with 58 additions and 17 deletions
+33
View File
@@ -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