From 738792efa1feb761dc4e9d5b6d8da3f7298db33c Mon Sep 17 00:00:00 2001 From: Andrey Nikolaev Date: Fri, 25 Oct 2019 08:51:32 +0300 Subject: [PATCH 1/5] Add lib wrapper for UUID validation. --- app/etc/di.xml | 1 + .../DataObject/IdentityValidator.php | 23 +++++++++++++++++++ .../DataObject/IdentityValidatorInterface.php | 21 +++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 lib/internal/Magento/Framework/DataObject/IdentityValidator.php create mode 100644 lib/internal/Magento/Framework/DataObject/IdentityValidatorInterface.php diff --git a/app/etc/di.xml b/app/etc/di.xml index f8818de2af842..27b85f0a924c0 100644 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -167,6 +167,7 @@ + diff --git a/lib/internal/Magento/Framework/DataObject/IdentityValidator.php b/lib/internal/Magento/Framework/DataObject/IdentityValidator.php new file mode 100644 index 0000000000000..0aeb16dfbd9bd --- /dev/null +++ b/lib/internal/Magento/Framework/DataObject/IdentityValidator.php @@ -0,0 +1,23 @@ + Date: Sun, 27 Oct 2019 12:39:20 +0300 Subject: [PATCH 2/5] Declare strict types --- .../Magento/Framework/DataObject/IdentityValidator.php | 4 +++- .../Framework/DataObject/IdentityValidatorInterface.php | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/internal/Magento/Framework/DataObject/IdentityValidator.php b/lib/internal/Magento/Framework/DataObject/IdentityValidator.php index 0aeb16dfbd9bd..b17e04585531a 100644 --- a/lib/internal/Magento/Framework/DataObject/IdentityValidator.php +++ b/lib/internal/Magento/Framework/DataObject/IdentityValidator.php @@ -3,6 +3,8 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Framework\DataObject; use Ramsey\Uuid\Uuid; @@ -15,7 +17,7 @@ class IdentityValidator implements IdentityValidatorInterface /** * @inheritDoc */ - public function isValid($value) + public function isValid(string $value): bool { $isValid = Uuid::isValid($value); return $isValid; diff --git a/lib/internal/Magento/Framework/DataObject/IdentityValidatorInterface.php b/lib/internal/Magento/Framework/DataObject/IdentityValidatorInterface.php index fd8b835665baf..a1979721f0cc9 100644 --- a/lib/internal/Magento/Framework/DataObject/IdentityValidatorInterface.php +++ b/lib/internal/Magento/Framework/DataObject/IdentityValidatorInterface.php @@ -15,7 +15,7 @@ interface IdentityValidatorInterface * * @param string $value * - * @return string + * @return bool */ - public function isValid($value); + public function isValid(string $value): bool; } From bf87df0b47014a7c083ff8fd4a3f6b4e0c157a61 Mon Sep 17 00:00:00 2001 From: Andrey Nikolaev Date: Sun, 27 Oct 2019 17:59:07 +0300 Subject: [PATCH 3/5] Cover identity validator with integration tests --- .../DataObject/IdentityValidatorTest.php | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 dev/tests/integration/testsuite/Magento/Framework/DataObject/IdentityValidatorTest.php diff --git a/dev/tests/integration/testsuite/Magento/Framework/DataObject/IdentityValidatorTest.php b/dev/tests/integration/testsuite/Magento/Framework/DataObject/IdentityValidatorTest.php new file mode 100644 index 0000000000000..15f54ba01a795 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Framework/DataObject/IdentityValidatorTest.php @@ -0,0 +1,41 @@ +identityValidator = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->get(IdentityValidator::class); + } + + public function testIsValid() + { + $isValid = $this->identityValidator->isValid(self::VALID_UUID); + $this->assertEquals(true, $isValid); + } + + public function testIsNotValid() + { + $isValid = $this->identityValidator->isValid(self::INVALID_UUID); + $this->assertEquals(false, $isValid); + } + + public function testEmptyValue() + { + $isValid = $this->identityValidator->isValid(''); + $this->assertEquals(false, $isValid); + } +} From 897bb9f0d51683c35de2403647149b08b10fd7a8 Mon Sep 17 00:00:00 2001 From: Lyzun Oleksandr Date: Wed, 8 Jan 2020 17:25:31 +0100 Subject: [PATCH 4/5] Add Ramsey dependency --- lib/internal/Magento/Framework/composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/composer.json b/lib/internal/Magento/Framework/composer.json index dfbfb5a25debe..3b365232bfc63 100644 --- a/lib/internal/Magento/Framework/composer.json +++ b/lib/internal/Magento/Framework/composer.json @@ -39,7 +39,8 @@ "zendframework/zend-validator": "^2.6.0", "zendframework/zend-mail": "^2.9.0", "zendframework/zend-mime": "^2.5.0", - "guzzlehttp/guzzle": "^6.3.3" + "guzzlehttp/guzzle": "^6.3.3", + "ramsey/uuid": "~3.8.0" }, "archive": { "exclude": [ From 8273d77d778cbff64ac35dfb14a2181a9112799d Mon Sep 17 00:00:00 2001 From: Lyzun Oleksandr Date: Fri, 10 Jan 2020 16:10:33 +0100 Subject: [PATCH 5/5] Add Class description --- lib/internal/Magento/Framework/DataObject/IdentityValidator.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/internal/Magento/Framework/DataObject/IdentityValidator.php b/lib/internal/Magento/Framework/DataObject/IdentityValidator.php index b17e04585531a..e8c068a093cb5 100644 --- a/lib/internal/Magento/Framework/DataObject/IdentityValidator.php +++ b/lib/internal/Magento/Framework/DataObject/IdentityValidator.php @@ -11,6 +11,8 @@ /** * Class IdentityValidator + * + * Class for validating Uuid's */ class IdentityValidator implements IdentityValidatorInterface {