Skip to content

Commit

Permalink
Merge branch '7.1' into 7.2
Browse files Browse the repository at this point in the history
* 7.1: (31 commits)
  [Serializer] Remove useless calls to `func_get_arg()`
  fix tests using Twig 3.12
  skip tests requiring the intl extension if it's not installed
  🐛 throw ParseException on invalid date
  [FrameworkBundle] Re-remove redundant name attribute from `default_context`
  fix permitted data type of the default choice
  [ExpressionLanguage] Improve test coverage
  Fix invalid phpdoc in ContainerBuilder
  [HttpKernel] [WebProfileBundle] Fix Routing panel for URLs with a colon
  [Form] NumberType: Fix parsing of numbers in exponential notation with negative exponent
  Fix importing PHP config in prepend extension method
  [Messenger] Prevent waiting time to overflow when using long delays
  [Security] consistent singular/plural translation in Dutch
  reset the validation context after validating nested constraints
  do not duplicate directory separators
  fix handling empty data in ValueToDuplicatesTransformer
  fix compatibility with redis extension 6.0.3+
  synchronize unsupported scheme tests
  [String] Fixed Quorum plural, that was inflected to be only "Quora" and never "Quorums"
  Fix symfony/kaz-info-teh-notifier package
  ...
  • Loading branch information
xabbuh committed Aug 12, 2024
2 parents baef2bc + b9e4bc6 commit 44c694c
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Tests/ExpressionLanguageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -552,4 +552,11 @@ function (ExpressionLanguage $el) {
],
];
}

public function testParseAlreadyParsedExpressionReturnsSameObject()
{
$el = new ExpressionLanguage();
$parsed = $el->parse('1 + 1', []);
$this->assertSame($parsed, $el->parse($parsed, []));
}
}
20 changes: 20 additions & 0 deletions Tests/Node/BinaryNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,26 @@ public function testCompileMatchesWithInvalidRegexpAsExpression()
eval('$regexp = "this is not a regexp"; '.$compiler->getSource().';');
}

public function testDivisionByZero()
{
$node = new BinaryNode('/', new ConstantNode(1), new ConstantNode(0));

$this->expectException(\DivisionByZeroError::class);
$this->expectExceptionMessage('Division by zero.');

$node->evaluate([], []);
}

public function testModuloByZero()
{
$node = new BinaryNode('%', new ConstantNode(1), new ConstantNode(0));

$this->expectException(\DivisionByZeroError::class);
$this->expectExceptionMessage('Modulo by zero.');

$node->evaluate([], []);
}

/**
* @testWith [1]
* ["true"]
Expand Down
30 changes: 30 additions & 0 deletions Tests/Node/NodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\ExpressionLanguage\Tests\Node;

use PHPUnit\Framework\TestCase;
use Symfony\Component\ExpressionLanguage\Compiler;
use Symfony\Component\ExpressionLanguage\Node\ConstantNode;
use Symfony\Component\ExpressionLanguage\Node\Node;

Expand All @@ -38,4 +39,33 @@ public function testSerialization()

$this->assertEquals($node, $unserializedNode);
}

public function testCompileActuallyCompilesAllNodes()
{
$nodes = [];
foreach (range(1, 10) as $ignored) {
$node = $this->createMock(Node::class);
$node->expects($this->once())->method('compile');

$nodes[] = $node;
}

$node = new Node($nodes);
$node->compile($this->createMock(Compiler::class));
}

public function testEvaluateActuallyEvaluatesAllNodes()
{
$nodes = [];
foreach (range(1, 3) as $i) {
$node = $this->createMock(Node::class);
$node->expects($this->once())->method('evaluate')
->willReturn($i);

$nodes[] = $node;
}

$node = new Node($nodes);
$this->assertSame([1, 2, 3], $node->evaluate([], []));
}
}
11 changes: 11 additions & 0 deletions Tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ public function testParseWithZeroInNames()
$parser->parse($lexer->tokenize('foo'), [0]);
}

public function testParsePrimaryExpressionWithUnknownFunctionThrows()
{
$parser = new Parser([]);
$stream = (new Lexer())->tokenize('foo()');

$this->expectException(SyntaxError::class);
$this->expectExceptionMessage('The function "foo" does not exist around position 1 for expression `foo()`.');

$parser->parse($stream);
}

public function testParseUnknownFunction()
{
$parser = new Parser([]);
Expand Down

0 comments on commit 44c694c

Please sign in to comment.