Repository: symfony/ux
Pull request #1436 (2024-01-31 12:19:06)

[Twig][Live] Drop Twig 2 support
As Symfony Twig Bridge / Twig Bundle have already dropped Twig 2 support... i think it's time for us to do the same thing :)

* TwigBundle:  https://github.com/symfony/twig-bundle/commit/bca6a836fdd2edad7c15278b2f11f3c7f204d395
* TwigBridge: https://github.com/symfony/twig-bridge/commit/34e9d77f152a8035cfafb27756930d898595b0c8

smnandre: Failure / deprecation look related to Foundry no ? cc @kbond  maybe ? 
smnandre: To Browser sorry i think ? cf the deprecations 

https://github.com/symfony/ux/actions/runs/7725916788/job/21061159963#step:7:147

And _resetDatabase too ? But i'm really not sure there
kbond: I'm seeing this:
- https://github.com/symfony/ux/actions/runs/7725916788/job/21061159963#step:7:103 - direct deprecation caused by Twig\Node\Node::count()
- https://github.com/symfony/ux/actions/runs/7725916788/job/21061161859#step:7:100 - wrong twig exception being expected
smnandre: Was talking about the deprecation in the other test suite ;) 

_resetDatabase and the others are generated inside Browser i believe.

I'll look at the errors tomorrow ! 
weaverryan: Sure! What do you mean by counting twig nodes?
smnandre: LiveComponent 8.1 fails because of direct deprecation

see: https://github.com/symfony/ux/actions/runs/7770236144/job/21190171213?pr=1436 

```
OK (220 tests, 708 assertions)

Remaining direct deprecation notices (1)

  1x: Return type of Twig\Node\Node::count() should either be compatible with Countable::count(): int, 
or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

    1x in BatchActionControllerTest::testCanBatchActions from Symfony\UX\LiveComponent\Tests\Functional\Controller
```



Patch:
diff --git a/src/LiveComponent/composer.json b/src/LiveComponent/composer.json
index 83b9f2af..77e5ef7f 100644
--- a/src/LiveComponent/composer.json
+++ b/src/LiveComponent/composer.json
@@ -29,7 +29,7 @@
         "php": ">=8.1",
         "symfony/property-access": "^5.4.5|^6.0|^7.0",
         "symfony/ux-twig-component": "^2.8",
-        "twig/twig": "^2.14.7|~3.8.0"
+        "twig/twig": "~3.8.0"
     },
     "require-dev": {
         "doctrine/annotations": "^1.0",
diff --git a/src/TwigComponent/composer.json b/src/TwigComponent/composer.json
index 090ffe23..766b8a60 100644
--- a/src/TwigComponent/composer.json
+++ b/src/TwigComponent/composer.json
@@ -31,7 +31,7 @@
         "symfony/deprecation-contracts": "^2.2|^3.0",
         "symfony/event-dispatcher": "^5.4|^6.0|^7.0",
         "symfony/property-access": "^5.4|^6.0|^7.0",
-        "twig/twig": "^2.14.7|~3.8.0"
+        "twig/twig": "~3.8.0"
     },
     "require-dev": {
         "symfony/console": "^5.4|^6.0|^7.0",
diff --git a/src/TwigComponent/src/ComponentRenderer.php b/src/TwigComponent/src/ComponentRenderer.php
index d45e95c6..48fdedca 100644
--- a/src/TwigComponent/src/ComponentRenderer.php
+++ b/src/TwigComponent/src/ComponentRenderer.php
@@ -72,10 +72,6 @@ final class ComponentRenderer implements ComponentRendererInterface
         }
 
         try {
-            if ($this->twig::MAJOR_VERSION < 3) {
-                return $this->twig->loadTemplate($event->getTemplate(), $event->getTemplateIndex())->render($variables);
-            }
-
             return $this->twig->loadTemplate(
                 $this->twig->getTemplateClass($event->getTemplate()),
                 $event->getTemplate(),


Test patch:
diff --git a/src/TwigComponent/tests/Integration/ComponentExtensionTest.php b/src/TwigComponent/tests/Integration/ComponentExtensionTest.php
index ee09fca9..ff891610 100644
--- a/src/TwigComponent/tests/Integration/ComponentExtensionTest.php
+++ b/src/TwigComponent/tests/Integration/ComponentExtensionTest.php
@@ -63,11 +63,7 @@ final class ComponentExtensionTest extends KernelTestCase
 
     public function testCanNotRenderComponentWithInvalidExpressions(): void
     {
-        if (Environment::MAJOR_VERSION === 2) {
-            $this->expectException(\TypeError::class);
-        } else {
-            $this->expectException(RuntimeError::class);
-        }
+        $this->expectException(\Throwable::class);
 
         self::getContainer()->get(Environment::class)->render('invalid_flexible_component.html.twig');
     }