Skip to content

Commit 553ea2b

Browse files
authored
github: fix static workflows update dependencies (#516)
* github: fix static workflows update dependencies * refac: use ConditionalTernary when possible * refac: use Nodes instate of Node * refac: set operator attribute on EqualBinary expression * refac: migrate phpunit.dist.xml and fix max deprecation setting * feat: remove twig 2.x support no more maintained * refac: fix Symfony\Component\HttpKernel\DependencyInjection\Extension deprecation * refac: fix self deprecation mb_convert_encoding
1 parent 73bfeae commit 553ea2b

File tree

6 files changed

+76
-62
lines changed

6 files changed

+76
-62
lines changed

.github/workflows/static.yml

+9-9
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ on:
99
jobs:
1010
phpstan:
1111
name: PHPStan
12-
runs-on: Ubuntu-20.04
12+
runs-on: Ubuntu-22.04
1313

1414
steps:
1515
- name: Checkout code
16-
uses: actions/checkout@v2
16+
uses: actions/checkout@v4
1717

1818
- name: Cache PHPStan
19-
uses: actions/cache@v2
19+
uses: actions/cache@v4
2020
with:
2121
path: .github/.cache/phpstan/
2222
key: phpstan-${{ github.sha }}
@@ -29,7 +29,7 @@ jobs:
2929
coverage: none
3030

3131
- name: Download dependencies
32-
uses: ramsey/composer-install@v2
32+
uses: ramsey/composer-install@v3
3333
with:
3434
composer-options: --no-interaction --prefer-dist --optimize-autoloader
3535

@@ -43,21 +43,21 @@ jobs:
4343
name: PHP-CS-Fixer
4444
runs-on: ubuntu-latest
4545
steps:
46-
- uses: actions/checkout@v2
46+
- uses: actions/checkout@v4
4747
- name: PHP-CS-Fixer
4848
uses: docker://oskarstark/php-cs-fixer-ga
4949
with:
5050
args: --diff --dry-run
5151

5252
psalm:
5353
name: Psalm
54-
runs-on: Ubuntu-20.04
54+
runs-on: Ubuntu-22.04
5555
steps:
5656
- name: Checkout code
57-
uses: actions/checkout@v2
57+
uses: actions/checkout@v4
5858

5959
- name: Cache Psalm
60-
uses: actions/cache@v2
60+
uses: actions/cache@v4
6161
with:
6262
path: .github/.cache/psalm/
6363
key: psalm-${{ github.sha }}
@@ -70,7 +70,7 @@ jobs:
7070
coverage: none
7171

7272
- name: Download dependencies
73-
uses: ramsey/composer-install@v1
73+
uses: ramsey/composer-install@v3
7474
with:
7575
composer-options: --no-interaction --prefer-dist --optimize-autoloader
7676

DependencyInjection/TranslationExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
use Symfony\Component\DependencyInjection\ChildDefinition;
1717
use Symfony\Component\DependencyInjection\ContainerBuilder;
1818
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
19+
use Symfony\Component\DependencyInjection\Extension\Extension;
1920
use Symfony\Component\DependencyInjection\Loader;
2021
use Symfony\Component\DependencyInjection\Reference;
21-
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
2222
use Symfony\Component\HttpKernel\Kernel;
2323
use Translation\Bundle\EventListener\AutoAddMissingTranslations;
2424
use Translation\Bundle\EventListener\EditInPlaceResponseListener;

Tests/Functional/Controller/EditInPlaceTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function testActivatedTest(): void
4040
self::assertStringContainsString('<!-- TranslationBundle -->', $response->getContent());
4141

4242
$dom = new \DOMDocument('1.0', 'utf-8');
43-
@$dom->loadHTML(mb_convert_encoding($response->getContent(), 'HTML-ENTITIES', 'UTF-8'));
43+
@$dom->loadHTML(mb_encode_numericentity($response->getContent(), [0x80, 0x10FFFF, 0, ~0], 'UTF-8'));
4444
$xpath = new \DOMXPath($dom);
4545

4646
// Check number of x-trans tags
@@ -79,7 +79,7 @@ public function testIfUntranslatableLabelGetsDisabled(): void
7979
self::assertStringContainsString('<!-- TranslationBundle -->', $response->getContent());
8080

8181
$dom = new \DOMDocument('1.0', 'utf-8');
82-
@$dom->loadHTML(mb_convert_encoding($response->getContent(), 'HTML-ENTITIES', 'UTF-8'));
82+
@$dom->loadHTML(mb_encode_numericentity($response->getContent(), [0x80, 0x10FFFF, 0, ~0], 'UTF-8'));
8383
$xpath = new \DOMXPath($dom);
8484

8585
// Check number of x-trans tags

Twig/Visitor/DefaultApplyingNodeVisitor.php

+40-13
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
use Twig\Node\Expression\ConditionalExpression;
1919
use Twig\Node\Expression\ConstantExpression;
2020
use Twig\Node\Expression\FilterExpression;
21+
use Twig\Node\Expression\Ternary\ConditionalTernary;
2122
use Twig\Node\Node;
23+
use Twig\Node\Nodes;
2224
use Twig\NodeVisitor\AbstractNodeVisitor;
25+
use Twig\TwigFilter;
2326

2427
/**
2528
* Applies the value of the "desc" filter if the "trans" filter has no
@@ -93,22 +96,46 @@ public function doEnterNode(Node $node, Environment $env): Node
9396
$testNode->getNode('arguments')->setNode(0, new ArrayExpression([], $lineno));
9497

9598
// wrap the default node in a |replace filter
96-
$defaultNode = new FilterExpression(
97-
clone $node->getNode('arguments')->getNode(0),
98-
new ConstantExpression('replace', $lineno),
99-
new Node([
100-
clone $wrappingNode->getNode('arguments')->getNode(0),
101-
]),
102-
$lineno
99+
if (Environment::VERSION_ID >= 31500) {
100+
$defaultNode = new FilterExpression(
101+
clone $node->getNode('arguments')->getNode(0),
102+
new TwigFilter('replace'),
103+
new Nodes([
104+
clone $wrappingNode->getNode('arguments')->getNode(0),
105+
]),
106+
$lineno
107+
);
108+
} else {
109+
$defaultNode = new FilterExpression(
110+
clone $node->getNode('arguments')->getNode(0),
111+
new ConstantExpression('replace', $lineno),
112+
new Node([
113+
clone $wrappingNode->getNode('arguments')->getNode(0),
114+
]),
115+
$lineno
116+
);
117+
}
118+
}
119+
120+
$expr = new EqualBinary($testNode, $transNode->getNode('node'), $wrappingNode->getTemplateLine());
121+
if (Environment::VERSION_ID >= 31700) {
122+
$expr->setAttribute('operator', 'binary_==');
123+
124+
$condition = new ConditionalTernary(
125+
$expr,
126+
$defaultNode,
127+
clone $wrappingNode,
128+
$wrappingNode->getTemplateLine()
129+
);
130+
} else {
131+
$condition = new ConditionalExpression(
132+
$expr,
133+
$defaultNode,
134+
clone $wrappingNode,
135+
$wrappingNode->getTemplateLine()
103136
);
104137
}
105138

106-
$condition = new ConditionalExpression(
107-
new EqualBinary($testNode, $transNode->getNode('node'), $wrappingNode->getTemplateLine()),
108-
$defaultNode,
109-
clone $wrappingNode,
110-
$wrappingNode->getTemplateLine()
111-
);
112139
$node->setNode('node', $condition);
113140

114141
return $node;

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"php-translation/symfony-storage": "^2.1",
2323
"php-translation/extractor": "^2.0",
2424
"nyholm/nsa": "^1.1",
25-
"twig/twig": "^2.14.4 || ^3.3",
25+
"twig/twig": "^3.3",
2626
"symfony/asset": "^5.3 || ^6.0 || ^7.0"
2727
},
2828
"require-dev": {

phpunit.xml.dist

+23-36
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,25 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
3-
<phpunit backupGlobals="false"
4-
backupStaticAttributes="false"
5-
colors="false"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnFailure="false"
11-
bootstrap="./vendor/autoload.php"
12-
>
13-
<php>
14-
<env name="ENV" value="test" />
15-
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[direct]=29&amp;verbose=1" />
16-
<env name="KERNEL_CLASS" value="Nyholm\BundleTest\TestKernel" />
17-
</php>
18-
19-
<listeners>
20-
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
21-
</listeners>
22-
23-
<testsuites>
24-
<testsuite name="Test Suite">
25-
<directory>./Tests</directory>
26-
</testsuite>
27-
</testsuites>
28-
29-
<filter>
30-
<whitelist>
31-
<directory suffix=".php">./</directory>
32-
<exclude>
33-
<directory>vendor</directory>
34-
<directory>Tests</directory>
35-
</exclude>
36-
</whitelist>
37-
</filter>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" colors="false" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" bootstrap="./vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3+
<coverage>
4+
<include>
5+
<directory suffix=".php">./</directory>
6+
</include>
7+
<exclude>
8+
<directory>vendor</directory>
9+
<directory>Tests</directory>
10+
</exclude>
11+
</coverage>
12+
<php>
13+
<env name="ENV" value="test"/>
14+
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[direct]=83&amp;verbose=1"/>
15+
<env name="KERNEL_CLASS" value="Nyholm\BundleTest\TestKernel"/>
16+
</php>
17+
<listeners>
18+
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
19+
</listeners>
20+
<testsuites>
21+
<testsuite name="Test Suite">
22+
<directory>./Tests</directory>
23+
</testsuite>
24+
</testsuites>
3825
</phpunit>

0 commit comments

Comments
 (0)