1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
<?php
declare(strict_types=1);
namespace Ramsey\Uuid\Test;
use DateTimeInterface;
use Mockery;
use Ramsey\Uuid\Codec\CodecInterface;
use Ramsey\Uuid\Converter\NumberConverterInterface;
use Ramsey\Uuid\Converter\Time\GenericTimeConverter;
use Ramsey\Uuid\Converter\TimeConverterInterface;
use Ramsey\Uuid\Exception\DateTimeException;
use Ramsey\Uuid\Math\BrickMathCalculator;
use Ramsey\Uuid\Rfc4122\Fields;
use Ramsey\Uuid\Rfc4122\FieldsInterface;
use Ramsey\Uuid\Type\Hexadecimal;
use Ramsey\Uuid\Type\Time;
use Ramsey\Uuid\Uuid;
class DeprecatedUuidMethodsTraitTest extends TestCase
{
public function testGetDateTime(): void
{
$calculator = new BrickMathCalculator();
$fields = new Fields((string) hex2bin('ff6f8cb0c57d11e19b210800200c9a66'));
$numberConverter = Mockery::mock(NumberConverterInterface::class);
$codec = Mockery::mock(CodecInterface::class);
$timeConverter = new GenericTimeConverter($calculator);
$uuid = new Uuid($fields, $numberConverter, $codec, $timeConverter);
$this->assertInstanceOf(DateTimeInterface::class, $uuid->getDateTime());
$this->assertSame('2012-07-04T02:14:34+00:00', $uuid->getDateTime()->format('c'));
$this->assertSame('1341368074.491000', $uuid->getDateTime()->format('U.u'));
}
public function testGetDateTimeThrowsException(): void
{
$fields = Mockery::mock(FieldsInterface::class, [
'getVersion' => 1,
'getTimestamp' => new Hexadecimal('0'),
]);
$numberConverter = Mockery::mock(NumberConverterInterface::class);
$codec = Mockery::mock(CodecInterface::class);
$timeConverter = Mockery::mock(TimeConverterInterface::class, [
'convertTime' => new Time('0', '1234567'),
]);
$uuid = new Uuid($fields, $numberConverter, $codec, $timeConverter);
$this->expectException(DateTimeException::class);
$uuid->getDateTime();
}
}
|