-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENGCOM-6184: Add lib wrapper for UUID validation. #25285
- Loading branch information
Showing
5 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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 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 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