Skip to content

Commit ad3931b

Browse files
committed
feat(HarRecorder): add clear() method
Add clear() method to remove all recorded entries.
1 parent aa50d1d commit ad3931b

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/HarRecorder.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff 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
*/

tests/src/Unit/HarRecorderTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)