Skip to content

Hotfix/Wrong operation in not equal filter. #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static function equal(string $field, mixed $value): self

public static function notEqual(string $field, mixed $value): self
{
return self::create($field, Operator::NOT_LIKE, $value);
return self::create($field, Operator::NOT_EQUAL, $value);
}

public static function greaterThan(string $field, mixed $value): self
Expand Down
12 changes: 6 additions & 6 deletions src/Operator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ enum Operator: string
case GTE = '>=';
case LT = '<';
case LTE = '<=';
case IN = 'IN';
case NOT_IN = 'NOT IN';
case LIKE = 'LIKE';
case NOT_LIKE = 'NOT LIKE';
case CONTAINS = 'CONTAINS';
case NOT_CONTAINS = 'NOT CONTAINS';
case IN = 'in';
case NOT_IN = 'not in';
case LIKE = 'like';
case NOT_LIKE = 'not like';
case CONTAINS = 'contains';
case NOT_CONTAINS = 'not contains';

public static function create(string $value): self
{
Expand Down
101 changes: 101 additions & 0 deletions tests/FilterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

declare(strict_types=1);

use ComplexHeart\Domain\Criteria\Filter;

test('Filter should be created with equal operator.', function () {
$filter = Filter::equal('name', 'Vincent');

expect($filter->field())->toBe('name')
->and($filter->operator()->value)->toBe('=')
->and($filter->value())->toBe('Vincent');
});

test('Filter should be created with not equal operator.', function () {
$filter = Filter::notEqual('name', 'Vincent');

expect($filter->field())->toBe('name')
->and($filter->operator()->value)->toBe('!=')
->and($filter->value())->toBe('Vincent');
});

test('Filter should be created with greater operator.', function () {
$filter = Filter::greaterThan('stars', 5);

expect($filter->field())->toBe('stars')
->and($filter->operator()->value)->toBe('>')
->and($filter->value())->toBe(5);
});

test('Filter should be created with greater or equal operator.', function () {
$filter = Filter::greaterOrEqualThan('stars', 5);

expect($filter->field())->toBe('stars')
->and($filter->operator()->value)->toBe('>=')
->and($filter->value())->toBe(5);
});

test('Filter should be created with less operator.', function () {
$filter = Filter::lessThan('stars', 5);

expect($filter->field())->toBe('stars')
->and($filter->operator()->value)->toBe('<')
->and($filter->value())->toBe(5);
});

test('Filter should be created with less or equal operator.', function () {
$filter = Filter::lessOrEqualThan('stars', 5);

expect($filter->field())->toBe('stars')
->and($filter->operator()->value)->toBe('<=')
->and($filter->value())->toBe(5);
});

test('Filter should be created with in operator.', function () {
$filter = Filter::in('country', ['es', 'fr', 'pt']);

expect($filter->field())->toBe('country')
->and($filter->operator()->value)->toBe('in')
->and($filter->value())->toBe(['es', 'fr', 'pt']);
});

test('Filter should be created with not in operator.', function () {
$filter = Filter::in('country', ['es', 'fr', 'pt']);

expect($filter->field())->toBe('country')
->and($filter->operator()->value)->toBe('in')
->and($filter->value())->toBe(['es', 'fr', 'pt']);
});

test('Filter should be created with like operator.', function () {
$filter = Filter::like('bio', 'developer');

expect($filter->field())->toBe('bio')
->and($filter->operator()->value)->toBe('like')
->and($filter->value())->toBe('developer');
});

test('Filter should be created with not like operator.', function () {
$filter = Filter::notLike('bio', 'developer');

expect($filter->field())->toBe('bio')
->and($filter->operator()->value)->toBe('not like')
->and($filter->value())->toBe('developer');
});

test('Filter should be created with contains operator.', function () {
$filter = Filter::contains('bio', 'developer');

expect($filter->field())->toBe('bio')
->and($filter->operator()->value)->toBe('contains')
->and($filter->value())->toBe('developer');
});

test('Filter should be created with not contains operator.', function () {
$filter = Filter::notContains('bio', 'developer');

expect($filter->field())->toBe('bio')
->and($filter->operator()->value)->toBe('not contains')
->and($filter->value())->toBe('developer');
});