markTestSkipped('ZF not in include_path, skipping ZendHttp adapter tests'); } Zend_Loader_Autoloader::getInstance(); $this->_adapter = new Solarium_Client_Adapter_ZendHttp(); } public function testForwardingToZendHttpInSetOptions() { $options = array('timeout' => 10, 'optionZ' => 123, 'options' => array('optionX' => 'Y')); $adapterOptions = array('timeout' => 10, 'optionX' => 'Y'); $mock = $this->getMock('Zend_Http_Client'); $mock->expects($this->once()) ->method('setConfig') ->with($this->equalTo($adapterOptions)); $this->_adapter->setZendHttp($mock); $this->_adapter->setOptions($options); } public function testSetAndGetZendHttp() { $dummy = new StdClass(); $this->_adapter->setZendHttp($dummy); $this->assertEquals( $dummy, $this->_adapter->getZendHttp() ); } public function testGetZendHttpAutoload() { $options = array('timeout' => 10, 'optionZ' => 123, 'options' => array('adapter' => 'Zend_Http_Client_Adapter_Curl')); $this->_adapter->setOptions($options); $zendHttp = $this->_adapter->getZendHttp(); $this->assertThat($zendHttp, $this->isInstanceOf('Zend_Http_Client')); } public function testExecute() { $method = Solarium_Client_Request::METHOD_GET; $rawData = 'xyz'; $responseData = 'abc'; $handler = 'myhandler'; $headers = array( 'Content-Type: application/x-www-form-urlencoded' ); $request = new Solarium_Client_Request(); $request->setMethod($method); $request->setHandler($handler); $request->setHeaders($headers); $request->setRawData($rawData); $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($headers)); $mock->expects($this->once()) ->method('setRawData') ->with($this->equalTo($rawData)); $mock->expects($this->once()) ->method('request') ->will($this->returnValue($response)); $this->_adapter->setZendHttp($mock); $adapterResponse = $this->_adapter->execute($request); $this->assertEquals( $responseData, $adapterResponse->getBody() ); } public function testExecuteErrorResponse() { $request = new Solarium_Client_Request(); $response = new Zend_Http_Response(404, array(), ''); $mock = $this->getMock('Zend_Http_Client'); $mock->expects($this->once()) ->method('request') ->will($this->returnValue($response)); $this->_adapter->setZendHttp($mock); $this->setExpectedException('Solarium_Client_HttpException'); $this->_adapter->execute($request); } public function testExecuteHeadRequestReturnsNoData() { $request = new Solarium_Client_Request(); $request->setMethod(Solarium_Client_Request::METHOD_HEAD); $response = new Zend_Http_Response(200, array('status' => 'HTTP 1.1 200 OK'), 'data'); $mock = $this->getMock('Zend_Http_Client'); $mock->expects($this->once()) ->method('request') ->will($this->returnValue($response)); $this->_adapter->setZendHttp($mock); $response = $this->_adapter->execute($request); $this->assertEquals( '', $response->getBody() ); } }