|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace spec\Http\Client\Plugin; |
| 4 | + |
| 5 | +use Http\Message\StreamFactory; |
| 6 | +use Http\Message\UriFactory; |
| 7 | +use Http\Promise\FulfilledPromise; |
| 8 | +use Psr\Http\Message\RequestInterface; |
| 9 | +use Psr\Http\Message\ResponseInterface; |
| 10 | +use Psr\Http\Message\StreamInterface; |
| 11 | +use Psr\Http\Message\UriInterface; |
| 12 | +use PhpSpec\ObjectBehavior; |
| 13 | +use Prophecy\Argument; |
| 14 | + |
| 15 | +class AddHostPluginSpec extends ObjectBehavior |
| 16 | +{ |
| 17 | + function let(UriInterface $uri) |
| 18 | + { |
| 19 | + $this->beConstructedWith($uri); |
| 20 | + } |
| 21 | + |
| 22 | + function it_is_initializable() |
| 23 | + { |
| 24 | + $this->shouldHaveType('Http\Client\Plugin\AddHostPlugin'); |
| 25 | + } |
| 26 | + |
| 27 | + function it_is_a_plugin() |
| 28 | + { |
| 29 | + $this->shouldImplement('Http\Client\Plugin\Plugin'); |
| 30 | + } |
| 31 | + |
| 32 | + function it_adds_domain( |
| 33 | + RequestInterface $request, |
| 34 | + UriInterface $baseUri, |
| 35 | + UriInterface $uri |
| 36 | + ) { |
| 37 | + $baseUri->getScheme()->shouldBeCalled()->willReturn('http://'); |
| 38 | + $baseUri->getHost()->shouldBeCalled()->willReturn('example.com'); |
| 39 | + |
| 40 | + $request->getUri()->shouldBeCalled()->willReturn($uri); |
| 41 | + $request->withUri($uri)->shouldBeCalled()->willReturn($request); |
| 42 | + |
| 43 | + $uri->withScheme('http://')->shouldBeCalled()->willReturn($uri); |
| 44 | + $uri->withHost('example.com')->shouldBeCalled()->willReturn($uri); |
| 45 | + $uri->getHost()->shouldBeCalled()->willReturn(''); |
| 46 | + |
| 47 | + $this->beConstructedWith($baseUri); |
| 48 | + $this->handleRequest($request, function () {}, function () {}); |
| 49 | + } |
| 50 | + |
| 51 | + function it_replaces_domain( |
| 52 | + RequestInterface $request, |
| 53 | + UriInterface $baseUri, |
| 54 | + UriInterface $uri |
| 55 | + ) { |
| 56 | + $baseUri->getScheme()->shouldBeCalled()->willReturn('http://'); |
| 57 | + $baseUri->getHost()->shouldBeCalled()->willReturn('example.com'); |
| 58 | + |
| 59 | + $request->getUri()->shouldBeCalled()->willReturn($uri); |
| 60 | + $request->withUri($uri)->shouldBeCalled()->willReturn($request); |
| 61 | + |
| 62 | + $uri->withScheme('http://')->shouldBeCalled()->willReturn($uri); |
| 63 | + $uri->withHost('example.com')->shouldBeCalled()->willReturn($uri); |
| 64 | + |
| 65 | + |
| 66 | + $this->beConstructedWith($baseUri, ['replace'=>true]); |
| 67 | + $this->handleRequest($request, function () {}, function () {}); |
| 68 | + } |
| 69 | + |
| 70 | + function it_does_nothing_when_domain_exists( |
| 71 | + RequestInterface $request, |
| 72 | + UriInterface $baseUri, |
| 73 | + UriInterface $uri |
| 74 | + ) { |
| 75 | + $request->getUri()->shouldBeCalled()->willReturn($uri); |
| 76 | + $uri->getHost()->shouldBeCalled()->willReturn('default.com'); |
| 77 | + |
| 78 | + $this->beConstructedWith($baseUri); |
| 79 | + $this->handleRequest($request, function () {}, function () {}); |
| 80 | + } |
| 81 | +} |
0 commit comments