Skip to content

EspoCRM – Open Source CRM Application

formula: return last expression

Yuri Kuznetsov6e43dc87f2b4
diff --git a/application/Espo/Core/Formula/Functions/BundleType.php b/application/Espo/Core/Formula/Functions/BundleType.php
index a9c82f2911..5cb20456db 100644
--- a/application/Espo/Core/Formula/Functions/BundleType.php
+++ b/application/Espo/Core/Formula/Functions/BundleType.php
@@ -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;
}
}
diff --git a/tests/unit/Espo/Core/Formula/EvaluatorTest.php b/tests/unit/Espo/Core/Formula/EvaluatorTest.php
index 864b1fef55..5fdb2700cd 100644
--- a/tests/unit/Espo/Core/Formula/EvaluatorTest.php
+++ b/tests/unit/Espo/Core/Formula/EvaluatorTest.php
@@ -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);
+ }
}