From c14c696e7e89378027ac96d32d006ed134d6ab5e Mon Sep 17 00:00:00 2001 From: Mateusz Zalewski Date: Fri, 17 Oct 2025 12:31:55 +0200 Subject: [PATCH] [Icons] Do not fail application if there is not internet connection --- src/Icons/src/Twig/UXIconRuntime.php | 5 +++++ src/Icons/tests/Unit/Twig/UXIconRuntimeTest.php | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/Icons/src/Twig/UXIconRuntime.php b/src/Icons/src/Twig/UXIconRuntime.php index edaffd8bf5b..0a84d810653 100644 --- a/src/Icons/src/Twig/UXIconRuntime.php +++ b/src/Icons/src/Twig/UXIconRuntime.php @@ -12,6 +12,7 @@ namespace Symfony\UX\Icons\Twig; use Psr\Log\LoggerInterface; +use Symfony\Component\HttpClient\Exception\TransportException; use Symfony\UX\Icons\Exception\IconNotFoundException; use Symfony\UX\Icons\IconRendererInterface; use Twig\Extension\RuntimeExtensionInterface; @@ -45,6 +46,10 @@ public function renderIcon(string $name, array $attributes = []): string } throw $e; + } catch (TransportException $e) { + $this->logger?->warning($e->getMessage()); + + return ''; } } diff --git a/src/Icons/tests/Unit/Twig/UXIconRuntimeTest.php b/src/Icons/tests/Unit/Twig/UXIconRuntimeTest.php index dd82853d3a4..3183ee066cf 100644 --- a/src/Icons/tests/Unit/Twig/UXIconRuntimeTest.php +++ b/src/Icons/tests/Unit/Twig/UXIconRuntimeTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; +use Symfony\Component\HttpClient\Exception\TransportException; use Symfony\UX\Icons\Exception\IconNotFoundException; use Symfony\UX\Icons\IconRendererInterface; use Symfony\UX\Icons\Twig\UXIconRuntime; @@ -40,4 +41,19 @@ public function testRenderIconIgnoreNotFound() $this->expectException(IconNotFoundException::class); $runtime->renderIcon('not_found'); } + + public function testRenderIconReturnsEmptyStringIfConnectionIsNotPossible() + { + $renderer = $this->createMock(IconRendererInterface::class); + $renderer->method('renderIcon') + ->willThrowException(new TransportException('Could not resolve host api.iconify.design')); + + $logger = $this->createMock(LoggerInterface::class); + $logger->expects($this->once()) + ->method('warning') + ->with('Could not resolve host api.iconify.design'); + + $runtime = new UXIconRuntime($renderer, true, $logger); + $this->assertEquals('', $runtime->renderIcon('tabler:search')); + } }