Skip to content

Commit 3248d45

Browse files
author
Yuri Kovsher
committed
Merge remote-tracking branch 'tango-ce/MAGETWO-33063' into MAGETWO-32571
2 parents b225f47 + 643187a commit 3248d45

File tree

44 files changed

+873
-223
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+873
-223
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Test\Tools\I18n\Parser\Adapter\Php\Tokenizer;
7+
8+
use Magento\Framework\ObjectManager;
9+
use Magento\TestFramework\Helper\Bootstrap;
10+
use Magento\Tools\I18n\Parser\Adapter\Php\Tokenizer\PhraseCollector;
11+
12+
/**
13+
* @covers \Magento\Tools\I18n\Parser\Adapter\Php\Tokenizer\PhraseCollector
14+
*/
15+
class PhraseCollectorTest extends \PHPUnit_Framework_TestCase
16+
{
17+
/**
18+
* @var PhraseCollector
19+
*/
20+
protected $phraseCollector;
21+
22+
/**
23+
* @var ObjectManager
24+
*/
25+
protected $objectManager;
26+
27+
protected function setUp()
28+
{
29+
$this->objectManager = Bootstrap::getObjectManager();
30+
$this->phraseCollector = $this->objectManager->create(
31+
'Magento\\Tools\\I18n\\Parser\\Adapter\\Php\\Tokenizer\\PhraseCollector'
32+
);
33+
}
34+
35+
/**
36+
* @covers \Magento\Tools\I18n\Parser\Adapter\Php\Tokenizer\PhraseCollector::parse
37+
*/
38+
public function testParse()
39+
{
40+
$file = __DIR__.'/_files/objectsCode.php.txt';
41+
$this->phraseCollector->setIncludeObjects();
42+
$this->phraseCollector->parse($file);
43+
$expectation = [
44+
[
45+
'phrase' => '\'Testing\'',
46+
'arguments' => 0,
47+
'file' => $file,
48+
'line' => 3
49+
],
50+
[
51+
'phrase' => '\'More testing\'',
52+
'arguments' => 0,
53+
'file' => $file,
54+
'line' => 4
55+
]
56+
];
57+
$this->assertEquals($expectation, $this->phraseCollector->getPhrases());
58+
}
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Test\Tools\I18n\Parser\Adapter\Php\Tokenizer\Translate;
7+
8+
use Magento\Framework\ObjectManager;
9+
use Magento\TestFramework\Helper\Bootstrap;
10+
use Magento\Tools\I18n\Parser\Adapter\Php\Tokenizer\Translate\MethodCollector;
11+
12+
/**
13+
* @covers \Magento\Tools\I18n\Parser\Adapter\Php\Tokenizer\Translate\MethodCollector
14+
*/
15+
class MethodCollectorTest extends \PHPUnit_Framework_TestCase
16+
{
17+
/**
18+
* @var MethodCollector
19+
*/
20+
protected $methodCollector;
21+
22+
/**
23+
* @var ObjectManager
24+
*/
25+
protected $objectManager;
26+
27+
protected function setUp()
28+
{
29+
$this->objectManager = Bootstrap::getObjectManager();
30+
$this->methodCollector = $this->objectManager->create(
31+
'Magento\\Tools\\I18n\\Parser\\Adapter\\Php\\Tokenizer\\Translate\\MethodCollector'
32+
);
33+
}
34+
35+
/**
36+
* @covers \Magento\Tools\I18n\Parser\Adapter\Php\Tokenizer\Translate\MethodCollector::parse
37+
*/
38+
public function testParse()
39+
{
40+
$file = __DIR__.'/../_files/methodsCode.php.txt';
41+
$this->methodCollector->parse($file);
42+
$expectation = [
43+
[
44+
'phrase' => '\'Some string\'',
45+
'arguments' => 0,
46+
'file' => $file,
47+
'line' => 4
48+
],
49+
[
50+
'phrase' => '\'One more string\'',
51+
'arguments' => 0,
52+
'file' => $file,
53+
'line' => 5
54+
]
55+
];
56+
$this->assertEquals($expectation, $this->methodCollector->getPhrases());
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
$obj1->___toString('Irrelevant string');
4+
$obj2->__('Some string');
5+
$obj3->__('One more string');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
new \Magento\Framework\Phrase('Testing');
4+
new Phrase('More testing');
5+
new \Magento\Framework\Object();

dev/tests/static/testsuite/Magento/Test/Integrity/Library/DependencyTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Test\Integrity\Library;
77

88
use Magento\Framework\Test\Utility\Files;
9+
use Magento\Framework\Test\Utility\AggregateInvoker;
910
use Magento\TestFramework\Integrity\Library\Injectable;
1011
use Magento\TestFramework\Integrity\Library\PhpParser\ParserFactory;
1112
use Magento\TestFramework\Integrity\Library\PhpParser\Tokens;
@@ -67,6 +68,27 @@ function ($file) {
6768
);
6869
}
6970

71+
public function testAppCodeUsage()
72+
{
73+
$files = Files::init();
74+
$path = $files->getPathToSource();
75+
$invoker = new AggregateInvoker($this);
76+
$invoker(
77+
function ($file) use ($path) {
78+
$content = file_get_contents($file);
79+
if (strpos($file, $path . '/lib/') === 0) {
80+
$this->assertSame(
81+
0,
82+
preg_match('~(?<![a-z\\d_:]|->|function\\s)__\\s*\\(~iS', $content),
83+
'Function __() is defined outside of the library and must not be used there. ' .
84+
'Replacement suggestion: new \\Magento\\Framework\\Phrase()'
85+
);
86+
}
87+
},
88+
$files->getPhpFiles(false, true, false)
89+
);
90+
}
91+
7092
/**
7193
* @inheritdoc
7294
*/

0 commit comments

Comments
 (0)