Add fromDateTime() to create version 1 UUIDs from DateTime instances

Fixes #28
This commit is contained in:
Ben Ramsey
2020-02-03 00:48:41 -06:00
parent e269c16cd4
commit 5fa4eb4f17
13 changed files with 265 additions and 5 deletions
@@ -12,8 +12,11 @@ use PHPUnit\Framework\MockObject\MockObject;
use Ramsey\Uuid\BinaryUtils;
use Ramsey\Uuid\Converter\TimeConverterInterface;
use Ramsey\Uuid\Exception\RandomSourceException;
use Ramsey\Uuid\Exception\TimeSourceException;
use Ramsey\Uuid\FeatureSet;
use Ramsey\Uuid\Generator\DefaultTimeGenerator;
use Ramsey\Uuid\Provider\NodeProviderInterface;
use Ramsey\Uuid\Provider\Time\FixedTimeProvider;
use Ramsey\Uuid\Provider\TimeProviderInterface;
use Ramsey\Uuid\Test\TestCase;
use Ramsey\Uuid\Type\Hexadecimal;
@@ -189,4 +192,22 @@ class DefaultTimeGeneratorTest extends TestCase
$defaultTimeGenerator->generate($this->nodeId);
}
public function testDefaultTimeGeneratorThrowsExceptionForLargeGeneratedValue(): void
{
$timeProvider = new FixedTimeProvider(new Time('1832455114570', '955162'));
$featureSet = new FeatureSet();
$timeGenerator = new DefaultTimeGenerator(
$featureSet->getNodeProvider(),
$featureSet->getTimeConverter(),
$timeProvider
);
$this->expectException(TimeSourceException::class);
$this->expectExceptionMessage(
'The generated time of \'10000000000000004\' is larger than expected'
);
$timeGenerator->generate();
}
}