Skip to content

Commit aaa9e01

Browse files
committed
Fix Unit Test.
1 parent b40d2b4 commit aaa9e01

File tree

1 file changed

+68
-72
lines changed

1 file changed

+68
-72
lines changed

app/code/Magento/Translation/Test/Unit/Model/Js/DataProviderTest.php

Lines changed: 68 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -3,95 +3,99 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Translation\Test\Unit\Model\Js;
89

910
use Magento\Framework\App\State;
1011
use Magento\Framework\App\Utility\Files;
11-
use Magento\Framework\Filesystem;
12+
use Magento\Framework\Component\ComponentRegistrar;
13+
use Magento\Framework\Component\DirSearch;
14+
use Magento\Framework\Filesystem\File\Read;
15+
use Magento\Framework\Filesystem\File\ReadFactory;
1216
use Magento\Framework\Filesystem\File\ReadInterface;
13-
use Magento\Translation\Model\Js\DataProvider;
14-
use Magento\Translation\Model\Js\Config;
1517
use Magento\Framework\Phrase\Renderer\Translate;
18+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
19+
use Magento\Translation\Model\Js\Config;
20+
use Magento\Translation\Model\Js\DataProvider as ModelDataProvider;
21+
use PHPUnit\Framework\TestCase;
22+
use PHPUnit_Framework_MockObject_MockObject as MockObject;
1623

1724
/**
1825
* Verify data provider translation
1926
*
2027
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2128
*/
22-
class DataProviderTest extends \PHPUnit\Framework\TestCase
29+
class DataProviderTest extends TestCase
2330
{
2431
/**
25-
* @var DataProvider
32+
* @var ModelDataProvider
2633
*/
27-
protected $model;
34+
private $model;
2835

2936
/**
30-
* @var State|\PHPUnit_Framework_MockObject_MockObject
37+
* @var State|MockObject
3138
*/
32-
protected $appStateMock;
39+
private $appStateMock;
3340

3441
/**
35-
* @var Config|\PHPUnit_Framework_MockObject_MockObject
42+
* @var Config|MockObject
3643
*/
37-
protected $configMock;
44+
private $configMock;
3845

3946
/**
40-
* @var Files|\PHPUnit_Framework_MockObject_MockObject
47+
* @var Files|MockObject
4148
*/
42-
protected $filesUtilityMock;
49+
private $filesUtilityMock;
4350

4451
/**
45-
* @var ReadInterface|\PHPUnit_Framework_MockObject_MockObject
52+
* @var ReadInterface|MockObject
4653
*/
47-
protected $fileReadMock;
54+
private $fileReadMock;
4855

4956
/**
50-
* @var Translate|\PHPUnit_Framework_MockObject_MockObject
57+
* @var Translate|MockObject
5158
*/
52-
protected $translateMock;
59+
private $translateMock;
5360

5461
/**
5562
* @inheritDoc
5663
*/
5764
protected function setUp()
5865
{
59-
$this->appStateMock = $this->createMock(\Magento\Framework\App\State::class);
60-
$this->configMock = $this->createMock(\Magento\Translation\Model\Js\Config::class);
61-
$this->filesUtilityMock = $this->createMock(\Magento\Framework\App\Utility\Files::class);
62-
$fileReadFactory = $this->createMock(\Magento\Framework\Filesystem\File\ReadFactory::class);
63-
$this->fileReadMock = $this->createMock(\Magento\Framework\Filesystem\File\Read::class);
64-
$this->translateMock = $this->createMock(\Magento\Framework\Phrase\Renderer\Translate::class);
66+
$this->appStateMock = $this->createMock(State::class);
67+
$this->configMock = $this->createMock(Config::class);
68+
$this->filesUtilityMock = $this->createMock(Files::class);
69+
$fileReadFactory = $this->createMock(ReadFactory::class);
70+
$this->fileReadMock = $this->createMock(Read::class);
71+
$this->translateMock = $this->createMock(Translate::class);
6572
$fileReadFactory->expects($this->atLeastOnce())
6673
->method('create')
6774
->willReturn($this->fileReadMock);
68-
$dirSearch = $this->createMock(\Magento\Framework\Component\DirSearch::class);
69-
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
75+
$dirSearch = $this->createMock(DirSearch::class);
76+
$objectManager = new ObjectManager($this);
7077
$this->model = $objectManager->getObject(
71-
\Magento\Translation\Model\Js\DataProvider::class,
78+
ModelDataProvider::class,
7279
[
7380
'appState' => $this->appStateMock,
7481
'config' => $this->configMock,
7582
'fileReadFactory' => $fileReadFactory,
7683
'translate' => $this->translateMock,
7784
'dirSearch' => $dirSearch,
7885
'filesUtility' => $this->filesUtilityMock,
79-
'componentRegistrar' =>
80-
$this->createMock(\Magento\Framework\Component\ComponentRegistrar::class)
86+
'componentRegistrar' => $this->createMock(ComponentRegistrar::class)
8187
]
8288
);
8389
}
8490

8591
/**
86-
* Verify data translate
92+
* Verify data translate.
8793
*
8894
* @param array $config
8995
* @return void
9096
* @dataProvider configDataProvider
91-
*
92-
* @throws \Magento\Framework\Exception\LocalizedException
9397
*/
94-
public function testGetData(array $config)
98+
public function testGetData(array $config): void
9599
{
96100
$themePath = 'blank';
97101
$areaCode = 'adminhtml';
@@ -140,14 +144,14 @@ public function testGetData(array $config)
140144
}
141145

142146
/**
143-
* Verify Get Data Throwing Exception
147+
* Verify get data throwing exception.
144148
*
145149
* @param array $config
146-
* @expectedException \Magento\Framework\Exception\LocalizedException
147-
*
150+
* @return void
148151
* @dataProvider configDataProvider
152+
* @expectedException \Magento\Framework\Exception\LocalizedException
149153
*/
150-
public function testGetDataThrowingException(array $config)
154+
public function testGetDataThrowingException(array $config): void
151155
{
152156
$themePath = 'blank';
153157
$areaCode = 'adminhtml';
@@ -156,7 +160,6 @@ public function testGetDataThrowingException(array $config)
156160
$this->fileReadMock->expects($this->once())
157161
->method('readAll')
158162
->willReturn('content1$.mage.__("hello1")content1');
159-
160163
$this->appStateMock->expects($this->once())
161164
->method('getAreaCode')
162165
->willReturn($areaCode);
@@ -166,11 +169,9 @@ public function testGetDataThrowingException(array $config)
166169
$this->filesUtilityMock->expects($this->any())
167170
->method('getStaticHtmlFiles')
168171
->willReturn(['test']);
169-
170172
$this->configMock->expects($this->any())
171173
->method('getPatterns')
172174
->willReturn($patterns);
173-
174175
$this->translateMock->expects($this->once())
175176
->method('render')
176177
->willThrowException(new \Exception('Test exception'));
@@ -179,47 +180,42 @@ public function testGetDataThrowingException(array $config)
179180
}
180181

181182
/**
182-
* Config Data Provider
183+
* Config data provider.
183184
*
184185
* @return array
185186
*/
186187
public function configDataProvider(): array
187188
{
188189
return [
189-
[
190-
[
191-
'patterns' => [
192-
'~\$\.mage\.__\(([\'"])(.+?)\1\)~',
193-
'~i18n\:\s*(["\'])(.*?)(?<!\\\)\1~',
194-
'~translate\=("\')([^\'].*?)\'\"~',
195-
'~(?s)\$t\(\s*([\'"])(\?\<translate\>.+?)(?<!\\\)\1\s*(*SKIP)\)(?s)~',
196-
'~translate args\=("|\'|"\'|\\\"\')([^\'].*?)(\'\\\"|\'"|\'|")~',
197-
],
198-
199-
'expectedResult' => [
200-
'hello1' => 'hello1translated',
201-
'hello2' => 'hello2translated',
202-
'hello3' => 'hello3translated',
203-
'hello4' => 'hello4translated'
204-
],
205-
206-
'contentsMap' =>
207-
[
208-
'content1$.mage.__("hello1")content1',
209-
'content2$.mage.__("hello2")content2',
210-
'content2$.mage.__("hello4")content4',
211-
'content2$.mage.__("hello3")content3',
212-
],
213-
214-
'translateMap' => [
215-
[['hello1'], [], 'hello1translated'],
216-
[['hello2'], [], 'hello2translated'],
217-
[['hello3'], [], 'hello3translated'],
218-
[['hello4'], [], 'hello4translated']
219-
]
190+
[
191+
[
192+
'patterns' => [
193+
'~\$\.mage\.__\(([\'"])(.+?)\1\)~',
194+
'~i18n\:\s*(["\'])(.*?)(?<!\\\)\1~',
195+
'~translate\=("\')([^\'].*?)\'\"~',
196+
'~(?s)\$t\(\s*([\'"])(\?\<translate\>.+?)(?<!\\\)\1\s*(*SKIP)\)(?s)~',
197+
'~translate args\=("|\'|"\'|\\\"\')([^\'].*?)(\'\\\"|\'"|\'|")~',
220198
],
221-
222-
]
199+
'expectedResult' => [
200+
'hello1' => 'hello1translated',
201+
'hello2' => 'hello2translated',
202+
'hello3' => 'hello3translated',
203+
'hello4' => 'hello4translated',
204+
],
205+
'contentsMap' => [
206+
'content1$.mage.__("hello1")content1',
207+
'content2$.mage.__("hello2")content2',
208+
'content2$.mage.__("hello4")content4',
209+
'content2$.mage.__("hello3")content3',
210+
],
211+
'translateMap' => [
212+
[['hello1'], [], 'hello1translated'],
213+
[['hello2'], [], 'hello2translated'],
214+
[['hello3'], [], 'hello3translated'],
215+
[['hello4'], [], 'hello4translated'],
216+
]
217+
],
218+
]
223219
];
224220
}
225221
}

0 commit comments

Comments
 (0)