diff --git a/src/Mercure/Service/UrlService.php b/src/Mercure/Service/UrlService.php index 70e424099..22f83f46f 100644 --- a/src/Mercure/Service/UrlService.php +++ b/src/Mercure/Service/UrlService.php @@ -32,7 +32,7 @@ public function __construct( public function getServerSideUrl(): string { if (empty($this->serverSideUrl)) { - return $this->getDefaultServerUrl(); + throw new LogicException('Mercure server URL is not configured.'); } return $this->serverSideUrl; @@ -47,10 +47,6 @@ public function getClientSideUrl(): string return str_replace(Mercure::HOST_PLACEHOLDER->value, $this->getHostUrl(), $this->clientSideUrl); } - private function getDefaultServerUrl(): string - { - return $this->getHostUrl() . '/hub/.well-known/mercure'; - } private function getDefaultClientUrl(): string { diff --git a/tests/Unit/Mercure/Service/UrlServiceTest.php b/tests/Unit/Mercure/Service/UrlServiceTest.php index 39031572a..aa564f515 100644 --- a/tests/Unit/Mercure/Service/UrlServiceTest.php +++ b/tests/Unit/Mercure/Service/UrlServiceTest.php @@ -28,15 +28,13 @@ public function testGetServerSideUrlWithCustomUrl(): void $this->assertSame('https://custom/mercure', $service->getServerSideUrl()); } - public function testGetServerSideUrlWithDefault(): void + public function testGetServerSideUrlThrowsWhenNotConfigured(): void { - $service = new UrlService( - null, - null, - $this->createRequestStackWithRequest('https://example.com') - ); + $service = new UrlService(null, null, new RequestStack()); - $this->assertSame('https://example.com/hub/.well-known/mercure', $service->getServerSideUrl()); + $this->expectException(LogicException::class); + $this->expectExceptionMessage('Mercure server URL is not configured.'); + $service->getServerSideUrl(); } public function testGetClientSideUrlWithCustomUrlReplacesPlaceholder(): void @@ -66,10 +64,11 @@ public function testThrowsLogicExceptionWithoutRequest(): void $service = new UrlService(null, null, new RequestStack()); $this->expectException(LogicException::class); - $service->getServerSideUrl(); + $this->expectExceptionMessage('Mercure fallback URL resolution requires an active HTTP request.'); + $service->getClientSideUrl(); } - public function testDefaultUrlIncludesNonStandardPort(): void + public function testDefaultClientUrlIncludesNonStandardPort(): void { $service = new UrlService( null, @@ -77,7 +76,7 @@ public function testDefaultUrlIncludesNonStandardPort(): void $this->createRequestStackWithRequest('http://localhost:8080') ); - $this->assertSame('http://localhost:8080/hub/.well-known/mercure', $service->getServerSideUrl()); + $this->assertSame('http://localhost:8080/hub', $service->getClientSideUrl()); } private function createRequestStackWithRequest(string $uri): RequestStack