formula: return last expression

This commit is contained in:
Yuri Kuznetsov
2025-03-10 16:17:27 +02:00
parent 06dc8ef281
commit 6e43dc87f2
2 changed files with 79 additions and 5 deletions

View File

@@ -29,17 +29,21 @@
namespace Espo\Core\Formula\Functions;
use Espo\Core\Formula\{
Functions\BaseFunction,
ArgumentList,
};
use Espo\Core\Formula\ArgumentList;
/**
* @noinspection PhpUnused
*/
class BundleType extends BaseFunction
{
public function process(ArgumentList $args)
{
$value = null;
foreach ($args as $item) {
$this->evaluate($item);
$value = $this->evaluate($item);
}
return $value;
}
}

View File

@@ -1620,4 +1620,74 @@ class EvaluatorTest extends TestCase
$this->assertEquals("<p><strong>test</strong></p>\n", $result);
}
public function testLastExpressionEvaluation1(): void
{
$expression = "\$a = 1; \$b = \$a + 1; \$b;";
/** @noinspection PhpUnhandledExceptionInspection */
$result = $this->evaluator->process($expression);
$this->assertEquals(2, $result);
}
public function testLastExpressionEvaluation2(): void
{
$expression = "\$a = 1; \$b = \$a + 1; \$b";
/** @noinspection PhpUnhandledExceptionInspection */
$result = $this->evaluator->process($expression);
$this->assertEquals(2, $result);
}
public function testLastExpressionEvaluation3(): void
{
$expression = "\$a = 1; \$a + 1;";
/** @noinspection PhpUnhandledExceptionInspection */
$result = $this->evaluator->process($expression);
$this->assertEquals(2, $result);
}
public function testLastExpressionEvaluation4(): void
{
$expression = "\$a = 1; \$b = \$a + 1;";
/** @noinspection PhpUnhandledExceptionInspection */
$result = $this->evaluator->process($expression);
$this->assertEquals(2, $result);
}
public function testLastExpressionEvaluation5(): void
{
$expression = "\$c = (\$a = 1; \$b = \$a + 1;); \$c;";
/** @noinspection PhpUnhandledExceptionInspection */
$result = $this->evaluator->process($expression);
$this->assertEquals(2, $result);
}
public function testLastExpressionEvaluationNull1(): void
{
$expression = "null";
/** @noinspection PhpUnhandledExceptionInspection */
$result = $this->evaluator->process($expression);
$this->assertEquals(null, $result);
}
public function testLastExpressionEvaluationNull2(): void
{
$expression = "";
/** @noinspection PhpUnhandledExceptionInspection */
$result = $this->evaluator->process($expression);
$this->assertEquals(null, $result);
}
}