Skip to content

Commit fe9f1cd

Browse files
committed
minor symfony#58461 [ExpressionLanguage] Improve tests on BinaryNode (alexandre-daubois)
This PR was merged into the 7.2 branch. Discussion ---------- [ExpressionLanguage] Improve tests on `BinaryNode` | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT `in` and `not in` have a shortcut above the operator switch. Also, `BinaryNode::evaluate()` may throw an error, lacking a return value when the operator is unsupported. Commits ------- c03cbe3 [ExpressionLanguage] Improve tests on `BinaryNode`
2 parents 128efbb + c03cbe3 commit fe9f1cd

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/Symfony/Component/ExpressionLanguage/Node/BinaryNode.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,6 @@ public function evaluate(array $functions, array $values): mixed
154154
return $left >= $right;
155155
case '<=':
156156
return $left <= $right;
157-
case 'not in':
158-
return !\in_array($left, $right, true);
159-
case 'in':
160-
return \in_array($left, $right, true);
161157
case '+':
162158
return $left + $right;
163159
case '-':
@@ -181,6 +177,8 @@ public function evaluate(array $functions, array $values): mixed
181177
case 'matches':
182178
return $this->evaluateMatches($right, $left);
183179
}
180+
181+
throw new \LogicException(\sprintf('"%s" does not support the "%s" operator.', __CLASS__, $operator));
184182
}
185183

186184
public function toArray(): array

src/Symfony/Component/ExpressionLanguage/Tests/Node/BinaryNodeTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,4 +279,14 @@ public function testInOperatorStrictness(mixed $value)
279279

280280
$this->assertFalse($node->evaluate([], []));
281281
}
282+
283+
public function testEvaluateUnsupportedOperator()
284+
{
285+
$node = new BinaryNode('unsupported', new ConstantNode(1), new ConstantNode(2));
286+
287+
$this->expectException(\LogicException::class);
288+
$this->expectExceptionMessage('"Symfony\Component\ExpressionLanguage\Node\BinaryNode" does not support the "unsupported" operator.');
289+
290+
$node->evaluate([], []);
291+
}
282292
}

0 commit comments

Comments
 (0)