Commit db1bdffb authored by Bas de Nooijer's avatar Bas de Nooijer

- refactored result objects

- adjusted response handlers for the changes
- updated tests for the result objects
parent b080feed
......@@ -38,7 +38,11 @@ class Solarium_Client_Response_Ping extends Solarium_Client_Response
public function getResult()
{
$resultClass = $this->_query->getOption('resultclass');
return new $resultClass;
return new $resultClass(
$this->_data['responseHeader']['status'],
$this->_data['responseHeader']['QTime']
);
}
}
\ No newline at end of file
......@@ -60,10 +60,12 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response
}
}
$status = $this->_data['responseHeader']['status'];
$queryTime = $this->_data['responseHeader']['QTime'];
$numFound = $this->_data['response']['numFound'];
$resultClass = $this->_query->getOption('resultclass');
return new $resultClass($numFound, $documents, $this->_facets);
return new $resultClass($status, $queryTime, $numFound, $documents, $this->_facets);
}
protected function _addFacetField($facet)
......
......@@ -29,11 +29,7 @@
* policies, either expressed or implied, of the copyright holder.
*/
/**
* Ping result, holds no data as a ping request only tests the Solr
* communication
*/
class Solarium_Result_Ping
class Solarium_Result_Ping extends Solarium_Result_Query
{
}
\ No newline at end of file
<?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.
*/
/**
* Query result
*/
class Solarium_Result_Query
{
/**
* @var int
*/
protected $_status;
/**
* @var int
*/
protected $_queryTime;
/**
* @param int $status
* @param int $queryTime
* @return void
*/
public function __construct($status, $queryTime)
{
$this->_status = $status;
$this->_queryTime = $queryTime;
}
/**
* @return int
*/
public function getStatus()
{
return $this->_status;
}
/**
* @return int
*/
public function getQueryTime()
{
return $this->_queryTime;
}
}
\ No newline at end of file
......@@ -32,7 +32,7 @@
/**
* Select query result
*/
class Solarium_Result_Select implements Iterator, Countable
class Solarium_Result_Select extends Solarium_Result_Query implements Iterator, Countable
{
/**
......@@ -68,13 +68,17 @@ class Solarium_Result_Select implements Iterator, Countable
* Constructor. This is the only point where data can be set in this
* immutable value object.
*
* @param int $status
* @param int $queryTime
* @param int $numFound
* @param array $documents
* @param array $facets
* @return void
*/
public function __construct($numFound, $documents, $facets)
public function __construct($status, $queryTime, $numFound, $documents, $facets)
{
$this->_status = $status;
$this->_queryTime = $queryTime;
$this->_numFound = $numFound;
$this->_documents = $documents;
$this->_facets = $facets;
......
......@@ -32,43 +32,7 @@
/**
* Update result
*/
class Solarium_Result_Update
class Solarium_Result_Update extends Solarium_Result_Query
{
/**
* @var int
*/
protected $_status;
/**
* @var int
*/
protected $_queryTime;
/**
* @param int $status
* @param int $queryTime
* @return void
*/
public function __construct($status, $queryTime)
{
$this->_status = $status;
$this->_queryTime = $queryTime;
}
/**
* @return int
*/
public function getStatus()
{
return $this->_status;
}
/**
* @return int
*/
public function getQueryTime()
{
return $this->_queryTime;
}
}
\ No newline at end of file
<?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_Result_PingTest extends Solarium_Result_QueryTest
{
public function setUp()
{
$this->_result = new Solarium_Result_Ping(0,45);
}
}
<?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_Result_QueryTest extends PHPUnit_Framework_TestCase
{
protected $_result;
public function setUp()
{
$this->_result = new Solarium_Result_Query(0,45);
}
public function testGetStatus()
{
$this->assertEquals(0, $this->_result->getStatus());
}
public function testGetQueryTime()
{
$this->assertEquals(45, $this->_result->getQueryTime());
}
}
......@@ -29,7 +29,7 @@
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase
class Solarium_Result_SelectTest extends Solarium_Result_Query
{
protected $_result, $_docs, $_facets;
......@@ -47,7 +47,7 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase
'f2' => new Solarium_Result_Select_Facet_Field(array('b' => 5)),
);
$this->_result = new Solarium_Result_Select(100, $this->_docs, $this->_facets);
$this->_result = new Solarium_Result_Select(0,45,100, $this->_docs, $this->_facets);
}
public function testGetNumFound()
......
......@@ -29,24 +29,12 @@
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Result_UpdateTest extends PHPUnit_Framework_TestCase
class Solarium_Result_UpdateTest extends Solarium_Result_QueryTest
{
protected $_result;
public function setUp()
{
$this->_result = new Solarium_Result_Update(0,45);
}
public function testGetStatus()
{
$this->assertEquals(0, $this->_result->getStatus());
}
public function testGetQueryTime()
{
$this->assertEquals(45, $this->_result->getQueryTime());
}
}
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