Commit 995bcabb authored by Bas de Nooijer's avatar Bas de Nooijer

- unittest improvements

parent e5700ef2
......@@ -102,7 +102,7 @@ class Solarium_ClientTest extends PHPUnit_Framework_TestCase
public function testRegisterInvalidPlugin()
{
$this->setExpectedException('Solarium_Exception');
$this->_client->registerPlugin('testplugin','MyInvalidClientPlugin');
$this->_client->registerPlugin('testplugin','StdClass');
}
public function testGetInvalidPlugin()
......@@ -211,74 +211,293 @@ class Solarium_ClientTest extends PHPUnit_Framework_TestCase
public function testCreateResult()
{
$query = new Solarium_Query_Select();
$response = new Solarium_Client_Response('',array('HTTP 1.0 200 OK'));
$result = $this->_client->createResult($query, $response);
$this->assertThat(
$result,
$this->isInstanceOf($query->getResultClass())
);
}
public function testCreateResultInvalidQueryType()
public function testCreateResultPrePlugin()
{
$query = new Solarium_Query_Select();
$response = new Solarium_Client_Response('',array('HTTP 1.0 200 OK'));
$observer = $this->getMock('Solarium_Plugin_Abstract', array(), array($this->_client,array()));
$observer->expects($this->once())
->method('preCreateResult')
->with($this->equalTo($query),$this->equalTo($response));
$this->_client->registerPlugin('testplugin', $observer);
$this->_client->createResult($query, $response);
}
public function testCreateResultPrePlugin()
public function testCreateResultPostPlugin()
{
$query = new Solarium_Query_Select();
$response = new Solarium_Client_Response('',array('HTTP 1.0 200 OK'));
$result = $this->_client->createResult($query, $response);
$observer = $this->getMock('Solarium_Plugin_Abstract', array(), array($this->_client,array()));
$observer->expects($this->once())
->method('postCreateResult')
->with($this->equalTo($query), $this->equalTo($response), $this->equalTo($result));
$this->_client->registerPlugin('testplugin', $observer);
$this->_client->createResult($query, $response);
}
public function testCreateResultPostPlugin()
public function testCreateResultWithOverridingPlugin()
{
$overrideValue = 'dummyvalue';
$query = new Solarium_Query_Select();
$response = new Solarium_Client_Response('',array('HTTP 1.0 200 OK'));
$observer = $this->getMock('Solarium_Plugin_Abstract', array(), array($this->_client,array()));
$observer->expects($this->once())
->method('preCreateResult')
->with($this->equalTo($query), $this->equalTo($response))
->will($this->returnValue($overrideValue));
$this->_client->registerPlugin('testplugin', $observer);
$result = $this->_client->createResult($query, $response);
$this->assertEquals(
$overrideValue,
$result
);
}
public function testCreateResultWithOverridingPlugin()
public function testExecute()
{
$query = new Solarium_Query_Ping();
$observer = $this->getMock('Solarium_Client', array('createRequest','executeRequest','createResult'));
$observer->expects($this->once())
->method('createRequest')
->with($this->equalTo($query))
->will($this->returnValue('dummyrequest'));
$observer->expects($this->once())
->method('executeRequest')
->with($this->equalTo('dummyrequest'))
->will($this->returnValue('dummyresponse'));
$observer->expects($this->once())
->method('createResult')
->with($this->equalTo($query),$this->equalTo('dummyresponse'));
$observer->execute($query);
}
public function testPing()
public function testExecutePrePlugin()
{
$query = new Solarium_Query_Ping();
$mock = $this->getMock('Solarium_Client', array('createRequest','executeRequest','createResult'));
$mock->expects($this->once())
->method('createRequest')
->will($this->returnValue('dummyrequest'));
$mock->expects($this->once())
->method('executeRequest')
->will($this->returnValue('dummyresponse'));
$mock->expects($this->once())
->method('createResult')
->will($this->returnValue('dummyresult'));
$observer = $this->getMock('Solarium_Plugin_Abstract', array(), array($this->_client,array()));
$observer->expects($this->once())
->method('preExecute')
->with($this->equalTo($query));
$mock->registerPlugin('testplugin', $observer);
$mock->execute($query);
}
public function testSelect()
public function testExecutePostPlugin()
{
$query = new Solarium_Query_Ping();
$mock = $this->getMock('Solarium_Client', array('createRequest','executeRequest','createResult'));
$mock->expects($this->once())
->method('createRequest')
->will($this->returnValue('dummyrequest'));
$mock->expects($this->once())
->method('executeRequest')
->will($this->returnValue('dummyresponse'));
$mock->expects($this->once())
->method('createResult')
->will($this->returnValue('dummyresult'));
$observer = $this->getMock('Solarium_Plugin_Abstract', array(), array($this->_client,array()));
$observer->expects($this->once())
->method('postExecute')
->with($this->equalTo($query), $this->equalTo('dummyresult'));
$mock->registerPlugin('testplugin', $observer);
$mock->execute($query);
}
public function testUpdate()
public function testExecuteWithOverridingPlugin()
{
$query = new Solarium_Query_Ping();
$observer = $this->getMock('Solarium_Plugin_Abstract', array(), array($this->_client,array()));
$observer->expects($this->once())
->method('preExecute')
->with($this->equalTo($query))
->will($this->returnValue('dummyoverride'));
$this->_client->registerPlugin('testplugin', $observer);
$result = $this->_client->execute($query);
$this->assertEquals(
'dummyoverride',
$result
);
}
}
public function testExecuteRequest()
{
$request = new Solarium_Client_Request();
$dummyResponse = 'dummyresponse';
class MyAdapter extends Solarium_Client_Adapter_Http{
$observer = $this->getMock('Solarium_Client_Adapter', array('execute'));
$observer->expects($this->once())
->method('execute')
->with($this->equalTo($request))
->will($this->returnValue($dummyResponse));
public function execute($request)
$this->_client->setAdapter($observer);
$response = $this->_client->executeRequest($request);
$this->assertEquals(
$dummyResponse,
$response
);
}
public function testExecuteRequestPrePlugin()
{
$response = new Solarium_Client_Response('{}', array('HTTP/1.1 200 OK'));
return $response;
$request = new Solarium_Client_Request();
$dummyResponse = 'dummyresponse';
$mockAdapter = $this->getMock('Solarium_Client_Adapter', array('execute'));
$mockAdapter->expects($this->once())
->method('execute')
->with($this->equalTo($request))
->will($this->returnValue($dummyResponse));
$this->_client->setAdapter($mockAdapter);
$observer = $this->getMock('Solarium_Plugin_Abstract', array(), array($this->_client,array()));
$observer->expects($this->once())
->method('preExecuteRequest')
->with($this->equalTo($request));
$this->_client->registerPlugin('testplugin', $observer);
$this->_client->executeRequest($request);
}
}
class myConfig{
public function testExecuteRequestPostPlugin()
{
$request = new Solarium_Client_Request();
$dummyResponse = 'dummyresponse';
$mockAdapter = $this->getMock('Solarium_Client_Adapter', array('execute'));
$mockAdapter->expects($this->any())
->method('execute')
->with($this->equalTo($request))
->will($this->returnValue($dummyResponse));
$this->_client->setAdapter($mockAdapter);
$response = $this->_client->executeRequest($request);
$observer = $this->getMock('Solarium_Plugin_Abstract', array(), array($this->_client,array()));
$observer->expects($this->once())
->method('postExecuteRequest')
->with($this->equalTo($request), $this->equalTo($response));
$this->_client->registerPlugin('testplugin', $observer);
$this->_client->executeRequest($request);
}
public function testExecuteRequestWithOverridingPlugin()
{
$request = new Solarium_Client_Request();
$dummyOverride = 'dummyoverride';
$observer = $this->getMock('Solarium_Plugin_Abstract', array(), array($this->_client,array()));
$observer->expects($this->once())
->method('preExecuteRequest')
->with($this->equalTo($request))
->will($this->returnValue($dummyOverride));
$this->_client->registerPlugin('testplugin', $observer);
$response = $this->_client->executeRequest($request);
$this->assertEquals(
$dummyOverride,
$response
);
}
public function testPing()
{
$query = new Solarium_Query_Ping();
protected $_options;
$observer = $this->getMock('Solarium_Client', array('execute'));
$observer->expects($this->once())
->method('execute')
->with($this->equalTo($query));
$observer->ping($query);
}
public function __construct($options)
public function testSelect()
{
$this->_options = $options;
$query = new Solarium_Query_Select();
$observer = $this->getMock('Solarium_Client', array('execute'));
$observer->expects($this->once())
->method('execute')
->with($this->equalTo($query));
$observer->select($query);
}
public function toArray()
public function testUpdate()
{
return $this->_options;
$query = new Solarium_Query_Update();
$observer = $this->getMock('Solarium_Client', array('execute'));
$observer->expects($this->once())
->method('execute')
->with($this->equalTo($query));
$observer->update($query);
}
}
class MyClientPlugin extends Solarium_Plugin_Abstract{
class MyAdapter extends Solarium_Client_Adapter_Http{
public function execute($request)
{
$response = new Solarium_Client_Response('{}', array('HTTP/1.1 200 OK'));
return $response;
}
}
class MyInvalidClientPlugin{
class MyClientPlugin extends Solarium_Plugin_Abstract{
}
\ 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