Skip to content
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

Add isNotNull to ExpressionBuilder #408

Merged
merged 5 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
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
------
raziel057 marked this conversation as resolved.
Show resolved Hide resolved

.. 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
Loading