From 65b0c091c036d42018abf02addd27b86d60f4dc8 Mon Sep 17 00:00:00 2001 From: Ben Ramsey Date: Fri, 21 Feb 2020 13:37:06 -0600 Subject: [PATCH] Deprecate VALID_PATTERN, UUID_TYPE_IDENTIFIER; suggest replacements --- CHANGELOG.md | 5 +++++ src/Rfc4122/UuidV2.php | 2 +- src/Uuid.php | 12 +++++++++++- tests/ExpectedBehaviorTest.php | 29 +++++++++++++++++++++++++++++ tests/FunctionsTest.php | 2 +- tests/UuidTest.php | 2 +- 6 files changed, 48 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4787274..0209d5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Deprecated +* `Uuid::UUID_TYPE_IDENTIFIER` is deprecated. Use `Uuid::UUID_TYPE_DCE_SECURITY` + instead. +* `Uuid::VALID_PATTERN` is deprecated. Use `Validator\GenericValidator::VALID_PATTERN` + instead. + ### Removed ### Fixed diff --git a/src/Rfc4122/UuidV2.php b/src/Rfc4122/UuidV2.php index 16477e8..6164d65 100644 --- a/src/Rfc4122/UuidV2.php +++ b/src/Rfc4122/UuidV2.php @@ -52,7 +52,7 @@ final class UuidV2 extends Uuid implements UuidInterface CodecInterface $codec, TimeConverterInterface $timeConverter ) { - if ($fields->getVersion() !== Uuid::UUID_TYPE_IDENTIFIER) { + if ($fields->getVersion() !== Uuid::UUID_TYPE_DCE_SECURITY) { throw new InvalidArgumentException( 'Fields used to create a UuidV2 must represent a ' . 'version 2 (DCE Security) UUID' diff --git a/src/Uuid.php b/src/Uuid.php index df3b6ed..7046d5d 100644 --- a/src/Uuid.php +++ b/src/Uuid.php @@ -111,6 +111,11 @@ class Uuid implements UuidInterface */ public const RESERVED_FUTURE = 7; + /** + * @deprecated Use {@see GenericValidator::VALID_PATTERN} instead. + */ + public const VALID_PATTERN = '^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$'; + /** * Version 1 (time-based) UUID * @@ -119,10 +124,15 @@ class Uuid implements UuidInterface public const UUID_TYPE_TIME = 1; /** - * Version 2 (identifier-based) UUID + * Version 2 (DCE Security) UUID * * @link https://tools.ietf.org/html/rfc4122#section-4.1.3 RFC 4122, ยง 4.1.3: Version */ + public const UUID_TYPE_DCE_SECURITY = 2; + + /** + * @deprecated Use {@see Uuid::UUID_TYPE_DCE_SECURITY} instead. + */ public const UUID_TYPE_IDENTIFIER = 2; /** diff --git a/tests/ExpectedBehaviorTest.php b/tests/ExpectedBehaviorTest.php index c0a70ca..cc3028f 100644 --- a/tests/ExpectedBehaviorTest.php +++ b/tests/ExpectedBehaviorTest.php @@ -624,4 +624,33 @@ class ExpectedBehaviorTest extends TestCase $this->assertSame($expectedBytes, $uuid->getBytes()); $this->assertSame($expectedHex, (string) $uuid->getHex()); } + + /** + * @dataProvider provideUuidConstantTests + */ + public function testUuidConstants($constantName, $expected) + { + $this->assertSame($expected, constant("Ramsey\\Uuid\\Uuid::{$constantName}")); + } + + public function provideUuidConstantTests() + { + return [ + ['NAMESPACE_DNS', '6ba7b810-9dad-11d1-80b4-00c04fd430c8'], + ['NAMESPACE_URL', '6ba7b811-9dad-11d1-80b4-00c04fd430c8'], + ['NAMESPACE_OID', '6ba7b812-9dad-11d1-80b4-00c04fd430c8'], + ['NAMESPACE_X500', '6ba7b814-9dad-11d1-80b4-00c04fd430c8'], + ['NIL', '00000000-0000-0000-0000-000000000000'], + ['RESERVED_NCS', 0], + ['RFC_4122', 2], + ['RESERVED_MICROSOFT', 6], + ['RESERVED_FUTURE', 7], + ['VALID_PATTERN', '^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$'], + ['UUID_TYPE_TIME', 1], + ['UUID_TYPE_IDENTIFIER', 2], + ['UUID_TYPE_HASH_MD5', 3], + ['UUID_TYPE_RANDOM', 4], + ['UUID_TYPE_HASH_SHA1', 5], + ]; + } } diff --git a/tests/FunctionsTest.php b/tests/FunctionsTest.php index 3ce838f..26d84c1 100644 --- a/tests/FunctionsTest.php +++ b/tests/FunctionsTest.php @@ -38,7 +38,7 @@ class FunctionsTest extends TestCase $fields = Uuid::fromString($v2)->getFields(); $this->assertIsString($v2); - $this->assertSame(Uuid::UUID_TYPE_IDENTIFIER, $fields->getVersion()); + $this->assertSame(Uuid::UUID_TYPE_DCE_SECURITY, $fields->getVersion()); } public function testV3ReturnsVersion3UuidString(): void diff --git a/tests/UuidTest.php b/tests/UuidTest.php index 24cdd88..4332c43 100644 --- a/tests/UuidTest.php +++ b/tests/UuidTest.php @@ -1440,7 +1440,7 @@ class UuidTest extends TestCase public function testUuidVersionConstantForVersion2(): void { $uuid = Uuid::fromString('6fa459ea-ee8a-2ca4-894e-db77e160355e'); - $this->assertEquals($uuid->getVersion(), Uuid::UUID_TYPE_IDENTIFIER); + $this->assertEquals($uuid->getVersion(), Uuid::UUID_TYPE_DCE_SECURITY); } /**