7
7
use Http \Promise \FulfilledPromise ;
8
8
use Http \Promise \RejectedPromise ;
9
9
use Http \Message \Formatter ;
10
+ use Prophecy \Argument ;
10
11
use Psr \Http \Message \RequestInterface ;
11
12
use Psr \Http \Message \ResponseInterface ;
12
13
use Psr \Http \Message \UriInterface ;
@@ -40,7 +41,17 @@ function it_logs_request_and_response(
40
41
$ formatter ->formatResponse ($ response )->willReturn ('200 OK 1.1 ' );
41
42
42
43
$ logger ->info ("Sending request: \nGET / 1.1 " , ['request ' => $ request ])->shouldBeCalled ();
43
- $ logger ->info ("Received response: \n200 OK 1.1 \n\nfor request: \nGET / 1.1 " , ['request ' => $ request , 'response ' => $ response ])->shouldBeCalled ();
44
+ $ logger ->info (
45
+ "Received response: \n200 OK 1.1 \n\nfor request: \nGET / 1.1 " ,
46
+ Argument::that (
47
+ function (array $ context ) use ($ request , $ response ) {
48
+ return $ context ['request ' ] === $ request ->getWrappedObject ()
49
+ && $ context ['response ' ] === $ response ->getWrappedObject ()
50
+ && is_int ($ context ['milliseconds ' ])
51
+ ;
52
+ }
53
+ )
54
+ )->shouldBeCalled ();
44
55
45
56
$ next = function () use ($ response ) {
46
57
return new FulfilledPromise ($ response ->getWrappedObject ());
@@ -56,7 +67,17 @@ function it_logs_exception(LoggerInterface $logger, Formatter $formatter, Reques
56
67
$ exception = new NetworkException ('Cannot connect ' , $ request ->getWrappedObject ());
57
68
58
69
$ logger ->info ("Sending request: \nGET / 1.1 " , ['request ' => $ request ])->shouldBeCalled ();
59
- $ logger ->error ("Error: \nCannot connect \nwhen sending request: \nGET / 1.1 " , ['request ' => $ request , 'exception ' => $ exception ])->shouldBeCalled ();
70
+ $ logger ->error (
71
+ "Error: \nCannot connect \nwhen sending request: \nGET / 1.1 " ,
72
+ Argument::that (
73
+ function (array $ context ) use ($ request , $ exception ) {
74
+ return $ context ['request ' ] === $ request ->getWrappedObject ()
75
+ && $ context ['exception ' ] === $ exception
76
+ && is_int ($ context ['milliseconds ' ])
77
+ ;
78
+ }
79
+ )
80
+ )->shouldBeCalled ();
60
81
61
82
$ next = function () use ($ exception ) {
62
83
return new RejectedPromise ($ exception );
@@ -77,11 +98,18 @@ function it_logs_response_within_exception(
77
98
$ exception = new HttpException ('Forbidden ' , $ request ->getWrappedObject (), $ response ->getWrappedObject ());
78
99
79
100
$ logger ->info ("Sending request: \nGET / 1.1 " , ['request ' => $ request ])->shouldBeCalled ();
80
- $ logger ->error ("Error: \nForbidden \nwith response: \n403 Forbidden 1.1 \n\nwhen sending request: \nGET / 1.1 " , [
81
- 'request ' => $ request ,
82
- 'response ' => $ response ,
83
- 'exception ' => $ exception
84
- ])->shouldBeCalled ();
101
+ $ logger ->error (
102
+ "Error: \nForbidden \nwith response: \n403 Forbidden 1.1 \n\nwhen sending request: \nGET / 1.1 " ,
103
+ Argument::that (
104
+ function (array $ context ) use ($ request , $ response , $ exception ) {
105
+ return $ context ['request ' ] === $ request ->getWrappedObject ()
106
+ && $ context ['response ' ] === $ response ->getWrappedObject ()
107
+ && $ context ['exception ' ] === $ exception
108
+ && is_int ($ context ['milliseconds ' ])
109
+ ;
110
+ }
111
+ )
112
+ )->shouldBeCalled ();
85
113
86
114
$ next = function () use ($ exception ) {
87
115
return new RejectedPromise ($ exception );
0 commit comments