Merge pull request #270 from fenom-template/develop

Fix bugs; phpunit things
This commit is contained in:
Ivan Shalganov 2017-04-22 22:48:52 +03:00 committed by GitHub
commit 7d0db43050
10 changed files with 609 additions and 420 deletions

View File

@ -11,10 +11,11 @@ php:
- 7.1
before_script:
- composer update --dev --quiet
- composer global require satooshi/php-coveralls
# - composer update --dev --quiet
script:
- phpunit
- phpunit -c phpunit.xml.dist
after_script:
- php vendor/bin/coveralls
- coveralls

View File

@ -15,7 +15,7 @@
"ext-tokenizer": "*"
},
"require-dev": {
"phpunit/phpunit": "*",
"phpunit/phpunit": "<6.0",
"satooshi/php-coveralls": "*"
},
"autoload": {

908
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,8 @@
Модификатор in
===========
Модификатор является реализацией оператора содержания [in](../operators.md#Оператор-содержания).
```smarty

View File

@ -6,11 +6,13 @@ require_once __DIR__.'/../tests/tools.php';
\Fenom::registerAutoload();
$fenom = Fenom::factory(__DIR__.'/templates', __DIR__.'/compiled');
$fenom->setOptions(Fenom::AUTO_RELOAD | Fenom::FORCE_VERIFY | Fenom::FORCE_INCLUDE);
//$fenom->setOptions(Fenom::AUTO_RELOAD | Fenom::FORCE_VERIFY | Fenom::FORCE_INCLUDE);
//var_dump($fenom->compile("nested.tpl", [])->getTemplateCode());
//exit;
var_dump($fenom->compile('bug241/recursive.tpl', false)->getBody());
//var_dump($fenom->compile('bug241/recursive.tpl', false)->getBody());
//var_dump($fenom->compile('bug249/bread.tpl', false)->getBody());
//var_dump($fenom->compile("bug158/main.tpl", [])->getTemplateCode());
//var_dump($fenom->display("bug158/main.tpl", []));
// $fenom->getTemplate("problem.tpl");
var_dump($fenom->compileCode('{$.php.Fenom::factory()->addDay()}')->getBody());

View File

@ -829,7 +829,14 @@ class Template extends Render
case '$':
$code = $this->parseAccessor($tokens, $is_var);
if (!$is_var) {
$code = $unary . $code;
if($tokens->is(T_OBJECT_OPERATOR)) {
if ($this->_options & Fenom::DENY_METHODS) {
throw new \LogicException("Forbidden to call methods");
}
$code = $unary . $this->parseChain($tokens, $code);
} else {
$code = $unary . $code;
}
break;
}
/* no break */

View File

@ -3,10 +3,15 @@
require(__DIR__ . "/../src/Fenom.php");
Fenom::registerAutoload();
if(!class_exists('\PHPUnit_Framework_TestCase') && class_exists('\PHPUnit\Framework\TestCase')) {
class_alias('\PHPUnit\Framework\TestCase', '\PHPUnit_Framework_TestCase');
}
define('FENOM_RESOURCES', __DIR__ . "/resources");
require_once FENOM_RESOURCES . "/actions.php";
require_once __DIR__ . "/TestCase.php";
require_once __DIR__ . "/tools.php";
ini_set('date.timezone', 'Europe/Moscow');
ini_set('date.timezone', 'Europe/Moscow');

View File

@ -94,58 +94,66 @@ class AccessorTest extends TestCase
}
public static function providerPHP() {
public static function providerCall() {
return array(
array('$.php.strrev("string")', strrev("string")),
array('$.php.strrev("string")', strrev("string"), 'str*'),
array('$.php.strrev("string")', strrev("string"), 'strrev'),
array('$.php.get_current_user', get_current_user()),
array('$.php.Fenom.helper_func("string", 12)', helper_func("string", 12)),
array('$.php.Fenom.helper_func("string", 12)', helper_func("string", 12), 'Fenom\\*'),
array('$.php.Fenom.helper_func("string", 12)', helper_func("string", 12), 'Fenom\helper_func'),
array('$.php.Fenom.helper_func("string", 12)', helper_func("string", 12), '*helper_func'),
array('$.php.Fenom.helper_func("string", 12)', helper_func("string", 12), '*'),
array('$.php.Fenom.TestCase::dots("string")', TestCase::dots("string")),
array('$.php.Fenom.TestCase::dots("string")', TestCase::dots("string"), 'Fenom\*'),
array('$.php.Fenom.TestCase::dots("string")', TestCase::dots("string"), 'Fenom\TestCase*'),
array('$.php.Fenom.TestCase::dots("string")', TestCase::dots("string"), 'Fenom\TestCase::*'),
array('$.php.Fenom.TestCase::dots("string")', TestCase::dots("string"), 'Fenom\*::dots'),
array('$.php.Fenom.TestCase::dots("string")', TestCase::dots("string"), 'Fenom\*::*'),
array('$.php.Fenom.TestCase::dots("string")', TestCase::dots("string"), 'Fenom\TestCase::dots'),
array('$.php.Fenom.TestCase::dots("string")', TestCase::dots("string"), '*::dots'),
array('$.php.Fenom.TestCase::dots("string")', TestCase::dots("string"), '*'),
array('$.call.strrev("string")', strrev("string")),
array('$.call.strrev("string")', strrev("string"), 'str*'),
array('$.call.strrev("string")', strrev("string"), 'strrev'),
array('$.call.get_current_user', get_current_user()),
array('$.call.Fenom.helper_func("string", 12)', helper_func("string", 12)),
array('$.call.Fenom.helper_func("string", 12)', helper_func("string", 12), 'Fenom\\*'),
array('$.call.Fenom.helper_func("string", 12)', helper_func("string", 12), 'Fenom\helper_func'),
array('$.call.Fenom.helper_func("string", 12)', helper_func("string", 12), '*helper_func'),
array('$.call.Fenom.helper_func("string", 12)', helper_func("string", 12), '*'),
array('$.call.Fenom.TestCase::dots("string")', TestCase::dots("string")),
array('$.call.Fenom.TestCase::dots("string")', TestCase::dots("string"), 'Fenom\*'),
array('$.call.Fenom.TestCase::dots("string")', TestCase::dots("string"), 'Fenom\TestCase*'),
array('$.call.Fenom.TestCase::dots("string")', TestCase::dots("string"), 'Fenom\TestCase::*'),
array('$.call.Fenom.TestCase::dots("string")', TestCase::dots("string"), 'Fenom\*::dots'),
array('$.call.Fenom.TestCase::dots("string")', TestCase::dots("string"), 'Fenom\*::*'),
array('$.call.Fenom.TestCase::dots("string")', TestCase::dots("string"), 'Fenom\TestCase::dots'),
array('$.call.Fenom.TestCase::dots("string")', TestCase::dots("string"), '*::dots'),
array('$.call.Fenom.TestCase::dots("string")', TestCase::dots("string"), '*'),
);
}
/**
* @dataProvider providerPHP
* @dataProvider providerCall
* @group php
*/
public function testPHP($tpl, $result, $mask = null) {
public function testCall($tpl, $result, $mask = null) {
if($mask) {
$this->fenom->addCallFilter($mask);
}
$this->assertRender('{'.$tpl.'}', $result);
}
/**
* @group issue260
*/
public function testBug260() {
$this->fenom->compileCode('{$.php.Fenom::factory()->addModifier("intval", "intval")}');
}
public static function providerPHPInvalid() {
return array(
array('$.php.aaa("string")', 'Fenom\Error\CompileException', 'PHP method aaa does not exists'),
array('$.php.strrev("string")', 'Fenom\Error\SecurityException', 'Callback strrev is not available by settings', 'strrevZ'),
array('$.php.strrev("string")', 'Fenom\Error\SecurityException', 'Callback strrev is not available by settings', 'str*Z'),
array('$.php.strrev("string")', 'Fenom\Error\SecurityException', 'Callback strrev is not available by settings', '*Z'),
array('$.php.Fenom.aaa("string")', 'Fenom\Error\CompileException', 'PHP method Fenom.aaa does not exists'),
array('$.php.Fenom.helper_func("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.helper_func is not available by settings', 'Reflection\*'),
array('$.php.Fenom.helper_func("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.helper_func is not available by settings', 'Fenom\*Z'),
array('$.php.Fenom.helper_func("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.helper_func is not available by settings', 'Fenom\*::*'),
array('$.php.TestCase::aaa("string")', 'Fenom\Error\CompileException', 'PHP method TestCase::aaa does not exists'),
array('$.php.Fenom.TestCase::aaa("string")', 'Fenom\Error\CompileException', 'PHP method Fenom.TestCase::aaa does not exists'),
array('$.php.Fenom.TestCase::dots("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.TestCase::dots is not available by settings', 'Reflection\*'),
array('$.php.Fenom.TestCase::dots("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.TestCase::dots is not available by settings', 'Fenom\*Z'),
array('$.php.Fenom.TestCase::dots("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.TestCase::dots is not available by settings', 'Fenom\*::get*'),
array('$.php.Fenom.TestCase::dots("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.TestCase::dots is not available by settings', 'Fenom\TestCase::get*'),
array('$.php.Fenom.TestCase::dots("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.TestCase::dots is not available by settings', 'Fenom\TestCase::*Z'),
array('$.php.Fenom.TestCase::dots("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.TestCase::dots is not available by settings', '*::*Z'),
array('$.call.aaa("string")', 'Fenom\Error\CompileException', 'PHP method aaa does not exists'),
array('$.call.strrev("string")', 'Fenom\Error\SecurityException', 'Callback strrev is not available by settings', 'strrevZ'),
array('$.call.strrev("string")', 'Fenom\Error\SecurityException', 'Callback strrev is not available by settings', 'str*Z'),
array('$.call.strrev("string")', 'Fenom\Error\SecurityException', 'Callback strrev is not available by settings', '*Z'),
array('$.call.Fenom.aaa("string")', 'Fenom\Error\CompileException', 'PHP method Fenom.aaa does not exists'),
array('$.call.Fenom.helper_func("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.helper_func is not available by settings', 'Reflection\*'),
array('$.call.Fenom.helper_func("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.helper_func is not available by settings', 'Fenom\*Z'),
array('$.call.Fenom.helper_func("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.helper_func is not available by settings', 'Fenom\*::*'),
array('$.call.TestCase::aaa("string")', 'Fenom\Error\CompileException', 'PHP method TestCase::aaa does not exists'),
array('$.call.Fenom.TestCase::aaa("string")', 'Fenom\Error\CompileException', 'PHP method Fenom.TestCase::aaa does not exists'),
array('$.call.Fenom.TestCase::dots("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.TestCase::dots is not available by settings', 'Reflection\*'),
array('$.call.Fenom.TestCase::dots("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.TestCase::dots is not available by settings', 'Fenom\*Z'),
array('$.call.Fenom.TestCase::dots("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.TestCase::dots is not available by settings', 'Fenom\*::get*'),
array('$.call.Fenom.TestCase::dots("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.TestCase::dots is not available by settings', 'Fenom\TestCase::get*'),
array('$.call.Fenom.TestCase::dots("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.TestCase::dots is not available by settings', 'Fenom\TestCase::*Z'),
array('$.call.Fenom.TestCase::dots("string")', 'Fenom\Error\SecurityException', 'Callback Fenom.TestCase::dots is not available by settings', '*::*Z'),
);
}
@ -258,7 +266,7 @@ class AccessorTest extends TestCase
}
/**
* @group dev
*
*/
public function testCallbackAccessor() {
$index = 1;

View File

@ -4,7 +4,7 @@ namespace Fenom;
use Fenom,
Fenom\Render;
class RenderTest extends \PHPUnit_Framework_TestCase
class RenderTest extends TestCase
{
/**

View File

@ -4,7 +4,7 @@ namespace Fenom;
use Fenom\Error\UnexpectedTokenException;
use Fenom\Tokenizer;
class TokenizerTest extends \PHPUnit_Framework_TestCase
class TokenizerTest extends TestCase
{
public function testGetName()