function testCommandResultFromJson()
 {
     $json = '{"status":0,"results":[{"status":true,"value":"foo"},{"status":true,"value":false},{"status":true,"value":["foo","bar"]}],"message":"Test message"}';
     $result = tx_caretakerinstance_CommandResult::fromJson($json);
     $this->assertInstanceOf('tx_caretakerinstance_CommandResult', $result);
     $this->assertEquals('Test message', $result->getMessage());
     $this->assertTrue($result->isSuccessful());
     $this->assertEquals(array(new tx_caretakerinstance_OperationResult(true, 'foo'), new tx_caretakerinstance_OperationResult(true, false), new tx_caretakerinstance_OperationResult(true, array('foo', 'bar'))), $result->getOperationResults());
 }
 /**
  * Execute the given command request
  *
  * @param tx_caretakerinstance_CommandRequest $commandRequest
  * @return tx_caretakerinstance_CommandResult
  */
 public function executeRequest($commandRequest)
 {
     $httpRequestResult = $this->executeHttpRequest($commandRequest->getServerUrl(), array('st' => $commandRequest->getSessionToken(), 'd' => $commandRequest->getData(), 's' => $commandRequest->getSignature()));
     if (is_array($httpRequestResult)) {
         if ($httpRequestResult['info']['http_code'] === 200) {
             $json = $this->securityManager->decodeResult($httpRequestResult['response']);
             // TODO: check if valid json
             if ($json) {
                 return tx_caretakerinstance_CommandResult::fromJson($json);
             } else {
                 if (!empty($httpRequestResult['response'])) {
                     $json = json_decode($httpRequestResult['response'], TRUE);
                     if ($json && $json['status'] == -1) {
                         return $this->getCommandResult(tx_caretakerinstance_CommandResult::status_undefined, NULL, 'Error while executing remote command: ' . $json['message'] . ' (' . $json['exception']['code'] . ')');
                     }
                 }
                 return $this->getCommandResult(tx_caretakerinstance_CommandResult::status_undefined, NULL, 'Cant decode remote command result');
             }
         } else {
             if ($httpRequestResult['info']['http_code'] === 0) {
                 // seems to be a timeout
                 return $this->getCommandResult(tx_caretakerinstance_CommandResult::status_undefined, NULL, 'No Response/Timeout (Total-Time: ' . $httpRequestResult['info']['total_time'] . ')');
             } else {
                 return $this->getCommandResult(tx_caretakerinstance_CommandResult::status_error, NULL, 'Invalid result: ' . $httpRequestResult['response'] . chr(10) . 'CURL Info: ' . var_export($httpRequestResult['info'], true));
             }
         }
     } else {
         return $this->getCommandResult(tx_caretakerinstance_CommandResult::status_error, NULL, 'Invalid result request could not be executed' . chr(10) . 'CURL Info: ' . var_export($httpRequestResult['info'], true));
     }
 }