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