Skip to content

Commit 08404b2

Browse files
[HttpFoundation] Add tests for uncovered sections
1 parent b5dba85 commit 08404b2

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/Symfony/Component/HttpFoundation/Tests/InputBagTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,22 @@ public function testFilterArrayWithoutArrayFlagIsDeprecated()
9898
$this->expectDeprecation('Since symfony/http-foundation 5.1: Filtering an array value with "Symfony\Component\HttpFoundation\InputBag::filter()" without passing the FILTER_REQUIRE_ARRAY or FILTER_FORCE_ARRAY flag is deprecated');
9999
$bag->filter('foo', \FILTER_VALIDATE_INT);
100100
}
101+
102+
public function testAdd()
103+
{
104+
$bag = new InputBag(['foo' => 'bar']);
105+
$bag->add(['baz' => 'qux']);
106+
107+
$this->assertSame('bar', $bag->get('foo'), '->add() does not remove existing parameters');
108+
$this->assertSame('qux', $bag->get('baz'), '->add() adds new parameters');
109+
}
110+
111+
public function testReplace()
112+
{
113+
$bag = new InputBag(['foo' => 'bar']);
114+
$bag->replace(['baz' => 'qux']);
115+
116+
$this->assertNull($bag->get('foo'), '->replace() removes existing parameters');
117+
$this->assertSame('qux', $bag->get('baz'), '->replace() adds new parameters');
118+
}
101119
}

src/Symfony/Component/HttpFoundation/Tests/RateLimiter/AbstractRequestRateLimiterTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,26 @@ public function testConsume(array $rateLimits, ?RateLimit $expected)
3333
$this->assertSame($expected, $rateLimiter->consume(new Request()));
3434
}
3535

36+
public function testConsumeWithoutLimiterAddSpecialNoLimiter()
37+
{
38+
$rateLimiter = new MockAbstractRequestRateLimiter([]);
39+
40+
$this->assertSame(\PHP_INT_MAX, $rateLimiter->consume(new Request())->getLimit());
41+
}
42+
43+
public function testResetLimiters()
44+
{
45+
$rateLimiter = new MockAbstractRequestRateLimiter([
46+
$limiter1 = $this->createMock(LimiterInterface::class),
47+
$limiter2 = $this->createMock(LimiterInterface::class),
48+
]);
49+
50+
$limiter1->expects($this->once())->method('reset');
51+
$limiter2->expects($this->once())->method('reset');
52+
53+
$rateLimiter->reset(new Request());
54+
}
55+
3656
public static function provideRateLimits()
3757
{
3858
$now = new \DateTimeImmutable();

0 commit comments

Comments
 (0)