77use Http \Promise \FulfilledPromise ;
88use Http \Promise \RejectedPromise ;
99use Http \Message \Formatter ;
10+ use Prophecy \Argument ;
1011use Psr \Http \Message \RequestInterface ;
1112use Psr \Http \Message \ResponseInterface ;
1213use Psr \Http \Message \UriInterface ;
@@ -40,7 +41,17 @@ function it_logs_request_and_response(
4041 $ formatter ->formatResponse ($ response )->willReturn ('200 OK 1.1 ' );
4142
4243 $ 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 ();
4455
4556 $ next = function () use ($ response ) {
4657 return new FulfilledPromise ($ response ->getWrappedObject ());
@@ -56,7 +67,17 @@ function it_logs_exception(LoggerInterface $logger, Formatter $formatter, Reques
5667 $ exception = new NetworkException ('Cannot connect ' , $ request ->getWrappedObject ());
5768
5869 $ 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 ();
6081
6182 $ next = function () use ($ exception ) {
6283 return new RejectedPromise ($ exception );
@@ -77,11 +98,18 @@ function it_logs_response_within_exception(
7798 $ exception = new HttpException ('Forbidden ' , $ request ->getWrappedObject (), $ response ->getWrappedObject ());
7899
79100 $ 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 ();
85113
86114 $ next = function () use ($ exception ) {
87115 return new RejectedPromise ($ exception );
0 commit comments