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

- unittest improvements and style fixes

parent 01c05ed2
......@@ -231,6 +231,10 @@ class Solarium_Client extends Solarium_Configurable
public function registerPlugin($key, $class, $options = array())
{
$plugin = new $class($this, $options);
if (!($plugin instanceof Solarium_Plugin_Abstract)) {
throw new Solarium_Exception('All plugins must extend Solarium_Plugin_Abstract');
}
$this->_plugins[$key] = $plugin;
return $this;
......@@ -285,8 +289,8 @@ class Solarium_Client extends Solarium_Configurable
*/
protected function _callPlugins($event, $params, $resultOverride = false)
{
foreach($this->_plugins AS $plugin) {
$result = call_user_func_array(array($plugin,$event),$params);
foreach ($this->_plugins AS $plugin) {
$result = call_user_func_array(array($plugin, $event), $params);
if ($result !== null && $resultOverride) {
return $result;
......
......@@ -289,11 +289,10 @@ class Solarium_Client_Request extends Solarium_Configurable
/**
* Add a request header
*
* @header string $key
* @header string|array $value
* @return Solarium_Client_Request
*/
public function addHeader($key, $value)
public function addHeader($value)
{
$this->_headers[] = $value;
......
......@@ -54,7 +54,7 @@ class Solarium_Client_RequestBuilder_Select_Component_MoreLikeThis
public function build($component, $request)
{
// enable morelikethis
$request->addParam('mlt','true');
$request->addParam('mlt', 'true');
$request->addParam('mlt.fl', $component->getFields());
$request->addParam('mlt.mintf', $component->getMinimumTermFrequency());
......
......@@ -53,8 +53,6 @@ class Solarium_Client_ResponseParser_Update extends Solarium_Client_ResponsePars
public function parse($result)
{
$data = $result->getData();
$query = $result->getQuery();
$resultClass = $query->getResultClass();
return array(
'status' => $data['responseHeader']['status'],
......
......@@ -68,7 +68,8 @@ abstract class Solarium_Plugin_Abstract extends Solarium_Configurable
* @return void|Solarium_Client_Request
*/
public function preCreateRequest($query)
{ }
{
}
/**
* @param Solarium_Query $query
......@@ -76,14 +77,16 @@ abstract class Solarium_Plugin_Abstract extends Solarium_Configurable
* @return void
*/
public function postCreateRequest($query, $request)
{ }
{
}
/**
* @param Solarium_Client_Request $request
* @return void|Solarium_Client_Response
*/
public function preExecuteRequest($request)
{ }
{
}
/**
* @param Solarium_Client_Request $request
......@@ -91,7 +94,8 @@ abstract class Solarium_Plugin_Abstract extends Solarium_Configurable
* @return void
*/
public function postExecuteRequest($request, $response)
{ }
{
}
/**
* @param Solarium_Query $query
......@@ -99,7 +103,8 @@ abstract class Solarium_Plugin_Abstract extends Solarium_Configurable
* @return void|Solarium_Result
*/
public function preCreateResult($query, $response)
{ }
{
}
/**
* @param Solarium_Query $query
......@@ -108,14 +113,16 @@ abstract class Solarium_Plugin_Abstract extends Solarium_Configurable
* @return void
*/
public function postCreateResult($query, $response, $result)
{ }
{
}
/**
* @param Solarium_Query $query
* @return void|Solarium_Result
*/
public function preExecute($query)
{ }
{
}
/**
* @param Solarium_Query $query
......@@ -123,6 +130,7 @@ abstract class Solarium_Plugin_Abstract extends Solarium_Configurable
* @return void
*/
public function postExecute($query, $result)
{ }
{
}
}
\ No newline at end of file
......@@ -173,7 +173,7 @@ class Solarium_Query_Select_Helper
*/
public function functionCall($name, $params = array())
{
return $name . '(' . implode($params,',') . ')';
return $name . '(' . implode($params, ',') . ')';
}
}
\ No newline at end of file
......@@ -83,7 +83,7 @@ class Solarium_Result_QueryType extends Solarium_Result
*/
protected function _mapData($mapData)
{
foreach($mapData AS $key => $data) {
foreach ($mapData AS $key => $data) {
$this->{'_'.$key} = $data;
}
}
......
......@@ -69,7 +69,7 @@ class Solarium_Version
*
* @var string
*/
const VERSION = '1.0.0';
const VERSION = '2.0.0';
/**
......
......@@ -56,6 +56,76 @@ class Solarium_ClientTest extends PHPUnit_Framework_TestCase
$this->assertThat($client->getAdapter(), $this->isInstanceOf($adapterClass));
}
public function testRegisterQueryTypeAndGetQueryTypes()
{
}
public function testRegisterAndGetPlugin()
{
}
public function testRemoveAndGetPlugins()
{
}
public function testCreateRequest()
{
}
public function testCreateRequestInvalidQueryType()
{
}
public function testCreateRequestWithOverridingPlugin()
{
}
public function testCreateRequestPostPlugin()
{
}
public function testCreateResult()
{
}
public function testCreateResultInvalidQueryType()
{
}
public function testCreateResultWithOverridingPlugin()
{
}
public function testCreateResultPostPlugin()
{
}
public function testPing()
{
}
public function testSelect()
{
}
public function testUpdate()
{
}
}
class MyAdapter extends Solarium_Client_Adapter_Http{
......
......@@ -98,7 +98,28 @@ class Solarium_ConfigurableTest extends PHPUnit_Framework_TestCase
$this->setExpectedException('Solarium_Exception');
new ConfigTestInit;
}
public function testSetOptions()
{
$configTest = new ConfigTest();
$configTest->setOptions(array('option2' => 2, 'option3' => 3));
$this->assertEquals(
array('option1' => 1, 'option2' => 2, 'option3' => 3),
$configTest->getOptions()
);
}
public function testSetOptionsWithOverride()
{
$configTest = new ConfigTest();
$configTest->setOptions(array('option2' => 2, 'option3' => 3), true);
$this->assertEquals(
array('option2' => 2, 'option3' => 3),
$configTest->getOptions()
);
}
}
class ConfigTest extends Solarium_Configurable
......
<?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_Plugin_AbstractTest extends PHPUnit_Framework_TestCase
{
public function testConstructor()
{
$client = 'dummy';
$options = array('option1' => 1);
$plugin = new MyPlugin($client, $options);
$this->assertEquals(
$client,
$plugin->getClient()
);
$this->assertEquals(
$options,
$plugin->getOptions()
);
}
}
class MyPlugin extends Solarium_Plugin_Abstract{
public function getClient()
{
return $this->_client;
}
}
\ 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_Query_PingTest extends PHPUnit_Framework_TestCase
{
protected $_query;
public function setUp()
{
$this->_query = new Solarium_Query_Ping;
}
public function testGetType()
{
$this->assertEquals(Solarium_Client::QUERYTYPE_PING, $this->_query->getType());
}
}
\ No newline at end of file
......@@ -39,6 +39,11 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
$this->_query = new Solarium_Query_Select;
}
public function testGetType()
{
$this->assertEquals(Solarium_Client::QUERYTYPE_SELECT, $this->_query->getType());
}
public function testSetAndGetStart()
{
$this->_query->setStart(234);
......@@ -479,6 +484,16 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
);
}
public function testGetHighlighting()
{
$dismax = $this->_query->getHighlighting();
$this->assertEquals(
'Solarium_Query_Select_Component_Highlighting',
get_class($dismax)
);
}
public function testGetHelper()
{
$helper = $this->_query->getHelper();
......@@ -488,4 +503,21 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
get_class($helper)
);
}
public function testRegisterComponentType()
{
$components = $this->_query->getComponentTypes();
$components['mykey'] = array(
'component' => 'mycomponent',
'requestbuilder' => 'mybuilder',
'responseparser' => 'myparser',
);
$this->_query->registerComponentType('mykey','mycomponent','mybuilder','myparser');
$this->assertEquals(
$components,
$this->_query->getComponentTypes()
);
}
}
\ No newline at end of file
......@@ -39,6 +39,11 @@ class Solarium_Query_UpdateTest extends PHPUnit_Framework_TestCase
$this->_query = new Solarium_Query_Update;
}
public function testGetType()
{
$this->assertEquals(Solarium_Client::QUERYTYPE_UPDATE, $this->_query->getType());
}
public function testAddWithoutKey()
{
$command = new Solarium_Query_Update_Command_Rollback;
......
<?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_ResultTest extends PHPUnit_Framework_TestCase
{
protected $_client, $_query, $_response, $_result;
public function setUp()
{
$this->_client = new Solarium_Client();
$this->_query = new Solarium_Query_Select();
$headers = array('HTTP/1.0 304 Not Modified');
$data = '{"responseHeader":{"status":0,"QTime":1,"params":{"wt":"json","q":"xyz"}},"response":{"numFound":0,"start":0,"docs":[]}}';
$this->_response = new Solarium_Client_Response($data, $headers);
$this->_result = new Solarium_Result($this->_client, $this->_query, $this->_response);
}
public function testResultWithErrorResponse()
{
$headers = array('HTTP/1.0 404 Not Found');
$response = new Solarium_Client_Response('', $headers);
$this->setExpectedException('Solarium_Exception');
new Solarium_Result($this->_client, $this->_query, $response);
}
public function testGetResponse()
{
$this->assertEquals($this->_response, $this->_result->getResponse());
}
public function testGetQuery()
{
$this->assertEquals($this->_query, $this->_result->getQuery());
}
public function testGetData()
{
$data = array(
'responseHeader' => array('status' => 0, 'QTime' => 1, 'params' => array('wt' => 'json', 'q' => 'xyz')),
'response' => array('numFound' => 0, 'start' => 0, 'docs' => array())
);
$this->assertEquals($data, $this->_result->getData());
}
}
\ No newline at end of file
......@@ -42,5 +42,11 @@ set_include_path(implode(PATH_SEPARATOR, array(
get_include_path(),
)));
function solariumUnittestAutoload($class)
{
@include(str_replace("_", DIRECTORY_SEPARATOR, $class) . ".php");
}
// set up an autoload for Zend / Pear style class loading
spl_autoload_register(create_function('$class', '@include(str_replace("_", DIRECTORY_SEPARATOR, $class) . ".php");'));
\ No newline at end of file
spl_autoload_register('solariumUnittestAutoload');
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