Rollback phpunit to require-dev

This commit is contained in:
Ivan Shalganov 2013-09-13 21:19:51 +04:00
parent bcd9358fe0
commit 1428c86cac
7 changed files with 108 additions and 47 deletions

View File

@ -1,6 +1,15 @@
Changelog
=========
### 1.4.4
- Bug fixes
- Tests++
### 1.4.3
- Bug fixes
### 1.4.2 (2013-09-06)
- Added check the cache directory to record

View File

@ -71,7 +71,7 @@ class Compiler
}
$inc = $tpl->getStorage()->compile($name, false);
$tpl->addDepend($inc);
return '?>' . $tpl->getBody() . '<?php';
return '?>' . $inc->getBody() . '<?php';
}
@ -1034,24 +1034,4 @@ class Compiler
{
$scope->tpl->escape = $scope["escape"];
}
/**
* Unset present variables
*
* @param Tokenizer $tokens
* @param Template $tpl
* @return string
* @throws InvalidUsageException
*/
public static function tagUnset(Tokenizer $tokens, Template $tpl)
{
$vars = array();
while ($tokens->valid()) {
$vars[] = $tpl->parseVariable($tokens);
}
if (!$vars) {
throw new InvalidUsageException("Unset must accept variable(s)");
}
return 'unset(' . implode(', ', $vars) . ')';
}
}

View File

@ -304,26 +304,6 @@ class Tokenizer
return $this->next ? $this->next[1] == $token : false;
}
/**
* Return substring. This method doesn't move pointer.
* @param int $offset
* @param int $limit
* @return string
*/
public function getSubstr($offset, $limit = 0)
{
$str = '';
if (!$limit) {
$limit = $this->_max;
} else {
$limit += $offset;
}
for ($i = $offset; $i <= $limit; $i++) {
$str .= $this->tokens[$i][1] . $this->tokens[$i][2];
}
return $str;
}
/**
* Return token and move pointer
* @return mixed

View File

@ -103,6 +103,7 @@ class TestCase extends \PHPUnit_Framework_TestCase
mkdir(FENOM_RESOURCES . '/template/' . $dir, 0777, true);
}
file_put_contents(FENOM_RESOURCES . '/template/' . $name, $code);
return filemtime(FENOM_RESOURCES . '/template/' . $name);
}
/**

View File

@ -229,6 +229,7 @@ class TemplateTest extends TestCase
$result4 = 'Include <b>Welcome, Flame (flame@dev.null)</b> template';
return array(
array('Include {include "welcome.tpl"} template', $a, $result),
array('Include {include "welcome.tpl"} template', $a, $result, Fenom::FORCE_INCLUDE),
array('Include {include $tpl} template', $a, $result),
array('Include {include "$tpl"} template', $a, $result),
array('Include {include "{$tpl}"} template', $a, $result),
@ -238,7 +239,9 @@ class TemplateTest extends TestCase
array('Include {include "wel{$fragment}.tpl"} template', $a, $result),
array('Include {include "wel{$pr_fragment|lower}.tpl"} template', $a, $result),
array('Include {include "welcome.tpl" username="Flame"} template', $a, $result2),
array('Include {include "welcome.tpl" username="Flame"} template', $a, $result2, Fenom::FORCE_INCLUDE),
array('Include {include "welcome.tpl" email="flame@dev.null"} template', $a, $result3),
array('Include {include "welcome.tpl" email="flame@dev.null"} template', $a, $result3, Fenom::FORCE_INCLUDE),
array('Include {include "welcome.tpl" username="Flame" email="flame@dev.null"} template',
$a, $result4),
);
@ -252,6 +255,40 @@ class TemplateTest extends TestCase
);
}
public static function providerInsert()
{
$a = array(
"name" => "welcome",
"tpl" => "welcome.tpl",
"fragment" => "come",
"pr_fragment" => "Come",
"pr_name" => "Welcome",
"username" => "Master",
"email" => "dev@null.net"
);
$result = 'Include <b>Welcome, Master (dev@null.net)</b> template';
return array(
array('Include {insert "welcome.tpl"} template', $a, $result),
array("Include {insert 'welcome.tpl'} template", $a, $result),
);
}
public static function providerInsertInvalid()
{
return array(
array('Include {insert} template', 'Fenom\Error\CompileException', "Unexpected end of expression"),
array('Include {insert another="welcome.tpl"} template', 'Fenom\Error\CompileException', "Template another not found"),
array('Include {insert $tpl} template', 'Fenom\Error\CompileException', "Tag {insert} accept only static template name"),
array('Include {insert "$tpl"} template', 'Fenom\Error\CompileException', "Tag {insert} accept only static template name"),
array('Include {insert "{$tpl}"} template', 'Fenom\Error\CompileException', "Tag {insert} accept only static template name"),
array('Include {insert "$name.tpl"} template', 'Fenom\Error\CompileException', "Tag {insert} accept only static template name"),
array('Include {insert "{$name}.tpl"} template', 'Fenom\Error\CompileException', "Tag {insert} accept only static template name"),
array('Include {insert "{$pr_name|lower}.tpl"} template', 'Fenom\Error\CompileException', "Tag {insert} accept only static template name"),
array('Include {insert "wel{$fragment}.tpl"} template', 'Fenom\Error\CompileException', "Tag {insert} accept only static template name"),
array('Include {insert "welcome.tpl" email="flame@dev.null"} template', 'Fenom\Error\CompileException', "Unexpected token 'email'"),
);
}
public static function providerIf()
{
$a = array(
@ -783,9 +820,9 @@ class TemplateTest extends TestCase
* @group include
* @dataProvider providerInclude
*/
public function testInclude($code, $vars, $result)
public function testInclude($code, $vars, $result, $options = 0)
{
$this->exec($code, $vars, $result);
$this->exec($code, $vars, $result, $options);
}
/**
@ -796,6 +833,24 @@ class TemplateTest extends TestCase
$this->execError($code, $exception, $message, $options);
}
/**
* @group insert
* @dataProvider providerInsert
*/
public function testInsert($code, $vars, $result)
{
$this->exec($code, $vars, $result);
}
/**
* @group insert
* @dataProvider providerInsertInvalid
*/
public function testInsertInvalid($code, $exception, $message, $options = 0)
{
$this->execError($code, $exception, $message, $options);
}
/**
* @dataProvider providerIf
* @group test-if

View File

@ -7,12 +7,16 @@ class TokenizerTest extends \PHPUnit_Framework_TestCase
public function testTokens()
{
$code = 'hello, please resolve this example: sin($x)+tan($x*$t) = {U|[0,1]}';
$code = 'hello, please resolve this example: sin($x)+tan($x*$t) = {U|[0,1]}';
$tokens = new Tokenizer($code);
$this->assertSame($tokens, $tokens->back());
$this->assertSame(T_STRING, $tokens->key());
$this->assertSame("hello", $tokens->current());
$this->assertSame(1, $tokens->getLine());
$this->assertTrue($tokens->isNext(","));
$this->assertFalse($tokens->isNext("="));
$this->assertFalse($tokens->isNext(T_STRING));
$this->assertFalse($tokens->isNext($tokens::MACRO_UNARY));
@ -23,6 +27,13 @@ class TokenizerTest extends \PHPUnit_Framework_TestCase
$this->assertSame(",", $tokens->getNext());
$this->assertSame(",", $tokens->key());
$this->assertSame("please", $tokens->getNext(T_STRING));
$this->assertSame(array(
T_STRING,
'please',
' ',
1,
'T_STRING'
), $tokens->curr);
$this->assertSame("resolve", $tokens->getNext($tokens::MACRO_UNARY, T_STRING));
$tokens->next();
@ -46,6 +57,9 @@ class TokenizerTest extends \PHPUnit_Framework_TestCase
$tokens->next();
$tokens->next();
$this->assertSame("+", $tokens->getNext($tokens::MACRO_BINARY));
$this->assertSame('sin($x)+tan($x*$t)', $tokens->getSnippetAsString(-4, 6));
$this->assertSame($code, $tokens->getSnippetAsString(-100, 100));
}
public function testSkip()
@ -62,7 +76,14 @@ class TokenizerTest extends \PHPUnit_Framework_TestCase
}
$this->assertTrue($tokens->valid());
$this->assertSame("3", $tokens->current());
$this->assertSame(T_LNUMBER, $tokens->key());
$this->assertSame($tokens, $tokens->next());
$tokens->next();
$this->assertSame("double", $tokens->getAndNext());
$this->assertSame(")", $tokens->current());
$this->assertTrue($tokens->isLast());
$this->assertSame($tokens, $tokens->next());
}
}

View File

@ -10,7 +10,7 @@ class FenomTest extends \Fenom\TestCase
{
return array(
array("disable_methods", Fenom::DENY_METHODS),
array("disable_native_funcs", Fenom::DENY_INLINE_FUNCS),
array("disable_native_funcs", Fenom::DENY_NATIVE_FUNCS),
array("disable_cache", Fenom::DISABLE_CACHE),
array("force_compile", Fenom::FORCE_COMPILE),
array("auto_reload", Fenom::AUTO_RELOAD),
@ -20,6 +20,16 @@ class FenomTest extends \Fenom\TestCase
);
}
public function testCreating() {
$time = $this->tpl('template1.tpl', 'Template 1 a');
Fenom::factory(FENOM_RESOURCES . '/template', FENOM_RESOURCES . '/compile');
$fenom = new Fenom($provider =new \Fenom\Provider(FENOM_RESOURCES . '/template'), FENOM_RESOURCES . '/compile', Fenom::AUTO_ESCAPE);
$this->assertInstanceOf('Fenom\Template', $tpl = $fenom->getTemplate('template1.tpl'));
$this->assertSame($provider, $tpl->getProvider());
$this->assertSame('template1.tpl', $tpl->getBaseName());
$this->assertSame($time, $tpl->getTime());
}
public function testCompileFile()
{
$a = array(
@ -43,14 +53,19 @@ class FenomTest extends \Fenom\TestCase
$this->assertSame("Custom template", $this->fenom->fetch('custom.tpl', array()));
}
/**
* @group testCheckMTime
*/
public function testCheckMTime()
{
$this->fenom->setOptions(Fenom::FORCE_COMPILE);
$this->tpl('custom.tpl', 'Custom template');
$this->assertSame("Custom template", $this->fenom->fetch('custom.tpl', array()));
sleep(1);
$tpl = $this->fenom->getTemplate('custom.tpl');
$this->assertTrue($tpl->isValid());
usleep(1.5e6);
$this->tpl('custom.tpl', 'Custom template (new)');
$this->assertFalse($tpl->isValid());
$this->assertSame("Custom template (new)", $this->fenom->fetch('custom.tpl', array()));
}