Skip to content
Snippets Groups Projects
Commit d6ae55ed authored by David Maus's avatar David Maus
Browse files

Rethrow Summon exception as BackendException

* VuFindSearch/Backend/Summon/Backend.php (search, retrieve):
  Catch Summon Exception and rethrow as BackendException.
parent f2e41d19
No related merge requests found
...@@ -31,6 +31,7 @@ namespace VuFindSearch\Backend\Summon; ...@@ -31,6 +31,7 @@ namespace VuFindSearch\Backend\Summon;
use SerialsSolutions\Summon\Zend2 as Connector; use SerialsSolutions\Summon\Zend2 as Connector;
use SerialsSolutions_Summon_Query as SummonQuery; use SerialsSolutions_Summon_Query as SummonQuery;
use SerialsSolutions_Summon_Exception as SummonException;
use VuFindSearch\Query\AbstractQuery; use VuFindSearch\Query\AbstractQuery;
...@@ -40,6 +41,7 @@ use VuFindSearch\Response\RecordCollectionInterface; ...@@ -40,6 +41,7 @@ use VuFindSearch\Response\RecordCollectionInterface;
use VuFindSearch\Response\RecordCollectionFactoryInterface; use VuFindSearch\Response\RecordCollectionFactoryInterface;
use VuFindSearch\Backend\BackendInterface; use VuFindSearch\Backend\BackendInterface;
use VuFindSearch\Backend\Exception\BackendException;
use Zend\Log\LoggerInterface; use Zend\Log\LoggerInterface;
...@@ -139,7 +141,15 @@ class Backend implements BackendInterface ...@@ -139,7 +141,15 @@ class Backend implements BackendInterface
$baseParams->set('pageNumber', $page); $baseParams->set('pageNumber', $page);
$summonQuery = $this->paramBagToSummonQuery($baseParams); $summonQuery = $this->paramBagToSummonQuery($baseParams);
$response = $this->connector->query($summonQuery); try {
$response = $this->connector->query($summonQuery);
} catch (SummonException $e) {
throw new BackendException(
$e->getMessage(),
$e->getCode(),
$e
);
}
$collection = $this->createRecordCollection($response); $collection = $this->createRecordCollection($response);
$this->injectSourceIdentifier($collection); $this->injectSourceIdentifier($collection);
return $collection; return $collection;
...@@ -155,7 +165,15 @@ class Backend implements BackendInterface ...@@ -155,7 +165,15 @@ class Backend implements BackendInterface
*/ */
public function retrieve($id, ParamBag $params = null) public function retrieve($id, ParamBag $params = null)
{ {
$response = $this->connector->getRecord($id); try {
$response = $this->connector->getRecord($id);
} catch (SummonException $e) {
throw new BackendException(
$e->getMessage(),
$e->getCode(),
$e
);
}
$collection = $this->createRecordCollection($response); $collection = $this->createRecordCollection($response);
$this->injectSourceIdentifier($collection); $this->injectSourceIdentifier($collection);
return $collection; return $collection;
......
<?php
/**
* Unit tests for Summon Backend class.
*
* PHP version 5
*
* Copyright (C) Villanova University 2013.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @category VuFind2
* @package Search
* @author David Maus <maus@hab.de>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org
*/
namespace VuFindSearch\Backend\Summon;
use VuFindSearch\Query\Query;
use SerialsSolutions_Summon_Exception as SummonException;
use PHPUnit_Framework_TestCase as TestCase;
/**
* Unit tests for Summon Backend class.
*
* @category VuFind2
* @package Search
* @author David Maus <maus@hab.de>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org
*/
class BackendTest extends TestCase
{
protected function setup()
{
if (!class_exists('SerialsSolutions_Summon_Exception', true)) {
$this->markTestIncomplete('Unable to autoload class: SerialsSolutions\Summon\Exception');
}
}
/**
* @expectedException VuFindSearch\Backend\Exception\BackendException
*/
public function testRetrieveWrapsSummonException()
{
$fact = $this->getMock('VuFindSearch\Response\RecordCollectionFactoryInterface');
$conn = $this->getMock('SerialsSolutions\Summon\Zend2', array('getRecord'), array('id', 'key'));
$conn->expects($this->once())
->method('getRecord')
->will($this->throwException(new SummonException()));
$back = new Backend($conn, $fact);
$back->retrieve('id');
}
/**
* @expectedException VuFindSearch\Backend\Exception\BackendException
*/
public function testSearchWrapsSummonException()
{
$fact = $this->getMock('VuFindSearch\Response\RecordCollectionFactoryInterface');
$conn = $this->getMock('SerialsSolutions\Summon\Zend2', array('query'), array('id', 'key'));
$conn->expects($this->once())
->method('query')
->will($this->throwException(new SummonException()));
$back = new Backend($conn, $fact);
$back->search(new Query(), 1, 1);
}
}
\ 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