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

Better validation within similar() call.

parent d5334136
No related merge requests found
......@@ -289,12 +289,15 @@ class Service
$params = $params ?: new ParamBag();
$context = __FUNCTION__;
$args = compact('backend', 'id', 'params', 'context');
$backend = $this->resolve($backend, $args);
$args['backend_instance'] = $backend;
$backendInstance = $this->resolve($backend, $args);
$args['backend_instance'] = $backendInstance;
$this->triggerPre($backend, $args);
$this->triggerPre($backendInstance, $args);
try {
$response = $backend->similar($id, $params);
if (!($backendInstance instanceof Feature\SimilarInterface)) {
throw new BackendException("$backend does not support similar()");
}
$response = $backendInstance->similar($id, $params);
} catch (BackendException $e) {
$this->triggerError($e, $args);
throw $e;
......
......@@ -35,6 +35,7 @@ use VuFindSearch\Backend\BackendInterface;
use VuFindSearch\Backend\Exception\BackendException;
use VuFindSearch\Feature\RetrieveBatchInterface;
use VuFindSearch\Feature\RandomInterface;
use VuFindSearch\Feature\SimilarInterface;
use VuFindSearch\Query\Query;
use VuFindSearch\Response\AbstractRecordCollection;
......@@ -585,6 +586,20 @@ class SearchServiceTest extends TestCase
unset($this->backend);
}
/**
* Test similar action on bad backend.
*
* @return void
* @expectedException VuFindSearch\Backend\Exception\BackendException
* @expectedExceptionMessage foo does not support similar()
*/
public function testSimilarOnNonSupportingBackend()
{
$service = $this->getService();
$params = new ParamBag(array('x' => 'y'));
$service->similar('foo', 'bar', $params);
}
/**
* Test exception-throwing similar action.
*
......@@ -690,9 +705,8 @@ abstract class TestClassForRetrieveBatchInterface
* Stub class to test similar.
*/
abstract class TestBackendClassForSimilar
implements BackendInterface
implements BackendInterface, SimilarInterface
{
abstract function similar();
}
/**
......
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