8
8
use Magento \Setup \Module \I18n \Context ;
9
9
use Magento \Setup \Module \I18n \Locale ;
10
10
use Magento \Setup \Module \I18n \Dictionary ;
11
+ use Magento \Setup \Module \I18n \Factory ;
11
12
use Magento \Setup \Module \I18n \Dictionary \Phrase ;
12
- use Magento \Setup \Module \I18n \Pack \Writer \File \AbstractFile ;
13
+ use Magento \Setup \Module \I18n \Pack \Writer \File \Csv ;
14
+ use Magento \Setup \Module \I18n \Dictionary \WriterInterface ;
13
15
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
14
16
15
- class AbstractFileTest extends \PHPUnit_Framework_TestCase
17
+ require_once __DIR__ . '/_files/ioMock.php ' ;
18
+
19
+ class CsvTest extends \PHPUnit_Framework_TestCase
16
20
{
17
21
/**
18
22
* @var Context|\PHPUnit_Framework_MockObject_MockObject
@@ -35,7 +39,12 @@ class AbstractFileTest extends \PHPUnit_Framework_TestCase
35
39
protected $ phraseMock ;
36
40
37
41
/**
38
- * @var AbstractFile|\PHPUnit_Framework_MockObject_MockObject
42
+ * @var Factory|\PHPUnit_Framework_MockObject_MockObject
43
+ */
44
+ protected $ factoryMock ;
45
+
46
+ /**
47
+ * @var Csv|\PHPUnit_Framework_MockObject_MockObject
39
48
*/
40
49
protected $ object ;
41
50
@@ -51,15 +60,16 @@ protected function setUp()
51
60
$ this ->localeMock = $ this ->getMock (Locale::class, [], [], '' , false , false );
52
61
$ this ->dictionaryMock = $ this ->getMock (Dictionary::class, [], [], '' , false , false );
53
62
$ this ->phraseMock = $ this ->getMock (Phrase::class, [], [], '' , false , false );
63
+ $ this ->factoryMock = $ this ->getMock (Factory::class, [], [], '' , false , false );
54
64
55
65
$ constructorArguments = $ objectManagerHelper ->getConstructArguments (
56
- AbstractFile::class,
57
- ['context ' => $ this ->contextMock ]
66
+ Csv::class,
67
+ [
68
+ 'context ' => $ this ->contextMock ,
69
+ 'factory ' => $ this ->factoryMock
70
+ ]
58
71
);
59
- $ this ->object = $ this ->getMockBuilder (AbstractFile::class)
60
- ->setMethods (['_createDirectoryIfNotExist ' , '_writeFile ' ])
61
- ->setConstructorArgs ($ constructorArguments )
62
- ->getMockForAbstractClass ();
72
+ $ this ->object = $ objectManagerHelper ->getObject (Csv::class, $ constructorArguments );
63
73
}
64
74
65
75
/**
@@ -73,11 +83,6 @@ public function testWriteDictionaryWithRuntimeException($contextType, $contextVa
73
83
{
74
84
$ this ->configureGeneralPhrasesMock ($ contextType , $ contextValue );
75
85
76
- $ this ->object ->expects ($ this ->never ())
77
- ->method ('_createDirectoryIfNotExist ' );
78
- $ this ->object ->expects ($ this ->never ())
79
- ->method ('_writeFile ' );
80
-
81
86
$ this ->object ->writeDictionary ($ this ->dictionaryMock , $ this ->localeMock );
82
87
}
83
88
@@ -105,11 +110,6 @@ public function testWriteDictionaryWithInvalidArgumentException()
105
110
106
111
$ this ->configureGeneralPhrasesMock ($ contextType , [$ contextValue ]);
107
112
108
- $ this ->object ->expects ($ this ->never ())
109
- ->method ('_createDirectoryIfNotExist ' );
110
- $ this ->object ->expects ($ this ->never ())
111
- ->method ('_writeFile ' );
112
-
113
113
$ this ->contextMock ->expects ($ this ->once ())
114
114
->method ('buildPathToLocaleDirectoryByContext ' )
115
115
->with ($ contextType , $ contextValue )
@@ -128,16 +128,16 @@ public function testWriteDictionaryWherePathIsNull()
128
128
129
129
$ this ->configureGeneralPhrasesMock ($ contextType , [$ contextValue ]);
130
130
131
- $ this ->object ->expects ($ this ->never ())
132
- ->method ('_createDirectoryIfNotExist ' );
133
- $ this ->object ->expects ($ this ->never ())
134
- ->method ('_writeFile ' );
135
-
136
131
$ this ->contextMock ->expects ($ this ->once ())
137
132
->method ('buildPathToLocaleDirectoryByContext ' )
138
133
->with ($ contextType , $ contextValue )
139
134
->willReturn (null );
140
135
136
+ $ this ->phraseMock ->expects ($ this ->never ())
137
+ ->method ('setContextType ' );
138
+ $ this ->phraseMock ->expects ($ this ->never ())
139
+ ->method ('setContextValue ' );
140
+
141
141
$ this ->object ->writeDictionary ($ this ->dictionaryMock , $ this ->localeMock );
142
142
}
143
143
@@ -151,33 +151,37 @@ public function testWriteDictionary()
151
151
$ path = '/some/path/ ' ;
152
152
$ phrase = 'Phrase ' ;
153
153
$ locale = 'en_EN ' ;
154
- $ fileExtension = 'csv ' ;
155
- $ file = $ path . $ locale . '. ' . $ fileExtension ;
154
+ $ file = $ path . $ locale . '. ' . Csv::FILE_EXTENSION ;
156
155
157
156
$ this ->configureGeneralPhrasesMock ($ contextType , [$ contextValue ]);
158
157
159
158
$ this ->phraseMock ->expects ($ this ->once ())
160
159
->method ('getPhrase ' )
161
160
->willReturn ($ phrase );
161
+ $ this ->phraseMock ->expects ($ this ->once ())
162
+ ->method ('setContextType ' )
163
+ ->with (null );
164
+ $ this ->phraseMock ->expects ($ this ->once ())
165
+ ->method ('setContextValue ' )
166
+ ->with (null );
162
167
$ this ->localeMock ->expects ($ this ->once ())
163
168
->method ('__toString ' )
164
169
->willReturn ($ locale );
165
170
166
- $ this ->object ->expects ($ this ->once ())
167
- ->method ('_getFileExtension ' )
168
- ->willReturn ($ fileExtension );
169
- $ this ->object ->expects ($ this ->once ())
170
- ->method ('_createDirectoryIfNotExist ' )
171
- ->with (dirname ($ file ));
172
- $ this ->object ->expects ($ this ->once ())
173
- ->method ('_writeFile ' )
174
- ->with ($ file , [$ phrase => $ this ->phraseMock ]);
175
-
176
171
$ this ->contextMock ->expects ($ this ->once ())
177
172
->method ('buildPathToLocaleDirectoryByContext ' )
178
173
->with ($ contextType , $ contextValue )
179
174
->willReturn ($ path );
180
175
176
+ $ writerMock = $ this ->getMockForAbstractClass (WriterInterface::class);
177
+ $ writerMock ->expects ($ this ->once ())
178
+ ->method ('write ' )
179
+ ->with ($ this ->phraseMock );
180
+ $ this ->factoryMock ->expects ($ this ->once ())
181
+ ->method ('createDictionaryWriter ' )
182
+ ->with ($ file )
183
+ ->willReturn ($ writerMock );
184
+
181
185
$ this ->object ->writeDictionary ($ this ->dictionaryMock , $ this ->localeMock );
182
186
}
183
187
0 commit comments