Merge pull request #682 from MyIgel/php7.4

PHP 7.4 compatibility, PHP min version 7.2, Twig 3
main
msquare 5 years ago committed by GitHub
commit a18c7d13fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -11,7 +11,7 @@ To report bugs use [engelsystem/issues](https://github.com/engelsystem/engelsyst
## Installation ## Installation
### Requirements ### Requirements
* PHP >= 7.1 * PHP >= 7.2
* Required modules: * Required modules:
* dom * dom
* json * json
@ -150,7 +150,7 @@ docker-compose up
Run these commands once initially and then as required after changes Run these commands once initially and then as required after changes
``` ```bash
# Install composer dependencies # Install composer dependencies
docker exec -it engelsystem_dev_es_workspace_1 composer i docker exec -it engelsystem_dev_es_workspace_1 composer i
@ -169,7 +169,7 @@ docker exec -it engelsystem_dev_es_workspace_1 bin/migrate
While developing you may use the watch mode to rebuild the system on changes While developing you may use the watch mode to rebuild the system on changes
``` ```bash
# Run a front-end build # Run a front-end build
docker exec -it engelsystem_dev_es_workspace_1 yarn build:watch docker exec -it engelsystem_dev_es_workspace_1 yarn build:watch
``` ```
@ -199,10 +199,10 @@ We use gettext. You may use POEdit to extract new texts from the sourcecode. Ple
### Code style ### Code style
Please ensure that your pull requests follow the [PSR-12](https://www.php-fig.org/psr/psr-12/) coding style guide. Please ensure that your pull requests follow the [PSR-12](https://www.php-fig.org/psr/psr-12/) coding style guide.
You can check that by running You can check that by running
```php ```bash
composer run phpcs composer run phpcs
``` ```
You may auto fix reported issues by running You may auto fix reported issues by running
```php ```bash
composer run phpcbf composer run phpcbf
``` ```

@ -18,7 +18,7 @@
"phpcbf": "phpcbf -p" "phpcbf": "phpcbf -p"
}, },
"require": { "require": {
"php": ">=7.1.0", "php": ">=7.2.0",
"ext-json": "*", "ext-json": "*",
"ext-libxml": "*", "ext-libxml": "*",
"ext-mbstring": "*", "ext-mbstring": "*",
@ -40,8 +40,7 @@
"swiftmailer/swiftmailer": "^6.2", "swiftmailer/swiftmailer": "^6.2",
"symfony/http-foundation": "^4.3", "symfony/http-foundation": "^4.3",
"symfony/psr-http-message-bridge": "^1.2", "symfony/psr-http-message-bridge": "^1.2",
"twig/extensions": "^1.5", "twig/twig": "^3.0",
"twig/twig": "~2.6.0",
"vlucas/phpdotenv": "^3.3" "vlucas/phpdotenv": "^3.3"
}, },
"require-dev": { "require-dev": {

@ -1,5 +1,3 @@
{% import _self as elements %}
{% macro toolbar_item(label, link, active_page, icon) %} {% macro toolbar_item(label, link, active_page, icon) %}
<li{% if page() == active_page %} class="active"{% endif %}> <li{% if page() == active_page %} class="active"{% endif %}>
<a href="{{ link }}"> <a href="{{ link }}">
@ -36,23 +34,23 @@
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
{% if is_user() %} {% if is_user() %}
{{ elements.toolbar_item(menuUserShiftState(user), url('shifts', {'action': 'next'}), '', 'glyphicon-time') }} {{ _self.toolbar_item(menuUserShiftState(user), url('shifts', {'action': 'next'}), '', 'glyphicon-time') }}
{% elseif has_permission_to('register') and config('registration_enabled') %} {% elseif has_permission_to('register') and config('registration_enabled') %}
{{ elements.toolbar_item(__('Register'), url('register'), 'register', 'glyphicon-plus') }} {{ _self.toolbar_item(__('Register'), url('register'), 'register', 'glyphicon-plus') }}
{% endif %} {% endif %}
{% if has_permission_to('login') %} {% if has_permission_to('login') %}
{{ elements.toolbar_item(__('Login'), url('login'), 'login', 'glyphicon-log-in') }} {{ _self.toolbar_item(__('Login'), url('login'), 'login', 'glyphicon-log-in') }}
{% endif %} {% endif %}
{% if is_user() and has_permission_to('user_messages') %} {% if is_user() and has_permission_to('user_messages') %}
{{ elements.toolbar_item(menuUserMessages(), url('user-messages'), 'user-messages', 'glyphicon-envelope') }} {{ _self.toolbar_item(menuUserMessages(), url('user-messages'), 'user-messages', 'glyphicon-envelope') }}
{% endif %} {% endif %}
{{ menuUserHints() }} {{ menuUserHints() }}
{% if has_permission_to('user_myshifts') %} {% if has_permission_to('user_myshifts') %}
{{ elements.toolbar_item(user.name, url('users', {'action': 'view'}), 'users', 'icon icon-icon_angel') }} {{ _self.toolbar_item(user.name, url('users', {'action': 'view'}), 'users', 'icon icon-icon_angel') }}
{% endif %} {% endif %}
<li class="dropdown"> <li class="dropdown">

@ -17,7 +17,7 @@
(__('Event starts')): config('event_start'), (__('Event starts')): config('event_start'),
(__('Event ends')): config('event_end'), (__('Event ends')): config('event_end'),
(__('Teardown ends')): config('teardown_end') (__('Teardown ends')): config('teardown_end')
} if date %} } | filter(date => date) %}
{% if date > date() %} {% if date > date() %}
<div class="col-sm-3 text-center hidden-xs"> <div class="col-sm-3 text-center hidden-xs">
<h4>{{ name }}</h4> <h4>{{ name }}</h4>

@ -40,10 +40,11 @@ class ConfigServiceProvider extends ServiceProvider
continue; continue;
} }
$config->set(array_replace_recursive( $configuration = array_replace_recursive(
$config->get(null), $config->get(null),
require $file require $file
)); );
$config->set($configuration);
} }
if (empty($config->get(null))) { if (empty($config->get(null))) {

@ -142,7 +142,7 @@ class MetricsEngine implements EngineInterface
* @param string|mixed[] $key * @param string|mixed[] $key
* @param mixed $value * @param mixed $value
*/ */
public function share($key, $value = null) public function share($key, $value = null): void
{ {
} }
} }

@ -25,7 +25,7 @@ class Authenticator
/** @var string[] */ /** @var string[] */
protected $permissions; protected $permissions;
/** @var int */ /** @var int|string|null */
protected $passwordAlgorithm = PASSWORD_DEFAULT; protected $passwordAlgorithm = PASSWORD_DEFAULT;
/** /**
@ -163,13 +163,11 @@ class Authenticator
*/ */
public function verifyPassword(User $user, string $password) public function verifyPassword(User $user, string $password)
{ {
$algorithm = $this->passwordAlgorithm;
if (!password_verify($password, $user->password)) { if (!password_verify($password, $user->password)) {
return false; return false;
} }
if (password_needs_rehash($user->password, $algorithm)) { if (password_needs_rehash($user->password, $this->passwordAlgorithm)) {
$this->setPassword($user, $password); $this->setPassword($user, $password);
} }
@ -182,14 +180,12 @@ class Authenticator
*/ */
public function setPassword(User $user, string $password) public function setPassword(User $user, string $password)
{ {
$algorithm = $this->passwordAlgorithm; $user->password = password_hash($password, $this->passwordAlgorithm);
$user->password = password_hash($password, $algorithm);
$user->save(); $user->save();
} }
/** /**
* @return int * @return int|string|null
*/ */
public function getPasswordAlgorithm() public function getPasswordAlgorithm()
{ {
@ -197,9 +193,9 @@ class Authenticator
} }
/** /**
* @param int $passwordAlgorithm * @param int|string|null $passwordAlgorithm
*/ */
public function setPasswordAlgorithm(int $passwordAlgorithm) public function setPasswordAlgorithm($passwordAlgorithm)
{ {
$this->passwordAlgorithm = $passwordAlgorithm; $this->passwordAlgorithm = $passwordAlgorithm;
} }

@ -11,7 +11,7 @@ use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface; use Psr\Http\Server\RequestHandlerInterface;
use Twig_LoaderInterface as TwigLoader; use Twig\Loader\LoaderInterface as TwigLoader;
class ErrorHandler implements MiddlewareInterface class ErrorHandler implements MiddlewareInterface
{ {
@ -67,13 +67,11 @@ class ErrorHandler implements MiddlewareInterface
if ($request instanceof Request) { if ($request instanceof Request) {
$session = $request->getSession(); $session = $request->getSession();
$session->set( $errors = array_merge_recursive(
'errors',
array_merge_recursive(
$session->get('errors', []), $session->get('errors', []),
['validation' => $e->getValidator()->getErrors()] ['validation' => $e->getValidator()->getErrors()]
)
); );
$session->set('errors', $errors);
$session->set('form-data', Arr::except($request->request->all(), $this->formIgnore)); $session->set('form-data', Arr::except($request->request->all(), $this->formIgnore));
} }

@ -11,7 +11,7 @@ abstract class Engine implements EngineInterface
* @param mixed[]|string $key * @param mixed[]|string $key
* @param null $value * @param null $value
*/ */
public function share($key, $value = null) public function share($key, $value = null): void
{ {
if (!is_array($key)) { if (!is_array($key)) {
$key = [$key => $value]; $key = [$key => $value];

@ -23,5 +23,5 @@ interface EngineInterface
* @param string|mixed[] $key * @param string|mixed[] $key
* @param mixed $value * @param mixed $value
*/ */
public function share($key, $value = null); public function share($key, $value = null): void;
} }

@ -18,7 +18,7 @@ class Renderer
* @param mixed[] $data * @param mixed[] $data
* @return string * @return string
*/ */
public function render($template, $data = []) public function render(string $template, array $data = []): string
{ {
foreach ($this->renderer as $renderer) { foreach ($this->renderer as $renderer) {
if (!$renderer->canRender($template)) { if (!$renderer->canRender($template)) {
@ -40,7 +40,7 @@ class Renderer
* *
* @param EngineInterface $renderer * @param EngineInterface $renderer
*/ */
public function addRenderer(EngineInterface $renderer) public function addRenderer(EngineInterface $renderer): void
{ {
$this->renderer[] = $renderer; $this->renderer[] = $renderer;
} }

@ -3,8 +3,8 @@
namespace Engelsystem\Renderer\Twig\Extensions; namespace Engelsystem\Renderer\Twig\Extensions;
use Engelsystem\Http\UrlGenerator; use Engelsystem\Http\UrlGenerator;
use Twig_Extension as TwigExtension; use Twig\Extension\AbstractExtension as TwigExtension;
use Twig_Function as TwigFunction; use Twig\TwigFunction;
class Assets extends TwigExtension class Assets extends TwigExtension
{ {
@ -22,7 +22,7 @@ class Assets extends TwigExtension
/** /**
* @return TwigFunction[] * @return TwigFunction[]
*/ */
public function getFunctions() public function getFunctions(): array
{ {
return [ return [
new TwigFunction('asset', [$this, 'getAsset']), new TwigFunction('asset', [$this, 'getAsset']),
@ -31,9 +31,9 @@ class Assets extends TwigExtension
/** /**
* @param string $path * @param string $path
* @return UrlGenerator|string * @return string
*/ */
public function getAsset($path) public function getAsset(string $path): string
{ {
$path = ltrim($path, '/'); $path = ltrim($path, '/');

@ -3,8 +3,8 @@
namespace Engelsystem\Renderer\Twig\Extensions; namespace Engelsystem\Renderer\Twig\Extensions;
use Engelsystem\Helpers\Authenticator; use Engelsystem\Helpers\Authenticator;
use Twig_Extension as TwigExtension; use Twig\Extension\AbstractExtension as TwigExtension;
use Twig_Function as TwigFunction; use Twig\TwigFunction;
class Authentication extends TwigExtension class Authentication extends TwigExtension
{ {
@ -22,7 +22,7 @@ class Authentication extends TwigExtension
/** /**
* @return TwigFunction[] * @return TwigFunction[]
*/ */
public function getFunctions() public function getFunctions(): array
{ {
return [ return [
new TwigFunction('is_user', [$this, 'isAuthenticated']), new TwigFunction('is_user', [$this, 'isAuthenticated']),
@ -34,7 +34,7 @@ class Authentication extends TwigExtension
/** /**
* @return bool * @return bool
*/ */
public function isAuthenticated() public function isAuthenticated(): bool
{ {
return (bool)$this->auth->user(); return (bool)$this->auth->user();
} }
@ -42,7 +42,7 @@ class Authentication extends TwigExtension
/** /**
* @return bool * @return bool
*/ */
public function isGuest() public function isGuest(): bool
{ {
return !$this->isAuthenticated(); return !$this->isAuthenticated();
} }

@ -3,8 +3,8 @@
namespace Engelsystem\Renderer\Twig\Extensions; namespace Engelsystem\Renderer\Twig\Extensions;
use Engelsystem\Config\Config as EngelsystemConfig; use Engelsystem\Config\Config as EngelsystemConfig;
use Twig_Extension as TwigExtension; use Twig\Extension\AbstractExtension as TwigExtension;
use Twig_Function as TwigFunction; use Twig\TwigFunction;
class Config extends TwigExtension class Config extends TwigExtension
{ {
@ -22,7 +22,7 @@ class Config extends TwigExtension
/** /**
* @return TwigFunction[] * @return TwigFunction[]
*/ */
public function getFunctions() public function getFunctions(): array
{ {
return [ return [
new TwigFunction('config', [$this->config, 'get']), new TwigFunction('config', [$this->config, 'get']),

@ -3,8 +3,8 @@
namespace Engelsystem\Renderer\Twig\Extensions; namespace Engelsystem\Renderer\Twig\Extensions;
use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Twig_Extension as TwigExtension; use Twig\Extension\AbstractExtension as TwigExtension;
use Twig_Function as TwigFunction; use Twig\TwigFunction;
class Csrf extends TwigExtension class Csrf extends TwigExtension
{ {
@ -22,7 +22,7 @@ class Csrf extends TwigExtension
/** /**
* @return TwigFunction[] * @return TwigFunction[]
*/ */
public function getFunctions() public function getFunctions(): array
{ {
return [ return [
new TwigFunction('csrf', [$this, 'getCsrfField'], ['is_safe' => ['html']]), new TwigFunction('csrf', [$this, 'getCsrfField'], ['is_safe' => ['html']]),
@ -33,7 +33,7 @@ class Csrf extends TwigExtension
/** /**
* @return string * @return string
*/ */
public function getCsrfField() public function getCsrfField(): string
{ {
return sprintf('<input type="hidden" name="_token" value="%s">', $this->getCsrfToken()); return sprintf('<input type="hidden" name="_token" value="%s">', $this->getCsrfToken());
} }
@ -41,7 +41,7 @@ class Csrf extends TwigExtension
/** /**
* @return string * @return string
*/ */
public function getCsrfToken() public function getCsrfToken(): string
{ {
return $this->session->get('_token'); return $this->session->get('_token');
} }

@ -3,8 +3,8 @@
namespace Engelsystem\Renderer\Twig\Extensions; namespace Engelsystem\Renderer\Twig\Extensions;
use Engelsystem\Helpers\Authenticator; use Engelsystem\Helpers\Authenticator;
use Twig_Extension as TwigExtension; use Twig\Extension\AbstractExtension as TwigExtension;
use Twig_Extension_GlobalsInterface as GlobalsInterface; use Twig\Extension\GlobalsInterface as GlobalsInterface;
class Globals extends TwigExtension implements GlobalsInterface class Globals extends TwigExtension implements GlobalsInterface
{ {
@ -24,7 +24,7 @@ class Globals extends TwigExtension implements GlobalsInterface
* *
* @return array An array of global variables * @return array An array of global variables
*/ */
public function getGlobals() public function getGlobals(): array
{ {
$user = $this->auth->user(); $user = $this->auth->user();

@ -3,8 +3,8 @@
namespace Engelsystem\Renderer\Twig\Extensions; namespace Engelsystem\Renderer\Twig\Extensions;
use Engelsystem\Http\Request; use Engelsystem\Http\Request;
use Twig_Extension as TwigExtension; use Twig\Extension\AbstractExtension as TwigExtension;
use Twig_Function as TwigFunction; use Twig\TwigFunction;
class Legacy extends TwigExtension class Legacy extends TwigExtension
{ {
@ -22,7 +22,7 @@ class Legacy extends TwigExtension
/** /**
* @return TwigFunction[] * @return TwigFunction[]
*/ */
public function getFunctions() public function getFunctions(): array
{ {
$isSafeHtml = ['is_safe' => ['html']]; $isSafeHtml = ['is_safe' => ['html']];
return [ return [
@ -39,7 +39,7 @@ class Legacy extends TwigExtension
/** /**
* @return string * @return string
*/ */
public function getPage() public function getPage(): string
{ {
if ($this->request->has('p')) { if ($this->request->has('p')) {
return $this->request->get('p'); return $this->request->get('p');

@ -3,8 +3,8 @@
namespace Engelsystem\Renderer\Twig\Extensions; namespace Engelsystem\Renderer\Twig\Extensions;
use Parsedown; use Parsedown;
use Twig_Extension as TwigExtension; use Twig\Extension\AbstractExtension as TwigExtension;
use Twig_Filter as TwigFilter; use Twig\TwigFilter;
class Markdown extends TwigExtension class Markdown extends TwigExtension
{ {
@ -36,7 +36,7 @@ class Markdown extends TwigExtension
* @param string $text * @param string $text
* @return string * @return string
*/ */
public function render($text): string public function render(string $text): string
{ {
return $this->renderer->text(htmlspecialchars($text)); return $this->renderer->text(htmlspecialchars($text));
} }

@ -3,8 +3,8 @@
namespace Engelsystem\Renderer\Twig\Extensions; namespace Engelsystem\Renderer\Twig\Extensions;
use Symfony\Component\HttpFoundation\Session\Session as SymfonySession; use Symfony\Component\HttpFoundation\Session\Session as SymfonySession;
use Twig_Extension as TwigExtension; use Twig\Extension\AbstractExtension as TwigExtension;
use Twig_Function as TwigFunction; use Twig\TwigFunction;
class Session extends TwigExtension class Session extends TwigExtension
{ {
@ -22,7 +22,7 @@ class Session extends TwigExtension
/** /**
* @return TwigFunction[] * @return TwigFunction[]
*/ */
public function getFunctions() public function getFunctions(): array
{ {
return [ return [
new TwigFunction('session_get', [$this->session, 'get']), new TwigFunction('session_get', [$this->session, 'get']),

@ -3,34 +3,27 @@
namespace Engelsystem\Renderer\Twig\Extensions; namespace Engelsystem\Renderer\Twig\Extensions;
use Engelsystem\Helpers\Translation\Translator; use Engelsystem\Helpers\Translation\Translator;
use Twig_Extension as TwigExtension; use Twig\Extension\AbstractExtension as TwigExtension;
use Twig_Extensions_TokenParser_Trans as TranslationTokenParser; use Twig\TwigFilter;
use Twig_Filter as TwigFilter; use Twig\TwigFunction;
use Twig_Function as TwigFunction;
use Twig_TokenParserInterface as TwigTokenParser;
class Translation extends TwigExtension class Translation extends TwigExtension
{ {
/** @var Translator */ /** @var Translator */
protected $translator; protected $translator;
/** @var TranslationTokenParser */
protected $tokenParser;
/** /**
* @param Translator $translator * @param Translator $translator
* @param TranslationTokenParser $tokenParser
*/ */
public function __construct(Translator $translator, TranslationTokenParser $tokenParser) public function __construct(Translator $translator)
{ {
$this->translator = $translator; $this->translator = $translator;
$this->tokenParser = $tokenParser;
} }
/** /**
* @return array * @return array
*/ */
public function getFilters() public function getFilters(): array
{ {
return [ return [
new TwigFilter('trans', [$this->translator, 'translate']), new TwigFilter('trans', [$this->translator, 'translate']),
@ -40,19 +33,11 @@ class Translation extends TwigExtension
/** /**
* @return TwigFunction[] * @return TwigFunction[]
*/ */
public function getFunctions() public function getFunctions(): array
{ {
return [ return [
new TwigFunction('__', [$this->translator, 'translate']), new TwigFunction('__', [$this->translator, 'translate']),
new TwigFunction('_e', [$this->translator, 'translatePlural']), new TwigFunction('_e', [$this->translator, 'translatePlural']),
]; ];
} }
/**
* @return TwigTokenParser[]
*/
public function getTokenParsers()
{
return [$this->tokenParser];
}
} }

@ -3,8 +3,8 @@
namespace Engelsystem\Renderer\Twig\Extensions; namespace Engelsystem\Renderer\Twig\Extensions;
use Engelsystem\Http\UrlGenerator; use Engelsystem\Http\UrlGenerator;
use Twig_Extension as TwigExtension; use Twig\Extension\AbstractExtension as TwigExtension;
use Twig_Function as TwigFunction; use Twig\TwigFunction;
class Url extends TwigExtension class Url extends TwigExtension
{ {
@ -22,7 +22,7 @@ class Url extends TwigExtension
/** /**
* @return TwigFunction[] * @return TwigFunction[]
*/ */
public function getFunctions() public function getFunctions(): array
{ {
return [ return [
new TwigFunction('url', [$this, 'getUrl']), new TwigFunction('url', [$this, 'getUrl']),
@ -32,9 +32,9 @@ class Url extends TwigExtension
/** /**
* @param string $path * @param string $path
* @param array $parameters * @param array $parameters
* @return UrlGenerator|string * @return string
*/ */
public function getUrl($path, $parameters = []) public function getUrl(string $path, array $parameters = []): string
{ {
$path = str_replace('_', '-', $path); $path = str_replace('_', '-', $path);

@ -2,10 +2,10 @@
namespace Engelsystem\Renderer; namespace Engelsystem\Renderer;
use Twig_Environment as Twig; use Twig\Environment as Twig;
use Twig_Error_Loader as LoaderError; use Twig\Error\LoaderError as LoaderError;
use Twig_Error_Runtime as RuntimeError; use Twig\Error\RuntimeError as RuntimeError;
use Twig_Error_Syntax as SyntaxError; use Twig\Error\SyntaxError as SyntaxError;
class TwigEngine extends Engine class TwigEngine extends Engine
{ {

@ -2,18 +2,18 @@
namespace Engelsystem\Renderer; namespace Engelsystem\Renderer;
use Twig_Error_Loader; use Twig\Error\LoaderError as ErrorLoader;
use Twig_Loader_Filesystem as FilesystemLoader; use Twig\Loader\FilesystemLoader as FilesystemLoader;
class TwigLoader extends FilesystemLoader class TwigLoader extends FilesystemLoader
{ {
/** /**
* @param string $name * @param string $name
* @param bool $throw * @param bool $throw
* @return false|string * @return string|null
* @throws Twig_Error_Loader * @throws ErrorLoader
*/ */
public function findTemplate($name, $throw = true) public function findTemplate(string $name, bool $throw = true): ?string
{ {
$extension = '.twig'; $extension = '.twig';
$extensionLength = mb_strlen($extension); $extensionLength = mb_strlen($extension);

@ -14,9 +14,9 @@ use Engelsystem\Renderer\Twig\Extensions\Markdown;
use Engelsystem\Renderer\Twig\Extensions\Session; use Engelsystem\Renderer\Twig\Extensions\Session;
use Engelsystem\Renderer\Twig\Extensions\Translation; use Engelsystem\Renderer\Twig\Extensions\Translation;
use Engelsystem\Renderer\Twig\Extensions\Url; use Engelsystem\Renderer\Twig\Extensions\Url;
use Twig_Environment as Twig; use Twig\Environment as Twig;
use Twig_Extension_Core as TwigCore; use Twig\Extension\CoreExtension as TwigCore;
use Twig_LoaderInterface as TwigLoaderInterface; use Twig\Loader\LoaderInterface as TwigLoaderInterface;
class TwigServiceProvider extends ServiceProvider class TwigServiceProvider extends ServiceProvider
{ {
@ -95,7 +95,7 @@ class TwigServiceProvider extends ServiceProvider
* @param string $class * @param string $class
* @param string $alias * @param string $alias
*/ */
protected function registerTwigExtensions($class, $alias) protected function registerTwigExtensions(string $class, string $alias)
{ {
$alias = 'twig.extension.' . $alias; $alias = 'twig.extension.' . $alias;

@ -19,7 +19,7 @@ use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface; use Psr\Http\Server\RequestHandlerInterface;
use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Twig_LoaderInterface as TwigLoader; use Twig\Loader\LoaderInterface as TwigLoader;
class ErrorHandlerTest extends TestCase class ErrorHandlerTest extends TestCase
{ {

@ -6,8 +6,8 @@ use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
use Exception; use Exception;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Twig_Function as TwigFunction; use Twig\TwigFunction;
use Twig_Node as TwigNode; use Twig\Node\Node as TwigNode;
abstract class ExtensionTest extends TestCase abstract class ExtensionTest extends TestCase
{ {

@ -5,7 +5,6 @@ namespace Engelsystem\Test\Unit\Renderer\Twig\Extensions;
use Engelsystem\Helpers\Translation\Translator; use Engelsystem\Helpers\Translation\Translator;
use Engelsystem\Renderer\Twig\Extensions\Translation; use Engelsystem\Renderer\Twig\Extensions\Translation;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use Twig_Extensions_TokenParser_Trans as TranslationTokenParser;
class TranslationTest extends ExtensionTest class TranslationTest extends ExtensionTest
{ {
@ -17,10 +16,8 @@ class TranslationTest extends ExtensionTest
{ {
/** @var Translator|MockObject $translator */ /** @var Translator|MockObject $translator */
$translator = $this->createMock(Translator::class); $translator = $this->createMock(Translator::class);
/** @var TranslationTokenParser|MockObject $parser */
$parser = $this->createMock(TranslationTokenParser::class);
$extension = new Translation($translator, $parser); $extension = new Translation($translator);
$filters = $extension->getFilters(); $filters = $extension->getFilters();
$this->assertExtensionExists('trans', [$translator, 'translate'], $filters); $this->assertExtensionExists('trans', [$translator, 'translate'], $filters);
@ -33,29 +30,11 @@ class TranslationTest extends ExtensionTest
{ {
/** @var Translator|MockObject $translator */ /** @var Translator|MockObject $translator */
$translator = $this->createMock(Translator::class); $translator = $this->createMock(Translator::class);
/** @var TranslationTokenParser|MockObject $parser */
$parser = $this->createMock(TranslationTokenParser::class);
$extension = new Translation($translator, $parser); $extension = new Translation($translator);
$functions = $extension->getFunctions(); $functions = $extension->getFunctions();
$this->assertExtensionExists('__', [$translator, 'translate'], $functions); $this->assertExtensionExists('__', [$translator, 'translate'], $functions);
$this->assertExtensionExists('_e', [$translator, 'translatePlural'], $functions); $this->assertExtensionExists('_e', [$translator, 'translatePlural'], $functions);
} }
/**
* @covers \Engelsystem\Renderer\Twig\Extensions\Translation::getTokenParsers
*/
public function testGetTokenParsers()
{
/** @var Translator|MockObject $translator */
$translator = $this->createMock(Translator::class);
/** @var TranslationTokenParser|MockObject $parser */
$parser = $this->createMock(TranslationTokenParser::class);
$extension = new Translation($translator, $parser);
$tokenParsers = $extension->getTokenParsers();
$this->assertTokenParserExists($parser, $tokenParsers);
}
} }

@ -5,8 +5,8 @@ namespace Engelsystem\Test\Unit\Renderer;
use Engelsystem\Renderer\TwigEngine; use Engelsystem\Renderer\TwigEngine;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Twig_Environment as Twig; use Twig\Environment as Twig;
use Twig_LoaderInterface as LoaderInterface; use Twig\Loader\LoaderInterface as LoaderInterface;
class TwigEngineTest extends TestCase class TwigEngineTest extends TestCase
{ {

@ -11,10 +11,11 @@ use PHPUnit\Framework\MockObject\MockObject;
use ReflectionClass as Reflection; use ReflectionClass as Reflection;
use ReflectionException; use ReflectionException;
use stdClass; use stdClass;
use Twig_Environment as Twig; use Twig\Environment as Twig;
use Twig_Extension_Core as TwigCore; use Twig\Extension\AbstractExtension;
use Twig_ExtensionInterface as ExtensionInterface; use Twig\Extension\CoreExtension as TwigCore;
use Twig_LoaderInterface as TwigLoaderInterface; use Twig\Extension\ExtensionInterface as ExtensionInterface;
use Twig\Loader\LoaderInterface as TwigLoaderInterface;
class TwigServiceProviderTest extends ServiceProviderTest class TwigServiceProviderTest extends ServiceProviderTest
{ {
@ -103,9 +104,15 @@ class TwigServiceProviderTest extends ServiceProviderTest
/** @var Config|MockObject $config */ /** @var Config|MockObject $config */
$config = $this->createMock(Config::class); $config = $this->createMock(Config::class);
/** @var TwigCore|MockObject $twigCore */ /** @var TwigCore|MockObject $twigCore */
$twigCore = $this->getMockBuilder(stdClass::class) $twigCore = $this->getMockForAbstractClass(
->addMethods(['setTimezone']) AbstractExtension::class,
->getMock(); [],
'',
true,
true,
true,
['setTimezone']
);
$app = $this->getApp(['make', 'instance', 'tag', 'get']); $app = $this->getApp(['make', 'instance', 'tag', 'get']);

Loading…
Cancel
Save