Permalink
Browse files

task latteSyntaxChecker: lints generated PHP code

  • Loading branch information...
dg committed Mar 26, 2018
1 parent dc19656 commit 8a05829107185caeaec0522cfda844cb9d2e9fe9
Showing with 11 additions and 1 deletion.
  1. +3 −1 src/Tasks.php
  2. +8 −0 tests/Tasks.latteSyntaxChecker.phpt
@@ -168,7 +168,9 @@ public static function latteSyntaxChecker($contents, Result $result)
Nette\Bridges\FormsLatte\FormMacros::install($latte->getCompiler());
try {
$latte->compile($contents);
$code = $latte->compile($contents);
static::phpSyntaxChecker($code, $result);
} catch (Latte\CompileException $e) {
if (!preg_match('#Unknown (macro|attribute)#A', $e->getMessage())) {
$result->error($e->getMessage(), $e->sourceLine);
@@ -24,3 +24,11 @@ test(function () {
Tasks::latteSyntaxChecker('{hello', $result);
Assert::same([[Result::ERROR, 'Malformed macro', 1]], $result->getMessages());
});
test(function () {
$result = new Result;
Tasks::latteSyntaxChecker('{var $x = +}', $result); // invalid PHP code
Assert::count(1, $result->getMessages());
Assert::same(Result::ERROR, $result->getMessages()[0][0]);
Assert::contains('syntax error, unexpected', $result->getMessages()[0][1]);
});

0 comments on commit 8a05829

Please sign in to comment.