Skip to content

Commit

Permalink
Add isNotNull to ExpressionBuilder (#408)
Browse files Browse the repository at this point in the history
Add isNotNull() in ExpressionBuilder

Co-authored-by: Alexander M. Turek <me@derrabus.de>
Co-authored-by: Grégoire Paris <postmaster@greg0ire.fr>
  • Loading branch information
3 people authored Apr 3, 2024
1 parent 9b9c38a commit 4353bc4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/en/expression-builder.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ isNull
$collection->matching(new Criteria($expression));
isNotNull
---------

.. code-block:: php
$expressionBuilder = Criteria::expr();
$expression = $expressionBuilder->isNotNull('foo');
$collection->matching(new Criteria($expression));
in
---

Expand Down
5 changes: 5 additions & 0 deletions src/ExpressionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public function isNull(string $field)
return new Comparison($field, Comparison::EQ, new Value(null));
}

public function isNotNull(string $field): Comparison
{
return new Comparison($field, Comparison::NEQ, new Value(null));
}

/**
* @param mixed[] $values
*
Expand Down
8 changes: 8 additions & 0 deletions tests/ExpressionBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ public function testIsNull(): void
self::assertEquals(Comparison::EQ, $expr->getOperator());
}

public function testIsNotNull(): void
{
$expr = $this->builder->isNotNull('a');

self::assertInstanceOf(Comparison::class, $expr);
self::assertEquals(Comparison::NEQ, $expr->getOperator());
}

public function testContains(): void
{
$expr = $this->builder->contains('a', 'b');
Expand Down

0 comments on commit 4353bc4

Please sign in to comment.