2
2
3
3
namespace spec \Xabbuh \XApi \Client \Request ;
4
4
5
- use Http \Client \HttpClient ;
6
5
use Http \Message \RequestFactory ;
7
6
use PhpSpec \ObjectBehavior ;
7
+ use Psr \Http \Client \ClientInterface ;
8
+ use Psr \Http \Message \RequestFactoryInterface ;
8
9
use Psr \Http \Message \RequestInterface ;
9
10
use Psr \Http \Message \ResponseInterface ;
10
11
use Xabbuh \XApi \Common \Exception \AccessDeniedException ;
14
15
15
16
class HandlerSpec extends ObjectBehavior
16
17
{
17
- function let (HttpClient $ client , RequestFactory $ requestFactory )
18
+ function let (ClientInterface $ client , RequestFactoryInterface $ requestFactory )
18
19
{
19
20
$ this ->beConstructedWith ($ client , $ requestFactory , 'http://example.com/xapi/ ' , '1.0.1 ' );
20
21
}
@@ -24,8 +25,10 @@ function it_throws_an_exception_if_a_request_is_created_with_an_invalid_method()
24
25
$ this ->shouldThrow ('\InvalidArgumentException ' )->during ('createRequest ' , array ('options ' , '/xapi/statements ' ));
25
26
}
26
27
27
- function it_returns_get_request_created_by_the_http_client (RequestFactory $ requestFactory , RequestInterface $ request )
28
- {
28
+ function it_returns_get_request_created_by_the_http_client (
29
+ RequestFactoryInterface $ requestFactory ,
30
+ RequestInterface $ request
31
+ ) {
29
32
$ requestFactory ->createRequest ('GET ' , 'http://example.com/xapi/statements ' , array (
30
33
'X-Experience-API-Version ' => '1.0.1 ' ,
31
34
'Content-Type ' => 'application/json ' ,
@@ -35,8 +38,10 @@ function it_returns_get_request_created_by_the_http_client(RequestFactory $reque
35
38
$ this ->createRequest ('GET ' , '/statements ' )->shouldReturn ($ request );
36
39
}
37
40
38
- function it_returns_post_request_created_by_the_http_client (RequestFactory $ requestFactory , RequestInterface $ request )
39
- {
41
+ function it_returns_post_request_created_by_the_http_client (
42
+ RequestFactoryInterface $ requestFactory ,
43
+ RequestInterface $ request
44
+ ) {
40
45
$ requestFactory ->createRequest ('POST ' , 'http://example.com/xapi/statements ' , array (
41
46
'X-Experience-API-Version ' => '1.0.1 ' ,
42
47
'Content-Type ' => 'application/json ' ,
@@ -46,8 +51,10 @@ function it_returns_post_request_created_by_the_http_client(RequestFactory $requ
46
51
$ this ->createRequest ('POST ' , '/statements ' , array (), 'body ' )->shouldReturn ($ request );
47
52
}
48
53
49
- function it_returns_put_request_created_by_the_http_client (RequestFactory $ requestFactory , RequestInterface $ request )
50
- {
54
+ function it_returns_put_request_created_by_the_http_client (
55
+ RequestFactoryInterface $ requestFactory ,
56
+ RequestInterface $ request
57
+ ) {
51
58
$ requestFactory ->createRequest ('PUT ' , 'http://example.com/xapi/statements ' , array (
52
59
'X-Experience-API-Version ' => '1.0.1 ' ,
53
60
'Content-Type ' => 'application/json ' ,
@@ -57,8 +64,10 @@ function it_returns_put_request_created_by_the_http_client(RequestFactory $reque
57
64
$ this ->createRequest ('PUT ' , '/statements ' , array (), 'body ' )->shouldReturn ($ request );
58
65
}
59
66
60
- function it_returns_delete_request_created_by_the_http_client (RequestFactory $ requestFactory , RequestInterface $ request )
61
- {
67
+ function it_returns_delete_request_created_by_the_http_client (
68
+ RequestFactoryInterface $ requestFactory ,
69
+ RequestInterface $ request
70
+ ) {
62
71
$ requestFactory ->createRequest ('DELETE ' , 'http://example.com/xapi/statements ' , array (
63
72
'X-Experience-API-Version ' => '1.0.1 ' ,
64
73
'Content-Type ' => 'application/json ' ,
@@ -68,53 +77,71 @@ function it_returns_delete_request_created_by_the_http_client(RequestFactory $re
68
77
$ this ->createRequest ('DELETE ' , '/statements ' )->shouldReturn ($ request );
69
78
}
70
79
71
- function it_throws_an_access_denied_exception_when_a_401_status_code_is_returned (HttpClient $ client , RequestInterface $ request , ResponseInterface $ response )
72
- {
80
+ function it_throws_an_access_denied_exception_when_a_401_status_code_is_returned (
81
+ ClientInterface $ client ,
82
+ RequestInterface $ request ,
83
+ ResponseInterface $ response
84
+ ) {
73
85
$ client ->sendRequest ($ request )->willReturn ($ response );
74
86
$ response ->getStatusCode ()->willReturn (401 );
75
87
$ response ->getBody ()->willReturn ('body ' );
76
88
77
89
$ this ->shouldThrow (AccessDeniedException::class)->during ('executeRequest ' , array ($ request , array (200 )));
78
90
}
79
91
80
- function it_throws_an_access_denied_exception_when_a_403_status_code_is_returned (HttpClient $ client , RequestInterface $ request , ResponseInterface $ response )
81
- {
92
+ function it_throws_an_access_denied_exception_when_a_403_status_code_is_returned (
93
+ ClientInterface $ client ,
94
+ RequestInterface $ request ,
95
+ ResponseInterface $ response
96
+ ) {
82
97
$ client ->sendRequest ($ request )->willReturn ($ response );
83
98
$ response ->getStatusCode ()->willReturn (403 );
84
99
$ response ->getBody ()->willReturn ('body ' );
85
100
86
101
$ this ->shouldThrow (AccessDeniedException::class)->during ('executeRequest ' , array ($ request , array (200 )));
87
102
}
88
103
89
- function it_throws_a_not_found_exception_when_a_404_status_code_is_returned (HttpClient $ client , RequestInterface $ request , ResponseInterface $ response )
90
- {
104
+ function it_throws_a_not_found_exception_when_a_404_status_code_is_returned (
105
+ ClientInterface $ client ,
106
+ RequestInterface $ request ,
107
+ ResponseInterface $ response
108
+ ) {
91
109
$ client ->sendRequest ($ request )->willReturn ($ response );
92
110
$ response ->getStatusCode ()->willReturn (404 );
93
111
$ response ->getBody ()->willReturn ('body ' );
94
112
95
113
$ this ->shouldThrow (NotFoundException::class)->during ('executeRequest ' , array ($ request , array (200 )));
96
114
}
97
115
98
- function it_throws_a_conflict_exception_when_a_409_status_code_is_returned (HttpClient $ client , RequestInterface $ request , ResponseInterface $ response )
99
- {
116
+ function it_throws_a_conflict_exception_when_a_409_status_code_is_returned (
117
+ ClientInterface $ client ,
118
+ RequestInterface $ request ,
119
+ ResponseInterface $ response
120
+ ) {
100
121
$ client ->sendRequest ($ request )->willReturn ($ response );
101
122
$ response ->getStatusCode ()->willReturn (409 );
102
123
$ response ->getBody ()->willReturn ('body ' );
103
124
104
125
$ this ->shouldThrow (ConflictException::class)->during ('executeRequest ' , array ($ request , array (200 )));
105
126
}
106
127
107
- function it_throws_an_xapi_exception_when_an_unexpected_status_code_is_returned (HttpClient $ client , RequestInterface $ request , ResponseInterface $ response )
108
- {
128
+ function it_throws_an_xapi_exception_when_an_unexpected_status_code_is_returned (
129
+ ClientInterface $ client ,
130
+ RequestInterface $ request ,
131
+ ResponseInterface $ response
132
+ ) {
109
133
$ client ->sendRequest ($ request )->willReturn ($ response );
110
134
$ response ->getStatusCode ()->willReturn (204 );
111
135
$ response ->getBody ()->willReturn ('body ' );
112
136
113
137
$ this ->shouldThrow (XApiException::class)->during ('executeRequest ' , array ($ request , array (200 )));
114
138
}
115
139
116
- function it_returns_the_response_on_success (HttpClient $ client , RequestInterface $ request , ResponseInterface $ response )
117
- {
140
+ function it_returns_the_response_on_success (
141
+ ClientInterface $ client ,
142
+ RequestInterface $ request ,
143
+ ResponseInterface $ response
144
+ ) {
118
145
$ client ->sendRequest ($ request )->willReturn ($ response );
119
146
$ response ->getStatusCode ()->willReturn (200 );
120
147
$ response ->getBody ()->willReturn ('body ' );
0 commit comments