|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace spec\Http\Message\RequestMatcher; |
| 4 | + |
| 5 | +use Http\Message\RequestMatcher; |
| 6 | +use Psr\Http\Message\RequestInterface; |
| 7 | +use Psr\Http\Message\UriInterface; |
| 8 | +use PhpSpec\ObjectBehavior; |
| 9 | + |
| 10 | +class RequestMatcherSpec extends ObjectBehavior |
| 11 | +{ |
| 12 | + function it_is_initializable() |
| 13 | + { |
| 14 | + $this->shouldHaveType('Http\Message\RequestMatcher\RequestMatcher'); |
| 15 | + } |
| 16 | + |
| 17 | + function it_is_a_request_matcher() |
| 18 | + { |
| 19 | + $this->shouldImplement('Http\Message\RequestMatcher'); |
| 20 | + } |
| 21 | + |
| 22 | + function it_matches_a_path(RequestInterface $request, UriInterface $uri) |
| 23 | + { |
| 24 | + $this->beConstructedWith('^/tes?'); |
| 25 | + |
| 26 | + $request->getUri()->willReturn($uri); |
| 27 | + $uri->getPath()->willReturn('/test/foo'); |
| 28 | + |
| 29 | + $this->matches($request)->shouldReturn(true); |
| 30 | + } |
| 31 | + |
| 32 | + function it_does_not_match_a_path(RequestInterface $request, UriInterface $uri) |
| 33 | + { |
| 34 | + $this->beConstructedWith('#^/tes?#'); |
| 35 | + |
| 36 | + $request->getUri()->willReturn($uri); |
| 37 | + $uri->getPath()->willReturn('/ttttt'); |
| 38 | + |
| 39 | + $this->matches($request)->shouldReturn(false); |
| 40 | + } |
| 41 | + |
| 42 | + |
| 43 | + function it_matches_a_host(RequestInterface $request, UriInterface $uri) |
| 44 | + { |
| 45 | + $this->beConstructedWith(null, 'php-htt?'); |
| 46 | + |
| 47 | + $request->getUri()->willReturn($uri); |
| 48 | + $uri->getHost()->willReturn('php-http.org'); |
| 49 | + |
| 50 | + $this->matches($request)->shouldReturn(true); |
| 51 | + } |
| 52 | + |
| 53 | + function it_does_not_match_a_host(RequestInterface $request, UriInterface $uri) |
| 54 | + { |
| 55 | + $this->beConstructedWith(null, 'php-htt?'); |
| 56 | + |
| 57 | + $request->getUri()->willReturn($uri); |
| 58 | + $uri->getHost()->willReturn('httplug.io'); |
| 59 | + |
| 60 | + $this->matches($request)->shouldReturn(false); |
| 61 | + } |
| 62 | + |
| 63 | + function it_matches_a_method(RequestInterface $request) |
| 64 | + { |
| 65 | + $this->beConstructedWith(null, null, 'get'); |
| 66 | + |
| 67 | + $request->getMethod()->willReturn('GET'); |
| 68 | + |
| 69 | + $this->matches($request)->shouldReturn(true); |
| 70 | + } |
| 71 | + |
| 72 | + function it_does_not_match_a_method(RequestInterface $request) |
| 73 | + { |
| 74 | + $this->beConstructedWith(null, null, 'get'); |
| 75 | + |
| 76 | + $request->getMethod()->willReturn('post'); |
| 77 | + |
| 78 | + $this->matches($request)->shouldReturn(false); |
| 79 | + } |
| 80 | + |
| 81 | + |
| 82 | + function it_matches_a_scheme(RequestInterface $request, UriInterface $uri) |
| 83 | + { |
| 84 | + $this->beConstructedWith(null, null, null, 'http'); |
| 85 | + |
| 86 | + $request->getUri()->willReturn($uri); |
| 87 | + $uri->getScheme()->willReturn('http'); |
| 88 | + |
| 89 | + $this->matches($request)->shouldReturn(true); |
| 90 | + } |
| 91 | + |
| 92 | + function it_does_not_match_a_scheme(RequestInterface $request, UriInterface $uri) |
| 93 | + { |
| 94 | + $this->beConstructedWith(null, null, null, 'http'); |
| 95 | + |
| 96 | + $request->getUri()->willReturn($uri); |
| 97 | + $uri->getScheme()->willReturn('https'); |
| 98 | + |
| 99 | + $this->matches($request)->shouldReturn(false); |
| 100 | + } |
| 101 | +} |
0 commit comments