Skip to content

Commit

Permalink
Allow twig 2.0 (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 authored and OskarStark committed Feb 13, 2017
1 parent 3e305b8 commit 1e15606
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Extension/BaseExtension.php
Expand Up @@ -13,7 +13,7 @@

use Twig_Environment;

abstract class BaseExtension implements \Twig_ExtensionInterface, ExtensionInterface
abstract class BaseExtension extends \Twig_Extension implements ExtensionInterface
{
/**
* {@inheritdoc}
Expand Down
2 changes: 1 addition & 1 deletion Extension/BaseProxyExtension.php
Expand Up @@ -13,7 +13,7 @@

use Twig_Environment;

abstract class BaseProxyExtension implements \Twig_ExtensionInterface, ExtensionInterface
abstract class BaseProxyExtension extends \Twig_Extension implements ExtensionInterface
{
/**
* @return \Twig_ExtensionInterface
Expand Down
24 changes: 18 additions & 6 deletions Tests/Formatter/PoolTest.php
Expand Up @@ -19,7 +19,9 @@ class PoolTest extends \PHPUnit_Framework_TestCase
public function testPool()
{
$formatter = new RawFormatter();
$env = $this->getMock('\Twig_Environment');
$env = $this->getMockBuilder('\Twig_Environment')
->disableOriginalConstructor()
->getMock();
$env->expects($this->once())->method('render')->will($this->returnValue('Salut'));

$pool = $this->getPool();
Expand All @@ -44,7 +46,9 @@ public function testNonExistantFormatter()
public function testSyntaxError()
{
$formatter = new RawFormatter();
$env = $this->getMock('\Twig_Environment');
$env = $this->getMockBuilder('\Twig_Environment')
->disableOriginalConstructor()
->getMock();
$env->expects($this->once())->method('render')->will($this->throwException(new \Twig_Error_Syntax('Error')));

$pool = $this->getPool();
Expand All @@ -56,7 +60,9 @@ public function testSyntaxError()
public function testTwig_Sandbox_SecurityError()
{
$formatter = new RawFormatter();
$env = $this->getMock('\Twig_Environment');
$env = $this->getMockBuilder('\Twig_Environment')
->disableOriginalConstructor()
->getMock();
$env->expects($this->once())->method('render')->will($this->throwException(new \Twig_Sandbox_SecurityError('Error')));

$pool = $this->getPool();
Expand All @@ -70,7 +76,9 @@ public function testUnexpectedException()
$this->setExpectedException('RuntimeException');

$formatter = new RawFormatter();
$env = $this->getMock('\Twig_Environment');
$env = $this->getMockBuilder('\Twig_Environment')
->disableOriginalConstructor()
->getMock();
$env->expects($this->once())->method('render')->will($this->throwException(new \RuntimeException('Error')));

$pool = $this->getPool();
Expand All @@ -95,7 +103,9 @@ public function testDefaultFormatter()
public function testBcDefaultFormatter()
{
$formatter = new RawFormatter();
$env = $this->getMock('\Twig_Environment');
$env = $this->getMockBuilder('\Twig_Environment')
->disableOriginalConstructor()
->getMock();

$pool = new Pool();

Expand All @@ -113,7 +123,9 @@ public function testLoggerProvidedThroughConstuctor()
{
$formatter = new RawFormatter();
$pool = new Pool($logger = $this->getMock('Psr\Log\LoggerInterface'));
$env = $this->getMock('\Twig_Environment');
$env = $this->getMockBuilder('\Twig_Environment')
->disableOriginalConstructor()
->getMock();
$env->expects($this->once())->method('render')->will(
$this->throwException(new \Twig_Sandbox_SecurityError('Error'))
);
Expand Down
14 changes: 13 additions & 1 deletion Tests/Formatter/TwigFormatterTest.php
Expand Up @@ -26,7 +26,9 @@ public function testFormatter()
$this->assertSame('0,1,2,3,', $formatter->transform('{% for i in range(0, 3) %}{{ i }},{% endfor %}'));

// Checking, that formatter does not changed loader
$this->assertNotInstanceOf('\\Twig_Loader_String', $twig->getLoader());
if (class_exists('\Twig_Loader_String')) {
$this->assertNotInstanceOf('\\Twig_Loader_String', $twig->getLoader());
}
$this->assertInstanceOf('Sonata\\FormatterBundle\\Tests\\Formatter\\MyStringLoader', $twig->getLoader());
}

Expand Down Expand Up @@ -58,6 +60,11 @@ public function testGetFormatterExtension()

class MyStringLoader implements \Twig_LoaderInterface
{
public function getSourceContext($name)
{
return $name;
}

public function getSource($name)
{
return $name;
Expand All @@ -72,4 +79,9 @@ public function isFresh($name, $time)
{
return true;
}

public function exists($name)
{
return true;
}
}
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -25,7 +25,7 @@
"symfony/form": "^2.3 || ^3.0",
"symfony/framework-bundle": "^2.3 || ^3.0",
"symfony/property-access": "^2.3 || ^3.0",
"twig/twig": "^1.12"
"twig/twig": "^1.12 || ^2.0"
},
"require-dev": {
"sllh/php-cs-fixer-styleci-bridge": "^2.0",
Expand Down

0 comments on commit 1e15606

Please sign in to comment.