/** * * @param sfLuceneResults $lucene_results * @param sfLucene $search */ public function __construct($lucene_results, $search = null) { if (!$lucene_results instanceof sfLuceneResults) { throw new sfLuceneException('first arguments must be a sfLuceneResults instance'); } $this->lucene_results = $lucene_results; $this->results = $lucene_results->toArray(); $this->search_parameters = $lucene_results->getRawResult()->sf_lucene_search; // compute the page number from the results $limit = $lucene_results->getRawResult()->sf_lucene_search['limit']; $start = $this->getResults()->getRawResult()->response->start; $this->setMaxPerPage($limit); $this->setPage((int) ($start / $limit) + 1); $this->must_reload = false; $this->search = $search === null ? $lucene_results->getSearch() : $search; if (!$this->search instanceof sfLucene) { throw new sfLuceneException('second arguments must be a sfLucene instance'); } }
} class MockDocument { public function getFieldValue($field) { if ($field == 'sfl_type') { return 'regular'; } throw new Exception('d'); } } $data = array(new MockResult('foo'), new MockResult('bar'), new MockResult('baz')); $search = sfLucene::getInstance('testLucene'); $results = new sfLuceneResults($data, $search); $t->diag('testing ->getSearch(), ->toArray()'); $t->is($results->getSearch(), $search, '->getSearch() returns the same search instance'); $t->is($results->toArray(), $data, '->toArray() returns the same search data'); $t->diag('testing Iterator interface'); $got = array(); $once = false; foreach ($results as $key => $value) { if (!$once) { $t->ok($value instanceof sfLuceneResult, 'iterator interface returns instances of sfLuceneResult'); $once = true; } $got[$key] = $value->getResult(); } $t->is($got, $data, 'sfLuceneResults implements the Iterator interface'); $t->diag('testing Countable interface'); $t->is(count($results), count($data), 'sfLuceneResults implements the Countable interface'); $t->diag('testing ArrayAccess interface');