Skip to content

Commit e461597

Browse files
committed
Fix history with empty size does not work
1 parent 0d63468 commit e461597

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. This projec
44
to [Semantic Versioning] (http://semver.org/). For change log format,
55
use [Keep a Changelog] (http://keepachangelog.com/).
66

7+
## [2.5.2] - 2026-01-21
8+
9+
### Fixed
10+
11+
- History with empty size does not work
12+
713
## [2.5.1] - 2026-01-13
814

915
### Fixed

src/History/History.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class History implements Countable, IteratorAggregate
3232

3333
public function __construct(private int|float $size = INF)
3434
{
35+
$this->size = abs($this->size);
3536
}
3637

3738
public function setSize(int|float $size): void
@@ -42,6 +43,10 @@ public function setSize(int|float $size): void
4243

4344
public function flush(): void
4445
{
46+
if (0 === $this->size) {
47+
$this->history = [];
48+
}
49+
4550
if ($this->count() > $this->size) {
4651
$this->history = array_slice($this->history, -$this->size);
4752
}

tests/History/HistoryTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,12 @@ public function testSize()
143143
$this->assertSame($request2, $history->get(0)->getRequest());
144144
$this->assertSame($request3, $history->get(1)->getRequest());
145145
}
146+
147+
public function testSizeEmpty()
148+
{
149+
$history = new History(0);
150+
$history->add(new CookiesManager(), new Request('GET', 'fake'));
151+
152+
$this->assertCount(0, $history);
153+
}
146154
}

0 commit comments

Comments
 (0)