Skip to content

Commit ad2bcd2

Browse files
committed
Upgrade Twig
1 parent 4fdd976 commit ad2bcd2

File tree

8 files changed

+71
-53
lines changed

8 files changed

+71
-53
lines changed

.github/workflows/run-tests.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- "*"
10+
schedule:
11+
- cron: '0 0 * * *'
12+
13+
jobs:
14+
php-tests:
15+
runs-on: ${{ matrix.os }}
16+
timeout-minutes: 15
17+
env:
18+
COMPOSER_NO_INTERACTION: 1
19+
20+
strategy:
21+
matrix:
22+
php: [8.1, 8.0, 7.4, 7.3]
23+
laravel: [8.*, 9.*]
24+
dependency-version: [prefer-lowest, prefer-stable]
25+
exclude:
26+
- php: 8.0
27+
dependency-version: prefer-lowest
28+
- php: 7.4
29+
laravel: 9.*
30+
- php: 7.3
31+
laravel: 9.*
32+
include:
33+
- php: 7.2
34+
laravel: 6.*
35+
steps:
36+
- name: Checkout code
37+
uses: actions/checkout@v2
38+
39+
- name: Setup PHP
40+
uses: shivammathur/setup-php@v2
41+
with:
42+
php-version: ${{ matrix.php }}
43+
coverage: none
44+
45+
- name: Install dependencies
46+
run: |
47+
composer require "laravel/framework:${{ matrix.laravel }}" --no-update --no-progress
48+
composer update --prefer-dist --no-progress
49+
50+
- name: Execute Unit Tests
51+
run: vendor/bin phpunit

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/vendor
22
composer.phar
33
composer.lock
4-
.DS_Store
4+
.DS_Store
5+
.phpunit.result.cache

.travis.yml

Lines changed: 0 additions & 35 deletions
This file was deleted.

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"illuminate/support": "^6|^7|^8",
1515
"symfony/form": "^4|^5|^6",
1616
"symfony/validator": "^4|^5|^6",
17-
"symfony/twig-bridge": "^4|^5|^6"
17+
"symfony/twig-bridge": "^4|^5|^6",
18+
"twig/twig": "^2.13|^3.0.4"
1819
},
1920
"autoload": {
2021
"psr-4": {
@@ -28,7 +29,7 @@
2829
},
2930
"extra": {
3031
"branch-alias": {
31-
"dev-master": "0.5-dev"
32+
"dev-master": "0.6-dev"
3233
},
3334
"laravel": {
3435
"providers": [

src/Extension/Http/HttpExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class HttpExtension extends AbstractExtension
66
{
7-
protected function loadTypeExtensions()
7+
protected function loadTypeExtensions(): array
88
{
99
return array(
1010
new FormTypeHttpExtension(),

src/Extension/SessionExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class SessionExtension extends AbstractExtension
1111
/**
1212
* {@inheritdoc}
1313
*/
14-
protected function loadTypeExtensions()
14+
protected function loadTypeExtensions(): array
1515
{
1616
return array(
1717
new Session\CsrfTypeExtension,

src/ServiceProvider.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ public function boot()
3939
$loader = $twig->getLoader();
4040

4141
// If the loader is not already a chain, make it one
42-
if (! $loader instanceof \Twig_Loader_Chain) {
43-
$loader = new \Twig_Loader_Chain([$loader]);
42+
if (! $loader instanceof \Twig\Loader\ChainLoader) {
43+
$loader = new \Twig\Loader\ChainLoader([$loader]);
4444
$twig->setLoader($loader);
4545
}
4646

47-
$loader->addLoader(new \Twig_Loader_Filesystem($this->getTemplateDirectories()));
47+
$loader->addLoader(new \Twig\Loader\FilesystemLoader($this->getTemplateDirectories()));
4848

49-
$twig->addRuntimeLoader(new \Twig_FactoryRuntimeLoader(array(
49+
$twig->addRuntimeLoader(new \Twig\RuntimeLoader\FactoryRuntimeLoader(array(
5050
\Symfony\Component\Form\FormRenderer::class => function () {
5151
return $this->app->make(\Symfony\Component\Form\FormRenderer::class);
5252
}
@@ -56,15 +56,15 @@ public function boot()
5656
$twig->addExtension(new FormExtension());
5757

5858
// trans filter is used in the forms
59-
$twig->addFilter(new \Twig_SimpleFilter('trans', function ($id = null, $replace = [], $locale = null) {
59+
$twig->addFilter(new \Twig\TwigFilter('trans', function ($id = null, $replace = [], $locale = null) {
6060
if (empty($id)) {
6161
return '';
6262
}
6363
return app('translator')->get($id, $replace, $locale);
6464
}));
6565

6666
// csrf_token needs to be replaced for Laravel
67-
$twig->addFunction(new \Twig_SimpleFunction('csrf_token', 'csrf_token'));
67+
$twig->addFunction(new \Twig\TwigFunction('csrf_token', 'csrf_token'));
6868

6969
$this->registerBladeDirectives();
7070
$this->registerViewComposer();
@@ -203,19 +203,19 @@ protected function getTemplateDirectories()
203203
/**
204204
* Get or create a new TwigEnvironment
205205
*
206-
* @return \Twig_Environment
206+
* @return \Twig\Environment
207207
*/
208208
protected function getTwigEnvironment()
209209
{
210-
if (! $this->app->bound(\Twig_Environment::class)) {
211-
$this->app->singleton(\Twig_Environment::class, function () {
212-
return new \Twig_Environment(new \Twig_Loader_Chain([]), [
210+
if (! $this->app->bound(\Twig\Environment::class)) {
211+
$this->app->singleton(\Twig\Environment::class, function () {
212+
return new \Twig\Environment(new \Twig\Loader\ChainLoader([]), [
213213
'cache' => storage_path('framework/views/twig'),
214214
]);
215215
});
216216
}
217217

218-
/** @var \Twig_Environment $twig */
219-
return $this->app->make(\Twig_Environment::class);
218+
/** @var \Twig\Environment $twig */
219+
return $this->app->make(\Twig\Environment::class);
220220
}
221221
}

tests/BladeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function testInlineForm()
5050
{
5151
$crawler = $this->call('GET', 'create');
5252

53-
$this->assertContains('<form name="user_form" method="post">', $crawler->getContent());
53+
$this->assertStringContainsString('<form name="user_form" method="post">', $crawler->getContent());
5454
}
5555

5656
/**

0 commit comments

Comments
 (0)