private function sync()
 {
     if ($this->synchronized) {
         return;
     }
     /** @var ResponseInterface $clientResponse */
     $clientResponse = $this->promise->wait();
     if (200 !== $clientResponse->getStatusCode()) {
         throw new RemoteCallFailedException();
     }
     $data = (string) $clientResponse->getBody();
     // Null (empty response) is expected if only notifications were sent
     $rawResponses = [];
     if ('' !== $data) {
         $rawResponses = json_decode($data, false);
         if (json_last_error() !== JSON_ERROR_NONE) {
             throw ResponseParseException::notAJsonResponse();
         }
     }
     if (!is_array($rawResponses) && $rawResponses instanceof \stdClass) {
         $rawResponses = [$rawResponses];
     }
     $this->responses = [];
     foreach ($rawResponses as $rawResponse) {
         try {
             $response = new SyncResponse($rawResponse);
         } catch (ResponseParseException $exception) {
             //todo: logging??? (@scaytrase)
             continue;
         }
         $this->responses[$response->getId()] = $response;
     }
     $this->synchronized = true;
 }
 public function testNestedContext()
 {
     $client = self::createClient();
     $response = $this->sendRequest($client, '/test/private/', ['jsonrpc' => JsonRpcBundle::VERSION, 'method' => 'prefix/annotation/sub', 'id' => 'test', 'params' => ['payload' => 'my-payload']]);
     self::assertTrue($response->isSuccessful());
     $content = json_decode($response->getContent());
     self::assertInstanceOf(\stdClass::class, $content);
     $jsonResponse = new SyncResponse($content);
     self::assertTrue($jsonResponse->isSuccessful());
 }
 public function testArrayRequest()
 {
     $response = $this->sendRequest(self::createClient(), '/test/', ['jsonrpc' => JsonRpcBundle::VERSION, 'method' => 'array', 'id' => 'test', 'params' => ['payload' => 'my-payload']]);
     self::assertTrue($response->isSuccessful());
     $content = json_decode($response->getContent());
     self::assertInstanceOf(\stdClass::class, $content);
     $jsonResponse = new SyncResponse($content);
     self::assertTrue($jsonResponse->isSuccessful(), json_encode($content));
     self::assertTrue(isset($jsonResponse->getBody()[0]->{'sample_payload'}));
     self::assertEquals('my-payload', $jsonResponse->getBody()[0]->{'sample_payload'});
 }
 public function testNestedContext()
 {
     $response = $this->sendRequest(self::createClient(), '/test/private/', ['jsonrpc' => JsonRpcBundle::VERSION, 'method' => 'entity/nested', 'id' => 'test', 'params' => ['payload' => 'my-payload']]);
     self::assertTrue($response->isSuccessful());
     $content = json_decode($response->getContent());
     self::assertInstanceOf(\stdClass::class, $content);
     $jsonResponse = new SyncResponse($content);
     self::assertTrue($jsonResponse->isSuccessful());
     self::assertTrue(isset($jsonResponse->getBody()->{'sample_payload'}));
     self::assertEquals('my-payload', $jsonResponse->getBody()->{'sample_payload'});
     self::assertTrue(isset($jsonResponse->getBody()->{'private_payload'}), json_encode($content, JSON_PRETTY_PRINT));
     self::assertEquals('secret-payload', $jsonResponse->getBody()->{'private_payload'});
 }