Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with Twig 3 #220

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions Tests/Twig/Extension/PhoneNumberHelperExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@

namespace Misd\PhoneNumberBundle\Tests\Twig\Extension;


use Misd\PhoneNumberBundle\Twig\Extension\PhoneNumberHelperExtension;


/**
* Phone number helper Twig extension test.
*/
Expand All @@ -41,23 +39,23 @@ protected function setUp()

public function testConstructor()
{
$this->assertInstanceOf('Twig_Extension', $this->extension);
$this->assertInstanceOf('Twig\Extension\AbstractExtension', $this->extension);
}

public function testGetFunctions()
{
$functions = $this->extension->getFunctions();

$this->assertCount(2, $functions);
$this->assertInstanceOf('Twig_SimpleFunction', $functions[0]);
$this->assertInstanceOf('Twig\TwigFunction', $functions[0]);
$this->assertSame('phone_number_format', $functions[0]->getName());

$callable = $functions[0]->getCallable();

$this->assertSame($this->helper, $callable[0]);
$this->assertSame('format', $callable[1]);

$this->assertInstanceOf('Twig_SimpleFunction', $functions[1]);
$this->assertInstanceOf('Twig\TwigFunction', $functions[1]);
$this->assertSame('phone_number_is_type', $functions[1]->getName());

$callable = $functions[1]->getCallable();
Expand All @@ -71,7 +69,7 @@ public function testGetFilters()
$filters = $this->extension->getFilters();

$this->assertCount(1, $filters);
$this->assertInstanceOf('Twig_SimpleFilter', $filters[0]);
$this->assertInstanceOf('Twig\TwigFilter', $filters[0]);
$this->assertSame('phone_number_format', $filters[0]->getName());

$callable = $filters[0]->getCallable();
Expand All @@ -85,7 +83,7 @@ public function testGetTests()
$tests = $this->extension->getTests();

$this->assertCount(1, $tests);
$this->assertInstanceOf('Twig_SimpleTest', $tests[0]);
$this->assertInstanceOf('Twig\TwigTest', $tests[0]);
$this->assertSame('phone_number_of_type', $tests[0]->getName());

$callable = $tests[0]->getCallable();
Expand Down
14 changes: 9 additions & 5 deletions Twig/Extension/PhoneNumberHelperExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@
namespace Misd\PhoneNumberBundle\Twig\Extension;

use Misd\PhoneNumberBundle\Templating\Helper\PhoneNumberHelper;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use Twig\TwigFunction;
use Twig\TwigTest;

/**
* Phone number helper Twig extension.
*/
class PhoneNumberHelperExtension extends \Twig_Extension
class PhoneNumberHelperExtension extends AbstractExtension
{
/**
* Phone number helper.
Expand All @@ -41,8 +45,8 @@ public function __construct(PhoneNumberHelper $helper)
public function getFunctions()
{
return array(
new \Twig_SimpleFunction('phone_number_format', array($this->helper, 'format'), array('deprecated' => '1.2')),
new \Twig_SimpleFunction('phone_number_is_type', array($this->helper, 'isType'), array('deprecated' => '1.2')),
new TwigFunction('phone_number_format', array($this->helper, 'format'), array('deprecated' => '1.2')),
new TwigFunction('phone_number_is_type', array($this->helper, 'isType'), array('deprecated' => '1.2')),
);
}

Expand All @@ -52,7 +56,7 @@ public function getFunctions()
public function getFilters()
{
return array(
new \Twig_SimpleFilter('phone_number_format', array($this->helper, 'format')),
new TwigFilter('phone_number_format', array($this->helper, 'format')),
);
}

Expand All @@ -62,7 +66,7 @@ public function getFilters()
public function getTests()
{
return array(
new \Twig_SimpleTest('phone_number_of_type', array($this->helper, 'isType')),
new TwigTest('phone_number_of_type', array($this->helper, 'isType')),
);
}

Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
"symfony/serializer": "~2.7|~3.1|~4.0",
"symfony/templating": "~2.7|~3.0|~4.0",
"symfony/twig-bundle": "~2.7|~3.0|~4.0",
"symfony/validator": "~2.7|~3.0|~4.0"
"symfony/validator": "~2.7|~3.0|~4.0",
"symfony/intl": "~2.7|~3.0|~4.0"
},
"conflict": {
"twig/twig": "<1.12.0"
"twig/twig": "<1.34.0"
},
"suggest": {
"doctrine/doctrine-bundle": "Add a DBAL mapping type",
Expand Down