@@ -44,6 +44,11 @@ class ParamFetcherTest extends \PHPUnit_Framework_TestCase
4444 */
4545 private $ validator ;
4646
47+ /**
48+ * @var string
49+ */
50+ private $ validatorMethod ;
51+
4752 /**
4853 * @var \PHPUnit_Framework_MockObject_MockObject
4954 */
@@ -143,7 +148,14 @@ public function setup()
143148 ->method ('read ' )
144149 ->will ($ this ->returnValue ($ annotations ));
145150
146- $ this ->validator = $ this ->getMock ('Symfony\Component\Validator\ValidatorInterface ' );
151+ if (interface_exists ('Symfony\Component\Validator\Validator\ValidatorInterface ' )) {
152+ $ this ->validator = $ this ->getMock ('Symfony\Component\Validator\Validator\ValidatorInterface ' );
153+ $ this ->validatorMethod = 'validate ' ;
154+ } else {
155+ $ this ->validator = $ this ->getMock ('Symfony\Component\Validator\ValidatorInterface ' );
156+ $ this ->validatorMethod = 'validateValue ' ;
157+ }
158+
147159 $ this ->violationFormatter = $ this ->getMock ('FOS\RestBundle\Util\ViolationFormatterInterface ' );
148160 }
149161
@@ -188,7 +200,7 @@ public function testValidatesConfiguredParam($param, $expected, $expectedAll, $q
188200 if (null !== $ callback ) {
189201 $ self = $ this ;
190202 $ validator = $ this ->validator ;
191- $ callback ($ validator , $ self );
203+ $ callback ($ validator , $ this -> validatorMethod , $ self );
192204 }
193205
194206 $ queryFetcher = $ this ->getParamFetcher ($ query , $ request );
@@ -226,17 +238,17 @@ public static function validatesConfiguredParamDataProvider()
226238 array ('foo ' => '1 ' , 'bar ' => '1 ' , 'baz ' => '4 ' , 'buzz ' => array (1 ), 'boo ' => array (), 'boozz ' => null , 'biz ' => null , 'arr ' => array (), 'arr_null_strict ' => array (), 'moo ' => null , 'i_cant_be_with_moo ' => null ),
227239 array ('foo ' => 'bar ' ),
228240 array ('bar ' => '1 ' , 'baz ' => '4 ' , 'arr ' => array ()),
229- function (\PHPUnit_Framework_MockObject_MockObject $ validator , \PHPUnit_Framework_TestCase $ self ) {
241+ function (\PHPUnit_Framework_MockObject_MockObject $ validator , $ validatorMethod , \PHPUnit_Framework_TestCase $ self ) {
230242 $ errors = new ConstraintViolationList (array (
231243 new ConstraintViolation ('expected error ' , null , array (), null , null , null ),
232244 ));
233245
234246 $ validator ->expects ($ self ->at (0 ))
235- ->method (' validateValue ' )
247+ ->method ($ validatorMethod )
236248 ->with ('bar ' , new Regex (array ('pattern ' => '#^ \\d+$#xsu ' , 'message ' => "Query parameter value 'bar', does not match requirements ' \\d+' " )), null )
237249 ->will ($ self ->returnValue ($ errors ));
238250 $ validator ->expects ($ self ->at (1 ))
239- ->method (' validateValue ' )
251+ ->method ($ validatorMethod )
240252 ->with ('bar ' , new Regex (array ('pattern ' => '#^ \\d+$#xsu ' , 'message ' => "Query parameter value 'bar', does not match requirements ' \\d+' " )), null )
241253 ->will ($ self ->returnValue ($ errors ));
242254
@@ -277,18 +289,18 @@ function (\PHPUnit_Framework_MockObject_MockObject $validator, \PHPUnit_Framewor
277289 array ('foo ' => '1 ' , 'bar ' => '1 ' , 'baz ' => '4 ' , 'buzz ' => array (2 , 1 , 4 ), 'boo ' => array (), 'boozz ' => null , 'biz ' => null , 'arr ' => array (), 'arr_null_strict ' => array (), 'moo ' => null , 'i_cant_be_with_moo ' => null ),
278290 array ('buzz ' => array (2 , 'invaliddata ' , 4 )),
279291 array ('bar ' => '1 ' , 'baz ' => '4 ' , 'arr ' => array ()),
280- function (\PHPUnit_Framework_MockObject_MockObject $ validator , \PHPUnit_Framework_TestCase $ self ) {
292+ function (\PHPUnit_Framework_MockObject_MockObject $ validator , $ validatorMethod , \PHPUnit_Framework_TestCase $ self ) {
281293 $ errors = new ConstraintViolationList (array (
282294 new ConstraintViolation ('expected error ' , null , array (), null , null , null ),
283295 ));
284296
285297 $ validator ->expects ($ self ->at (1 ))
286- ->method (' validateValue ' )
298+ ->method ($ validatorMethod )
287299 ->with ('invaliddata ' , new Regex (array ('pattern ' => '#^ \\d+$#xsu ' , 'message ' => "Query parameter value 'invaliddata', does not match requirements ' \\d+' " )), null )
288300 ->will ($ self ->returnValue ($ errors ));
289301
290302 $ validator ->expects ($ self ->at (6 ))
291- ->method (' validateValue ' )
303+ ->method ($ validatorMethod )
292304 ->with ('invaliddata ' , new Regex (array ('pattern ' => '#^ \\d+$#xsu ' , 'message ' => "Query parameter value 'invaliddata', does not match requirements ' \\d+' " )), null )
293305 ->will ($ self ->returnValue ($ errors ));
294306 },
@@ -369,7 +381,7 @@ public function testValidatesConfiguredParamStrictly()
369381 ));
370382
371383 $ this ->validator ->expects ($ this ->once ())
372- ->method (' validateValue ' )
384+ ->method ($ this -> validatorMethod )
373385 ->with ('354 ' , $ constraint )
374386 ;
375387
@@ -400,7 +412,7 @@ public function testExceptionOnValidatesFailure($query, $request, $param, \Closu
400412 if (null !== $ callback ) {
401413 $ self = $ this ;
402414 $ validator = $ this ->validator ;
403- $ callback ($ validator , $ self );
415+ $ callback ($ validator , $ this -> validatorMethod , $ self );
404416 }
405417
406418 $ queryFetcher = $ this ->getParamFetcher ($ query , $ request );
@@ -448,18 +460,18 @@ public static function exceptionOnValidatesFailureDataProvider()
448460 array (),
449461 array ('bar ' => 'foo ' ),
450462 'bar ' ,
451- function (\PHPUnit_Framework_MockObject_MockObject $ validator , \PHPUnit_Framework_TestCase $ self ) {
463+ function (\PHPUnit_Framework_MockObject_MockObject $ validator , $ validatorMethod , \PHPUnit_Framework_TestCase $ self ) {
452464 $ errors = new ConstraintViolationList (array (
453465 new ConstraintViolation ('expected error ' , null , array (), null , null , null ),
454466 ));
455467
456468 $ validator ->expects ($ self ->at (0 ))
457- ->method (' validateValue ' )
469+ ->method ($ validatorMethod )
458470 ->with ('foo ' , new Regex (array ('pattern ' => '#^ \\d+$#xsu ' , 'message ' => "Request parameter value 'foo', does not match requirements ' \\d+' " )), null )
459471 ->will ($ self ->returnValue ($ errors ));
460472
461473 $ validator ->expects ($ self ->at (1 ))
462- ->method (' validateValue ' )
474+ ->method ($ validatorMethod )
463475 ->with ('foo ' , new Regex (array ('pattern ' => '#^ \\d+$#xsu ' , 'message ' => "Request parameter value 'foo', does not match requirements ' \\d+' " )), null )
464476 ->will ($ self ->returnValue ($ errors ));
465477 },
@@ -468,13 +480,13 @@ function (\PHPUnit_Framework_MockObject_MockObject $validator, \PHPUnit_Framewor
468480 array (),
469481 array ('baz ' => 'foo ' ),
470482 'baz ' ,
471- function (\PHPUnit_Framework_MockObject_MockObject $ validator , \PHPUnit_Framework_TestCase $ self ) {
483+ function (\PHPUnit_Framework_MockObject_MockObject $ validator , $ validatorMethod , \PHPUnit_Framework_TestCase $ self ) {
472484 $ errors = new ConstraintViolationList (array (
473485 new ConstraintViolation ('expected error ' , null , array (), null , null , null ),
474486 ));
475487
476488 $ validator ->expects ($ self ->at (0 ))
477- ->method (' validateValue ' )
489+ ->method ($ validatorMethod )
478490 ->with ('foo ' , new Regex (array ('pattern ' => '#^ \\d?$#xsu ' , 'message ' => "Request parameter value 'foo', does not match requirements ' \\d?' " )), null )
479491 ->will ($ self ->returnValue ($ errors ));
480492 },
@@ -551,7 +563,7 @@ public function testConstraintThrowExceptionInStrictMode()
551563 ));
552564
553565 $ this ->validator ->expects ($ this ->once ())
554- ->method (' validateValue ' )
566+ ->method ($ this -> validatorMethod )
555567 ->with ('foobar ' , $ this ->constraint )
556568 ->will ($ this ->returnValue ($ errors ));
557569
@@ -601,7 +613,7 @@ public function testConstraintReturnDefaultInSafeMode()
601613 $ violation1 ->expects ($ this ->never ())->method ('getMessage ' );
602614
603615 $ this ->validator ->expects ($ this ->once ())
604- ->method (' validateValue ' )
616+ ->method ($ this -> validatorMethod )
605617 ->with ('foobar ' , $ this ->constraint )
606618 ->will ($ this ->returnValue (array ($ violation1 )));
607619
@@ -636,7 +648,7 @@ public function testConstraintOk()
636648 }
637649
638650 $ this ->validator ->expects ($ this ->once ())
639- ->method (' validateValue ' )
651+ ->method ($ this -> validatorMethod )
640652 ->with ('foobar ' , $ this ->constraint )
641653 ->will ($ this ->returnValue (array ()));
642654
@@ -671,7 +683,7 @@ public function testDeepArrayAllowedWithConstraint()
671683 }
672684
673685 $ this ->validator ->expects ($ this ->once ())
674- ->method (' validateValue ' )
686+ ->method ($ this -> validatorMethod )
675687 ->with (array ('foo ' => array ('b ' , 'a ' , 'r ' )), $ this ->constraint )
676688 ->will ($ this ->returnValue (array ()));
677689
@@ -786,7 +798,7 @@ public function testCustomErrorMessage()
786798 ));
787799
788800 $ this ->validator ->expects ($ this ->once ())
789- ->method (' validateValue ' )
801+ ->method ($ this -> validatorMethod )
790802 ->with ('foobar ' , $ constraint )
791803 ->will ($ this ->returnValue ($ errors ));
792804
0 commit comments