1515use Symfony \Bundle \FrameworkBundle \Translation \TranslationLoader ;
1616use Symfony \Component \Translation \MessageCatalogue ;
1717use Symfony \Component \Translation \MessageCatalogueInterface ;
18+ use Symfony \Component \Translation \Reader \TranslationReader ;
1819use Symfony \Component \Translation \Writer \TranslationWriter ;
1920use Translation \Common \Model \Message ;
2021use Translation \SymfonyStorage \FileStorage ;
@@ -27,7 +28,7 @@ class FileStorageTest extends TestCase
2728{
2829 public function testConstructor ()
2930 {
30- $ storage = new FileStorage (new TranslationWriter (), new TranslationLoader (), ['foo ' ]);
31+ $ storage = new FileStorage (new TranslationWriter (), $ this -> createTranslationLoader (), ['foo ' ]);
3132 $ this ->assertInstanceOf (FileStorage::class, $ storage );
3233 }
3334
@@ -44,7 +45,7 @@ public function testConstructorInvalidLoader()
4445 */
4546 public function testConstructorEmptyArray ()
4647 {
47- new FileStorage (new TranslationWriter (), new TranslationLoader (), []);
48+ new FileStorage (new TranslationWriter (), $ this -> createTranslationLoader (), []);
4849 }
4950
5051 public function testCreateNewCatalogue ()
@@ -61,7 +62,7 @@ public function testCreateNewCatalogue()
6162 ['path ' => 'foo ' , 'xliff_version ' => '2.0 ' ]
6263 );
6364
64- $ storage = new FileStorage ($ writer , new TranslationLoader (), ['foo ' ]);
65+ $ storage = new FileStorage ($ writer , $ this -> createTranslationLoader (), ['foo ' ]);
6566 $ storage ->create (new Message ('key ' , 'domain ' , 'en ' , 'Message ' ));
6667
6768 $ writer = $ this ->getMockBuilder (TranslationWriter::class)
@@ -76,7 +77,7 @@ public function testCreateNewCatalogue()
7677 ['path ' => 'bar ' , 'default_output_format ' => 'format ' , 'xliff_version ' => '2.0 ' ]
7778 );
7879
79- $ storage = new FileStorage ($ writer , new TranslationLoader (), ['bar ' ], ['default_output_format ' => 'format ' ]);
80+ $ storage = new FileStorage ($ writer , $ this -> createTranslationLoader (), ['bar ' ], ['default_output_format ' => 'format ' ]);
8081 $ storage ->create (new Message ('key ' , 'domain ' , 'en ' , 'Message ' ));
8182 }
8283
@@ -94,7 +95,7 @@ public function testCreateExistingCatalogue()
9495 ['path ' => $ this ->getFixturePath (), 'xliff_version ' => '2.0 ' ]
9596 );
9697
97- $ loader = new TranslationLoader ();
98+ $ loader = $ this -> createTranslationLoader ();
9899 $ loader ->addLoader ('xlf ' , new XliffLoader ());
99100 $ storage = new FileStorage ($ writer , $ loader , ['foo ' , $ this ->getFixturePath ()]);
100101
@@ -107,7 +108,7 @@ public function testGet()
107108 ->disableOriginalConstructor ()
108109 ->getMock ();
109110
110- $ loader = new TranslationLoader ();
111+ $ loader = $ this -> createTranslationLoader ();
111112 $ loader ->addLoader ('xlf ' , new XliffLoader ());
112113 $ storage = new FileStorage ($ writer , $ loader , [$ this ->getFixturePath ()]);
113114
@@ -137,7 +138,7 @@ public function testUpdate()
137138 ['path ' => $ this ->getFixturePath (), 'xliff_version ' => '2.0 ' ]
138139 );
139140
140- $ loader = new TranslationLoader ();
141+ $ loader = $ this -> createTranslationLoader ();
141142 $ loader ->addLoader ('xlf ' , new XliffLoader ());
142143 $ storage = new FileStorage ($ writer , $ loader , [$ this ->getFixturePath ()]);
143144
@@ -162,7 +163,7 @@ public function testDelete()
162163 ['path ' => $ this ->getFixturePath (), 'xliff_version ' => '2.0 ' ]
163164 );
164165
165- $ loader = new TranslationLoader ();
166+ $ loader = $ this -> createTranslationLoader ();
166167 $ loader ->addLoader ('xlf ' , new XliffLoader ());
167168 $ storage = new FileStorage ($ writer , $ loader , [$ this ->getFixturePath ()]);
168169
@@ -186,7 +187,7 @@ public function testImport()
186187 ['path ' => $ this ->getFixturePath (), 'xliff_version ' => '2.0 ' ]
187188 );
188189
189- $ loader = new TranslationLoader ();
190+ $ loader = $ this -> createTranslationLoader ();
190191 $ loader ->addLoader ('xlf ' , new XliffLoader ());
191192 $ storage = new FileStorage ($ writer , $ loader , [$ this ->getFixturePath ()]);
192193 $ catalogue = new MessageCatalogue ('en ' , ['messages ' => ['test_4711 ' => 'foobar ' ]]);
@@ -200,7 +201,7 @@ public function testExport()
200201 ->disableOriginalConstructor ()
201202 ->getMock ();
202203
203- $ loader = new TranslationLoader ();
204+ $ loader = $ this -> createTranslationLoader ();
204205 $ loader ->addLoader ('xlf ' , new XliffLoader ());
205206 $ storage = new FileStorage ($ writer , $ loader , [$ this ->getFixturePath ()]);
206207
@@ -222,4 +223,16 @@ private function getFixturePath()
222223 {
223224 return realpath (__DIR__ .'/../Fixtures/single-file ' );
224225 }
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+ }
225238}
0 commit comments