diff --git a/benchmark/run.php b/benchmark/run.php index e5802eb..8cde7b6 100644 --- a/benchmark/run.php +++ b/benchmark/run.php @@ -12,20 +12,20 @@ echo "Done\n"; echo "Testing a lot output...\n"; Benchmark::runs("smarty3", 'echo/smarty.tpl', __DIR__.'/templates/echo/data.json'); -Benchmark::runs("twig", 'echo/twig.tpl', __DIR__.'/templates/echo/data.json'); -Benchmark::runs("aspect", 'echo/smarty.tpl', __DIR__.'/templates/echo/data.json'); +Benchmark::runs("twig", 'echo/twig.tpl', __DIR__.'/templates/echo/data.json'); +Benchmark::runs("cytro", 'echo/smarty.tpl', __DIR__.'/templates/echo/data.json'); echo "\nTesting 'foreach' of big array...\n"; Benchmark::runs("smarty3", 'foreach/smarty.tpl', __DIR__.'/templates/foreach/data.json'); -Benchmark::runs("twig", 'foreach/twig.tpl', __DIR__.'/templates/foreach/data.json'); -Benchmark::runs("aspect", 'foreach/smarty.tpl', __DIR__.'/templates/foreach/data.json'); +Benchmark::runs("twig", 'foreach/twig.tpl', __DIR__.'/templates/foreach/data.json'); +Benchmark::runs("cytro", 'foreach/smarty.tpl', __DIR__.'/templates/foreach/data.json'); echo "\nTesting deep 'inheritance'...\n"; Benchmark::runs("smarty3", 'inheritance/smarty/b100.tpl', __DIR__.'/templates/foreach/data.json'); -Benchmark::runs("twig", 'inheritance/twig/b100.tpl', __DIR__.'/templates/foreach/data.json'); -Benchmark::runs("aspect", 'inheritance/smarty/b100.tpl', __DIR__.'/templates/foreach/data.json'); +Benchmark::runs("twig", 'inheritance/twig/b100.tpl', __DIR__.'/templates/foreach/data.json'); +Benchmark::runs("cytro", 'inheritance/smarty/b100.tpl', __DIR__.'/templates/foreach/data.json'); echo "\nDone. Cleanup.\n"; //passthru("rm -rf ".__DIR__."/compile/*"); diff --git a/benchmark/scripts/bootstrap.php b/benchmark/scripts/bootstrap.php index 6741b42..d9af065 100644 --- a/benchmark/scripts/bootstrap.php +++ b/benchmark/scripts/bootstrap.php @@ -43,7 +43,7 @@ class Benchmark { printf(self::$t, __FUNCTION__, $message, round(microtime(true)-$start, 4), round(memory_get_peak_usage()/1024/1024, 2)); } - public static function aspect($tpl, $data, $double, $message) { + public static function cytro($tpl, $data, $double, $message) { $cytro = Cytro::factory(__DIR__.'/../templates', __DIR__."/../compile/"); @@ -56,9 +56,14 @@ class Benchmark { } public static function run($engine, $template, $data, $double, $message) { - passthru(sprintf("php -dmemory_limit=512M %s/run.php --engine '%s' --template '%s' --data '%s' --message '%s' %s", __DIR__, $engine, $template, $data, $message, $double ? '--double' : '')); + passthru(sprintf("php -dmemory_limit=512M -dxdebug.max_nesting_level=1024 %s/run.php --engine '%s' --template '%s' --data '%s' --message '%s' %s", __DIR__, $engine, $template, $data, $message, $double ? '--double' : '')); } + /** + * @param $engine + * @param $template + * @param $data + */ public static function runs($engine, $template, $data) { self::run($engine, $template, $data, false, '!compiled and !loaded'); self::run($engine, $template, $data, false, ' compiled and !loaded'); diff --git a/docs/benchmark.md b/docs/benchmark.md index 3d84090..10651a5 100644 --- a/docs/benchmark.md +++ b/docs/benchmark.md @@ -3,7 +3,7 @@ Benchmark To start benchmark run script `benchmark/run.php`. -### Smarty3 vs Twig vs Aspect +### Smarty3 vs Twig vs Cytro Print varaibles diff --git a/tests/cases/Aspect/ExtendsTemplateTest.php b/tests/cases/Aspect/ExtendsTemplateTest.php deleted file mode 100644 index 45ccfb4..0000000 --- a/tests/cases/Aspect/ExtendsTemplateTest.php +++ /dev/null @@ -1,79 +0,0 @@ -cytro = Cytro::factory(CYTRO_RESOURCES.'/template', CYTRO_RESOURCES.'/compile'); - } - - /** - * @dataProvider providerExtends - * @param $name - * @param $code - * @param $vars - * @param $result - */ - public function _testStaticExtends($name, $code, $vars, $result) { - static $i = 0; - $vars["iteration"] = $i++; - $this->execTpl($name, $code, $vars, $result); - } - - /** - * @dataProvider providerDynamicExtends - * @param $name - * @param $code - * @param $vars - * @param $result - */ - public function _testDynamicExtends($name, $code, $vars, $result) { - static $i = 0; - $vars["iteration"] = $i++; - $this->execTpl($name, $code, $vars, $result, 0); - } - - /** - * @group extends - */ - public function _testParentLevel() { - //echo($this->aspect->getTemplate("parent.tpl")->_body); exit; - $this->assertSame($this->cytro->fetch("parent.tpl", array("a" => "a char")), "Parent template\nBlock1: Block2: Block3: default"); - } - - /** - * @group extends - */ - public function testChildLevel1() { - //echo($this->aspect->fetch("child1.tpl", array("a" => "a char"))); exit; - } - - /** - * @group extends - */ - public function _testChildLevel3() { - echo($this->cytro->getTemplate("child3.tpl")->getBody()); exit; - } -} - diff --git a/tests/cases/Aspect/CustomProvider.php b/tests/cases/Cytro/CustomProvider.php similarity index 100% rename from tests/cases/Aspect/CustomProvider.php rename to tests/cases/Cytro/CustomProvider.php diff --git a/tests/cases/Cytro/ExtendsTemplateTest.php b/tests/cases/Cytro/ExtendsTemplateTest.php new file mode 100644 index 0000000..e6b84df --- /dev/null +++ b/tests/cases/Cytro/ExtendsTemplateTest.php @@ -0,0 +1,151 @@ + "level.0.tpl", + "level" => 0, + "blocks" => array( + "b1" => "", + "b2" => "empty 0" + ), + "result" => array( + "b1" => "", + "b2" => "empty 0" + ), + ), + array( + "name" => "level.1.tpl", + "level" => 1, + "blocks" => array( + "b1" => "from level 1" + ), + "result" => array( + "b1" => "from level 1", + "b2" => "empty 0" + ), + ), + array( + "name" => "level.2.tpl", + "level" => 2, + "blocks" => array( + "b2" => "from level 2", + "b4" => "unused block" + ), + "result" => array( + "b1" => "from level 1", + "b2" => "from level 2" + ), + ), + array( + "name" => "level.3.tpl", + "level" => 3, + "blocks" => array( + "b1" => "from level 3", + "b2" => "also from level 3" + ), + "result" => array( + "b1" => "from level 3", + "b2" => "also from level 3" + ), + ) + ); + } + + public static function generate($block_mask, $extend_mask) { + $t = array(); + foreach(self::templates() as $level => $tpl) { + $src = 'level#'.$level.' '; + foreach($tpl["blocks"] as $bname => &$bcode) { + $src .= sprintf($block_mask, $bname, $bname.': '.$bcode)." level#$level "; + } + $dst = "level#0 "; + foreach($tpl["result"] as $bname => &$bcode) { + $dst .= $bname.': '.$bcode.' level#0 '; + } + if($level) { + $src = sprintf($extend_mask, $level-1).' '.$src; + } + $t[ $tpl["name"] ] = array("src" => $src, "dst" => $dst); + } + return $t; + } + /** + * @group static-extend + */ + public function testTemplateExtends() { + foreach(self::generate('{block "%s"}%s{/block}', '{extends "level.%d.tpl"}') as $name => $tpl) { + $this->tpl($name, $tpl["src"]); + //var_dump($src, "----\n\n----", $dst);ob_flush();fgetc(STDIN); + $this->assertSame($this->cytro->fetch($name, array()), $tpl["dst"]); + } + } + +// public static function providerDynamicExtends() { +// $tpls = array(); +// //foreach(self::templates() as $i => $tpl) { +// // $tpls[] = array($tpl[0], ); +// //} +// $data = self::providerExtends(); +// $data[2][1] = str_replace('"b2"', '"b{$two}"', $data[2][1]); +// return $data; +// } + +// public function setUp() { +// $this->cytro = Cytro::factory(CYTRO_RESOURCES.'/template', CYTRO_RESOURCES.'/compile'); +// } +// +// /** +// * @dataProvider providerExtends +// * @param $name +// * @param $code +// * @param $vars +// * @param $result +// */ +// public function testStaticExtends($name, $code, $vars, $result) { +// static $i = 0; +// $vars["iteration"] = $i++; +// $this->execTpl($name, $code, $vars, $result); +// } +// +// /** +// * @dataProvider providerDynamicExtends +// * @param $name +// * @param $code +// * @param $vars +// * @param $result +// */ +// public function testDynamicExtends($name, $code, $vars, $result) { +// static $i = 0; +// $vars["iteration"] = $i++; +// $this->execTpl($name, $code, $vars, $result, 0); +// } +// +// /** +// * @group extends +// */ +// public function _testParentLevel() { +// //echo($this->aspect->getTemplate("parent.tpl")->_body); exit; +// $this->assertSame($this->cytro->fetch("parent.tpl", array("a" => "a char")), "Parent template\nBlock1: Block2: Block3: default"); +// } +// +// /** +// * @group extends +// */ +// public function testChildLevel1() { +// //echo($this->aspect->fetch("child1.tpl", array("a" => "a char"))); exit; +// } +// +// /** +// * @group extends +// */ +// public function _testChildLevel3() { +// echo($this->cytro->getTemplate("child3.tpl")->getBody()); exit; +// } +} + diff --git a/tests/cases/Aspect/MacrosTest.php b/tests/cases/Cytro/MacrosTest.php similarity index 100% rename from tests/cases/Aspect/MacrosTest.php rename to tests/cases/Cytro/MacrosTest.php diff --git a/tests/cases/Aspect/ModifiersTest.php b/tests/cases/Cytro/ModifiersTest.php similarity index 100% rename from tests/cases/Aspect/ModifiersTest.php rename to tests/cases/Cytro/ModifiersTest.php diff --git a/tests/cases/Aspect/ProviderTest.php b/tests/cases/Cytro/ProviderTest.php similarity index 100% rename from tests/cases/Aspect/ProviderTest.php rename to tests/cases/Cytro/ProviderTest.php diff --git a/tests/cases/Aspect/RenderTest.php b/tests/cases/Cytro/RenderTest.php similarity index 100% rename from tests/cases/Aspect/RenderTest.php rename to tests/cases/Cytro/RenderTest.php diff --git a/tests/cases/Aspect/ScopeTest.php b/tests/cases/Cytro/ScopeTest.php similarity index 100% rename from tests/cases/Aspect/ScopeTest.php rename to tests/cases/Cytro/ScopeTest.php diff --git a/tests/cases/Aspect/TemplateTest.php b/tests/cases/Cytro/TemplateTest.php similarity index 100% rename from tests/cases/Aspect/TemplateTest.php rename to tests/cases/Cytro/TemplateTest.php diff --git a/tests/cases/Aspect/TokenizerTest.php b/tests/cases/Cytro/TokenizerTest.php similarity index 100% rename from tests/cases/Aspect/TokenizerTest.php rename to tests/cases/Cytro/TokenizerTest.php diff --git a/tests/cases/AspectTest.php b/tests/cases/CytroTest.php similarity index 100% rename from tests/cases/AspectTest.php rename to tests/cases/CytroTest.php