1212namespace Translation \SymfonyStorage \Tests \Unit ;
1313
1414use Symfony \Bundle \FrameworkBundle \Translation \TranslationLoader ;
15+ use Symfony \Component \Translation \MessageCatalogueInterface ;
1516use Symfony \Component \Translation \Writer \TranslationWriter ;
17+ use Translation \Common \Model \Message ;
1618use Translation \SymfonyStorage \FileStorage ;
19+ use Translation \SymfonyStorage \Loader \XliffLoader ;
1720
1821/**
1922 * @author Tobias Nyholm <tobias.nyholm@gmail.com>
@@ -40,4 +43,58 @@ public function testConstructorEmptyArray()
4043 {
4144 new FileStorage (new TranslationWriter (), new TranslationLoader (), []);
4245 }
46+
47+ public function testCreateNewCatalogue ()
48+ {
49+ $ writer = $ this ->getMockBuilder (TranslationWriter::class)
50+ ->setMethods (['writeTranslations ' ])
51+ ->disableOriginalConstructor ()
52+ ->getMock ();
53+ $ writer ->expects ($ this ->once ())
54+ ->method ('writeTranslations ' )
55+ ->with (
56+ $ this ->isInstanceOf (MessageCatalogueInterface::class),
57+ 'xlf ' ,
58+ ['path ' => 'foo ' ]
59+ );
60+
61+ $ storage = new FileStorage ($ writer , new TranslationLoader (), ['foo ' ]);
62+ $ storage ->create (new Message ('key ' , 'domain ' , 'en ' , 'Message ' ));
63+
64+ $ writer = $ this ->getMockBuilder (TranslationWriter::class)
65+ ->setMethods (['writeTranslations ' ])
66+ ->disableOriginalConstructor ()
67+ ->getMock ();
68+ $ writer ->expects ($ this ->once ())
69+ ->method ('writeTranslations ' )
70+ ->with (
71+ $ this ->isInstanceOf (MessageCatalogueInterface::class),
72+ 'format ' ,
73+ ['path ' => 'bar ' , 'default_output_format ' => 'format ' ]
74+ );
75+
76+ $ storage = new FileStorage ($ writer , new TranslationLoader (), ['bar ' ], ['default_output_format ' => 'format ' ]);
77+ $ storage ->create (new Message ('key ' , 'domain ' , 'en ' , 'Message ' ));
78+ }
79+
80+ public function testCreateExistingCatalogue ()
81+ {
82+ $ writer = $ this ->getMockBuilder (TranslationWriter::class)
83+ ->setMethods (['writeTranslations ' ])
84+ ->disableOriginalConstructor ()
85+ ->getMock ();
86+ $ writer ->expects ($ this ->once ())
87+ ->method ('writeTranslations ' )
88+ ->with (
89+ $ this ->isInstanceOf (MessageCatalogueInterface::class),
90+ 'xlf ' ,
91+ ['path ' => __DIR__ ]
92+ );
93+
94+ $ loader = new TranslationLoader ();
95+ $ loader ->addLoader ('xlf ' , new XliffLoader ());
96+ $ storage = new FileStorage ($ writer , $ loader , ['foo ' , __DIR__ ]);
97+
98+ $ storage ->create (new Message ('key ' , 'messages ' , 'en ' , 'Translation ' ));
99+ }
43100}
0 commit comments