From 5b8d701f1ae1f3804776259d5753ce022cde2d56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Andr=C3=A9?= Date: Wed, 30 Jul 2025 00:20:11 +0200 Subject: [PATCH] [LiveComponent] Fix LiveUrlSubscriber throw `MethodNotAllowed` --- src/LiveComponent/src/Util/UrlFactory.php | 3 ++- .../tests/Unit/Util/UrlFactoryTest.php | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/LiveComponent/src/Util/UrlFactory.php b/src/LiveComponent/src/Util/UrlFactory.php index f082394eaa9..da25ecf9763 100644 --- a/src/LiveComponent/src/Util/UrlFactory.php +++ b/src/LiveComponent/src/Util/UrlFactory.php @@ -11,6 +11,7 @@ namespace Symfony\UX\LiveComponent\Util; +use Symfony\Component\Routing\Exception\MethodNotAllowedException; use Symfony\Component\Routing\Exception\MissingMandatoryParametersException; use Symfony\Component\Routing\Exception\ResourceNotFoundException; use Symfony\Component\Routing\RouterInterface; @@ -43,7 +44,7 @@ public function createFromPreviousAndProps( try { $newUrl = $this->createPath($previousUrl, $pathMappedProps); - } catch (ResourceNotFoundException|MissingMandatoryParametersException) { + } catch (ResourceNotFoundException|MethodNotAllowedException|MissingMandatoryParametersException) { return null; } diff --git a/src/LiveComponent/tests/Unit/Util/UrlFactoryTest.php b/src/LiveComponent/tests/Unit/Util/UrlFactoryTest.php index 653e2072dd5..07fe93ee400 100644 --- a/src/LiveComponent/tests/Unit/Util/UrlFactoryTest.php +++ b/src/LiveComponent/tests/Unit/Util/UrlFactoryTest.php @@ -12,6 +12,7 @@ namespace Symfony\UX\LiveComponent\Tests\Unit\Util; use PHPUnit\Framework\TestCase; +use Symfony\Component\Routing\Exception\MethodNotAllowedException; use Symfony\Component\Routing\Exception\MissingMandatoryParametersException; use Symfony\Component\Routing\Exception\ResourceNotFoundException; use Symfony\Component\Routing\RouterInterface; @@ -140,6 +141,19 @@ public function testResourceNotFoundException() $this->assertNull($factory->createFromPreviousAndProps($previousUrl, [], [])); } + public function testMethodNotAllowedException() + { + $previousUrl = '/foo/bar'; + $router = $this->createMock(RouterInterface::class); + $router->expects(self::once()) + ->method('match') + ->with($previousUrl) + ->willThrowException(new MethodNotAllowedException(['GET'])); + $factory = new UrlFactory($router); + + $this->assertNull($factory->createFromPreviousAndProps($previousUrl, [], [])); + } + public function testMissingMandatoryParametersException() { $previousUrl = '/foo/bar';