Skip to content
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

Add lib wrapper for UUID validation. #25285

Merged
merged 6 commits into from
Feb 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
ihor-sviziev marked this conversation as resolved.
Show resolved Hide resolved

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