Skip to content
Snippets Groups Projects
Commit 228588fc authored by Demian Katz's avatar Demian Katz
Browse files

Improved test coverage.

parent 6558e3c4
No related merge requests found
...@@ -31,6 +31,8 @@ namespace VuFindTest; ...@@ -31,6 +31,8 @@ namespace VuFindTest;
use VuFindSearch\Service; use VuFindSearch\Service;
use VuFindSearch\ParamBag; use VuFindSearch\ParamBag;
use VuFindSearch\Backend\Exception\BackendException;
use VuFindSearch\Response\AbstractRecordCollection;
use PHPUnit_Framework_TestCase as TestCase; use PHPUnit_Framework_TestCase as TestCase;
...@@ -74,6 +76,62 @@ class SearchServiceTest extends TestCase ...@@ -74,6 +76,62 @@ class SearchServiceTest extends TestCase
$service->retrieve('foo', 'bar', $params); $service->retrieve('foo', 'bar', $params);
} }
/**
* Test exception-throwing retrieve action.
*
* @return void
* @expectedException VuFindSearch\Backend\Exception\BackendException
* @expectedExceptionMessage test
*/
public function testRetrieveException()
{
$service = $this->getService();
$backend = $this->getBackend();
$response = 'fake';
$params = new ParamBag(array('x' => 'y'));
$exception = new BackendException('test');
$backend->expects($this->once())->method('retrieve')
->with($this->equalTo('bar'), $this->equalTo($params))
->will($this->throwException($exception));
$em = $service->getEventManager();
$em->expects($this->at(0))->method('trigger')
->with($this->equalTo('pre'), $this->equalTo($backend));
$em->expects($this->at(1))->method('trigger')
->with($this->equalTo('error'), $this->equalTo($exception));
$service->retrieve('foo', 'bar', $params);
}
/**
* Test batch retrieve.
*
* @return void
*/
public function testRetrieveBatch()
{
$service = $this->getService();
$backend = $this->getBackend();
$mockRecord = $this->getMock('VuFindSearch\Response\RecordInterface');
$response1 = $this->getRecordCollection();
$response1->expects($this->once())->method('add')
->with($this->equalTo($mockRecord));
$response2 = $this->getRecordCollection();
$response2->expects($this->once())->method('first')
->will($this->returnValue($mockRecord));
$params = new ParamBag(array('x' => 'y'));
$backend->expects($this->at(0))->method('retrieve')
->with($this->equalTo('bar'), $this->equalTo($params))
->will($this->returnValue($response1));
$backend->expects($this->at(1))->method('retrieve')
->with($this->equalTo('baz'), $this->equalTo($params))
->will($this->returnValue($response2));
$em = $service->getEventManager();
$em->expects($this->at(0))->method('trigger')
->with($this->equalTo('pre'), $this->equalTo($backend));
$em->expects($this->at(1))->method('trigger')
->with($this->equalTo('post'), $this->equalTo($response1));
$service->retrieveBatch('foo', array('bar', 'baz'), $params);
}
// Internal API // Internal API
/** /**
...@@ -103,4 +161,16 @@ class SearchServiceTest extends TestCase ...@@ -103,4 +161,16 @@ class SearchServiceTest extends TestCase
$service->setEventManager($em); $service->setEventManager($em);
return $service; return $service;
} }
/**
* Generate a fake record collection.
*
* @param string $id ID of record to include in collection.
*
* @return AbstractRecordCollection
*/
protected function getRecordCollection()
{
return $this->getMock('VuFindSearch\Response\AbstractRecordCollection');
}
} }
\ No newline at end of file
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