Commit 326d0a65 authored by Bas de Nooijer's avatar Bas de Nooijer

- unittest improvements and style fixes

parent c040d36a
...@@ -78,7 +78,7 @@ class Solarium_Client_HttpException extends Solarium_Exception ...@@ -78,7 +78,7 @@ class Solarium_Client_HttpException extends Solarium_Exception
{ {
$this->_statusMessage = $statusMessage; $this->_statusMessage = $statusMessage;
$message = 'Solr HTTP error, ' . $statusMessage; $message = 'Solr HTTP error: ' . $statusMessage;
if (null !== $code) { if (null !== $code) {
$message .= ' (' . $code . ')'; $message .= ' (' . $code . ')';
} }
......
<?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_HttpExceptionTest extends PHPUnit_Framework_TestCase
{
public function testConstructor()
{
$exception = new Solarium_Client_HttpException('message text', 123);
$this->assertEquals(
'Solr HTTP error: message text (123)',
$exception->getMessage()
);
}
public function testGetMessage()
{
$exception = new Solarium_Client_HttpException('message text', 123);
$this->assertEquals(
'message text',
$exception->getStatusMessage()
);
}
public function testConstructorNoCode()
{
$exception = new Solarium_Client_HttpException('message text');
$this->assertEquals(
'Solr HTTP error: message text',
$exception->getMessage()
);
}
}
\ No newline at end of file
...@@ -66,4 +66,12 @@ class Solarium_Client_ResponseTest extends PHPUnit_Framework_TestCase ...@@ -66,4 +66,12 @@ class Solarium_Client_ResponseTest extends PHPUnit_Framework_TestCase
$this->assertEquals($this->_data, $this->_response->getBody()); $this->assertEquals($this->_data, $this->_response->getBody());
} }
public function testMissingHeader()
{
$headers = array();
$this->setExpectedException('Solarium_Exception');
new Solarium_Client_Response($this->_data, $headers);
}
} }
\ No newline at end of file
...@@ -31,25 +31,41 @@ ...@@ -31,25 +31,41 @@
class Solarium_Plugin_AbstractTest extends PHPUnit_Framework_TestCase class Solarium_Plugin_AbstractTest extends PHPUnit_Framework_TestCase
{ {
protected $_plugin, $_client, $_options;
public function testConstructor() public function setUp()
{ {
$client = 'dummy'; $this->_client = 'dummy';
$options = array('option1' => 1); $this->_options = array('option1' => 1);
$plugin = new MyPlugin($client, $options); $this->_plugin = new MyPlugin($this->_client, $this->_options);
}
$this->assertEquals( public function testConstructor()
$client, {
$plugin->getClient() $this->assertEquals(
$this->_client,
$this->_plugin->getClient()
); );
$this->assertEquals( $this->assertEquals(
$options, $this->_options,
$plugin->getOptions() $this->_plugin->getOptions()
); );
} }
public function testEventHooks()
{
$this->assertEquals(null, $this->_plugin->preCreateRequest());
$this->assertEquals(null, $this->_plugin->postCreateRequest());
$this->assertEquals(null, $this->_plugin->preExecuteRequest());
$this->assertEquals(null, $this->_plugin->postExcuteRequest());
$this->assertEquals(null, $this->_plugin->preExecute());
$this->assertEquals(null, $this->_plugin->postExecute());
$this->assertEquals(null, $this->_plugin->preCreateResult());
$this->assertEquals(null, $this->_plugin->postCreateResult());
}
} }
class MyPlugin extends Solarium_Plugin_Abstract{ class MyPlugin extends Solarium_Plugin_Abstract{
......
...@@ -38,9 +38,9 @@ class Solarium_ResultTest extends PHPUnit_Framework_TestCase ...@@ -38,9 +38,9 @@ class Solarium_ResultTest extends PHPUnit_Framework_TestCase
{ {
$this->_client = new Solarium_Client(); $this->_client = new Solarium_Client();
$this->_query = new Solarium_Query_Select(); $this->_query = new Solarium_Query_Select();
$headers = array('HTTP/1.0 304 Not Modified'); $this->_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":[]}}'; $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->_response = new Solarium_Client_Response($data, $this->_headers);
$this->_result = new Solarium_Result($this->_client, $this->_query, $this->_response); $this->_result = new Solarium_Result($this->_client, $this->_query, $this->_response);
} }
...@@ -73,5 +73,15 @@ class Solarium_ResultTest extends PHPUnit_Framework_TestCase ...@@ -73,5 +73,15 @@ class Solarium_ResultTest extends PHPUnit_Framework_TestCase
$this->assertEquals($data, $this->_result->getData()); $this->assertEquals($data, $this->_result->getData());
} }
public function testGetInvalidData()
{
$data = 'invalid';
$this->_response = new Solarium_Client_Response($data, $this->_headers);
$this->_result = new Solarium_Result($this->_client, $this->_query, $this->_response);
$this->setExpectedException('Solarium_Exception');
$this->_result->getData();
}
} }
\ 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