|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace spec\Http\Message\Authentication; |
| 4 | + |
| 5 | +use Http\Message\Authentication; |
| 6 | +use Psr\Http\Message\RequestInterface; |
| 7 | +use PhpSpec\ObjectBehavior; |
| 8 | + |
| 9 | +class ChainSpec extends ObjectBehavior |
| 10 | +{ |
| 11 | + use AuthenticationBehavior; |
| 12 | + |
| 13 | + function it_is_initializable() |
| 14 | + { |
| 15 | + $this->shouldHaveType('Http\Message\Authentication\Chain'); |
| 16 | + } |
| 17 | + |
| 18 | + function it_accepts_an_authentication_chain_in_the_constructor(Authentication $auth1, Authentication $auth2) |
| 19 | + { |
| 20 | + $chain = [$auth1, $auth2]; |
| 21 | + |
| 22 | + $this->beConstructedWith($chain); |
| 23 | + |
| 24 | + $this->getAuthenticationChain()->shouldReturn($chain); |
| 25 | + } |
| 26 | + |
| 27 | + function it_sets_the_authentication_chain(Authentication $auth1, Authentication $auth2) |
| 28 | + { |
| 29 | + // This SHOULD be replaced |
| 30 | + $this->beConstructedWith([$auth1]); |
| 31 | + |
| 32 | + $this->setAuthenticationChain([$auth2]); |
| 33 | + |
| 34 | + $this->getAuthenticationChain()->shouldReturn([$auth2]); |
| 35 | + } |
| 36 | + |
| 37 | + function it_adds_an_authentication_method(Authentication $auth1, Authentication $auth2) |
| 38 | + { |
| 39 | + // This SHOULD NOT be replaced |
| 40 | + $this->beConstructedWith([$auth1]); |
| 41 | + |
| 42 | + $this->addAuthentication($auth2); |
| 43 | + |
| 44 | + $this->getAuthenticationChain()->shouldReturn([$auth1, $auth2]); |
| 45 | + } |
| 46 | + |
| 47 | + function it_clears_the_authentication_chain(Authentication $auth1, Authentication $auth2) |
| 48 | + { |
| 49 | + // This SHOULD be replaced |
| 50 | + $this->beConstructedWith([$auth1]); |
| 51 | + |
| 52 | + $this->clearAuthenticationChain(); |
| 53 | + |
| 54 | + $this->addAuthentication($auth2); |
| 55 | + |
| 56 | + $this->getAuthenticationChain()->shouldReturn([$auth2]); |
| 57 | + } |
| 58 | + |
| 59 | + function it_authenticates_a_request( |
| 60 | + Authentication $auth1, |
| 61 | + Authentication $auth2, |
| 62 | + RequestInterface $originalRequest, |
| 63 | + RequestInterface $request1, |
| 64 | + RequestInterface $request2 |
| 65 | + ) { |
| 66 | + $originalRequest->withHeader('AuthMethod1', 'AuthValue')->willReturn($request1); |
| 67 | + $request1->withHeader('AuthMethod2', 'AuthValue')->willReturn($request2); |
| 68 | + |
| 69 | + $auth1->authenticate($originalRequest)->will(function ($args) { |
| 70 | + return $args[0]->withHeader('AuthMethod1', 'AuthValue'); |
| 71 | + }); |
| 72 | + |
| 73 | + $auth2->authenticate($request1)->will(function ($args) { |
| 74 | + return $args[0]->withHeader('AuthMethod2', 'AuthValue'); |
| 75 | + }); |
| 76 | + |
| 77 | + $this->beConstructedWith([$auth1, $auth2]); |
| 78 | + |
| 79 | + $this->authenticate($originalRequest)->shouldReturn($request2); |
| 80 | + } |
| 81 | +} |
0 commit comments