diff --git a/src/Sylius/Bundle/CoreBundle/SectionResolver/UriBasedSectionProvider.php b/src/Sylius/Bundle/CoreBundle/SectionResolver/UriBasedSectionProvider.php index a91f339221..2dfd41fd73 100644 --- a/src/Sylius/Bundle/CoreBundle/SectionResolver/UriBasedSectionProvider.php +++ b/src/Sylius/Bundle/CoreBundle/SectionResolver/UriBasedSectionProvider.php @@ -44,6 +44,6 @@ final class UriBasedSectionProvider implements SectionProviderInterface } } - return null; + throw new SectionCannotBeResolvedException(sprintf('Section cannot be resolved for URI "%s".', $uri)); } } diff --git a/src/Sylius/Bundle/CoreBundle/tests/SectionResolver/UriBasedSectionProviderTest.php b/src/Sylius/Bundle/CoreBundle/tests/SectionResolver/UriBasedSectionProviderTest.php index 6037a8effe..bec895d3e5 100644 --- a/src/Sylius/Bundle/CoreBundle/tests/SectionResolver/UriBasedSectionProviderTest.php +++ b/src/Sylius/Bundle/CoreBundle/tests/SectionResolver/UriBasedSectionProviderTest.php @@ -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(); + } }