From 5dd06b5af44f69bdb369381547bb1840ddfcc3a9 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Thu, 7 Nov 2019 19:11:31 +0300 Subject: [PATCH] use twig/twig 1.34 for easy to migrate to latest stable PHPUnit --- composer.json | 2 +- src/Twig/Extension/PaginationExtension.php | 128 ++++++++---------- .../Extension/PaginationExtensionTest.php | 14 +- 3 files changed, 65 insertions(+), 79 deletions(-) diff --git a/composer.json b/composer.json index 2b5c4c5..b3739d6 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "symfony/framework-bundle": "~2.3|~3.0|~4.0", "symfony/expression-language": "~2.3|~3.0|~4.0", "doctrine/orm": "~2.4|~2.5|~2.6", - "twig/twig": "^1.12|^2.0" + "twig/twig": "^1.34|^2.0" }, "require-dev": { "phpunit/phpunit": "~4.8", diff --git a/src/Twig/Extension/PaginationExtension.php b/src/Twig/Extension/PaginationExtension.php index 9a90bf8..e54e7db 100644 --- a/src/Twig/Extension/PaginationExtension.php +++ b/src/Twig/Extension/PaginationExtension.php @@ -8,85 +8,71 @@ * @license http://opensource.org/licenses/MIT */ -// hook for support Twig > 2.7 +namespace GpsLab\Bundle\PaginationBundle\Twig\Extension; -namespace +use GpsLab\Bundle\PaginationBundle\Service\Configuration; +use Twig\Environment; +use Twig\Extension\AbstractExtension; +use Twig\TwigFunction; + +class PaginationExtension extends AbstractExtension { - use Twig\Extension\AbstractExtension; - use Twig\TwigFunction; + /** + * @var string + */ + private $template; - if (!class_exists('Twig_Extension') && class_exists('Twig\Extension\AbstractExtension')) { - class Twig_Extension extends AbstractExtension - { - } + /** + * @param string $template + */ + public function __construct($template) + { + $this->template = $template; } - if (!class_exists('Twig_SimpleFunction') && class_exists('Twig\TwigFunction')) { - class Twig_SimpleFunction extends TwigFunction - { - } + /** + * @return array + */ + public function getFunctions() + { + return [ + new TwigFunction( + 'pagination_render', + [$this, 'renderPagination'], + ['is_safe' => ['html'], 'needs_environment' => true] + ), + ]; } -} -namespace GpsLab\Bundle\PaginationBundle\Twig\Extension -{ - use GpsLab\Bundle\PaginationBundle\Service\Configuration; + /** + * @param \Twig\Environment $env + * @param Configuration $pagination + * @param string $template + * @param array $view_params + * + * @throws \Twig\Error\LoaderError + * @throws \Twig\Error\RuntimeError + * @throws \Twig\Error\SyntaxError + * + * @return string + */ + public function renderPagination( + Environment $env, + Configuration $pagination, + $template = null, + array $view_params = [] + ) { + return $env->render( + $template ?: $this->template, + array_merge($view_params, ['pagination' => $pagination->getView()]) + ); + } - class PaginationExtension extends \Twig_Extension + /** + * @return string + */ + public function getName() { - /** - * @var string - */ - private $template; - - /** - * @param string $template - */ - public function __construct($template) - { - $this->template = $template; - } - - /** - * @return array - */ - public function getFunctions() - { - return [ - new \Twig_SimpleFunction( - 'pagination_render', - [$this, 'renderPagination'], - ['is_safe' => ['html'], 'needs_environment' => true] - ), - ]; - } - - /** - * @param \Twig_Environment $env - * @param Configuration $pagination - * @param string $template - * @param array $view_params - * - * @return string - */ - public function renderPagination( - \Twig_Environment $env, - Configuration $pagination, - $template = null, - array $view_params = [] - ) { - return $env->render( - $template ?: $this->template, - array_merge($view_params, ['pagination' => $pagination->getView()]) - ); - } - - /** - * @return string - */ - public function getName() - { - return 'gpslab_pagination_extension'; - } + return 'gpslab_pagination_extension'; } } diff --git a/tests/Twig/Extension/PaginationExtensionTest.php b/tests/Twig/Extension/PaginationExtensionTest.php index 27727a6..824b14c 100644 --- a/tests/Twig/Extension/PaginationExtensionTest.php +++ b/tests/Twig/Extension/PaginationExtensionTest.php @@ -37,15 +37,15 @@ public function testGetFunctions() self::assertInternalType('array', $functions); self::assertCount(1, $functions); - self::assertInstanceOf('Twig_SimpleFunction', $functions[0]); + self::assertInstanceOf('Twig\TwigFunction', $functions[0]); } public function testRender() { $expected = 'bar'; $view = 'baz'; - /* @var $env \PHPUnit_Framework_MockObject_MockObject|\Twig_Environment */ - $env = $this->getMockNoConstructor('Twig_Environment'); + /* @var $env \PHPUnit_Framework_MockObject_MockObject|\Twig\Environment */ + $env = $this->getMockNoConstructor('Twig\Environment'); $env ->expects($this->once()) ->method('render') @@ -70,8 +70,8 @@ public function testRenderChangeTemplate() $expected = 'bar'; $view = 'baz'; $template = 'my_template'; - /* @var $env \PHPUnit_Framework_MockObject_MockObject|\Twig_Environment */ - $env = $this->getMockNoConstructor('Twig_Environment'); + /* @var $env \PHPUnit_Framework_MockObject_MockObject|\Twig\Environment */ + $env = $this->getMockNoConstructor('Twig\Environment'); $env ->expects($this->once()) ->method('render') @@ -97,8 +97,8 @@ public function testRenderNoOverrideTemplateParams() { $expected = 'bar'; $view = 'baz'; - /* @var $env \PHPUnit_Framework_MockObject_MockObject|\Twig_Environment */ - $env = $this->getMockNoConstructor('Twig_Environment'); + /* @var $env \PHPUnit_Framework_MockObject_MockObject|\Twig\Environment */ + $env = $this->getMockNoConstructor('Twig\Environment'); $env ->expects($this->once()) ->method('render')