11<?php
22
33use Symfony \Component \HttpFoundation \Request ;
4+ use Symfony \Component \Serializer \SerializerInterface ;
45use Wa72 \JsonRpcBundle \Controller \JsonRpcController ;
56use Wa72 \JsonRpcBundle \Tests \Fixtures \Testparameter ;
67
@@ -15,11 +16,22 @@ class JsonRpcController2Test extends \PHPUnit\Framework\TestCase {
1516
1617 private JsonRpcController $ controller ;
1718
19+ private SerializerInterface $ serializer ;
20+
1821 public function setUp (): void
1922 {
23+ if (!interface_exists (SerializerInterface::class)) {
24+ if (class_exists (\JMS \SerializerBundle \JMSSerializerBundle::class)) {
25+ //
26+ $ this ->markTestSkipped ('Symfony Serializer not available. ' );
27+ } else {
28+ $ this ->fail ('No serializer available. Please install JMS Serializer Bundle or Symfony Serializer. ' );
29+ }
30+ }
2031 $ this ->kernel = new \Wa72JsonRpcBundleTestKernel2 ('test ' , true );
2132 $ this ->kernel ->boot ();
2233 $ container = $ this ->kernel ->getContainer ();
34+ $ this ->serializer = $ container ->get ('wa72_jsonrpc.serializer ' );
2335 $ this ->controller = $ container ->get ('wa72_jsonrpc.jsonrpccontroller ' );
2436 }
2537
@@ -171,16 +183,8 @@ public function testAddMethod()
171183
172184 private function makeRequest ($ controller , $ requestdata )
173185 {
174- $ container = $ this ->kernel ->getContainer ();
175- if ($ container ->has ('jms_serializer ' )) {
176- $ serializer = $ container ->get ('jms_serializer ' );
177- } elseif ($ container ->has ('wa72_jsonrpc.serializer ' )) {
178- $ serializer = $ container ->get ('wa72_jsonrpc.serializer ' );
179- } else {
180- $ this ->fail ('No serializer service found in container. ' );
181- }
182186 return json_decode ($ controller ->execute (
183- new Request ([], [], [], [], [], [], $ serializer ->serialize ($ requestdata , 'json ' ))
187+ new Request ([], [], [], [], [], [], $ this -> serializer ->serialize ($ requestdata , 'json ' ))
184188 )->getContent (), true );
185189 }
186190
0 commit comments