Skip to content

Commit ed25c9c

Browse files
author
Yuri Kovsher
committed
MAGETWO-33062: Update dictionary search tool to support \Magento\Framework\Phrase
1 parent 22dba53 commit ed25c9c

File tree

7 files changed

+143
-16
lines changed

7 files changed

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

dev/tests/unit/testsuite/Magento/Tools/I18n/Parser/Adapter/Php/Tokenizer/PhraseCollectorTest.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,15 @@ public function testParseDataProvider()
113113
'file' => $file,
114114
'isEndOfLoopReturnValues' => [
115115
false, //before $phrase1
116-
false, //before =
117-
false, //before new \Magento\Framework\Phrase('Testing')
118-
false, //before ;
119-
false, //before $phrase2
120-
false, //before =
121-
false, //before __('More testing')
122-
false, //before ;
123-
true //end of loop
116+
false, //at $phrase1
117+
false, //at =
118+
false, //at new
119+
false, //at ;
120+
false, //at $phrase2
121+
false, //at =
122+
false, //at __
123+
false, //at ;
124+
true //after ;
124125
],
125126
'getNextRealTokenReturnValues' => [
126127
$this->createToken(false, false, false, false, '$phrase1'),
@@ -130,24 +131,26 @@ public function testParseDataProvider()
130131
$this->createToken(false, false, false, false, '$phrase2'),
131132
$this->createToken(false, false, false, false, '='),
132133
$this->createToken(true, false, false, false, '__', $line),
133-
$this->createToken(false, true, false, false, '(')
134+
$this->createToken(false, true, false, false, '('),
135+
$this->createToken(false, false, false, false, ';'),
136+
false
134137
],
135138
'getFunctionArgumentsTokensReturnValues' => [
136-
[[$this->createToken(false, false, false, true, 'Testing')]], // 'Testing')
137-
[[$this->createToken(false, false, false, true, 'More testing')]] // 'More testing')
139+
[[$this->createToken(false, false, false, true, '\'Testing\'')]], // 'Testing')
140+
[[$this->createToken(false, false, false, true, '\'More testing\'')]] // 'More testing')
138141
],
139142
'isMatchingClassReturnValues' => [
140143
true // \Magento\Framework\Phrase(
141144
],
142145
'result' => [
143146
[
144-
'phrase' => 'Testing',
147+
'phrase' => '\'Testing\'',
145148
'arguments' => 0,
146149
'file' => $file,
147150
'line' => $line
148151
],
149152
[
150-
'phrase' => 'More testing',
153+
'phrase' => '\'More testing\'',
151154
'arguments' => 0,
152155
'file' => $file,
153156
'line' => $line

dev/tests/unit/testsuite/Magento/Tools/I18n/Parser/Adapter/Php/TokenizerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ public function testIsEndOfLoop()
8181
//We have 27 total tokens in objectsCode.php file (excluding whitespaces)
8282
//So the isEndOfLoop function should return true after we pick 28th non-existent token
8383
for ($i = 0; $i < 28; $i += 1) {
84-
$this->assertEquals(false, $this->tokenizer->isEndOfLoop());
84+
$this->assertFalse($this->tokenizer->isEndOfLoop());
8585
$this->tokenizer->getNextRealToken();
8686
}
87-
$this->assertEquals(true, $this->tokenizer->isEndOfLoop());
87+
$this->assertTrue($this->tokenizer->isEndOfLoop());
8888
}
8989

9090
protected function parseFile()
9191
{
92-
$file = __DIR__.'/_files/objectsCode.php';
92+
$file = __DIR__.'/_files/objectsCode.php.txt';
9393
$this->tokenizer->parse($file);
9494
}
9595
}
Lines changed: 5 additions & 0 deletions
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();

0 commit comments

Comments
 (0)