File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed
Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -95,6 +95,14 @@ public function count(): int
9595 return \count ($ this ->entries );
9696 }
9797
98+ /**
99+ * Clear all recorded entries.
100+ */
101+ public function clear (): void
102+ {
103+ $ this ->entries = [];
104+ }
105+
98106 /**
99107 * Create a HAR entry from the request/response pair.
100108 */
Original file line number Diff line number Diff line change @@ -287,4 +287,22 @@ public function testCountReturnsCorrectNumber(): void
287287 $ recorder ->sendRequest (new Request ('GET ' , new Uri ('https://example.com ' )));
288288 $ this ->assertSame (2 , $ recorder ->count ());
289289 }
290+
291+ public function testClearRemovesAllEntries (): void
292+ {
293+ $ innerClient = $ this ->createMock (ClientInterface::class);
294+ $ innerClient ->method ('sendRequest ' )->willReturn (new Response (200 ));
295+
296+ $ recorder = new HarRecorder ($ innerClient );
297+ $ recorder ->sendRequest (new Request ('GET ' , new Uri ('https://example.com/1 ' )));
298+ $ recorder ->sendRequest (new Request ('GET ' , new Uri ('https://example.com/2 ' )));
299+
300+ $ this ->assertSame (2 , $ recorder ->count ());
301+
302+ $ recorder ->clear ();
303+
304+ $ this ->assertSame (0 , $ recorder ->count ());
305+ $ this ->assertEmpty ($ recorder ->getEntries ());
306+ $ this ->assertEmpty ($ recorder ->getHar ()->getLog ()->getEntries ());
307+ }
290308}
You can’t perform that action at this time.
0 commit comments