mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-17 21:07:18 +00:00
removed some test hacks
This commit is contained in:
@@ -14,7 +14,7 @@ class Twig_Tests_Node_Expression_CallTest extends PHPUnit_Framework_TestCase
|
||||
public function testGetArguments()
|
||||
{
|
||||
$node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'date'));
|
||||
$this->assertEquals(array('U', null), $node->getArguments('date', array('format' => 'U', 'timestamp' => null)));
|
||||
$this->assertEquals(array('U', null), $this->getArguments($node, array('date', array('format' => 'U', 'timestamp' => null))));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -24,7 +24,7 @@ class Twig_Tests_Node_Expression_CallTest extends PHPUnit_Framework_TestCase
|
||||
public function testGetArgumentsWhenPositionalArgumentsAfterNamedArguments()
|
||||
{
|
||||
$node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'date'));
|
||||
$node->getArguments('date', array('timestamp' => 123456, 'Y-m-d'));
|
||||
$this->getArguments($node, array('date', array('timestamp' => 123456, 'Y-m-d')));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,7 +34,7 @@ class Twig_Tests_Node_Expression_CallTest extends PHPUnit_Framework_TestCase
|
||||
public function testGetArgumentsWhenArgumentIsDefinedTwice()
|
||||
{
|
||||
$node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'date'));
|
||||
$node->getArguments('date', array('Y-m-d', 'format' => 'U'));
|
||||
$this->getArguments($node, array('date', array('Y-m-d', 'format' => 'U')));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,7 +44,7 @@ class Twig_Tests_Node_Expression_CallTest extends PHPUnit_Framework_TestCase
|
||||
public function testGetArgumentsWithWrongNamedArgumentName()
|
||||
{
|
||||
$node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'date'));
|
||||
$node->getArguments('date', array('Y-m-d', 'timestamp' => null, 'unknown' => ''));
|
||||
$this->getArguments($node, array('date', array('Y-m-d', 'timestamp' => null, 'unknown' => '')));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,7 +54,7 @@ class Twig_Tests_Node_Expression_CallTest extends PHPUnit_Framework_TestCase
|
||||
public function testGetArgumentsWithWrongNamedArgumentNames()
|
||||
{
|
||||
$node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'date'));
|
||||
$node->getArguments('date', array('Y-m-d', 'timestamp' => null, 'unknown1' => '', 'unknown2' => ''));
|
||||
$this->getArguments($node, array('date', array('Y-m-d', 'timestamp' => null, 'unknown1' => '', 'unknown2' => '')));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,20 +68,20 @@ class Twig_Tests_Node_Expression_CallTest extends PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
$node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'substr_compare'));
|
||||
$node->getArguments('substr_compare', array('abcd', 'bc', 'offset' => 1, 'case_sensitivity' => true));
|
||||
$this->getArguments($node, array('substr_compare', array('abcd', 'bc', 'offset' => 1, 'case_sensitivity' => true)));
|
||||
}
|
||||
|
||||
public function testResolveArgumentsOnlyNecessaryArgumentsForCustomFunction()
|
||||
{
|
||||
$node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'custom_function'));
|
||||
|
||||
$this->assertEquals(array('arg1'), $node->getArguments(array($this, 'customFunction'), array('arg1' => 'arg1')));
|
||||
$this->assertEquals(array('arg1'), $this->getArguments($node, array(array($this, 'customFunction'), array('arg1' => 'arg1'))));
|
||||
}
|
||||
|
||||
public function testGetArgumentsForStaticMethod()
|
||||
{
|
||||
$node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'custom_static_function'));
|
||||
$this->assertEquals(array('arg1'), $node->getArguments(__CLASS__.'::customStaticFunction', array('arg1' => 'arg1')));
|
||||
$this->assertEquals(array('arg1'), $this->getArguments($node, array(__CLASS__.'::customStaticFunction', array('arg1' => 'arg1'))));
|
||||
}
|
||||
|
||||
public static function customStaticFunction($arg1, $arg2 = 'default', $arg3 = array())
|
||||
@@ -91,12 +91,16 @@ class Twig_Tests_Node_Expression_CallTest extends PHPUnit_Framework_TestCase
|
||||
public function customFunction($arg1, $arg2 = 'default', $arg3 = array())
|
||||
{
|
||||
}
|
||||
|
||||
private function getArguments($call, $args)
|
||||
{
|
||||
$m = new ReflectionMethod($call, 'getArguments');
|
||||
$m->setAccessible(true);
|
||||
|
||||
return $m->invokeArgs($call, $args);
|
||||
}
|
||||
}
|
||||
|
||||
class Twig_Tests_Node_Expression_Call extends Twig_Node_Expression_Call
|
||||
{
|
||||
public function getArguments($callable, $arguments)
|
||||
{
|
||||
return parent::getArguments($callable, $arguments);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,8 +41,10 @@ class Twig_Tests_ParserTest extends PHPUnit_Framework_TestCase
|
||||
public function testFilterBodyNodes($input, $expected)
|
||||
{
|
||||
$parser = $this->getParser();
|
||||
$m = new ReflectionMethod($parser, 'filterBodyNodes');
|
||||
$m->setAccessible(true);
|
||||
|
||||
$this->assertEquals($expected, $parser->filterBodyNodes($input));
|
||||
$this->assertEquals($expected, $m->invoke($parser, $input));
|
||||
}
|
||||
|
||||
public function getFilterBodyNodesData()
|
||||
@@ -71,7 +73,10 @@ class Twig_Tests_ParserTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
$parser = $this->getParser();
|
||||
|
||||
$parser->filterBodyNodes($input);
|
||||
$m = new ReflectionMethod($parser, 'filterBodyNodes');
|
||||
$m->setAccessible(true);
|
||||
|
||||
$m->invoke($parser, $input);
|
||||
}
|
||||
|
||||
public function getFilterBodyNodesDataThrowsException()
|
||||
@@ -89,7 +94,10 @@ class Twig_Tests_ParserTest extends PHPUnit_Framework_TestCase
|
||||
public function testFilterBodyNodesWithBOM()
|
||||
{
|
||||
$parser = $this->getParser();
|
||||
$parser->filterBodyNodes(new Twig_Node_Text(chr(0xEF).chr(0xBB).chr(0xBF), 1));
|
||||
|
||||
$m = new ReflectionMethod($parser, 'filterBodyNodes');
|
||||
$m->setAccessible(true);
|
||||
$m->invoke($parser, new Twig_Node_Text(chr(0xEF).chr(0xBB).chr(0xBF), 1));
|
||||
}
|
||||
|
||||
public function testParseIsReentrant()
|
||||
@@ -137,24 +145,16 @@ EOF
|
||||
|
||||
protected function getParser()
|
||||
{
|
||||
$parser = new TestParser(new Twig_Environment());
|
||||
$parser = new Twig_Parser(new Twig_Environment());
|
||||
$parser->setParent(new Twig_Node());
|
||||
$parser->stream = $this->getMockBuilder('Twig_TokenStream')->disableOriginalConstructor()->getMock();
|
||||
$p = new ReflectionProperty($parser, 'stream');
|
||||
$p->setAccessible(true);
|
||||
$p->setValue($parser, $this->getMockBuilder('Twig_TokenStream')->disableOriginalConstructor()->getMock());
|
||||
|
||||
return $parser;
|
||||
}
|
||||
}
|
||||
|
||||
class TestParser extends Twig_Parser
|
||||
{
|
||||
public $stream;
|
||||
|
||||
public function filterBodyNodes(Twig_Node $node)
|
||||
{
|
||||
return parent::filterBodyNodes($node);
|
||||
}
|
||||
}
|
||||
|
||||
class TestTokenParser extends Twig_TokenParser
|
||||
{
|
||||
public function parse(Twig_Token $token)
|
||||
|
||||
Reference in New Issue
Block a user