-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Add lib wrapper for UUID validation. #25285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
magento-engcom-team
merged 6 commits into
magento:2.4-develop
from
nikolaevas:2.3-develop
Feb 9, 2020
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
738792e
Add lib wrapper for UUID validation.
nikolaevas 6bf9b7a
Declare strict types
nikolaevas bf87df0
Cover identity validator with integration tests
nikolaevas 2f25761
Merge branch '2.4-develop' into 2.3-develop
slavvka 897bb9f
Add Ramsey dependency
nuzil 8273d77
Add Class description
nuzil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
dev/tests/integration/testsuite/Magento/Framework/DataObject/IdentityValidatorTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Framework\DataObject; | ||
|
||
class IdentityValidatorTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
const VALID_UUID = 'fe563e12-cf9d-4faf-82cd-96e011b557b7'; | ||
const INVALID_UUID = 'abcdef'; | ||
|
||
/** | ||
* @var IdentityValidator | ||
*/ | ||
protected $identityValidator; | ||
|
||
protected function setUp() | ||
{ | ||
$this->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); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
lib/internal/Magento/Framework/DataObject/IdentityValidator.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Framework\DataObject; | ||
|
||
use Ramsey\Uuid\Uuid; | ||
|
||
/** | ||
* Class IdentityValidator | ||
* | ||
* Class for validating Uuid's | ||
*/ | ||
class IdentityValidator implements IdentityValidatorInterface | ||
{ | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public function isValid(string $value): bool | ||
{ | ||
$isValid = Uuid::isValid($value); | ||
return $isValid; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
lib/internal/Magento/Framework/DataObject/IdentityValidatorInterface.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Framework\DataObject; | ||
|
||
/** | ||
* Interface IdentityValidatorInterface | ||
*/ | ||
interface IdentityValidatorInterface | ||
{ | ||
/** | ||
* Checks if uuid is valid | ||
* | ||
* @param string $value | ||
* | ||
* @return bool | ||
*/ | ||
public function isValid(string $value): bool; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.