@@ -709,4 +709,47 @@ public function testNullValidatorWithoutRequirements()
709709 $ queryFetcher ->setController ($ this ->controller );
710710 $ this ->assertEquals ('foobar ' , $ queryFetcher ->get ('bizoo ' ));
711711 }
712+
713+ public function testCustomErrorMessage ()
714+ {
715+ $ param = new QueryParam ();
716+ $ param ->name = 'fero ' ;
717+ $ errorMessage = "variable must be an integer " ;
718+ $ param ->requirements = array ('rule ' => '\d+ ' , 'error_message ' => $ errorMessage );
719+ $ param ->description = 'integer value ' ;
720+ $ param ->strict = true ;
721+
722+ $ request = new Request (array ('fero ' => 'foobar ' ), array (), array ('_controller ' => __CLASS__ .'::stubAction ' ));
723+ $ reader = $ this ->getMockBuilder ('FOS\RestBundle\Request\ParamReader ' )
724+ ->disableOriginalConstructor ()
725+ ->getMock ();
726+
727+ $ reader ->expects ($ this ->any ())
728+ ->method ('read ' )
729+ ->will ($ this ->returnValue (array ('fero ' => $ param )));
730+
731+ $ constraint = new Regex (array (
732+ 'pattern ' => '#^\d+$#xsu ' ,
733+ 'message ' => $ errorMessage ,
734+ ));
735+
736+ $ errors = new ConstraintViolationList (array (
737+ new ConstraintViolation ($ errorMessage , null , array (), null , null , null ),
738+ ));
739+
740+ $ this ->validator ->expects ($ this ->once ())
741+ ->method ('validateValue ' )
742+ ->with ('foobar ' , $ constraint )
743+ ->will ($ this ->returnValue ($ errors ));
744+
745+ $ queryFetcher = new ParamFetcher ($ reader , $ request , $ this ->violationFormatter , $ this ->validator );
746+ $ queryFetcher ->setController ($ this ->controller );
747+
748+ try {
749+ $ queryFetcher ->get ('fero ' );
750+ $ this ->fail ('Fetching get() in strict mode with no default value did not throw an exception ' );
751+ } catch (HttpException $ httpException ) {
752+ $ this ->assertEquals ($ errorMessage , $ httpException ->getMessage ());
753+ }
754+ }
712755}
0 commit comments