diff --git a/Tests/Twig/GravatarExtensionTest.php b/Tests/Twig/GravatarExtensionTest.php index 553fd48..3a1892f 100644 --- a/Tests/Twig/GravatarExtensionTest.php +++ b/Tests/Twig/GravatarExtensionTest.php @@ -2,10 +2,21 @@ namespace Ornicar\GravatarBundle\Tests\Twig; +use Ornicar\GravatarBundle\Templating\Helper\GravatarHelperInterface; use Ornicar\GravatarBundle\Twig\GravatarExtension; class GravatarExtensionTest extends \PHPUnit_Framework_TestCase { + /** + * @var GravatarHelperInterface + */ + private $helper; + + /** + * @var GravatarExtension + */ + private $extension; + public function setUp() { if (!class_exists('Twig_Extension')) { @@ -34,13 +45,17 @@ public function testName() public function testFunctions() { - $this->assertContainsOnly('Twig_Function_Method', $this->extension->getFunctions()); + $this->assertContainsOnlyInstancesOf('\Twig_SimpleFunction', $this->extension->getFunctions()); - $this->assertEquals(array( + $expectedNames = array( 'gravatar', 'gravatar_hash', 'gravatar_exists', - ), array_keys($this->extension->getFunctions())); + ); + $functions = $this->extension->getFunctions(); + foreach ($expectedNames as $n =>$expectedName) { + $this->assertSame($expectedName, $functions[$n]->getName()); + } } } diff --git a/Twig/GravatarExtension.php b/Twig/GravatarExtension.php index 4c838b4..265260a 100644 --- a/Twig/GravatarExtension.php +++ b/Twig/GravatarExtension.php @@ -26,9 +26,9 @@ public function __construct(GravatarHelperInterface $helper) public function getFunctions() { return array( - 'gravatar' => new \Twig_Function_Method($this, 'getUrl'), - 'gravatar_hash' => new \Twig_Function_Method($this, 'getUrlForHash'), - 'gravatar_exists' => new \Twig_Function_Method($this, 'exists'), + new \Twig_SimpleFunction('gravatar', array($this, 'getUrl')), + new \Twig_SimpleFunction('gravatar_hash', array($this, 'getUrlForHash')), + new \Twig_SimpleFunction('gravatar_exists', array($this, 'exists')), ); } diff --git a/composer.json b/composer.json index 906f77a..765d20b 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,10 @@ "twig/extensions": "1.0.*" }, "suggest" : { - "twig/twig" : ">=1.3.0" + "twig/twig" : "For gravatar twig extension usage" + }, + "conflict": { + "twig/twig": "<1.12" }, "autoload": { "psr-0": {