コード例 #1
1
ファイル: RequestTest.php プロジェクト: lhess/solarium
 public function testGetUriWithHandlerAndParams()
 {
     $params = array('param1' => 1, 'param2' => array(2, 3));
     $this->request->setHandler('myHandler');
     $this->request->addParams($params);
     $this->assertEquals('myHandler?param1=1&param2=2&param2=3', $this->request->getUri());
 }
コード例 #2
0
 /**
  * Build request for a select query
  *
  * @param  Query   $query
  * @return Request
  */
 public function build(QueryInterface $query)
 {
     $request = new Request();
     $request->setHandler($query->getHandler());
     $request->addParam('omitHeader', $query->getOmitHeader());
     $request->addParams($query->getParams());
     $request->addParam('wt', $query->getResponseWriter());
     return $request;
 }
コード例 #3
0
 /**
  * Build request for a select query.
  *
  * @param QueryInterface|Query $query
  *
  * @return Request
  */
 public function build(QueryInterface $query)
 {
     $request = new Request();
     $request->setHandler($query->getHandler());
     $request->addParam('omitHeader', $query->getOmitHeader());
     $request->addParam('timeAllowed', $query->getTimeAllowed());
     $request->addParams($query->getParams());
     $request->addParam('wt', $query->getResponseWriter());
     if ($query->getResponseWriter() == $query::WT_JSON) {
         // only one JSON format is supported
         $request->addParam('json.nl', 'flat');
     }
     return $request;
 }
コード例 #4
0
 public function testCreateRequestWithOverridingPlugin()
 {
     $expectedRequest = new Request();
     $expectedRequest->setHandler('something-unique-345978');
     $query = new SelectQuery();
     $expectedEvent = new PreCreateRequestEvent($query);
     $expectedEvent->setDispatcher($this->client->getEventDispatcher());
     $expectedEvent->setName(Events::PRE_CREATE_REQUEST);
     $test = $this;
     $this->client->getEventDispatcher()->addListener(Events::PRE_CREATE_REQUEST, function (PreCreateRequestEvent $event) use($test, $expectedRequest, $expectedEvent) {
         $test->assertEquals($expectedEvent, $event);
         $event->setRequest($expectedRequest);
     });
     $returnedRequest = $this->client->createRequest($query);
     $this->assertEquals($expectedRequest, $returnedRequest);
 }
コード例 #5
0
 /**
  * Build request for a stats.jsp query.
  *
  * @param QueryInterface $query
  * @return Request
  */
 public function build(QueryInterface $query)
 {
     $request = new Request();
     $request->setHandler($query->getHandler());
     return $request;
 }
コード例 #6
0
 public function testExecutePost()
 {
     $method = Request::METHOD_POST;
     $rawData = 'xyz';
     $responseData = 'abc';
     $handler = 'myhandler';
     $headers = array('X-test: 123');
     $params = array('a' => 1, 'b' => 2);
     $request = new Request();
     $request->setMethod($method);
     $request->setHandler($handler);
     $request->setHeaders($headers);
     $request->setRawData($rawData);
     $request->setParams($params);
     $endpoint = new Endpoint();
     $response = new \Zend_Http_Response(200, array('status' => 'HTTP 1.1 200 OK'), $responseData);
     $mock = $this->getMock('Zend_Http_Client');
     $mock->expects($this->once())->method('setMethod')->with($this->equalTo($method));
     $mock->expects($this->once())->method('setUri')->with($this->equalTo('http://127.0.0.1:8983/solr/myhandler'));
     $mock->expects($this->once())->method('setHeaders')->with($this->equalTo(array('X-test: 123', 'Content-Type: text/xml; charset=UTF-8')));
     $mock->expects($this->once())->method('setRawData')->with($this->equalTo($rawData));
     $mock->expects($this->once())->method('setParameterGet')->with($this->equalTo($params));
     $mock->expects($this->once())->method('request')->will($this->returnValue($response));
     $this->adapter->setZendHttp($mock);
     $adapterResponse = $this->adapter->execute($request, $endpoint);
     $this->assertEquals($responseData, $adapterResponse->getBody());
 }