Skip to content

Commit

Permalink
ENGCOM-6184: Add lib wrapper for UUID validation. #25285
Browse files Browse the repository at this point in the history
  • Loading branch information
slavvka authored Feb 9, 2020
2 parents a0ceb97 + a5b16b8 commit 5877e54
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
<preference for="Magento\Framework\EntityManager\MapperInterface" type="Magento\Framework\EntityManager\CompositeMapper"/>
<preference for="Magento\Framework\Console\CommandListInterface" type="Magento\Framework\Console\CommandList"/>
<preference for="Magento\Framework\DataObject\IdentityGeneratorInterface" type="Magento\Framework\DataObject\IdentityService" />
<preference for="Magento\Framework\DataObject\IdentityValidatorInterface" type="Magento\Framework\DataObject\IdentityValidator" />
<preference for="Magento\Framework\Serialize\SerializerInterface" type="Magento\Framework\Serialize\Serializer\Json" />
<preference for="Magento\Framework\App\Scope\ValidatorInterface" type="Magento\Framework\App\Scope\Validator"/>
<preference for="Magento\Framework\App\ScopeResolverInterface" type="Magento\Framework\App\ScopeResolver" />
Expand Down
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 lib/internal/Magento/Framework/DataObject/IdentityValidator.php
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;
}
}
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;
}
3 changes: 2 additions & 1 deletion lib/internal/Magento/Framework/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down

0 comments on commit 5877e54

Please sign in to comment.