Skip to content

Commit a5b16b8

Browse files
ENGCOM-6184: Add lib wrapper for UUID validation. #25285
- Merge Pull Request #25285 from nikolaevas/magento2:2.3-develop - Merged commits: 1. 738792e 2. 6bf9b7a 3. bf87df0 4. 2f25761 5. 897bb9f 6. 8273d77
2 parents 5ad40fa + 8273d77 commit a5b16b8

File tree

5 files changed

+92
-1
lines changed

5 files changed

+92
-1
lines changed

app/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@
167167
<preference for="Magento\Framework\EntityManager\MapperInterface" type="Magento\Framework\EntityManager\CompositeMapper"/>
168168
<preference for="Magento\Framework\Console\CommandListInterface" type="Magento\Framework\Console\CommandList"/>
169169
<preference for="Magento\Framework\DataObject\IdentityGeneratorInterface" type="Magento\Framework\DataObject\IdentityService" />
170+
<preference for="Magento\Framework\DataObject\IdentityValidatorInterface" type="Magento\Framework\DataObject\IdentityValidator" />
170171
<preference for="Magento\Framework\Serialize\SerializerInterface" type="Magento\Framework\Serialize\Serializer\Json" />
171172
<preference for="Magento\Framework\App\Scope\ValidatorInterface" type="Magento\Framework\App\Scope\Validator"/>
172173
<preference for="Magento\Framework\App\ScopeResolverInterface" type="Magento\Framework\App\ScopeResolver" />
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\DataObject;
7+
8+
class IdentityValidatorTest extends \PHPUnit\Framework\TestCase
9+
{
10+
const VALID_UUID = 'fe563e12-cf9d-4faf-82cd-96e011b557b7';
11+
const INVALID_UUID = 'abcdef';
12+
13+
/**
14+
* @var IdentityValidator
15+
*/
16+
protected $identityValidator;
17+
18+
protected function setUp()
19+
{
20+
$this->identityValidator = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
21+
->get(IdentityValidator::class);
22+
}
23+
24+
public function testIsValid()
25+
{
26+
$isValid = $this->identityValidator->isValid(self::VALID_UUID);
27+
$this->assertEquals(true, $isValid);
28+
}
29+
30+
public function testIsNotValid()
31+
{
32+
$isValid = $this->identityValidator->isValid(self::INVALID_UUID);
33+
$this->assertEquals(false, $isValid);
34+
}
35+
36+
public function testEmptyValue()
37+
{
38+
$isValid = $this->identityValidator->isValid('');
39+
$this->assertEquals(false, $isValid);
40+
}
41+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\DataObject;
9+
10+
use Ramsey\Uuid\Uuid;
11+
12+
/**
13+
* Class IdentityValidator
14+
*
15+
* Class for validating Uuid's
16+
*/
17+
class IdentityValidator implements IdentityValidatorInterface
18+
{
19+
/**
20+
* @inheritDoc
21+
*/
22+
public function isValid(string $value): bool
23+
{
24+
$isValid = Uuid::isValid($value);
25+
return $isValid;
26+
}
27+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\DataObject;
7+
8+
/**
9+
* Interface IdentityValidatorInterface
10+
*/
11+
interface IdentityValidatorInterface
12+
{
13+
/**
14+
* Checks if uuid is valid
15+
*
16+
* @param string $value
17+
*
18+
* @return bool
19+
*/
20+
public function isValid(string $value): bool;
21+
}

lib/internal/Magento/Framework/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"zendframework/zend-validator": "^2.6.0",
4040
"zendframework/zend-mail": "^2.9.0",
4141
"zendframework/zend-mime": "^2.5.0",
42-
"guzzlehttp/guzzle": "^6.3.3"
42+
"guzzlehttp/guzzle": "^6.3.3",
43+
"ramsey/uuid": "~3.8.0"
4344
},
4445
"archive": {
4546
"exclude": [

0 commit comments

Comments
 (0)