2020use Symfony \Component \Form \FormFactoryInterface ;
2121use Symfony \Component \Form \Forms ;
2222use Symfony \Component \Translation \Translator ;
23+ use Symfony \Component \Translation \TranslatorInterface as LegacyTranslatorInterface ;
2324use Symfony \Component \Validator \Constraints \Length ;
2425use Symfony \Component \Validator \Validation ;
26+ use Symfony \Contracts \Translation \TranslatorInterface ;
2527
2628class FormErrorHandlerTest extends TestCase
2729{
@@ -145,7 +147,11 @@ public function testSerializeChildElements()
145147 public function testDefaultTranslationDomain ()
146148 {
147149 /** @var Translator|\PHPUnit_Framework_MockObject_MockObject $translator */
148- $ translator = $ this ->getMockBuilder ('Symfony\Component\Translation\TranslatorInterface ' )->getMock ();
150+
151+ $ interface = interface_exists (TranslatorInterface::class)
152+ ? TranslatorInterface::class
153+ : LegacyTranslatorInterface::class;
154+ $ translator = $ this ->getMockBuilder ($ interface )->getMock ();
149155
150156 $ handler = new FormErrorHandler ($ translator );
151157
@@ -168,18 +174,31 @@ public function testDefaultTranslationDomain()
168174 public function testDefaultTranslationDomainWithPluralTranslation ()
169175 {
170176 /** @var Translator|\PHPUnit_Framework_MockObject_MockObject $translator */
171- $ translator = $ this ->getMockBuilder ('Symfony\Component\Translation\TranslatorInterface ' )->getMock ();
177+ $ interface = interface_exists (TranslatorInterface::class)
178+ ? TranslatorInterface::class
179+ : LegacyTranslatorInterface::class;
180+ $ translator = $ this ->getMockBuilder ($ interface )->getMock ();
172181
173182 $ handler = new FormErrorHandler ($ translator );
174183
175- $ translator ->expects ($ this ->once ())
176- ->method ('transChoice ' )
177- ->with (
178- $ this ->equalTo ('error! ' ),
179- $ this ->equalTo (0 ),
180- $ this ->equalTo ([]),
181- $ this ->equalTo ('validators ' )
182- );
184+ if (TranslatorInterface::class === $ interface ) {
185+ $ translator ->expects ($ this ->once ())
186+ ->method ('trans ' )
187+ ->with (
188+ $ this ->equalTo ('error! ' ),
189+ $ this ->equalTo (['%count% ' => 0 ]),
190+ $ this ->equalTo ('validators ' )
191+ );
192+ } else {
193+ $ translator ->expects ($ this ->once ())
194+ ->method ('transChoice ' )
195+ ->with (
196+ $ this ->equalTo ('error! ' ),
197+ $ this ->equalTo (0 ),
198+ $ this ->equalTo ([]),
199+ $ this ->equalTo ('validators ' )
200+ );
201+ }
183202
184203 $ formError = $ this ->getMockBuilder ('Symfony\Component\Form\FormError ' )->disableOriginalConstructor ()->getMock ();
185204 $ formError ->expects ($ this ->once ())->method ('getMessageTemplate ' )->willReturn ('error! ' );
@@ -192,7 +211,10 @@ public function testDefaultTranslationDomainWithPluralTranslation()
192211 public function testCustomTranslationDomain ()
193212 {
194213 /** @var Translator|\PHPUnit_Framework_MockObject_MockObject $translator */
195- $ translator = $ this ->getMockBuilder ('Symfony\Component\Translation\TranslatorInterface ' )->getMock ();
214+ $ interface = interface_exists (TranslatorInterface::class)
215+ ? TranslatorInterface::class
216+ : LegacyTranslatorInterface::class;
217+ $ translator = $ this ->getMockBuilder ($ interface )->getMock ();
196218
197219 $ handler = new FormErrorHandler ($ translator , 'custom_domain ' );
198220
@@ -216,17 +238,31 @@ public function testCustomTranslationDomainWithPluralTranslation()
216238 {
217239 /** @var Translator|\PHPUnit_Framework_MockObject_MockObject $translator */
218240 $ translator = $ this ->getMockBuilder ('Symfony\Component\Translation\TranslatorInterface ' )->getMock ();
241+ $ interface = interface_exists (TranslatorInterface::class)
242+ ? TranslatorInterface::class
243+ : LegacyTranslatorInterface::class;
244+ $ translator = $ this ->getMockBuilder ($ interface )->getMock ();
219245
220246 $ handler = new FormErrorHandler ($ translator , 'custom_domain ' );
221247
222- $ translator ->expects ($ this ->once ())
223- ->method ('transChoice ' )
224- ->with (
225- $ this ->equalTo ('error! ' ),
226- $ this ->equalTo (0 ),
227- $ this ->equalTo ([]),
228- $ this ->equalTo ('custom_domain ' )
229- );
248+ if (TranslatorInterface::class === $ interface ) {
249+ $ translator ->expects ($ this ->once ())
250+ ->method ('trans ' )
251+ ->with (
252+ $ this ->equalTo ('error! ' ),
253+ $ this ->equalTo (['%count% ' => 0 ]),
254+ $ this ->equalTo ('custom_domain ' )
255+ );
256+ } else {
257+ $ translator ->expects ($ this ->once ())
258+ ->method ('transChoice ' )
259+ ->with (
260+ $ this ->equalTo ('error! ' ),
261+ $ this ->equalTo (0 ),
262+ $ this ->equalTo ([]),
263+ $ this ->equalTo ('custom_domain ' )
264+ );
265+ }
230266
231267 $ formError = $ this ->getMockBuilder ('Symfony\Component\Form\FormError ' )->disableOriginalConstructor ()->getMock ();
232268 $ formError ->expects ($ this ->once ())->method ('getMessageTemplate ' )->willReturn ('error! ' );
0 commit comments