Skip to content

Commit 3b23563

Browse files
authored
Merge pull request #164 from magento-folks/bulk
[Folks] Asynchronous Operations Framework
2 parents 211c668 + c7a0782 commit 3b23563

File tree

8 files changed

+411
-11
lines changed

8 files changed

+411
-11
lines changed

app/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@
152152
<preference for="Cm\RedisSession\Handler\LoggerInterface" type="Magento\Framework\Session\SaveHandler\Redis\Logger"/>
153153
<preference for="Magento\Framework\EntityManager\MapperInterface" type="Magento\Framework\EntityManager\CompositeMapper"/>
154154
<preference for="Magento\Framework\Console\CommandListInterface" type="Magento\Framework\Console\CommandList"/>
155+
<preference for="Magento\Framework\DataObject\IdentityGeneratorInterface" type="Magento\Framework\DataObject\IdentityService" />
155156
<type name="Magento\Framework\Model\ResourceModel\Db\TransactionManager" shared="false" />
156157
<type name="Magento\Framework\Logger\Handler\Base">
157158
<arguments>

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@
6464
"ext-mbstring": "*",
6565
"ext-openssl": "*",
6666
"ext-zip": "*",
67-
"sjparkinson/static-review": "~4.1"
67+
"sjparkinson/static-review": "~4.1",
68+
"ramsey/uuid": "3.4"
6869
},
6970
"require-dev": {
7071
"phpunit/phpunit": "4.1.0",

composer.lock

Lines changed: 130 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/tests/static/framework/Magento/TestFramework/Inspection/WordsFinder.php

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ class WordsFinder
8686
*/
8787
protected $componentRegistrar;
8888

89+
/**
90+
* Map of phrase to exclude from the file content
91+
*
92+
* @var array
93+
*/
94+
private $exclude = [];
95+
8996
/**
9097
* @param string|array $configFiles
9198
* @param string $baseDir
@@ -172,11 +179,14 @@ protected function _extractWords(\SimpleXMLElement $configXml)
172179
* @param \SimpleXMLElement $configXml
173180
* @return \Magento\TestFramework\Inspection\WordsFinder
174181
* @throws \Magento\TestFramework\Inspection\Exception
182+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
183+
* @SuppressWarnings(PHPMD.NPathComplexity)
175184
*/
176185
protected function _extractWhitelist(\SimpleXMLElement $configXml)
177186
{
178187
// Load whitelist entries
179188
$whitelist = [];
189+
$exclude = [];
180190
$nodes = $configXml->xpath('//config/whitelist/item');
181191
foreach ($nodes as $node) {
182192
$path = $node->xpath('path');
@@ -203,8 +213,21 @@ protected function _extractWhitelist(\SimpleXMLElement $configXml)
203213
$words[] = (string)$wordNode;
204214
}
205215
}
206-
207216
$whitelist[$path] = $words;
217+
218+
$excludeNodes = $node->xpath('exclude');
219+
$excludes = [];
220+
if ($excludeNodes) {
221+
foreach ($excludeNodes as $extractNode) {
222+
$excludes[] = (string)$extractNode;
223+
}
224+
}
225+
226+
if (isset($exclude[$path])) {
227+
$exclude[$path] = array_merge($excludes, $exclude[$path]) ;
228+
} else {
229+
$exclude[$path] = $excludes;
230+
}
208231
}
209232

210233
// Merge with already present whitelist
@@ -214,7 +237,13 @@ protected function _extractWhitelist(\SimpleXMLElement $configXml)
214237
}
215238
$this->_whitelist[$newPath] = array_unique($newWords);
216239
}
217-
240+
241+
foreach ($exclude as $newPath => $newWords) {
242+
if (isset($this->exclude[$newPath])) {
243+
$newWords = array_merge($this->exclude[$newPath], $newWords);
244+
}
245+
$this->exclude[$newPath] = array_unique($newWords);
246+
}
218247
return $this;
219248
}
220249

@@ -254,12 +283,18 @@ public function findWords($file)
254283
* @param string $file
255284
* @return array
256285
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
286+
* @SuppressWarnings(PHPMD.NPathComplexity)
257287
*/
258288
protected function _findWords($file)
259289
{
260290
$checkContents = !$this->_isBinaryFile($file);
261291
$path = $this->getSearchablePath($file);
262292
$contents = $checkContents ? file_get_contents($file) : '';
293+
if (isset($this->exclude[$file]) && !empty($this->exclude[$file])) {
294+
foreach ($this->exclude[$file] as $stringToEliminate) {
295+
$contents = str_replace($stringToEliminate, "", $contents);
296+
}
297+
}
263298

264299
$foundWords = [];
265300
foreach ($this->_words as $word) {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\DataObject;
7+
8+
/**
9+
* Interface UuidInterface
10+
*/
11+
interface IdentityGeneratorInterface
12+
{
13+
/**
14+
* Generate id
15+
*
16+
* @return string
17+
**/
18+
public function generateId();
19+
20+
/**
21+
* Generate id for data
22+
*
23+
* @param string $data
24+
* @return string
25+
**/
26+
public function generateIdForData($data);
27+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\DataObject;
7+
8+
use Ramsey\Uuid\Uuid;
9+
10+
/**
11+
* Class IdentityService
12+
*/
13+
class IdentityService implements IdentityGeneratorInterface
14+
{
15+
/**
16+
* @var \Ramsey\Uuid\UuidFactoryInterface
17+
*/
18+
private $uuidFactory;
19+
20+
/**
21+
* IdentityService constructor.
22+
* @param \Ramsey\Uuid\UuidFactory $uuidFactory
23+
*/
24+
public function __construct(
25+
\Ramsey\Uuid\UuidFactory $uuidFactory
26+
) {
27+
$this->uuidFactory = $uuidFactory;
28+
}
29+
30+
/**
31+
* @inheritDoc
32+
*/
33+
public function generateId()
34+
{
35+
$uuid = $this->uuidFactory->uuid4();
36+
return $uuid->toString();
37+
}
38+
39+
/**
40+
* @inheritDoc
41+
*/
42+
public function generateIdForData($data)
43+
{
44+
$uuid = $this->uuidFactory->uuid3(Uuid::NAMESPACE_DNS, $data);
45+
return $uuid->toString();
46+
}
47+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\DataObject\Test\Unit;
8+
9+
use Ramsey\Uuid\Uuid;
10+
11+
class IdentityServiceTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @var \Magento\Framework\DataObject\IdentityService
15+
*/
16+
private $identityService;
17+
18+
/**
19+
* @var \PHPUnit_Framework_MockObject_MockObject
20+
*/
21+
private $ramseyFactoryMock;
22+
23+
/**
24+
* @var \PHPUnit_Framework_MockObject_MockObject
25+
*/
26+
private $uuidMock;
27+
28+
protected function setUp()
29+
{
30+
$this->ramseyFactoryMock = $this->getMock(\Ramsey\Uuid\UuidFactory::class, [], [], '', false);
31+
$this->uuidMock = $this->getMock(\Ramsey\Uuid\Uuid::class, [], [], '', false);
32+
$this->identityService = new \Magento\Framework\DataObject\IdentityService(
33+
$this->ramseyFactoryMock
34+
);
35+
}
36+
37+
public function testGenerateId()
38+
{
39+
$this->ramseyFactoryMock->expects($this->once())->method('uuid4')->willReturn($this->uuidMock);
40+
$this->uuidMock->expects($this->once())->method('toString')->willReturn('string');
41+
$this->assertEquals('string', $this->identityService->generateId());
42+
}
43+
44+
public function testGenerateIdForData()
45+
{
46+
$this->ramseyFactoryMock
47+
->expects($this->once())
48+
->method('uuid3')
49+
->with(Uuid::NAMESPACE_DNS, 'name')
50+
->willReturn($this->uuidMock);
51+
$this->uuidMock->expects($this->once())->method('toString')->willReturn('string');
52+
$this->assertEquals('string', $this->identityService->generateIdForData('name'));
53+
}
54+
}

0 commit comments

Comments
 (0)