15
15
16
16
class LoggerPluginSpec extends ObjectBehavior
17
17
{
18
- function let (LoggerInterface $ logger, Normalizer $ normalizer )
18
+ function let (LoggerInterface $ logger )
19
19
{
20
- $ this ->beConstructedWith ($ logger, $ normalizer );
20
+ $ this ->beConstructedWith ($ logger );
21
21
}
22
22
23
23
function it_is_initializable ()
@@ -30,13 +30,18 @@ function it_is_a_plugin()
30
30
$ this ->shouldImplement ('Http\Client\Plugin\Plugin ' );
31
31
}
32
32
33
- function it_logs (LoggerInterface $ logger, Normalizer $ normalizer , RequestInterface $ request , ResponseInterface $ response )
33
+ function it_logs_request_and_response (LoggerInterface $ logger , RequestInterface $ request , ResponseInterface $ response )
34
34
{
35
35
$ logger ->info ('Emit request: "GET / 1.1" ' , ['request ' => $ request ])->shouldBeCalled ();
36
36
$ logger ->info ('Receive response: "200 Ok 1.1" for request: "GET / 1.1" ' , ['request ' => $ request , 'response ' => $ response ])->shouldBeCalled ();
37
37
38
- $ normalizer ->normalizeRequestToString ($ request )->willReturn ('GET / 1.1 ' );
39
- $ normalizer ->normalizeResponseToString ($ response )->willReturn ('200 Ok 1.1 ' );
38
+ $ request ->getMethod ()->willReturn ('GET ' );
39
+ $ request ->getRequestTarget ()->willReturn ('/ ' );
40
+ $ request ->getProtocolVersion ()->willReturn ('1.1 ' );
41
+
42
+ $ response ->getReasonPhrase ()->willReturn ('Ok ' );
43
+ $ response ->getProtocolVersion ()->willReturn ('1.1 ' );
44
+ $ response ->getStatusCode ()->willReturn ('200 ' );
40
45
41
46
$ next = function () use ($ response ) {
42
47
return new FulfilledPromise ($ response ->getWrappedObject ());
@@ -45,14 +50,16 @@ function it_logs(LoggerInterface $logger, Normalizer $normalizer, RequestInterfa
45
50
$ this ->handleRequest ($ request , $ next , function () {});
46
51
}
47
52
48
- function it_logs_exception (LoggerInterface $ logger , Normalizer $ normalizer , RequestInterface $ request )
53
+ function it_logs_exception (LoggerInterface $ logger , RequestInterface $ request )
49
54
{
50
55
$ exception = new NetworkException ('Cannot connect ' , $ request ->getWrappedObject ());
51
56
52
57
$ logger ->info ('Emit request: "GET / 1.1" ' , ['request ' => $ request ])->shouldBeCalled ();
53
58
$ logger ->error ('Error: "Cannot connect" when emitting request: "GET / 1.1" ' , ['request ' => $ request , 'exception ' => $ exception ])->shouldBeCalled ();
54
59
55
- $ normalizer ->normalizeRequestToString ($ request )->willReturn ('GET / 1.1 ' );
60
+ $ request ->getMethod ()->willReturn ('GET ' );
61
+ $ request ->getRequestTarget ()->willReturn ('/ ' );
62
+ $ request ->getProtocolVersion ()->willReturn ('1.1 ' );
56
63
57
64
$ next = function () use ($ exception ) {
58
65
return new RejectedPromise ($ exception );
@@ -61,7 +68,7 @@ function it_logs_exception(LoggerInterface $logger, Normalizer $normalizer, Requ
61
68
$ this ->handleRequest ($ request , $ next , function () {});
62
69
}
63
70
64
- function it_logs_response_within_exception (LoggerInterface $ logger , Normalizer $ normalizer , RequestInterface $ request , ResponseInterface $ response )
71
+ function it_logs_response_within_exception (LoggerInterface $ logger , RequestInterface $ request , ResponseInterface $ response )
65
72
{
66
73
$ exception = new HttpException ('Forbidden ' , $ request ->getWrappedObject (), $ response ->getWrappedObject ());
67
74
@@ -72,8 +79,13 @@ function it_logs_response_within_exception(LoggerInterface $logger, Normalizer $
72
79
'exception ' => $ exception
73
80
])->shouldBeCalled ();
74
81
75
- $ normalizer ->normalizeRequestToString ($ request )->willReturn ('GET / 1.1 ' );
76
- $ normalizer ->normalizeResponseToString ($ response )->willReturn ('403 Forbidden 1.1 ' );
82
+ $ request ->getMethod ()->willReturn ('GET ' );
83
+ $ request ->getRequestTarget ()->willReturn ('/ ' );
84
+ $ request ->getProtocolVersion ()->willReturn ('1.1 ' );
85
+
86
+ $ response ->getReasonPhrase ()->willReturn ('Forbidden ' );
87
+ $ response ->getProtocolVersion ()->willReturn ('1.1 ' );
88
+ $ response ->getStatusCode ()->willReturn ('403 ' );
77
89
78
90
$ next = function () use ($ exception ) {
79
91
return new RejectedPromise ($ exception );
0 commit comments