diff --git a/module/VuFindSearch/src/VuFindSearch/Backend/Summon/Backend.php b/module/VuFindSearch/src/VuFindSearch/Backend/Summon/Backend.php index 0ef8cab566674fa4d0d5331a7f6d49bc0b0c0e0c..ab506b4eece19ae6a98c9603237648f0ecc52f0e 100644 --- a/module/VuFindSearch/src/VuFindSearch/Backend/Summon/Backend.php +++ b/module/VuFindSearch/src/VuFindSearch/Backend/Summon/Backend.php @@ -31,6 +31,7 @@ namespace VuFindSearch\Backend\Summon; use SerialsSolutions\Summon\Zend2 as Connector; use SerialsSolutions_Summon_Query as SummonQuery; +use SerialsSolutions_Summon_Exception as SummonException; use VuFindSearch\Query\AbstractQuery; @@ -40,6 +41,7 @@ use VuFindSearch\Response\RecordCollectionInterface; use VuFindSearch\Response\RecordCollectionFactoryInterface; use VuFindSearch\Backend\BackendInterface; +use VuFindSearch\Backend\Exception\BackendException; use Zend\Log\LoggerInterface; @@ -139,7 +141,15 @@ class Backend implements BackendInterface $baseParams->set('pageNumber', $page); $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); $this->injectSourceIdentifier($collection); return $collection; @@ -155,7 +165,15 @@ class Backend implements BackendInterface */ 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); $this->injectSourceIdentifier($collection); return $collection; diff --git a/module/VuFindSearch/tests/unit-tests/src/VuFindTest/Backend/Summon/BackendTest.php b/module/VuFindSearch/tests/unit-tests/src/VuFindTest/Backend/Summon/BackendTest.php new file mode 100644 index 0000000000000000000000000000000000000000..7a997ee78d4d2e079c7ec8fd260633eba2ed1621 --- /dev/null +++ b/module/VuFindSearch/tests/unit-tests/src/VuFindTest/Backend/Summon/BackendTest.php @@ -0,0 +1,83 @@ +<?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