Skip to content

Commit

Permalink
Add NOT_EQUAL operator
Browse files Browse the repository at this point in the history
  • Loading branch information
fjesteban committed Apr 7, 2021
1 parent c1c0c77 commit 6277994
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/ArrayCriteriaVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ static function ($item) use ($filter) {
return $itemValue == self::cast($itemValue, $filter->value()->value());
}

if (FilterOperator::NOT_EQUAL === $filter->operator()->value()) {
return $itemValue != self::cast($itemValue, $filter->value()->value());
}

if (FilterOperator::GT === $filter->operator()->value()) {
return $itemValue > self::cast($itemValue, $filter->value()->value());
}
Expand Down
22 changes: 22 additions & 0 deletions tests/ArrayBuilderCriteriaVisitorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,26 @@ public function test_non_existing_filter_should_return_no_result()
$result = $this->repository->filter($criteria);
$this->assertEmpty($result);
}

public function test_not_equal_operator()
{
$article = ArticleObjectMother::random();
$this->repository->save($article);

$criteria = new Criteria(
new Filters(
new Filter(
FilterField::from('stock'),
FilterOperator::from(FilterOperator::NOT_EQUAL),
FilterValue::from((string) ($article->stock() - 1)),
),
),
null,
null,
null,
);

$result = $this->repository->filter($criteria);
$this->assertEquals($article, $result[0]);
}
}

0 comments on commit 6277994

Please sign in to comment.