Skip to content

Commit 62e8254

Browse files
authored
Merge pull request #4 from olekjs/dev-release-v1.3.0
Dev 1.3.0 release
2 parents 477fba4 + b56d7b8 commit 62e8254

File tree

4 files changed

+139
-25
lines changed

4 files changed

+139
-25
lines changed

.github/workflows/phpunit.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: "Continuous Integration"
2+
3+
on:
4+
pull_request: null
5+
6+
jobs:
7+
phpunit:
8+
name: "PHPUnit"
9+
runs-on: "ubuntu-22.04"
10+
11+
strategy:
12+
matrix:
13+
php-version:
14+
- "8.1"
15+
- "8.2"
16+
deps:
17+
- "normal"
18+
19+
steps:
20+
- name: "Checkout"
21+
uses: "actions/checkout@v2"
22+
with:
23+
fetch-depth: 2
24+
25+
- name: "Install PHP"
26+
uses: "shivammathur/setup-php@v2"
27+
with:
28+
php-version: "${{ matrix.php-version }}"
29+
30+
- name: "Cache dependencies installed with composer"
31+
uses: "actions/cache@v2"
32+
with:
33+
path: "~/.composer/cache"
34+
key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}"
35+
restore-keys: "php-${{ matrix.php-version }}-composer-locked-"
36+
37+
- name: "Update dependencies with composer"
38+
run: "composer update --no-interaction --no-progress --no-suggest"
39+
if: "${{ matrix.deps == 'normal' }}"
40+
41+
- name: "Install lowest possible dependencies with composer"
42+
run: "composer update --no-interaction --no-progress --no-suggest --prefer-dist --prefer-lowest"
43+
if: "${{ matrix.deps == 'low' }}"
44+
45+
- name: "Run PHPUnit"
46+
run: "vendor/bin/phpunit"

src/Builder/Builder.php

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,28 +46,28 @@ public function index(string $index): self
4646
return $this;
4747
}
4848

49-
public function where(string $field, string $value): self
49+
public function whereKeyword(string $field, string $value): self
5050
{
5151
$this->query['bool']['filter'][]['term'][$field . '.keyword'] = $value;
5252

5353
return $this;
5454
}
5555

56-
public function orWhere(string $field, string $value): self
56+
public function orWhereKeyword(string $field, string $value): self
5757
{
5858
$this->query['bool']['should'][]['term'][$field . '.keyword'] = $value;
5959

6060
return $this;
6161
}
6262

63-
public function whereLike(string $field, string|int|float|array $value): self
63+
public function where(string $field, string|int|float|array $value): self
6464
{
6565
$this->query['bool']['filter'][]['term'][$field] = $value;
6666

6767
return $this;
6868
}
6969

70-
public function orWhereLike(string $field, string|int|float|array $value): self
70+
public function orWhere(string $field, string|int|float|array $value): self
7171
{
7272
$this->query['bool']['should'][]['term'][$field] = $value;
7373

@@ -88,6 +88,34 @@ public function orWhereIn(string $field, array $values): self
8888
return $this;
8989
}
9090

91+
public function whereLike(string $field, string|int|float|array $value): self
92+
{
93+
$this->query['bool']['filter'][]['wildcard'][$field] = $value;
94+
95+
return $this;
96+
}
97+
98+
public function orWhereLike(string $field, string|int|float|array $value): self
99+
{
100+
$this->query['bool']['should'][]['wildcard'][$field] = $value;
101+
102+
return $this;
103+
}
104+
105+
public function whereNot(string $field, string|int|float|array $value): self
106+
{
107+
$this->query['bool']['must_not'][]['term'][$field] = $value;
108+
109+
return $this;
110+
}
111+
112+
public function orWhereNot(string $field, string|int|float|array $value): self
113+
{
114+
$this->query['bool']['should'][]['bool']['must_not'][]['term'][$field] = $value;
115+
116+
return $this;
117+
}
118+
91119
public function whereGreaterThan(string $field, int|float $value): self
92120
{
93121
return $this->whereRange($field, $value, 'gt');

src/Contracts/BuilderInterface.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,22 @@ public static function query(?ClientInterface $client = null): Builder;
1818

1919
public function index(string $index): self;
2020

21-
public function where(string $field, string $value): self;
21+
public function whereKeyword(string $field, string $value): self;
2222

23-
public function orWhere(string $field, string $value): self;
23+
public function orWhereKeyword(string $field, string $value): self;
2424

25-
public function whereLike(string $field, string|int|float|array $value): self;
25+
public function where(string $field, string|int|float|array $value): self;
2626

27-
public function orWhereLike(string $field, string|int|float|array $value): self;
27+
public function orWhere(string $field, string|int|float|array $value): self;
2828

2929
public function whereIn(string $field, array $values): self;
3030

3131
public function orWhereIn(string $field, array $values): self;
3232

33+
public function whereLike(string $field, string|int|float|array $value): self;
34+
35+
public function orWhereLike(string $field, string|int|float|array $value): self;
36+
3337
public function whereGreaterThan(string $field, int|float $value): self;
3438

3539
public function whereLessThan(string $field, int|float $value): self;

tests/Unit/BuilderTest.php

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ public function testIndexMethod(): void
2323
$this->assertSame('test', $builder->getIndex());
2424
}
2525

26-
public function testWhereMethod(): void
26+
public function testWhereKeywordMethod(): void
2727
{
28-
$builder = Builder::query()->where('email', 'test@test.com');
28+
$builder = Builder::query()->whereKeyword('email', 'test@test.com');
2929

3030
$this->assertSame([
3131
'bool' => ['filter' => [['term' => ['email.keyword' => 'test@test.com']]]]
3232
], $builder->getQuery());
3333
}
3434

35-
public function testWhereLikeMethod(): void
35+
public function testWhereMethod(): void
3636
{
37-
$builder = Builder::query()->whereLike('name', 'test');
37+
$builder = Builder::query()->where('name', 'test');
3838

3939
$this->assertSame([
4040
'bool' => ['filter' => [['term' => ['name' => 'test']]]]
@@ -77,7 +77,7 @@ public function testConditionableTrait(): void
7777
{
7878
$builder = Builder::query()->when(
7979
true,
80-
fn(Builder $builder) => $builder->where('email', 'test@test.com')
80+
fn(Builder $builder) => $builder->whereKeyword('email', 'test@test.com')
8181
);
8282

8383
$this->assertSame([
@@ -86,7 +86,7 @@ public function testConditionableTrait(): void
8686

8787
$builder = Builder::query()->when(
8888
false,
89-
fn(Builder $builder) => $builder->where('email', 'test@test.com')
89+
fn(Builder $builder) => $builder->whereKeyword('email', 'test@test.com')
9090
);
9191

9292
$this->assertEmpty($builder->getBody());
@@ -95,9 +95,9 @@ public function testConditionableTrait(): void
9595
public function testChainedMethods(): void
9696
{
9797
$builder = Builder::query()
98-
->where('email', 'test@test.com')
99-
->where('slug', 'test-slug')
100-
->whereLike('name', 'test')
98+
->whereKeyword('email', 'test@test.com')
99+
->whereKeyword('slug', 'test-slug')
100+
->where('name', 'test')
101101
->whereIn('_id', [123, 321])
102102
->limit(10);
103103

@@ -134,12 +134,12 @@ public function testChainedMethods(): void
134134
);
135135
}
136136

137-
public function testOrWhereMethod(): void
137+
public function testOrWhereKeywordMethod(): void
138138
{
139139
$builder = Builder::query()
140140
->index('test')
141-
->where('email', 'test@test.com')
142-
->orWhere('username', 'tester');
141+
->whereKeyword('email', 'test@test.com')
142+
->orWhereKeyword('username', 'tester');
143143

144144
$this->assertSame(
145145
[
@@ -155,7 +155,7 @@ public function testOrWhereMethod(): void
155155
$builder->getQuery()
156156
);
157157

158-
$builder->orWhere('surname', 'tests');
158+
$builder->orWhereKeyword('surname', 'tests');
159159

160160
$this->assertSame(
161161
[
@@ -173,12 +173,12 @@ public function testOrWhereMethod(): void
173173
);
174174
}
175175

176-
public function testOrWhereLikeMethod(): void
176+
public function testOrWhereMethod(): void
177177
{
178178
$builder = Builder::query()
179179
->index('test')
180-
->whereLike('email', 'test@test.com')
181-
->orWhereLike('username', 'tester');
180+
->where('email', 'test@test.com')
181+
->orWhere('username', 'tester');
182182

183183
$this->assertSame(
184184
[
@@ -194,7 +194,7 @@ public function testOrWhereLikeMethod(): void
194194
$builder->getQuery()
195195
);
196196

197-
$builder->orWhereLike('surname', 'tests');
197+
$builder->orWhere('surname', 'tests');
198198

199199
$this->assertSame(
200200
[
@@ -364,4 +364,40 @@ public function testPaginateMethod(): void
364364
$this->assertSame(10, $result->getCurrentPage());
365365
$this->assertSame(100, $result->getPerPage());
366366
}
367+
368+
public function testWhereLikeMethod(): void
369+
{
370+
$builder = Builder::query()->whereLike('name', '*test*');
371+
372+
$this->assertSame([
373+
'bool' => ['filter' => [['wildcard' => ['name' => '*test*']]]]
374+
], $builder->getQuery());
375+
}
376+
377+
public function testOrWhereLikeMethod(): void
378+
{
379+
$builder = Builder::query()->orWhereLike('name', '*test*');
380+
381+
$this->assertSame([
382+
'bool' => ['should' => [['wildcard' => ['name' => '*test*']]]]
383+
], $builder->getQuery());
384+
}
385+
386+
public function testWhereNotMethod(): void
387+
{
388+
$builder = Builder::query()->whereNot('name', 'test');
389+
390+
$this->assertSame([
391+
'bool' => ['must_not' => [['term' => ['name' => 'test']]]]
392+
], $builder->getQuery());
393+
}
394+
395+
public function testOrWhereNotMethod(): void
396+
{
397+
$builder = Builder::query()->orWhereNot('name', 'test');
398+
399+
$this->assertSame([
400+
'bool' => ['should' => [['bool' => ['must_not' => [['term' => ['name' => 'test']]]]]]]
401+
], $builder->getQuery());
402+
}
367403
}

0 commit comments

Comments
 (0)