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