Skip to content

Commit e41a769

Browse files
committed
test: add limit test for elasticsearch connection and model
1 parent 129c4b7 commit e41a769

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

tests/LimitTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use PDPhilip\Elasticsearch\Tests\Models\IdGenerated\Product;
6+
7+
beforeEach(function () {
8+
Product::executeSchema();
9+
10+
Product::insert([
11+
['product' => 'chocolate', 'price' => 5],
12+
['product' => 'pumpkin', 'price' => 30],
13+
['product' => 'apple', 'price' => 10],
14+
['product' => 'orange juice', 'price' => 5],
15+
['product' => 'coffee', 'price' => 15],
16+
['product' => 'tea', 'price' => 12],
17+
['product' => 'cookies', 'price' => 5],
18+
['product' => 'ice cream', 'price' => 22],
19+
['product' => 'bagel', 'price' => 8],
20+
['product' => 'salad', 'price' => 14],
21+
['product' => 'sandwich', 'price' => 5],
22+
['product' => 'pizza', 'price' => 45],
23+
['product' => 'water', 'price' => 5],
24+
['product' => 'soda', 'price' => 5],
25+
]);
26+
});
27+
28+
it('tests where clause', function () {
29+
30+
class ProductWithLimit extends Product
31+
{
32+
protected $defaultLimit = 7;
33+
}
34+
35+
class ProductWithDefaultConnectionLimit extends Product
36+
{
37+
protected $connection = 'elasticsearch_with_default_limit';
38+
}
39+
40+
$products = ProductWithLimit::all();
41+
expect($products)->toHaveCount(7);
42+
43+
$products = ProductWithDefaultConnectionLimit::all();
44+
expect($products)->toHaveCount(4);
45+
46+
$products = ProductWithLimit::limit(3)->get();
47+
expect($products)->toHaveCount(3);
48+
});

tests/TestCase.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ protected function getEnvironmentSetUp($app): void
3636
'logging' => true,
3737
],
3838
]);
39+
$app['config']->set('database.connections.elasticsearch_with_default_limit', [
40+
'driver' => 'elasticsearch',
41+
'auth_type' => 'http',
42+
'hosts' => ['http://localhost:9200'],
43+
'options' => [
44+
'default_limit' => 4,
45+
'logging' => true,
46+
],
47+
]);
3948

4049
$app['config']->set('database.connections.elasticsearch_unsafe', [
4150
'driver' => 'elasticsearch',

0 commit comments

Comments
 (0)