diff --git a/docs/en/expression-builder.rst b/docs/en/expression-builder.rst index e0224418..043b89cc 100644 --- a/docs/en/expression-builder.rst +++ b/docs/en/expression-builder.rst @@ -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 --- diff --git a/src/ExpressionBuilder.php b/src/ExpressionBuilder.php index fc25e3a9..7bf5a09a 100644 --- a/src/ExpressionBuilder.php +++ b/src/ExpressionBuilder.php @@ -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 * diff --git a/tests/ExpressionBuilderTest.php b/tests/ExpressionBuilderTest.php index cfba7626..1c272938 100644 --- a/tests/ExpressionBuilderTest.php +++ b/tests/ExpressionBuilderTest.php @@ -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');