Skip to content

Commit 9c375b2

Browse files
[HttpFoundation] Add tests for uncovered sections
1 parent 9249ad7 commit 9c375b2

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

Tests/InputBagTest.php

+18
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
}

Tests/RateLimiter/AbstractRequestRateLimiterTest.php

+29
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\HttpFoundation\Request;
1616
use Symfony\Component\RateLimiter\LimiterInterface;
17+
use Symfony\Component\RateLimiter\Policy\NoLimiter;
1718
use Symfony\Component\RateLimiter\RateLimit;
1819

1920
class AbstractRequestRateLimiterTest extends TestCase
@@ -33,6 +34,34 @@ public function testConsume(array $rateLimits, ?RateLimit $expected)
3334
$this->assertSame($expected, $rateLimiter->consume(new Request()));
3435
}
3536

37+
public function testConsumeWithoutLimiterAddsSpecialNoLimiter()
38+
{
39+
$rateLimiter = new MockAbstractRequestRateLimiter([]);
40+
41+
try {
42+
$this->assertSame(\PHP_INT_MAX, $rateLimiter->consume(new Request())->getLimit());
43+
} catch (\TypeError $error) {
44+
if (str_contains($error->getMessage(), 'RateLimit::__construct(): Argument #1 ($availableTokens) must be of type int, float given')) {
45+
$this->markTestSkipped('This test cannot be run on a version of the RateLimiter component that uses \INF instead of \PHP_INT_MAX in NoLimiter.');
46+
}
47+
48+
throw $error;
49+
}
50+
}
51+
52+
public function testResetLimiters()
53+
{
54+
$rateLimiter = new MockAbstractRequestRateLimiter([
55+
$limiter1 = $this->createMock(LimiterInterface::class),
56+
$limiter2 = $this->createMock(LimiterInterface::class),
57+
]);
58+
59+
$limiter1->expects($this->once())->method('reset');
60+
$limiter2->expects($this->once())->method('reset');
61+
62+
$rateLimiter->reset(new Request());
63+
}
64+
3665
public static function provideRateLimits()
3766
{
3867
$now = new \DateTimeImmutable();

0 commit comments

Comments
 (0)