Skip to content

Commit 07c04a6

Browse files
authored
Fixed Mockery expectations + faulty paginator (#7)
1 parent f354c61 commit 07c04a6

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/Engines/ArrayEngine.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ protected function performSearch(Builder $builder, array $options = [])
132132
$matches = Collection::make($matches);
133133

134134
return [
135-
'hits' => (isset($options['perPage']) ? $matches->slice(($options['page'] ?? 1) - 1, $options['perPage']) : $matches)->values()->all(),
135+
'hits' => (isset($options['perPage']) ? $matches->slice((($options['page'] ?? 1) - 1) * $options['perPage'], $options['perPage']) : $matches)->values()->all(),
136136
'total' => $matches->count(),
137137
];
138138
}

tests/Engines/ArrayEngineTest.php

+12-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class ArrayEngineTest extends TestCase
1919
protected function setUp(): void
2020
{
2121
Config::shouldReceive('get')->with('scout.after_commit', Mockery::any())->andReturn(false);
22+
Config::shouldReceive('get')->with('scout.soft_delete', Mockery::any())->andReturn(false);
2223
}
2324

2425
protected function tearDown(): void
@@ -272,14 +273,20 @@ public function it_can_paginate_results()
272273
$engine->update(Collection::make([
273274
new SearchableModel(['foo' => 'bar', 'scoutKey' => 1]),
274275
new SearchableModel(['foo' => 'bar', 'scoutKey' => 2]),
275-
new SearchableModel(['foo' => 'bar', 'scoutKey' => 3])
276+
new SearchableModel(['foo' => 'bar', 'scoutKey' => 3]),
277+
new SearchableModel(['foo' => 'bar', 'scoutKey' => 4]),
278+
new SearchableModel(['foo' => 'bar', 'scoutKey' => 5]),
279+
new SearchableModel(['foo' => 'bar', 'scoutKey' => 6]),
280+
new SearchableModel(['foo' => 'bar', 'scoutKey' => 7]),
281+
new SearchableModel(['foo' => 'bar', 'scoutKey' => 8]),
276282
]));
277283

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

280-
$this->assertCount(1, $results['hits']);
281-
$this->assertEquals(3, $results['total']);
282-
$this->assertEquals(1, $results['hits'][0]['scoutKey']);
286+
$this->assertCount(2, $results['hits']);
287+
$this->assertEquals(8, $results['total']);
288+
$this->assertEquals(4, $results['hits'][0]['scoutKey']);
289+
$this->assertEquals(3, $results['hits'][1]['scoutKey']);
283290
}
284291

285292
/** @test */

0 commit comments

Comments
 (0)