Skip to content

Commit 5b8d701

Browse files
smnandrekbond
authored andcommitted
[LiveComponent] Fix LiveUrlSubscriber throw MethodNotAllowed
1 parent 1f90d60 commit 5b8d701

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/LiveComponent/src/Util/UrlFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\UX\LiveComponent\Util;
1313

14+
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
1415
use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;
1516
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
1617
use Symfony\Component\Routing\RouterInterface;
@@ -43,7 +44,7 @@ public function createFromPreviousAndProps(
4344

4445
try {
4546
$newUrl = $this->createPath($previousUrl, $pathMappedProps);
46-
} catch (ResourceNotFoundException|MissingMandatoryParametersException) {
47+
} catch (ResourceNotFoundException|MethodNotAllowedException|MissingMandatoryParametersException) {
4748
return null;
4849
}
4950

src/LiveComponent/tests/Unit/Util/UrlFactoryTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\UX\LiveComponent\Tests\Unit\Util;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
1516
use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;
1617
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
1718
use Symfony\Component\Routing\RouterInterface;
@@ -140,6 +141,19 @@ public function testResourceNotFoundException()
140141
$this->assertNull($factory->createFromPreviousAndProps($previousUrl, [], []));
141142
}
142143

144+
public function testMethodNotAllowedException()
145+
{
146+
$previousUrl = '/foo/bar';
147+
$router = $this->createMock(RouterInterface::class);
148+
$router->expects(self::once())
149+
->method('match')
150+
->with($previousUrl)
151+
->willThrowException(new MethodNotAllowedException(['GET']));
152+
$factory = new UrlFactory($router);
153+
154+
$this->assertNull($factory->createFromPreviousAndProps($previousUrl, [], []));
155+
}
156+
143157
public function testMissingMandatoryParametersException()
144158
{
145159
$previousUrl = '/foo/bar';

0 commit comments

Comments
 (0)