diff --git a/Definition/Builder/ExprBuilder.php b/Definition/Builder/ExprBuilder.php index 3d79b2985..94f6e2075 100644 --- a/Definition/Builder/ExprBuilder.php +++ b/Definition/Builder/ExprBuilder.php @@ -97,6 +97,18 @@ public function ifNull() return $this; } + /** + * Tests if the value is empty. + * + * @return ExprBuilder + */ + public function ifEmpty() + { + $this->ifPart = function ($v) { return empty($v); }; + + return $this; + } + /** * Tests if the value is an array. * diff --git a/Tests/Definition/Builder/ExprBuilderTest.php b/Tests/Definition/Builder/ExprBuilderTest.php index ebb766eed..45413c219 100644 --- a/Tests/Definition/Builder/ExprBuilderTest.php +++ b/Tests/Definition/Builder/ExprBuilderTest.php @@ -75,6 +75,21 @@ public function testIfNullExpression() $this->assertFinalizedValueIs('value', $test); } + public function testIfEmptyExpression() + { + $test = $this->getTestBuilder() + ->ifEmpty() + ->then($this->returnClosure('new_value')) + ->end(); + $this->assertFinalizedValueIs('new_value', $test, array('key' => array())); + + $test = $this->getTestBuilder() + ->ifEmpty() + ->then($this->returnClosure('new_value')) + ->end(); + $this->assertFinalizedValueIs('value', $test); + } + public function testIfArrayExpression() { $test = $this->getTestBuilder()