/**
  * Returns the current result
  *
  * @returns xfDocumentHit
  */
 public function current()
 {
     $hit = $this->iterator->current();
     // this response is pluggable, we must do error checking
     if (!$hit instanceof xfDocumentHit) {
         throw new xfResultException('Iterator for engine must return instances of xfDocumentHit, ' . gettype($hit) . ' given');
     }
     $service = $this->registry->getService($hit->getServiceName());
     $hit->setRetorts($service->getRetorts());
     return $hit;
 }
$index = new TestIndex();
$invalid = new TestIndex();
$t->diag('->get*(), ->set*()');
$t->is($index->getName(), 'TestIndex', '->getName() is initially the name of the class');
$index->setName('foobar');
$t->is($index->getName(), 'foobar', '->setName() changes the name');
$t->isa_ok($index->getServiceRegistry(), 'xfServiceRegistry', '->getServiceRegistry() returns a service registry');
$registry = new xfServiceRegistry();
$index->setServiceRegistry($registry);
$t->is($index->getServiceRegistry(), $registry, '->setServiceRegistry() changes the service registry');
$engine = new xfMockEngine();
$index->setEngine($engine);
$t->is($index->getEngine(), $engine, '->setEngine() changes the engine');
$t->ok(!$index->isSetup(), '->isSetup() is false initially');
$index = new TestIndex();
$registry = new xfServiceRegistry();
$registry->register(new xfService(new xfMockIdentifier()));
$engine = new xfMockEngine();
$index->setServiceRegistry($registry);
$index->setEngine($engine);
$t->diag('->insert(), ->remove()');
$index->insert('foo');
$t->ok($index->isSetup(), '->insert() automatically runs setup');
$t->is(count($engine->getDocuments()), 1, '->insert() adds a document');
$index->remove('foo');
$t->is(count($engine->getDocuments()), 0, '->remove() deletes a document');
try {
    $msg = '->insert() fails if an engine does not exist';
    $invalid->insert('foo');
    $t->fail($msg);
} catch (Exception $e) {
require dirname(__FILE__) . '/../../bootstrap/unit.php';
require 'util/xfException.class.php';
require 'result/xfResultIterator.class.php';
require 'result/xfDocumentHit.class.php';
require 'result/xfResultException.class.php';
require 'mock/result/xfMockRetort.class.php';
require 'document/xfDocument.class.php';
require 'document/xfField.class.php';
require 'document/xfFieldValue.class.php';
require 'service/xfServiceRegistry.class.php';
require 'service/xfService.class.php';
require 'mock/service/xfMockIdentifier.class.php';
$service = new xfService(new xfMockIdentifier());
$retort = new xfMockRetort();
$service->addRetort($retort);
$registry = new xfServiceRegistry();
$registry->register($service);
$document = new xfDocument('guid');
$document->addField(new xfFieldValue(new xfField('_service', xfField::KEYWORD), 'foobar'));
$hit = new xfDocumentHit($document);
$array = array($hit, 'foo');
$iterator = new xfResultIterator(new ArrayIterator($array), $registry);
$t = new lime_test(9, new lime_output_color());
$t->diag('->current()');
$response = $iterator->current();
$t->isa_ok($response, 'xfDocumentHit', '->current() returns an xfDocumentHit');
$t->is($response->getDocument(), $document, '->current() returns an xfDocumentHit linked to the original document');
$iterator->next();
try {
    $msg = '->current() throws exception if internal iterator does not return an xfDocumentHit';
    $iterator->current();
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require dirname(__FILE__) . '/../../bootstrap/unit.php';
require 'util/xfException.class.php';
require 'service/xfService.class.php';
require 'service/xfServiceRegistry.class.php';
require 'service/xfServiceException.class.php';
require 'service/xfServiceNotFoundException.class.php';
require 'service/xfServiceIgnoredException.class.php';
require 'document/xfField.class.php';
require 'document/xfFieldValue.class.php';
require 'document/xfDocument.class.php';
require 'mock/service/xfMockIdentifier.class.php';
$t = new lime_test(8, new lime_output_color());
$registry = new xfServiceRegistry();
$t->is($registry->getServices(), array(), '->getServices() is empty initially');
try {
    $msg = '->getService() fails if service does not exist';
    $registry->getService('foo');
    $t->fail($msg);
} catch (Exception $e) {
    $t->pass($msg);
}
try {
    $msg = '->locate() fails if service does not exist';
    $registry->locate('foo');
    $t->fail($msg);
} catch (Exception $e) {
    $t->pass($msg);
}