Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/Mercure/Service/UrlService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand Down
19 changes: 9 additions & 10 deletions tests/Unit/Mercure/Service/UrlServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -66,18 +64,19 @@ 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,
null,
$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
Expand Down
Loading