Commit 281d770a authored by Bas de Nooijer's avatar Bas de Nooijer

- added getStatus and getQueryTime to Solarium_Result_Select

- improved unittests
parent cc34a078
...@@ -133,11 +133,14 @@ class Solarium_Client_Adapter_Http extends Solarium_Client_Adapter ...@@ -133,11 +133,14 @@ class Solarium_Client_Adapter_Http extends Solarium_Client_Adapter
protected function _getData($uri, $context) protected function _getData($uri, $context)
{ {
$data = @file_get_contents($uri, false, $context); $data = @file_get_contents($uri, false, $context);
// @codeCoverageIgnoreStart
if (isset($http_response_header)) { if (isset($http_response_header)) {
$headers = $http_response_header; $headers = $http_response_header;
} else { } else {
$headers = array(); $headers = array();
} }
// @codeCoverageIgnoreEnd
return array($data, $headers); return array($data, $headers);
} }
......
...@@ -47,7 +47,7 @@ class Solarium_Client_ResponseParser_Update extends Solarium_Client_ResponsePars ...@@ -47,7 +47,7 @@ class Solarium_Client_ResponseParser_Update extends Solarium_Client_ResponsePars
/** /**
* Parse response data * Parse response data
* *
* @param Solarium_Result_Select $result * @param Solarium_Result_Update $result
* @return array * @return array
*/ */
public function parse($result) public function parse($result)
......
...@@ -83,6 +83,52 @@ class Solarium_Result_Select extends Solarium_Result_QueryType ...@@ -83,6 +83,52 @@ class Solarium_Result_Select extends Solarium_Result_QueryType
*/ */
protected $_components; protected $_components;
/**
* Status code returned by Solr
*
* @var int
*/
protected $_status;
/**
* Solr index queryTime
*
* This doesn't include things like the HTTP responsetime. Purely the Solr
* query execution time.
*
* @var int
*/
protected $_queryTime;
/**
* Get Solr status code
*
* This is not the HTTP status code! The normal value for success is 0.
*
* @return int
*/
public function getStatus()
{
$this->_parseResponse();
return $this->_status;
}
/**
* Get Solr query time
*
* This doesn't include things like the HTTP responsetime. Purely the Solr
* query execution time.
*
* @return int
*/
public function getQueryTime()
{
$this->_parseResponse();
return $this->_queryTime;
}
/** /**
* get Solr numFound * get Solr numFound
* *
......
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Client_ResponseParser_Select_Component_HighlightingTest extends PHPUnit_Framework_TestCase
{
protected $_parser;
public function setUp()
{
$this->_parser = new Solarium_Client_ResponseParser_Select_Component_Highlighting;
}
public function testParse()
{
$highlights = array('key1' => 'dummy1', 'key2' => 'dummy2');
$data = array('highlighting' => $highlights);
$expected = array(
'key1' => new Solarium_Result_Select_Highlighting_Result('dummy1'),
'key2' => new Solarium_Result_Select_Highlighting_Result('dummy2'),
);
$result = $this->_parser->parse(null, null, $data);
$this->assertEquals($expected, $result->getResults());
}
public function testParseNoData()
{
$result = $this->_parser->parse(null, null, array());
$this->assertEquals(array(), $result->getResults());
}
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Client_ResponseParser_Select_Component_MoreLikeThisTest extends PHPUnit_Framework_TestCase
{
protected $_parser;
public function setUp()
{
$this->_parser = new Solarium_Client_ResponseParser_Select_Component_MoreLikeThis();
}
public function testParse()
{
$query = new Solarium_Query_Select();
$data = array(
'moreLikeThis' => array(
'id1' => array(
'numFound' => 12,
'maxScore' => 1.75,
'docs' => array(
array('field1' => 'value1')
)
)
)
);
$docs = array(new Solarium_Document_ReadOnly(array('field1' => 'value1')));
$expected = array(
'id1' => new Solarium_Result_Select_MoreLikeThis_Result(12, 1.75, $docs)
);
$result = $this->_parser->parse($query, null, $data);
$this->assertEquals($expected, $result->getResults());
}
public function testParseNoData()
{
$result = $this->_parser->parse(null, null, array());
$this->assertEquals(array(), $result->getResults());
}
}
...@@ -34,7 +34,15 @@ class Solarium_Client_ResponseParser_UpdateTest extends PHPUnit_Framework_TestCa ...@@ -34,7 +34,15 @@ class Solarium_Client_ResponseParser_UpdateTest extends PHPUnit_Framework_TestCa
public function testParse() public function testParse()
{ {
$data = '{"responseHeader" : {"status":1,"QTime":15}}';
$response = new Solarium_Client_Response($data, array('HTTP 1.1 200 OK'));
$result = new Solarium_Result_Update(null,null,$response);
$parser = new Solarium_Client_ResponseParser_Update;
$parsed = $parser->parse($result);
$this->assertEquals(1, $parsed['status']);
$this->assertEquals(15, $parsed['queryTime']);
} }
} }
...@@ -58,7 +58,7 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase ...@@ -58,7 +58,7 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase
Solarium_Query_Select::COMPONENT_HIGHLIGHTING => $this->_highlighting Solarium_Query_Select::COMPONENT_HIGHLIGHTING => $this->_highlighting
); );
$this->_result = new Solarium_Result_SelectDummy($this->_numFound, $this->_docs, $this->_components); $this->_result = new Solarium_Result_SelectDummy(1, 12, $this->_numFound, $this->_docs, $this->_components);
} }
public function testGetNumFound() public function testGetNumFound()
...@@ -128,6 +128,22 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase ...@@ -128,6 +128,22 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase
$this->assertEquals($this->_docs, $docs); $this->assertEquals($this->_docs, $docs);
} }
public function testGetStatus()
{
$this->assertEquals(
1,
$this->_result->getStatus()
);
}
public function testGetQueryTime()
{
$this->assertEquals(
12,
$this->_result->getQueryTime()
);
}
} }
...@@ -135,12 +151,13 @@ class Solarium_Result_SelectDummy extends Solarium_Result_Select ...@@ -135,12 +151,13 @@ class Solarium_Result_SelectDummy extends Solarium_Result_Select
{ {
protected $_parsed = true; protected $_parsed = true;
public function __construct($numfound, $docs, $components) public function __construct($status, $queryTime, $numfound, $docs, $components)
{ {
$this->_numfound = $numfound; $this->_numfound = $numfound;
$this->_documents = $docs; $this->_documents = $docs;
$this->_components = $components; $this->_components = $components;
$this->_queryTime = $queryTime;
$this->_status = $status;
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment