public function testModels() { $this->search->shouldReceive('config->models')->with([1, 2, 3, 4, 5], ['limit' => 2, 'offset' => 3])->andReturn([[1, 2, 3, 4, 5], 5]); $this->assertEquals(Collection::make([1, 2, 3, 4, 5]), $this->runner->models('test', ['limit' => 2, 'offset' => 3])); $this->assertEquals(5, $this->runner->getCachedCount('test')); $this->assertEquals(0, $this->runner->getCachedCount('other test')); }
/** * Execute the current query and return the total number of results. * * @return int */ public function count() { $this->filter->applyFilters($this->query); $count = $this->runner->getCachedCount($this->query); if ($count === null) { $count = count($this->runner->models($this->query)); } return $count; }
/** * Execute current query and return list of models. * * @return \Illuminate\Database\Eloquent\Collection */ public function get() { $models = $this->runner->getCachedModels($this->query); if (null === $models) { $models = $this->runner->models($this->query); $this->runner->setCachedModels($this->query, $models); $this->runner->setCachedTotal($this->query, $models->count()); } if ($this->limit) { $models = $models->slice($this->offset, $this->limit); } return Collection::make($models->reload()->all()); }
public function testModels() { $this->search->shouldReceive('config->models')->with([1, 2, 3, 4, 5])->andReturn([10, 20, 30, 40, 50]); $this->assertEquals([10, 20, 30, 40, 50], $this->runner->models('test')); }