Skip to content

Commit 785794f

Browse files
authored
Hotfix/Wrong operation in not equal filter. (#22)
1 parent 220a839 commit 785794f

File tree

3 files changed

+108
-7
lines changed

3 files changed

+108
-7
lines changed

src/Filter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static function equal(string $field, mixed $value): self
7474

7575
public static function notEqual(string $field, mixed $value): self
7676
{
77-
return self::create($field, Operator::NOT_LIKE, $value);
77+
return self::create($field, Operator::NOT_EQUAL, $value);
7878
}
7979

8080
public static function greaterThan(string $field, mixed $value): self

src/Operator.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ enum Operator: string
1818
case GTE = '>=';
1919
case LT = '<';
2020
case LTE = '<=';
21-
case IN = 'IN';
22-
case NOT_IN = 'NOT IN';
23-
case LIKE = 'LIKE';
24-
case NOT_LIKE = 'NOT LIKE';
25-
case CONTAINS = 'CONTAINS';
26-
case NOT_CONTAINS = 'NOT CONTAINS';
21+
case IN = 'in';
22+
case NOT_IN = 'not in';
23+
case LIKE = 'like';
24+
case NOT_LIKE = 'not like';
25+
case CONTAINS = 'contains';
26+
case NOT_CONTAINS = 'not contains';
2727

2828
public static function create(string $value): self
2929
{

tests/FilterTest.php

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use ComplexHeart\Domain\Criteria\Filter;
6+
7+
test('Filter should be created with equal operator.', function () {
8+
$filter = Filter::equal('name', 'Vincent');
9+
10+
expect($filter->field())->toBe('name')
11+
->and($filter->operator()->value)->toBe('=')
12+
->and($filter->value())->toBe('Vincent');
13+
});
14+
15+
test('Filter should be created with not equal operator.', function () {
16+
$filter = Filter::notEqual('name', 'Vincent');
17+
18+
expect($filter->field())->toBe('name')
19+
->and($filter->operator()->value)->toBe('!=')
20+
->and($filter->value())->toBe('Vincent');
21+
});
22+
23+
test('Filter should be created with greater operator.', function () {
24+
$filter = Filter::greaterThan('stars', 5);
25+
26+
expect($filter->field())->toBe('stars')
27+
->and($filter->operator()->value)->toBe('>')
28+
->and($filter->value())->toBe(5);
29+
});
30+
31+
test('Filter should be created with greater or equal operator.', function () {
32+
$filter = Filter::greaterOrEqualThan('stars', 5);
33+
34+
expect($filter->field())->toBe('stars')
35+
->and($filter->operator()->value)->toBe('>=')
36+
->and($filter->value())->toBe(5);
37+
});
38+
39+
test('Filter should be created with less operator.', function () {
40+
$filter = Filter::lessThan('stars', 5);
41+
42+
expect($filter->field())->toBe('stars')
43+
->and($filter->operator()->value)->toBe('<')
44+
->and($filter->value())->toBe(5);
45+
});
46+
47+
test('Filter should be created with less or equal operator.', function () {
48+
$filter = Filter::lessOrEqualThan('stars', 5);
49+
50+
expect($filter->field())->toBe('stars')
51+
->and($filter->operator()->value)->toBe('<=')
52+
->and($filter->value())->toBe(5);
53+
});
54+
55+
test('Filter should be created with in operator.', function () {
56+
$filter = Filter::in('country', ['es', 'fr', 'pt']);
57+
58+
expect($filter->field())->toBe('country')
59+
->and($filter->operator()->value)->toBe('in')
60+
->and($filter->value())->toBe(['es', 'fr', 'pt']);
61+
});
62+
63+
test('Filter should be created with not in operator.', function () {
64+
$filter = Filter::in('country', ['es', 'fr', 'pt']);
65+
66+
expect($filter->field())->toBe('country')
67+
->and($filter->operator()->value)->toBe('in')
68+
->and($filter->value())->toBe(['es', 'fr', 'pt']);
69+
});
70+
71+
test('Filter should be created with like operator.', function () {
72+
$filter = Filter::like('bio', 'developer');
73+
74+
expect($filter->field())->toBe('bio')
75+
->and($filter->operator()->value)->toBe('like')
76+
->and($filter->value())->toBe('developer');
77+
});
78+
79+
test('Filter should be created with not like operator.', function () {
80+
$filter = Filter::notLike('bio', 'developer');
81+
82+
expect($filter->field())->toBe('bio')
83+
->and($filter->operator()->value)->toBe('not like')
84+
->and($filter->value())->toBe('developer');
85+
});
86+
87+
test('Filter should be created with contains operator.', function () {
88+
$filter = Filter::contains('bio', 'developer');
89+
90+
expect($filter->field())->toBe('bio')
91+
->and($filter->operator()->value)->toBe('contains')
92+
->and($filter->value())->toBe('developer');
93+
});
94+
95+
test('Filter should be created with not contains operator.', function () {
96+
$filter = Filter::notContains('bio', 'developer');
97+
98+
expect($filter->field())->toBe('bio')
99+
->and($filter->operator()->value)->toBe('not contains')
100+
->and($filter->value())->toBe('developer');
101+
});

0 commit comments

Comments
 (0)