@@ -265,6 +265,56 @@ public function testStatusCode($annotationCode, $viewCode, $expectedCode)
265265 $ this ->assertSame ($ expectedCode , $ response ->getStatusCode ());
266266 }
267267
268+ public static function serializerEnableMaxDepthChecksProvider ()
269+ {
270+ return array (
271+ array (false , get_class (null )),
272+ array (true , 'JMS\Serializer\Exclusion\DepthExclusionStrategy ' ),
273+ );
274+ }
275+
276+ /**
277+ * @dataProvider serializerEnableMaxDepthChecksProvider
278+ */
279+ public function testSerializerEnableMaxDepthChecks ($ enableMaxDepthChecks , $ expectedClass )
280+ {
281+ $ viewAnnotation = new ViewAnnotation (array ());
282+ $ viewAnnotation ->setSerializerEnableMaxDepthChecks ($ enableMaxDepthChecks );
283+
284+ $ request = new Request ();
285+ $ request ->setRequestFormat ('json ' );
286+ $ request ->attributes ->set ('_view ' , $ viewAnnotation );
287+
288+ $ this ->viewHandler = new ViewHandler (array ('json ' => true ));
289+ $ this ->viewHandler ->setContainer ($ this ->container );
290+
291+ // This is why we avoid container dependencies!
292+ $ that = $ this ;
293+ $ this ->container ->expects ($ this ->exactly (2 ))
294+ ->method ('get ' )
295+ ->with ($ this ->logicalOr ('fos_rest.view_handler ' , 'fos_rest.templating ' ))
296+ ->will ($ this ->returnCallback (function ($ service ) use ($ that ) {
297+ return $ service === 'fos_rest.view_handler ' ?
298+ $ that ->viewHandler :
299+ $ that ->templating ;
300+ }));
301+
302+ $ this ->templating ->expects ($ this ->any ())
303+ ->method ('render ' )
304+ ->will ($ this ->returnValue ('foo ' ));
305+
306+ $ view = new View ();
307+
308+ $ event = $ this ->getResponseEvent ($ request , $ view );
309+
310+ $ this ->listener ->onKernelView ($ event );
311+
312+ $ context = $ view ->getSerializationContext ();
313+ $ exclusionStrategy = $ context ->getExclusionStrategy ();
314+
315+ $ this ->assertEquals ($ expectedClass , get_class ($ exclusionStrategy ));
316+ }
317+
268318 public function getDataForDefaultVarsCopy ()
269319 {
270320 return array (
0 commit comments