Skip to content
This repository has been archived by the owner on Mar 14, 2020. It is now read-only.

Commit

Permalink
Merge pull request #39 from Soullivaneuh/twig-function
Browse files Browse the repository at this point in the history
Fix deprecated Twig_Function_Method usage
  • Loading branch information
henrikbjorn committed Aug 31, 2015
2 parents 96163e2 + 963c2e7 commit 19914a3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
21 changes: 18 additions & 3 deletions Tests/Twig/GravatarExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down Expand Up @@ -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());
}
}
}
6 changes: 3 additions & 3 deletions Twig/GravatarExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
);
}

Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 19914a3

Please sign in to comment.