[Fix] Throw exception when no resolver can handle the URI in UriBasedSectionProvider

This commit is contained in:
Francis Hilaire 2026-06-01 11:09:10 +02:00
parent 5aa6e48fa3
commit 4b0b7503c5
No known key found for this signature in database
GPG key ID: 3392F830BF33D421
2 changed files with 33 additions and 1 deletions

View file

@ -44,6 +44,6 @@ final class UriBasedSectionProvider implements SectionProviderInterface
}
}
return null;
throw new SectionCannotBeResolvedException(sprintf('Section cannot be resolved for URI "%s".', $uri));
}
}

View file

@ -88,4 +88,36 @@ final class UriBasedSectionProviderTest extends TestCase
$this->requestStack->expects($this->once())->method('getMainRequest')->willReturn(null);
$this->assertNull($this->uriBasedSectionProvider->getSection());
}
public function testThrowsExceptionIfNoResolverCanHandleTheUri(): void
{
$request = $this->createMock(Request::class);
$this->requestStack
->expects($this->once())
->method('getMainRequest')
->willReturn($request);
$request
->expects($this->once())
->method('getPathInfo')
->willReturn('/unknown-section');
$this->firstSectionResolver
->expects($this->once())
->method('getSection')
->with('/unknown-section')
->willThrowException(new SectionCannotBeResolvedException())
;
$this->secondSectionResolver
->expects($this->once())
->method('getSection')
->with('/unknown-section')
->willThrowException(new SectionCannotBeResolvedException())
;
$this->expectException(SectionCannotBeResolvedException::class);
$this->uriBasedSectionProvider->getSection();
}
}