Skip to content

Commit

Permalink
Fixed Mockery expectations + faulty paginator (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
arondeparon authored Oct 26, 2021
1 parent f354c61 commit 07c04a6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Engines/ArrayEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ protected function performSearch(Builder $builder, array $options = [])
$matches = Collection::make($matches);

return [
'hits' => (isset($options['perPage']) ? $matches->slice(($options['page'] ?? 1) - 1, $options['perPage']) : $matches)->values()->all(),
'hits' => (isset($options['perPage']) ? $matches->slice((($options['page'] ?? 1) - 1) * $options['perPage'], $options['perPage']) : $matches)->values()->all(),
'total' => $matches->count(),
];
}
Expand Down
17 changes: 12 additions & 5 deletions tests/Engines/ArrayEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ArrayEngineTest extends TestCase
protected function setUp(): void
{
Config::shouldReceive('get')->with('scout.after_commit', Mockery::any())->andReturn(false);
Config::shouldReceive('get')->with('scout.soft_delete', Mockery::any())->andReturn(false);
}

protected function tearDown(): void
Expand Down Expand Up @@ -272,14 +273,20 @@ public function it_can_paginate_results()
$engine->update(Collection::make([
new SearchableModel(['foo' => 'bar', 'scoutKey' => 1]),
new SearchableModel(['foo' => 'bar', 'scoutKey' => 2]),
new SearchableModel(['foo' => 'bar', 'scoutKey' => 3])
new SearchableModel(['foo' => 'bar', 'scoutKey' => 3]),
new SearchableModel(['foo' => 'bar', 'scoutKey' => 4]),
new SearchableModel(['foo' => 'bar', 'scoutKey' => 5]),
new SearchableModel(['foo' => 'bar', 'scoutKey' => 6]),
new SearchableModel(['foo' => 'bar', 'scoutKey' => 7]),
new SearchableModel(['foo' => 'bar', 'scoutKey' => 8]),
]));

$results = $engine->paginate(new Builder(new SearchableModel(), 'bar'), 1, 3);
$results = $engine->paginate(new Builder(new SearchableModel(), 'bar'), 2, 3);

$this->assertCount(1, $results['hits']);
$this->assertEquals(3, $results['total']);
$this->assertEquals(1, $results['hits'][0]['scoutKey']);
$this->assertCount(2, $results['hits']);
$this->assertEquals(8, $results['total']);
$this->assertEquals(4, $results['hits'][0]['scoutKey']);
$this->assertEquals(3, $results['hits'][1]['scoutKey']);
}

/** @test */
Expand Down

0 comments on commit 07c04a6

Please sign in to comment.