Skip to content

Commit

Permalink
fix: failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
JoyceBabu committed Jul 16, 2024
1 parent fd13396 commit 7920817
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion example/advanced.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

$resource = <<<'FTL'
log-time = User { $user->name} logged in at { $date->format("Y-m-d G:i:a") } {LT($date, $deadline) ->
# Select expression only allows string/numeric types as selector.
# We will use STR function to convert the boolean output of LT to string.
log-time = User { $user->name} logged in at { $date->format("Y-m-d G:i:a") } {STR(LT($date, $deadline)) ->
[true] before
*[false] after
} deadline.
Expand Down Expand Up @@ -30,6 +32,7 @@ function preProcess(string $resource): string
$bundle->addFunction('LT', fn ($val1, $val2) => $val1 < $val2);
$bundle->addFunction('GTE', fn ($val1, $val2) => $val1 >= $val2);
$bundle->addFunction('LTE', fn ($val1, $val2) => $val1 <= $val2);
$bundle->addFunction('STR', fn ($val) => is_bool($val) ? ($val ? "true" : "false") : (string)$val);
$bundle->addFunction('OBJ_PROP', fn ($obj, $prop) => $obj->{$prop});
$bundle->addFunction('OBJ_METHOD', fn ($obj, $method, ...$args) => $obj->{$method}(...$args));

Expand Down
3 changes: 2 additions & 1 deletion tests/advanced.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Advanced example with multiple functions
--FILE--
<?php
$resource = <<<'FTL'
log-time = User { $user->name} logged in at { $date->format("Y-m-d G:i a") } {LT($date, $deadline) ->
log-time = User { $user->name} logged in at { $date->format("Y-m-d G:i a") } {STR(LT($date, $deadline)) ->
[true] before
*[false] after
} deadline.
Expand Down Expand Up @@ -32,6 +32,7 @@ try {
$bundle->addFunction('LT', fn ($val1, $val2) => $val1 < $val2);
$bundle->addFunction('GTE', fn ($val1, $val2) => $val1 >= $val2);
$bundle->addFunction('LTE', fn ($val1, $val2) => $val1 <= $val2);
$bundle->addFunction('STR', fn ($val) => is_bool($val) ? ($val ? "true" : "false") : (string)$val);
$bundle->addFunction('OBJ_PROP', fn ($obj, $prop) => $obj->{$prop});
$bundle->addFunction('OBJ_METHOD', fn ($obj, $method, ...$args) => $obj->{$method}(...$args));

Expand Down

0 comments on commit 7920817

Please sign in to comment.