88class HttpRequestMatcher extends Constraint
99{
1010
11- private string $ actualBody ;
1211
1312 /**
1413 * HttpRequestMatcher constructor.
@@ -35,11 +34,10 @@ protected function matches($other): bool
3534 if (!($ other instanceof RequestInterface)) {
3635 return false ;
3736 }
38- $ this ->actualBody = $ this ->actualBody ?? $ other ->getBody ()->getContents ();
3937 return
4038 ($ other ->getUri () == $ this ->url )
4139 && ($ other ->getMethod () === $ this ->method )
42- && $ this ->matchBody ()
40+ && $ this ->matchBody ($ other )
4341 && $ this ->matchHeadersWithoutUserAgent ($ other )
4442 && $ this ->matchUserAgent ($ other );
4543 }
@@ -50,9 +48,10 @@ private function matchUserAgent(RequestInterface $request): bool
5048 return preg_match ($ this ->userAgent , $ request ->getHeaderLine ('user-agent ' )) != false ;
5149 }
5250
53- private function matchBody (): bool
51+ private function matchBody (RequestInterface $ request ): bool
5452 {
55- return $ this ->body === $ this ->actualBody ;
53+ $ request ->getBody ()->rewind ();
54+ return $ this ->body === $ request ->getBody ()->getContents ();
5655 }
5756
5857 private function matchHeadersWithoutUserAgent (RequestInterface $ request ): bool
@@ -86,8 +85,9 @@ protected function additionalFailureDescription($other): string
8685 if ($ other ->getMethod () !== $ this ->method ) {
8786 $ diff [] = $ this ->diffLine ("Method " , $ this ->method , $ other ->getMethod ());
8887 }
89- if (!$ this ->matchBody ()) {
90- $ diff [] = $ this ->diffLine ("Body " , $ this ->body , $ this ->actualBody );
88+ if (!$ this ->matchBody ($ other )) {
89+ $ other ->getBody ()->rewind ();
90+ $ diff [] = $ this ->diffLine ("Body " , $ this ->body , $ other ->getBody ()->getContents ());
9191 }
9292
9393 if (!$ this ->matchUserAgent ($ other )) {
0 commit comments