From b3f96ff198ce030549aac722f1edb1b8c59fca52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Fri, 30 Aug 2024 21:19:02 -0300 Subject: [PATCH 1/7] Fix deprecation with Twig 3.12 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maurício Meneghini Fauth --- src/Node/TransNode.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Node/TransNode.php b/src/Node/TransNode.php index 9f7acf7..2782631 100644 --- a/src/Node/TransNode.php +++ b/src/Node/TransNode.php @@ -16,6 +16,7 @@ use Twig\Attribute\YieldReady; use Twig\Compiler; +use Twig\Environment; use Twig\Node\CheckToStringNode; use Twig\Node\Expression\AbstractExpression; use Twig\Node\Expression\ConstantExpression; @@ -100,6 +101,13 @@ public function __construct( $nodes['context'] = $context; } + /** @phpstan-ignore-next-line */ + if (Environment::VERSION_ID >= 301200) { + parent::__construct($nodes, [], $lineno); + + return; + } + parent::__construct($nodes, [], $lineno, $tag); } From 469924fb5a2b913e26b79ff73b059f9260e4ee2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 31 Aug 2024 11:53:02 -0300 Subject: [PATCH 2/7] Prepare for release 4.1.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [ci skip] Signed-off-by: Maurício Meneghini Fauth --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07ec2bd..66ac2b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## [4.1.2] - 2024-08-31 + +* Add support for Twig 3.12 (#14) + ## [4.1.1] - 2024-04-19 * Add support for Twig 3.9 (#12) @@ -39,6 +43,7 @@ * First release of this library. +[4.1.2]: https://github.com/phpmyadmin/twig-i18n-extension/compare/4.1.1...4.1.2 [4.1.1]: https://github.com/phpmyadmin/twig-i18n-extension/compare/4.1.0...4.1.1 [4.1.0]: https://github.com/phpmyadmin/twig-i18n-extension/compare/v4.0.1...4.1.0 [4.0.1]: https://github.com/phpmyadmin/twig-i18n-extension/compare/v4.0.0...v4.0.1 From 461835b5b01d85c229f3fa7259d142c8db514b3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sun, 8 Sep 2024 12:53:57 -0300 Subject: [PATCH 3/7] Fix deprecation introduced by Twig 3.12 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Related to https://github.com/phpmyadmin/twig-i18n-extension/pull/14 Signed-off-by: Maurício Meneghini Fauth --- src/Node/TransNode.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Node/TransNode.php b/src/Node/TransNode.php index 2782631..07f67ef 100644 --- a/src/Node/TransNode.php +++ b/src/Node/TransNode.php @@ -102,12 +102,13 @@ public function __construct( } /** @phpstan-ignore-next-line */ - if (Environment::VERSION_ID >= 301200) { + if (Environment::VERSION_ID >= 31300 || Environment::VERSION_ID >= 301200) { parent::__construct($nodes, [], $lineno); return; } + /** @phpstan-ignore-next-line */ parent::__construct($nodes, [], $lineno, $tag); } From 4c9e1e3554dfff3091679c8f16a9c2c28a397e38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sun, 8 Sep 2024 13:46:55 -0300 Subject: [PATCH 4/7] Prepare for release 4.1.3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [ci skip] Signed-off-by: Maurício Meneghini Fauth --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66ac2b0..8905a43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## [4.1.3] - 2024-09-08 + +* Add support for Twig 3.13 (#15) + ## [4.1.2] - 2024-08-31 * Add support for Twig 3.12 (#14) @@ -43,6 +47,7 @@ * First release of this library. +[4.1.3]: https://github.com/phpmyadmin/twig-i18n-extension/compare/4.1.2...4.1.3 [4.1.2]: https://github.com/phpmyadmin/twig-i18n-extension/compare/4.1.1...4.1.2 [4.1.1]: https://github.com/phpmyadmin/twig-i18n-extension/compare/4.1.0...4.1.1 [4.1.0]: https://github.com/phpmyadmin/twig-i18n-extension/compare/v4.0.1...4.1.0 From d74a7e3164e0c4333a2062971386ba63eb57fdb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Wed, 11 Sep 2024 16:28:30 -0300 Subject: [PATCH 5/7] Improve Twig's environment version check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maurício Meneghini Fauth --- composer.json | 2 +- src/Node/TransNode.php | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index dccb9dd..031276d 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ }, "require": { "php": "^7.2 || ^8.0", - "twig/twig": "^1.42.3|^2.0|^3.0" + "twig/twig": "^1.42.3 || ^2.0 || ^3.0" }, "require-dev": { "phpmyadmin/coding-standard": "^3.0.0", diff --git a/src/Node/TransNode.php b/src/Node/TransNode.php index 07f67ef..e3c0731 100644 --- a/src/Node/TransNode.php +++ b/src/Node/TransNode.php @@ -102,13 +102,12 @@ public function __construct( } /** @phpstan-ignore-next-line */ - if (Environment::VERSION_ID >= 31300 || Environment::VERSION_ID >= 301200) { + if (Environment::MAJOR_VERSION >= 3 && Environment::MINOR_VERSION >= 12) { parent::__construct($nodes, [], $lineno); return; } - /** @phpstan-ignore-next-line */ parent::__construct($nodes, [], $lineno, $tag); } From cea734d55627e6a26487e8140ad31c5c78696cdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Thu, 12 Sep 2024 14:32:48 -0300 Subject: [PATCH 6/7] Make echoOrYield methods static MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maurício Meneghini Fauth --- src/Node/TransNode.php | 6 +++--- test/Node/MoTranslatorTransTest.php | 18 +++++++++--------- test/Node/TransTest.php | 26 +++++++++++++------------- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/Node/TransNode.php b/src/Node/TransNode.php index e3c0731..d06d891 100644 --- a/src/Node/TransNode.php +++ b/src/Node/TransNode.php @@ -145,7 +145,7 @@ public function compile(Compiler $compiler) if ($vars) { $compiler - ->raw($this->echoOrYield() . ' strtr(' . $function . '('); + ->raw(self::echoOrYield() . ' strtr(' . $function . '('); if ($hasDomain) { [$domain] = $this->compileString($this->getNode('domain')); @@ -195,7 +195,7 @@ public function compile(Compiler $compiler) $compiler->raw("));\n"); } else { $compiler - ->raw($this->echoOrYield() . ' ' . $function . '('); + ->raw(self::echoOrYield() . ' ' . $function . '('); if ($hasDomain) { [$domain] = $this->compileString($this->getNode('domain')); @@ -326,7 +326,7 @@ protected function getTransFunction(bool $hasPlural, bool $hasContext, bool $has return $functionPrefix . ($hasContext ? 'pgettext' : 'gettext'); } - private function echoOrYield(): string + private static function echoOrYield(): string { return class_exists(YieldReady::class) ? 'yield' : 'echo'; } diff --git a/test/Node/MoTranslatorTransTest.php b/test/Node/MoTranslatorTransTest.php index 5ae0fe9..72eac84 100644 --- a/test/Node/MoTranslatorTransTest.php +++ b/test/Node/MoTranslatorTransTest.php @@ -28,7 +28,7 @@ class MoTranslatorTransTest extends NodeTestCase { - private function echoOrYield(): string + private static function echoOrYield(): string { return class_exists(YieldReady::class) ? 'yield' : 'echo'; } @@ -91,7 +91,7 @@ public function getTests(): array $node = new TransNode($body, null, null, null, null, $domain, 0); $tests[] = [ $node, - sprintf($this->echoOrYield() . ' _dgettext("coredomain", %s);', $this->getVariableGetter('foo')), + sprintf(self::echoOrYield() . ' _dgettext("coredomain", %s);', $this->getVariableGetter('foo')), ]; $body = new NameExpression('foo', 0); @@ -105,7 +105,7 @@ public function getTests(): array $tests[] = [ $node, sprintf( - $this->echoOrYield() . ' _dpgettext("coredomain", "The context", %s);', + self::echoOrYield() . ' _dpgettext("coredomain", "The context", %s);', $this->getVariableGetter('foo') ), ]; @@ -119,7 +119,7 @@ public function getTests(): array $tests[] = [ $node, sprintf( - $this->echoOrYield() . ' strtr(_gettext("J\'ai %%foo%% pommes"), array("%%foo%%" => %s, ));', + self::echoOrYield() . ' strtr(_gettext("J\'ai %%foo%% pommes"), array("%%foo%%" => %s, ));', $this->getVariableGetter('foo') ), ]; @@ -141,7 +141,7 @@ public function getTests(): array $tests[] = [ $node, sprintf( - $this->echoOrYield() . ' strtr(_ngettext("Hey %%name%%, I have one apple", "Hey %%name%%,' + self::echoOrYield() . ' strtr(_ngettext("Hey %%name%%, I have one apple", "Hey %%name%%,' . ' I have %%count%% apples", abs(12)), array("%%name%%" => %s,' . ' "%%name%%" => %s, "%%count%%" => abs(12), ));', $this->getVariableGetter('name'), @@ -161,7 +161,7 @@ public function getTests(): array $tests[] = [ $node, sprintf( - $this->echoOrYield() + self::echoOrYield() . ' strtr(_pgettext("The context", "J\'ai %%foo%% pommes"), array("%%foo%%" => %s, ));', $this->getVariableGetter('foo') ), @@ -187,7 +187,7 @@ public function getTests(): array $tests[] = [ $node, sprintf( - $this->echoOrYield() + self::echoOrYield() . ' strtr(_npgettext("The context", "Hey %%name%%, I have one apple", "Hey %%name%%,' . ' I have %%count%% apples", abs(12)), array("%%name%%" => %s,' . ' "%%name%%" => %s, "%%count%%" => abs(12), ));', @@ -211,7 +211,7 @@ public function getTests(): array $tests[] = [ $node, sprintf( - $this->echoOrYield() + self::echoOrYield() . ' strtr(_dpgettext("mydomain", "The context", "J\'ai %%foo%% pommes"), array("%%foo%%" => %s, ));', $this->getVariableGetter('foo') ), @@ -240,7 +240,7 @@ public function getTests(): array $tests[] = [ $node, sprintf( - $this->echoOrYield() + self::echoOrYield() . ' strtr(_dnpgettext("mydomain", "The context", "Hey %%name%%, I have one apple",' . ' "Hey %%name%%, I have %%count%% apples", abs(12)), array("%%name%%" => %s,' . ' "%%name%%" => %s, "%%count%%" => abs(12), ));', diff --git a/test/Node/TransTest.php b/test/Node/TransTest.php index d19aa37..396f7d5 100644 --- a/test/Node/TransTest.php +++ b/test/Node/TransTest.php @@ -29,7 +29,7 @@ class TransTest extends NodeTestCase { - private function echoOrYield(): string + private static function echoOrYield(): string { return class_exists(YieldReady::class) ? 'yield' : 'echo'; } @@ -97,7 +97,7 @@ public function testEnableDebugNotEnabled(): void $sourceCode = $compiler->compile($node)->getSource(); $this->assertSame( '// custom: Notes for translators' . "\n" - . $this->echoOrYield() . ' strtr(ngettext("There is 1 pending task",' + . self::echoOrYield() . ' strtr(ngettext("There is 1 pending task",' . ' "There are %count% pending tasks", abs(5)), array("%count%" => abs(5), ));' . "\n", $sourceCode ); @@ -126,7 +126,7 @@ public function testEnableDebugEnabled(): void $sourceCode = $compiler->compile($node)->getSource(); $this->assertSame( '// line 80' . "\n" . '// custom: Notes for translators' . "\n" - . $this->echoOrYield() . ' strtr(ngettext("There' + . self::echoOrYield() . ' strtr(ngettext("There' . ' is 1 pending task", "There are %count% pending tasks", abs(5)), array("%count%" => abs(5), ));' . "\n", $sourceCode ); @@ -149,22 +149,22 @@ public function getTests(): array $node = new TransNode($body, null, null, null, null, $domain, 0); $tests[] = [ $node, - sprintf($this->echoOrYield() . ' dgettext("coredomain", %s);', $this->getVariableGetter('foo')), + sprintf(self::echoOrYield() . ' dgettext("coredomain", %s);', $this->getVariableGetter('foo')), ]; $body = new NameExpression('foo', 0); $node = new TransNode($body, null, null, null, null, null, 0); - $tests[] = [$node, sprintf($this->echoOrYield() . ' gettext(%s);', $this->getVariableGetter('foo'))]; + $tests[] = [$node, sprintf(self::echoOrYield() . ' gettext(%s);', $this->getVariableGetter('foo'))]; $body = new ConstantExpression('Hello', 0); $node = new TransNode($body, null, null, null, null, null, 0); - $tests[] = [$node, $this->echoOrYield() . ' gettext("Hello");']; + $tests[] = [$node, self::echoOrYield() . ' gettext("Hello");']; $body = new Node([ new TextNode('Hello', 0), ], [], 0); $node = new TransNode($body, null, null, null, null, null, 0); - $tests[] = [$node, $this->echoOrYield() . ' gettext("Hello");']; + $tests[] = [$node, self::echoOrYield() . ' gettext("Hello");']; $body = new Node([ new TextNode('J\'ai ', 0), @@ -175,7 +175,7 @@ public function getTests(): array $tests[] = [ $node, sprintf( - $this->echoOrYield() . ' strtr(gettext("J\'ai %%foo%% pommes"), array("%%foo%%" => %s, ));', + self::echoOrYield() . ' strtr(gettext("J\'ai %%foo%% pommes"), array("%%foo%%" => %s, ));', $this->getVariableGetter('foo') ), ]; @@ -197,7 +197,7 @@ public function getTests(): array $tests[] = [ $node, sprintf( - $this->echoOrYield() . ' strtr(ngettext("Hey %%name%%, I have one apple", "Hey %%name%%, I have' + self::echoOrYield() . ' strtr(ngettext("Hey %%name%%, I have one apple", "Hey %%name%%, I have' . ' %%count%% apples", abs(12)), array("%%name%%" => %s,' . ' "%%name%%" => %s, "%%count%%" => abs(12), ));', $this->getVariableGetter('name'), @@ -219,7 +219,7 @@ public function getTests(): array $tests[] = [ $node, sprintf( - $this->echoOrYield() . ' strtr(gettext("J\'ai %%foo%% pommes"), array("%%foo%%" => %s, ));', + self::echoOrYield() . ' strtr(gettext("J\'ai %%foo%% pommes"), array("%%foo%%" => %s, ));', $this->getVariableGetter('foo') ), ]; @@ -228,7 +228,7 @@ public function getTests(): array $body = new ConstantExpression('Hello', 0); $notes = new TextNode('Notes for translators', 0); $node = new TransNode($body, null, null, null, $notes, null, 0); - $tests[] = [$node, "// notes: Notes for translators\n" . $this->echoOrYield() . ' gettext("Hello");']; + $tests[] = [$node, "// notes: Notes for translators\n" . self::echoOrYield() . ' gettext("Hello");']; $body = new ConstantExpression('Hello', 0); $notes = new TextNode("Notes for translators\nand line breaks", 0); @@ -236,7 +236,7 @@ public function getTests(): array $tests[] = [ $node, "// notes: Notes for translators and line breaks\n" - . $this->echoOrYield() . ' gettext("Hello");', + . self::echoOrYield() . ' gettext("Hello");', ]; $count = new ConstantExpression(5, 0); @@ -251,7 +251,7 @@ public function getTests(): array $tests[] = [ $node, '// notes: Notes for translators' . "\n" - . $this->echoOrYield() . ' strtr(ngettext("There is 1 pending task",' + . self::echoOrYield() . ' strtr(ngettext("There is 1 pending task",' . ' "There are %count% pending tasks", abs(5)), array("%count%" => abs(5), ));', ]; From 259453b1ebc99014a73279d4dea3eb723b7e2870 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Thu, 12 Sep 2024 15:08:22 -0300 Subject: [PATCH 7/7] Remove PHPUnit 7 from composer.json MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As PHP >= 7.2 is required, PHPUnit 7 is never installed. Signed-off-by: Maurício Meneghini Fauth --- .gitignore | 1 - composer.json | 2 +- phpunit.xml.dist | 26 ++++++++++++-------------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 6b80c2d..3b94c48 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,5 @@ phpunit.xml vendor/ build/ composer.lock -.phpunit.result.cache phpcs.xml .phpcs-cache diff --git a/composer.json b/composer.json index 031276d..9b2a3e8 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "phpmyadmin/coding-standard": "^3.0.0", "phpmyadmin/motranslator": "^5.2", "phpstan/phpstan": "^1.9.4", - "phpunit/phpunit": "^7 || ^8 || ^9" + "phpunit/phpunit": "^8.5 || ^9.6" }, "scripts": { "phpstan": "./vendor/bin/phpstan analyse", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 614234b..1f54f8d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,18 +1,16 @@ - - + cacheResultFile="build/.phpunit.cache/test-results" + beStrictAboutOutputDuringTests="true" + beStrictAboutTodoAnnotatedTests="true" + convertDeprecationsToExceptions="true" + colors="true" + verbose="true"> - - ./test/ + + test @@ -21,8 +19,8 @@ - - ./src/ + + src