setRedirector($this->getRedirectorForPreviousUrl('http://localhost/foo')); $this->assertEquals('http://localhost/foo#bar', $requestWithHash->getRedirectUrl()); } /** * Tests whether redirect URLs still get generated correctly when a redirect * hash isn't configured on the FormRequest class. * * @return void */ public function testRedirectWithoutHash(): void { $requestWithoutHash = new RequestDummyWithoutHash(); $requestWithoutHash->setRedirector($this->getRedirectorForPreviousUrl('http://localhost/foo')); $this->assertEquals('http://localhost/foo', $requestWithoutHash->getRedirectUrl()); } /** * Returns a Redirector whose UrlGenerator returns the passed URL when asked * for the previous URL. * * @param string $url The URL which should be returned. * * @return Redirector */ protected function getRedirectorForPreviousUrl(string $url): Redirector { $urlGenerator = $this->getMockBuilder(UrlGenerator::class) ->disableOriginalConstructor() ->setMethods(['previous']) ->getMock() ; $urlGenerator ->expects($this->any()) ->method('previous') ->willReturn($url) ; $redirector = $this->getMockBuilder(Redirector::class) ->disableOriginalConstructor() ->setMethods(['getUrlGenerator']) ->getMock() ; $redirector ->expects($this->any()) ->method('getUrlGenerator') ->willReturn($urlGenerator) ; return $redirector; } }