From: Fabien Potencier Date: Tue, 12 Apr 2011 08:21:00 +0000 (+0200) Subject: refactored some tests X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=d45c980a41729e9506148f46c4fd6dc70907b0ad;p=web%2Fkonrad%2Ftwig.git refactored some tests --- diff --git a/test/Twig/Tests/TemplateTest.php b/test/Twig/Tests/TemplateTest.php index 2ca9b49..116b0ea 100644 --- a/test/Twig/Tests/TemplateTest.php +++ b/test/Twig/Tests/TemplateTest.php @@ -26,10 +26,9 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase */ public function testUnknownPropertyOnArray($array) { - $env = new Twig_Environment(null, array('strict_variables' => true)); - $template = new Twig_TemplateTest($env); + list($template, $m) = $this->getTemplate(true); - $template->getAttribute($array, 'unknown', array(), Twig_TemplateInterface::ARRAY_CALL); + $m->invoke($template, $array, 'unknown', array(), Twig_TemplateInterface::ARRAY_CALL); } /** @@ -37,9 +36,20 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase */ public function testGetAttribute($expected, $object, $item, $arguments, $type) { - $template = new Twig_TemplateTest(new Twig_Environment()); + list($template, $m) = $this->getTemplate(false); - $this->assertEquals($expected, $template->getAttribute($object, $item, $arguments, $type)); + $this->assertEquals($expected, $m->invoke($template, $object, $item, $arguments, $type)); + } + + protected function getTemplate($strict) + { + $env = new Twig_Environment(null, array('strict_variables' => $strict)); + $template = $this->getMockForAbstractClass('Twig_Template', array($env)); + $r = new ReflectionObject($template); + $m = $r->getMethod('getAttribute'); + $m->setAccessible(true); + + return array($template, $m); } public function getGetAttributeTests() @@ -89,18 +99,6 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase } } -class Twig_TemplateTest extends Twig_Template -{ - protected function doDisplay(array $context, array $blocks = array()) - { - } - - public function getAttribute($object, $item, array $arguments = array(), $type = Twig_TemplateInterface::ANY_CALL, $noStrictCheck = false, $lineno = -1) - { - return parent::getAttribute($object, $item, $arguments, $type); - } -} - class Twig_TemplateObject { public $foo = 'foo';