Example #1
0
 /**
  * Get Solr response data
  *
  * Includes a lazy loading mechanism: JSON body data is decoded on first use and then saved for reuse.
  *
  * @throws UnexpectedValueException
  * @throws RuntimeException
  * @return array
  */
 public function getData()
 {
     if (null == $this->data) {
         switch ($this->query->getResponseWriter()) {
             case Query::WT_PHPS:
                 $this->data = unserialize($this->response->getBody());
                 break;
             case Query::WT_JSON:
                 $this->data = json_decode($this->response->getBody(), true);
                 break;
             default:
                 throw new RuntimeException('Responseparser cannot handle ' . $this->query->getResponseWriter());
         }
         if (null === $this->data) {
             throw new UnexpectedValueException('Solr JSON response could not be decoded');
         }
     }
     return $this->data;
 }
 public function testGetBody()
 {
     $this->assertEquals($this->data, $this->response->getBody());
 }