|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace spec\Http\Client\Plugin; |
| 4 | + |
| 5 | +use Http\Client\Plugin\Plugin; |
| 6 | +use Http\Message\RequestMatcher; |
| 7 | +use Http\Promise\Promise; |
| 8 | +use Psr\Http\Message\RequestInterface; |
| 9 | +use PhpSpec\ObjectBehavior; |
| 10 | +use Prophecy\Argument; |
| 11 | + |
| 12 | +class RequestConditionalPluginSpec extends ObjectBehavior |
| 13 | +{ |
| 14 | + function let(RequestMatcher $requestMatcher, Plugin $plugin) |
| 15 | + { |
| 16 | + $this->beConstructedWith($requestMatcher, $plugin); |
| 17 | + } |
| 18 | + |
| 19 | + function it_is_initializable() |
| 20 | + { |
| 21 | + $this->shouldHaveType('Http\Client\Plugin\RequestConditionalPlugin'); |
| 22 | + } |
| 23 | + |
| 24 | + function it_is_a_plugin() |
| 25 | + { |
| 26 | + $this->shouldImplement('Http\Client\Plugin\Plugin'); |
| 27 | + } |
| 28 | + |
| 29 | + function it_matches_a_request_and_delegates_to_plugin( |
| 30 | + RequestInterface $request, |
| 31 | + RequestMatcher $requestMatcher, |
| 32 | + Plugin $plugin |
| 33 | + ) { |
| 34 | + $requestMatcher->matches($request)->willReturn(true); |
| 35 | + $plugin->handleRequest($request, Argument::type('callable'), Argument::type('callable'))->shouldBeCalled(); |
| 36 | + |
| 37 | + $this->handleRequest($request, function () {}, function () {}); |
| 38 | + } |
| 39 | + |
| 40 | + function it_does_not_match_a_request( |
| 41 | + RequestInterface $request, |
| 42 | + RequestMatcher $requestMatcher, |
| 43 | + Plugin $plugin, |
| 44 | + Promise $promise |
| 45 | + ) { |
| 46 | + $requestMatcher->matches($request)->willReturn(false); |
| 47 | + $plugin->handleRequest($request, Argument::type('callable'), Argument::type('callable'))->shouldNotBeCalled(); |
| 48 | + |
| 49 | + $next = function (RequestInterface $request) use($promise) { |
| 50 | + return $promise->getWrappedObject(); |
| 51 | + }; |
| 52 | + |
| 53 | + $this->handleRequest($request, $next, function () {})->shouldReturn($promise); |
| 54 | + } |
| 55 | +} |
0 commit comments