Skip to content

Commit

Permalink
deal with debug mode reference issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Zordius Chen committed Mar 22, 2017
1 parent 34ba2e6 commit ed9d988
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/Runtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ class Runtime extends Encoder
* @expect '<!--MISSED((-->{{#123}}<!--))--><!--SKIPPED--><!--MISSED((-->{{/123}}<!--))-->' when input '123', 'wi', array('flags' => array('debug' => Runtime::DEBUG_TAGS_HTML), 'runtime' => 'LightnCandy\\Runtime'), false, null, false, function () {return 'A';}
*/
public static function debug($v, $f, $cx) {
$params = array_slice(func_get_args(), 2);
// Build array of reference for call_user_func_array
$P = func_get_args();
$params = array();
for ($i=2;$i<count($P);$i++) {
$params[] = &$P[$i];
}
$r = call_user_func_array((isset($cx['funcs'][$f]) ? $cx['funcs'][$f] : "{$cx['runtime']}::$f"), $params);

if ($cx['flags']['debug'] & static::DEBUG_TAGS) {
Expand Down
10 changes: 8 additions & 2 deletions tests/errorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public function testRenderingException($test)
$php = LightnCandy::compile($test['template'], $test['options']);
$renderer = LightnCandy::prepare($php);
try {
$renderer(isset($test['data']) ? $test['data'] : null, array('debug' => Runtime::DEBUG_ERROR_EXCEPTION));
$input = isset($test['data']) ? $test['data'] : null;
$renderer($input, array('debug' => Runtime::DEBUG_ERROR_EXCEPTION));
} catch (\Exception $E) {
$this->assertEquals($test['expected'], $E->getMessage());
return;
Expand All @@ -87,7 +88,12 @@ public function testRenderingErrorLog($test)
start_catch_error_log();
$php = LightnCandy::compile($test['template'], $test['options']);
$renderer = LightnCandy::prepare($php);
$renderer(null, array('debug' => Runtime::DEBUG_ERROR_LOG));
try {
$in = array('dummy' => 'reference');
$renderer($in, array('debug' => Runtime::DEBUG_ERROR_LOG));
} catch (\Exception $E) {
$this->fail("Unexpected render exception: " . $E->getMessage() . ", CODE: $php");
}
$e = stop_catch_error_log();
if ($e) {
$this->assertEquals(Array($test['expected']), $e);
Expand Down

0 comments on commit ed9d988

Please sign in to comment.