15
15
use Symfony \Bundle \FrameworkBundle \Translation \TranslationLoader ;
16
16
use Symfony \Component \Translation \MessageCatalogue ;
17
17
use Symfony \Component \Translation \MessageCatalogueInterface ;
18
+ use Symfony \Component \Translation \Reader \TranslationReader ;
18
19
use Symfony \Component \Translation \Writer \TranslationWriter ;
19
20
use Translation \Common \Model \Message ;
20
21
use Translation \SymfonyStorage \FileStorage ;
@@ -27,7 +28,7 @@ class FileStorageTest extends TestCase
27
28
{
28
29
public function testConstructor ()
29
30
{
30
- $ storage = new FileStorage (new TranslationWriter (), new TranslationLoader (), ['foo ' ]);
31
+ $ storage = new FileStorage (new TranslationWriter (), $ this -> createTranslationLoader (), ['foo ' ]);
31
32
$ this ->assertInstanceOf (FileStorage::class, $ storage );
32
33
}
33
34
@@ -44,7 +45,7 @@ public function testConstructorInvalidLoader()
44
45
*/
45
46
public function testConstructorEmptyArray ()
46
47
{
47
- new FileStorage (new TranslationWriter (), new TranslationLoader (), []);
48
+ new FileStorage (new TranslationWriter (), $ this -> createTranslationLoader (), []);
48
49
}
49
50
50
51
public function testCreateNewCatalogue ()
@@ -61,7 +62,7 @@ public function testCreateNewCatalogue()
61
62
['path ' => 'foo ' , 'xliff_version ' => '2.0 ' ]
62
63
);
63
64
64
- $ storage = new FileStorage ($ writer , new TranslationLoader (), ['foo ' ]);
65
+ $ storage = new FileStorage ($ writer , $ this -> createTranslationLoader (), ['foo ' ]);
65
66
$ storage ->create (new Message ('key ' , 'domain ' , 'en ' , 'Message ' ));
66
67
67
68
$ writer = $ this ->getMockBuilder (TranslationWriter::class)
@@ -76,7 +77,7 @@ public function testCreateNewCatalogue()
76
77
['path ' => 'bar ' , 'default_output_format ' => 'format ' , 'xliff_version ' => '2.0 ' ]
77
78
);
78
79
79
- $ storage = new FileStorage ($ writer , new TranslationLoader (), ['bar ' ], ['default_output_format ' => 'format ' ]);
80
+ $ storage = new FileStorage ($ writer , $ this -> createTranslationLoader (), ['bar ' ], ['default_output_format ' => 'format ' ]);
80
81
$ storage ->create (new Message ('key ' , 'domain ' , 'en ' , 'Message ' ));
81
82
}
82
83
@@ -94,7 +95,7 @@ public function testCreateExistingCatalogue()
94
95
['path ' => $ this ->getFixturePath (), 'xliff_version ' => '2.0 ' ]
95
96
);
96
97
97
- $ loader = new TranslationLoader ();
98
+ $ loader = $ this -> createTranslationLoader ();
98
99
$ loader ->addLoader ('xlf ' , new XliffLoader ());
99
100
$ storage = new FileStorage ($ writer , $ loader , ['foo ' , $ this ->getFixturePath ()]);
100
101
@@ -107,7 +108,7 @@ public function testGet()
107
108
->disableOriginalConstructor ()
108
109
->getMock ();
109
110
110
- $ loader = new TranslationLoader ();
111
+ $ loader = $ this -> createTranslationLoader ();
111
112
$ loader ->addLoader ('xlf ' , new XliffLoader ());
112
113
$ storage = new FileStorage ($ writer , $ loader , [$ this ->getFixturePath ()]);
113
114
@@ -137,7 +138,7 @@ public function testUpdate()
137
138
['path ' => $ this ->getFixturePath (), 'xliff_version ' => '2.0 ' ]
138
139
);
139
140
140
- $ loader = new TranslationLoader ();
141
+ $ loader = $ this -> createTranslationLoader ();
141
142
$ loader ->addLoader ('xlf ' , new XliffLoader ());
142
143
$ storage = new FileStorage ($ writer , $ loader , [$ this ->getFixturePath ()]);
143
144
@@ -162,7 +163,7 @@ public function testDelete()
162
163
['path ' => $ this ->getFixturePath (), 'xliff_version ' => '2.0 ' ]
163
164
);
164
165
165
- $ loader = new TranslationLoader ();
166
+ $ loader = $ this -> createTranslationLoader ();
166
167
$ loader ->addLoader ('xlf ' , new XliffLoader ());
167
168
$ storage = new FileStorage ($ writer , $ loader , [$ this ->getFixturePath ()]);
168
169
@@ -186,7 +187,7 @@ public function testImport()
186
187
['path ' => $ this ->getFixturePath (), 'xliff_version ' => '2.0 ' ]
187
188
);
188
189
189
- $ loader = new TranslationLoader ();
190
+ $ loader = $ this -> createTranslationLoader ();
190
191
$ loader ->addLoader ('xlf ' , new XliffLoader ());
191
192
$ storage = new FileStorage ($ writer , $ loader , [$ this ->getFixturePath ()]);
192
193
$ catalogue = new MessageCatalogue ('en ' , ['messages ' => ['test_4711 ' => 'foobar ' ]]);
@@ -200,7 +201,7 @@ public function testExport()
200
201
->disableOriginalConstructor ()
201
202
->getMock ();
202
203
203
- $ loader = new TranslationLoader ();
204
+ $ loader = $ this -> createTranslationLoader ();
204
205
$ loader ->addLoader ('xlf ' , new XliffLoader ());
205
206
$ storage = new FileStorage ($ writer , $ loader , [$ this ->getFixturePath ()]);
206
207
@@ -222,4 +223,16 @@ private function getFixturePath()
222
223
{
223
224
return realpath (__DIR__ .'/../Fixtures/single-file ' );
224
225
}
226
+
227
+ /**
228
+ * @return TranslationLoader|TranslationReader
229
+ */
230
+ private function createTranslationLoader ()
231
+ {
232
+ if (class_exists (TranslationReader::class)) {
233
+ return new TranslationReader ();
234
+ }
235
+
236
+ return new TranslationLoader ();
237
+ }
225
238
}
0 commit comments