spec/Plugin/RedirectPluginSpec.php
public function it_throws_circular_redirection_exception_on_redirect_that_does_not_change_url(
        UriInterface $redirectUri,
        RequestInterface $request,
        ResponseInterface $redirectResponse
    ) {
        $redirectResponse->getStatusCode()->willReturn(302);
        $redirectResponse->hasHeader('Location')->willReturn(true);
        $redirectResponse->getHeaderLine('Location')->willReturn('/redirect');

        $next = function () use ($redirectResponse): Promise {
            return new HttpFulfilledPromise($redirectResponse->getWrappedObject());
        };

        $first = function () {
            throw new \Exception('First should never be called');
        };

        $request->getUri()->willReturn($redirectUri);
        $redirectUri->__toString()->willReturn('/redirect');

        $redirectUri->withPath('/redirect')->willReturn($redirectUri);
        $redirectUri->withFragment('')->willReturn($redirectUri);
        $redirectUri->withQuery('')->willReturn($redirectUri);

        $request->withUri($redirectUri)->willReturn($request);
        $redirectUri->__toString()->willReturn('/redirect');
        $request->getMethod()->willReturn('GET');

        $promise = $this->handleRequest($request, $next, $first);
        $promise->shouldReturnAnInstanceOf(HttpRejectedPromise::class);
        $promise->shouldThrow(CircularRedirectionException::class)->duringWait();
    }
public function it_throws_circular_redirection_exception_on_redirect_that_does_not_change_url(
        UriInterface $redirectUri,
        RequestInterface $request,
        ResponseInterface $redirectResponse
    ) {
        $redirectResponse->getStatusCode()->willReturn(302);
        $redirectResponse->hasHeader('Location')->willReturn(true);
        $redirectResponse->getHeaderLine('Location')->willReturn('/redirect');

        $next = function () use ($redirectResponse): Promise {
            return new HttpFulfilledPromise($redirectResponse->getWrappedObject());
        };

        $first = function () {
            throw new \Exception('First should never be called');
        };

        $request->getUri()->willReturn($redirectUri);
        $redirectUri->__toString()->willReturn('/redirect');

        $redirectUri->withPath('/redirect')->willReturn($redirectUri);
        $redirectUri->withFragment('')->willReturn($redirectUri);
        $redirectUri->withQuery('')->willReturn($redirectUri);

        $request->withUri($redirectUri)->willReturn($request);
        $redirectUri->__toString()->willReturn('/redirect');
        $request->getMethod()->willReturn('GET');

        $promise = $this->handleRequest($request, $next, $first);
        $promise->shouldReturnAnInstanceOf(HttpRejectedPromise::class);
        $promise->shouldThrow(CircularRedirectionException::class)->duringWait();
    }
public function it_throws_circular_redirection_exception_on_redirect_that_does_not_change_url ( UriInterface $ redirectUri , RequestInterface $ request , ResponseInterface $ redirectResponse ) { $ redirectResponse -> getStatusCode ( ) -> willReturn ( 302 ) ; $ redirectResponse -> hasHeader ( 'Location' ) -> willReturn ( true ) ; $ redirectResponse -> getHeaderLine ( 'Location' ) -> willReturn ( '/redirect' ) ; $ next = function ( ) use ( $ redirectResponse ) : Promise { return new HttpFulfilledPromise ( $ redirectResponse -> getWrappedObject ( ) ) ; } ; $ first = function ( ) { throw new \ Exception ( 'First should never be called' ) ; } ; $ request -> getUri ( ) -> willReturn ( $ redirectUri ) ; $ redirectUri -> __toString ( ) -> willReturn ( '/redirect' ) ; $ redirectUri -> withPath ( '/redirect' ) -> willReturn ( $ redirectUri ) ; $ redirectUri -> withFragment ( '' ) -> willReturn ( $ redirectUri ) ; $ redirectUri -> withQuery ( '' ) -> willReturn ( $ redirectUri ) ; $ request -> withUri ( $ redirectUri ) -> willReturn ( $ request ) ; $ redirectUri -> __toString ( ) -> willReturn ( '/redirect' ) ; $ request -> getMethod ( ) -> willReturn ( 'GET' ) ; $ promise = $ this -> handleRequest ( $ request , $ next , $ first ) ; $ promise -> shouldReturnAnInstanceOf ( HttpRejectedPromise :: class ) ; $ promise -> shouldThrow ( CircularRedirectionException :: class ) -> duringWait ( ) ; }
This is the "redirection does not redirect case.
This is the redirection does not redirect case .