Remove deprecated getVersion() method

This commit is contained in:
Ben Ramsey
2022-03-27 21:47:55 -05:00
parent 8595a6d8c1
commit cc4df59001
9 changed files with 73 additions and 68 deletions
+1
View File
@@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
* `getTimestamp()`
* `getTimestampHex()`
* `getVariant()`
* `getVersion()`
* Remove dependency on ramsey/collection package.
-8
View File
@@ -36,12 +36,4 @@ interface DeprecatedUuidInterface
* interface. It is available at {@see UuidV1::getDateTime()}.
*/
public function getDateTime(): DateTimeInterface;
/**
* @deprecated Use {@see UuidInterface::getFields()} to get a
* {@see FieldsInterface} instance. If it is a
* {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call
* {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getVersion()}.
*/
public function getVersion(): ?int;
}
-11
View File
@@ -87,15 +87,4 @@ trait DeprecatedUuidMethodsTrait
throw new DateTimeException($e->getMessage(), (int) $e->getCode(), $e);
}
}
/**
* @deprecated Use {@see UuidInterface::getFields()} to get a
* {@see FieldsInterface} instance. If it is a
* {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call
* {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getVersion()}.
*/
public function getVersion(): ?int
{
return $this->fields->getVersion();
}
}
-7
View File
@@ -150,13 +150,6 @@ final class LazyUuidFromString implements UuidInterface
->getUrn();
}
/** @psalm-suppress DeprecatedMethod */
public function getVersion(): ?int
{
return ($this->unwrapped ?? $this->unwrap())
->getVersion();
}
public function compareTo(UuidInterface $other): int
{
return ($this->unwrapped ?? $this->unwrap())
+5 -1
View File
@@ -242,10 +242,14 @@ class OrderedTimeCodecTest extends TestCase
);
$decoded = $codec->decode($expected);
$serialized = serialize($decoded);
/** @var \Ramsey\Uuid\Rfc4122\UuidInterface $unserializedUuid */
$unserializedUuid = unserialize($serialized);
/** @var \Ramsey\Uuid\Rfc4122\UuidInterface $expectedUuid */
$expectedUuid = Uuid::fromString($expected);
$this->assertSame($expectedUuid->getVersion(), $unserializedUuid->getVersion());
$this->assertSame($expectedUuid->getFields()->getVersion(), $unserializedUuid->getFields()->getVersion());
$this->assertTrue($expectedUuid->equals($unserializedUuid));
}
}
+8 -6
View File
@@ -31,9 +31,11 @@ use stdClass;
class ExpectedBehaviorTest extends TestCase
{
/**
* @param mixed[] $args
*
* @dataProvider provideStaticCreationMethods
*/
public function testStaticCreationMethodsAndStandardBehavior($method, $args)
public function testStaticCreationMethodsAndStandardBehavior(string $method, array $args): void
{
/** @var UuidInterface $uuid */
$uuid = call_user_func_array(['Ramsey\Uuid\Uuid', $method], $args);
@@ -84,7 +86,7 @@ class ExpectedBehaviorTest extends TestCase
);
$this->assertSame(2, $uuid->getFields()->getVariant());
$this->assertSame((int) substr($method, -1), $uuid->getVersion());
$this->assertSame((int) substr($method, -1), $uuid->getFields()->getVersion());
$this->assertTrue(ctype_digit((string) $uuid->getInteger()));
}
@@ -205,7 +207,7 @@ class ExpectedBehaviorTest extends TestCase
$this->assertInstanceOf('Ramsey\Uuid\UuidInterface', $uuid);
$this->assertSame($string, $uuid->toString());
$this->assertSame($version, $uuid->getVersion());
$this->assertSame($version, $uuid->getFields()->getVersion());
$this->assertSame($variant, $uuid->getFields()->getVariant());
$components = explode('-', $string);
@@ -235,7 +237,7 @@ class ExpectedBehaviorTest extends TestCase
$this->assertInstanceOf('Ramsey\Uuid\UuidInterface', $uuid);
$this->assertSame($string, $uuid->toString());
$this->assertSame($version, $uuid->getVersion());
$this->assertSame($version, $uuid->getFields()->getVersion());
$this->assertSame($variant, $uuid->getFields()->getVariant());
$components = explode('-', $string);
@@ -265,7 +267,7 @@ class ExpectedBehaviorTest extends TestCase
$this->assertInstanceOf('Ramsey\Uuid\UuidInterface', $uuid);
$this->assertSame($string, $uuid->toString());
$this->assertSame($version, $uuid->getVersion());
$this->assertSame($version, $uuid->getFields()->getVersion());
$this->assertSame($variant, $uuid->getFields()->getVariant());
$components = explode('-', $string);
@@ -543,7 +545,7 @@ class ExpectedBehaviorTest extends TestCase
$this->assertInstanceOf('Ramsey\Uuid\UuidInterface', $uuid);
$this->assertSame(2, $uuid->getFields()->getVariant());
$this->assertSame(4, $uuid->getVersion());
$this->assertSame(4, $uuid->getFields()->getVersion());
$this->assertSame($expectedBytes, $uuid->getBytes());
$this->assertSame($expectedHex, (string) $uuid->getHex());
}
+17 -4
View File
@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Ramsey\Uuid\Test;
use Ramsey\Uuid\Rfc4122\FieldsInterface;
use Ramsey\Uuid\Rfc4122\UuidInterface;
use Ramsey\Uuid\Type\Hexadecimal;
use Ramsey\Uuid\Type\Integer as IntegerObject;
use Ramsey\Uuid\Uuid;
@@ -22,8 +23,11 @@ class FunctionsTest extends TestCase
{
$v1 = v1();
/** @var UuidInterface $uuid */
$uuid = Uuid::fromString($v1);
$this->assertIsString($v1);
$this->assertSame(Uuid::UUID_TYPE_TIME, Uuid::fromString($v1)->getVersion());
$this->assertSame(Uuid::UUID_TYPE_TIME, $uuid->getFields()->getVersion());
}
public function testV2ReturnsVersion2UuidString(): void
@@ -47,16 +51,22 @@ class FunctionsTest extends TestCase
$ns = Uuid::fromString(Uuid::NAMESPACE_URL);
$v3 = v3($ns, 'https://example.com/foo');
/** @var UuidInterface $uuid */
$uuid = Uuid::fromString($v3);
$this->assertIsString($v3);
$this->assertSame(Uuid::UUID_TYPE_HASH_MD5, Uuid::fromString($v3)->getVersion());
$this->assertSame(Uuid::UUID_TYPE_HASH_MD5, $uuid->getFields()->getVersion());
}
public function testV4ReturnsVersion4UuidString(): void
{
$v4 = v4();
/** @var UuidInterface $uuid */
$uuid = Uuid::fromString($v4);
$this->assertIsString($v4);
$this->assertSame(Uuid::UUID_TYPE_RANDOM, Uuid::fromString($v4)->getVersion());
$this->assertSame(Uuid::UUID_TYPE_RANDOM, $uuid->getFields()->getVersion());
}
public function testV5ReturnsVersion5UuidString(): void
@@ -64,8 +74,11 @@ class FunctionsTest extends TestCase
$ns = Uuid::fromString(Uuid::NAMESPACE_URL);
$v5 = v5($ns, 'https://example.com/foo');
/** @var UuidInterface $uuid */
$uuid = Uuid::fromString($v5);
$this->assertIsString($v5);
$this->assertSame(Uuid::UUID_TYPE_HASH_SHA1, Uuid::fromString($v5)->getVersion());
$this->assertSame(Uuid::UUID_TYPE_HASH_SHA1, $uuid->getFields()->getVersion());
}
public function testV6ReturnsVersion6UuidString(): void
+42 -30
View File
@@ -364,32 +364,37 @@ class UuidTest extends TestCase
public function testGetVersionForVersion1(): void
{
/** @var \Ramsey\Uuid\Rfc4122\UuidInterface $uuid */
$uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66');
$this->assertSame(1, $uuid->getVersion());
$this->assertSame(1, $uuid->getFields()->getVersion());
}
public function testGetVersionForVersion2(): void
{
/** @var \Ramsey\Uuid\Rfc4122\UuidInterface $uuid */
$uuid = Uuid::fromString('6fa459ea-ee8a-2ca4-894e-db77e160355e');
$this->assertSame(2, $uuid->getVersion());
$this->assertSame(2, $uuid->getFields()->getVersion());
}
public function testGetVersionForVersion3(): void
{
/** @var \Ramsey\Uuid\Rfc4122\UuidInterface $uuid */
$uuid = Uuid::fromString('6fa459ea-ee8a-3ca4-894e-db77e160355e');
$this->assertSame(3, $uuid->getVersion());
$this->assertSame(3, $uuid->getFields()->getVersion());
}
public function testGetVersionForVersion4(): void
{
/** @var \Ramsey\Uuid\Rfc4122\UuidInterface $uuid */
$uuid = Uuid::fromString('6fabf0bc-603a-42f2-925b-d9f779bd0032');
$this->assertSame(4, $uuid->getVersion());
$this->assertSame(4, $uuid->getFields()->getVersion());
}
public function testGetVersionForVersion5(): void
{
/** @var \Ramsey\Uuid\Rfc4122\UuidInterface $uuid */
$uuid = Uuid::fromString('886313e1-3b8a-5372-9b90-0c9aee199e5d');
$this->assertSame(5, $uuid->getVersion());
$this->assertSame(5, $uuid->getFields()->getVersion());
}
public function testToString(): void
@@ -411,7 +416,7 @@ class UuidTest extends TestCase
$uuid = Uuid::uuid1();
$this->assertInstanceOf(DateTimeInterface::class, $uuid->getDateTime());
$this->assertSame(2, $uuid->getFields()->getVariant());
$this->assertSame(1, $uuid->getVersion());
$this->assertSame(1, $uuid->getFields()->getVersion());
}
public function testUuid1WithNodeAndClockSequence(): void
@@ -420,7 +425,7 @@ class UuidTest extends TestCase
$uuid = Uuid::uuid1('0800200c9a66', 0x1669);
$this->assertInstanceOf(DateTimeInterface::class, $uuid->getDateTime());
$this->assertSame(2, $uuid->getFields()->getVariant());
$this->assertSame(1, $uuid->getVersion());
$this->assertSame(1, $uuid->getFields()->getVersion());
$this->assertSame('1669', $uuid->getFields()->getClockSeq()->toString());
$this->assertSame('0800200c9a66', $uuid->getFields()->getNode()->toString());
$this->assertSame('9669-0800200c9a66', substr($uuid->toString(), 19));
@@ -432,7 +437,7 @@ class UuidTest extends TestCase
$uuid = Uuid::uuid1(new Hexadecimal('0800200c9a66'), 0x1669);
$this->assertInstanceOf(DateTimeInterface::class, $uuid->getDateTime());
$this->assertSame(2, $uuid->getFields()->getVariant());
$this->assertSame(1, $uuid->getVersion());
$this->assertSame(1, $uuid->getFields()->getVersion());
$this->assertSame('1669', $uuid->getFields()->getClockSeq()->toString());
$this->assertSame('0800200c9a66', $uuid->getFields()->getNode()->toString());
$this->assertSame('9669-0800200c9a66', substr($uuid->toString(), 19));
@@ -445,7 +450,7 @@ class UuidTest extends TestCase
$this->assertInstanceOf(DateTimeInterface::class, $uuid->getDateTime());
$this->assertSame(2, $uuid->getFields()->getVariant());
$this->assertSame(1, $uuid->getVersion());
$this->assertSame(1, $uuid->getFields()->getVersion());
$this->assertSame('00007160355e', $uuid->getFields()->getNode()->toString());
}
@@ -456,7 +461,7 @@ class UuidTest extends TestCase
$this->assertInstanceOf(DateTimeInterface::class, $uuid->getDateTime());
$this->assertSame(2, $uuid->getFields()->getVariant());
$this->assertSame(1, $uuid->getVersion());
$this->assertSame(1, $uuid->getFields()->getVersion());
$this->assertSame('00007160355e', $uuid->getFields()->getNode()->toString());
}
@@ -467,7 +472,7 @@ class UuidTest extends TestCase
$this->assertInstanceOf(DateTimeInterface::class, $uuid->getDateTime());
$this->assertSame(2, $uuid->getFields()->getVariant());
$this->assertSame(1, $uuid->getVersion());
$this->assertSame(1, $uuid->getFields()->getVersion());
$this->assertSame('000071b0ad5e', $uuid->getFields()->getNode()->toString());
}
@@ -503,7 +508,7 @@ class UuidTest extends TestCase
$uuid = Uuid::uuid1();
$this->assertInstanceOf(DateTimeInterface::class, $uuid->getDateTime());
$this->assertSame(2, $uuid->getFields()->getVariant());
$this->assertSame(1, $uuid->getVersion());
$this->assertSame(1, $uuid->getFields()->getVersion());
}
public function testUuid1WithUserGeneratedRandomNode(): void
@@ -512,7 +517,7 @@ class UuidTest extends TestCase
$uuid = Uuid::uuid1(new Hexadecimal((string) (new RandomNodeProvider())->getNode()));
$this->assertInstanceOf(DateTimeInterface::class, $uuid->getDateTime());
$this->assertSame(2, $uuid->getFields()->getVariant());
$this->assertSame(1, $uuid->getVersion());
$this->assertSame(1, $uuid->getFields()->getVersion());
}
public function testUuid6(): void
@@ -521,7 +526,7 @@ class UuidTest extends TestCase
$uuid = Uuid::uuid6();
$this->assertInstanceOf(DateTimeInterface::class, $uuid->getDateTime());
$this->assertSame(2, $uuid->getFields()->getVariant());
$this->assertSame(6, $uuid->getVersion());
$this->assertSame(6, $uuid->getFields()->getVersion());
}
public function testUuid6WithNodeAndClockSequence(): void
@@ -530,7 +535,7 @@ class UuidTest extends TestCase
$uuid = Uuid::uuid6(new Hexadecimal('0800200c9a66'), 0x1669);
$this->assertInstanceOf(DateTimeInterface::class, $uuid->getDateTime());
$this->assertSame(2, $uuid->getFields()->getVariant());
$this->assertSame(6, $uuid->getVersion());
$this->assertSame(6, $uuid->getFields()->getVersion());
$this->assertSame('1669', $uuid->getFields()->getClockSeq()->toString());
$this->assertSame('0800200c9a66', $uuid->getFields()->getNode()->toString());
$this->assertSame('9669-0800200c9a66', substr($uuid->toString(), 19));
@@ -543,7 +548,7 @@ class UuidTest extends TestCase
$this->assertInstanceOf(DateTimeInterface::class, $uuid->getDateTime());
$this->assertSame(2, $uuid->getFields()->getVariant());
$this->assertSame(6, $uuid->getVersion());
$this->assertSame(6, $uuid->getFields()->getVersion());
$this->assertSame('00007160355e', $uuid->getFields()->getNode()->toString());
}
@@ -554,7 +559,7 @@ class UuidTest extends TestCase
$this->assertInstanceOf(DateTimeInterface::class, $uuid->getDateTime());
$this->assertSame(2, $uuid->getFields()->getVariant());
$this->assertSame(6, $uuid->getVersion());
$this->assertSame(6, $uuid->getFields()->getVersion());
$this->assertSame('000071b0ad5e', $uuid->getFields()->getNode()->toString());
}
@@ -582,7 +587,7 @@ class UuidTest extends TestCase
$uuid = Uuid::uuid6();
$this->assertInstanceOf(DateTimeInterface::class, $uuid->getDateTime());
$this->assertSame(2, $uuid->getFields()->getVariant());
$this->assertSame(6, $uuid->getVersion());
$this->assertSame(6, $uuid->getFields()->getVersion());
}
public function testUuid6WithUserGeneratedRandomNode(): void
@@ -591,7 +596,7 @@ class UuidTest extends TestCase
$uuid = Uuid::uuid6(new Hexadecimal((string) (new RandomNodeProvider())->getNode()));
$this->assertInstanceOf(DateTimeInterface::class, $uuid->getDateTime());
$this->assertSame(2, $uuid->getFields()->getVariant());
$this->assertSame(6, $uuid->getVersion());
$this->assertSame(6, $uuid->getFields()->getVersion());
}
/**
@@ -614,7 +619,7 @@ class UuidTest extends TestCase
$uobj2 = Uuid::uuid3(Uuid::fromString($ns), $name);
$this->assertSame(2, $uobj1->getFields()->getVariant());
$this->assertSame(3, $uobj1->getVersion());
$this->assertSame(3, $uobj1->getFields()->getVersion());
$this->assertSame(Uuid::fromString($uuid)->toString(), $uobj1->toString());
$this->assertTrue($uobj1->equals($uobj2));
}
@@ -653,7 +658,7 @@ class UuidTest extends TestCase
/** @var \Ramsey\Uuid\Rfc4122\UuidInterface $uuid */
$uuid = Uuid::uuid4();
$this->assertSame(2, $uuid->getFields()->getVariant());
$this->assertSame(4, $uuid->getVersion());
$this->assertSame(4, $uuid->getFields()->getVersion());
}
/**
@@ -729,9 +734,10 @@ class UuidTest extends TestCase
$factory->setRandomGenerator($generator);
/** @var \Ramsey\Uuid\Rfc4122\UuidInterface $uuid */
$uuid = $factory->uuid4();
$this->assertSame(4, $uuid->getVersion());
$this->assertSame(4, $uuid->getFields()->getVersion());
}
/**
@@ -754,7 +760,7 @@ class UuidTest extends TestCase
$uobj2 = Uuid::uuid5(Uuid::fromString($ns), $name);
$this->assertSame(2, $uobj1->getFields()->getVariant());
$this->assertSame(5, $uobj1->getVersion());
$this->assertSame(5, $uobj1->getFields()->getVersion());
$this->assertSame(Uuid::fromString($uuid)->toString(), $uobj1->toString());
$this->assertTrue($uobj1->equals($uobj2));
}
@@ -1137,7 +1143,7 @@ class UuidTest extends TestCase
$this->assertSame($time, $uuid->getFields()->getTimestamp()->toString());
$this->assertSame($clockSeq, $uuid->getFields()->getClockSeq()->toString());
$this->assertSame($variant, $uuid->getFields()->getVariant());
$this->assertSame($version, $uuid->getVersion());
$this->assertSame($version, $uuid->getFields()->getVersion());
}
}
@@ -1511,8 +1517,9 @@ class UuidTest extends TestCase
*/
public function testUuidVersionConstantForVersion1(): void
{
/** @var \Ramsey\Uuid\Rfc4122\UuidInterface $uuid */
$uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66');
$this->assertSame($uuid->getVersion(), Uuid::UUID_TYPE_TIME);
$this->assertSame($uuid->getFields()->getVersion(), Uuid::UUID_TYPE_TIME);
}
/**
@@ -1520,8 +1527,9 @@ class UuidTest extends TestCase
*/
public function testUuidVersionConstantForVersion2(): void
{
/** @var \Ramsey\Uuid\Rfc4122\UuidInterface $uuid */
$uuid = Uuid::fromString('6fa459ea-ee8a-2ca4-894e-db77e160355e');
$this->assertSame($uuid->getVersion(), Uuid::UUID_TYPE_DCE_SECURITY);
$this->assertSame($uuid->getFields()->getVersion(), Uuid::UUID_TYPE_DCE_SECURITY);
}
/**
@@ -1529,8 +1537,9 @@ class UuidTest extends TestCase
*/
public function testUuidVersionConstantForVersion3(): void
{
/** @var \Ramsey\Uuid\Rfc4122\UuidInterface $uuid */
$uuid = Uuid::fromString('6fa459ea-ee8a-3ca4-894e-db77e160355e');
$this->assertSame($uuid->getVersion(), Uuid::UUID_TYPE_HASH_MD5);
$this->assertSame($uuid->getFields()->getVersion(), Uuid::UUID_TYPE_HASH_MD5);
}
/**
@@ -1538,8 +1547,9 @@ class UuidTest extends TestCase
*/
public function testUuidVersionConstantForVersion4(): void
{
/** @var \Ramsey\Uuid\Rfc4122\UuidInterface $uuid */
$uuid = Uuid::fromString('6fabf0bc-603a-42f2-925b-d9f779bd0032');
$this->assertSame($uuid->getVersion(), Uuid::UUID_TYPE_RANDOM);
$this->assertSame($uuid->getFields()->getVersion(), Uuid::UUID_TYPE_RANDOM);
}
/**
@@ -1547,14 +1557,16 @@ class UuidTest extends TestCase
*/
public function testUuidVersionConstantForVersion5(): void
{
/** @var \Ramsey\Uuid\Rfc4122\UuidInterface $uuid */
$uuid = Uuid::fromString('886313e1-3b8a-5372-9b90-0c9aee199e5d');
$this->assertSame($uuid->getVersion(), Uuid::UUID_TYPE_HASH_SHA1);
$this->assertSame($uuid->getFields()->getVersion(), Uuid::UUID_TYPE_HASH_SHA1);
}
public function testUuidVersionConstantForVersion6(): void
{
/** @var \Ramsey\Uuid\Rfc4122\UuidInterface $uuid */
$uuid = Uuid::fromString('886313e1-3b8a-6372-9b90-0c9aee199e5d');
$this->assertSame($uuid->getVersion(), Uuid::UUID_TYPE_PEABODY);
$this->assertSame($uuid->getFields()->getVersion(), Uuid::UUID_TYPE_PEABODY);
}
/**
@@ -56,7 +56,6 @@ final class UuidIsImmutable
$a->getDateTime(),
$a->getInteger(),
$a->getUrn(),
$a->getVersion(),
$a->toString(),
$a->__toString(),
$a->getFields(),