Skip to content

[HttpFoundation] Add tests for uncovered sections #57714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/Symfony/Component/HttpFoundation/Tests/InputBagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,22 @@ public function testFilterArrayWithoutArrayFlagIsDeprecated()
$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');
$bag->filter('foo', \FILTER_VALIDATE_INT);
}

public function testAdd()
{
$bag = new InputBag(['foo' => 'bar']);
$bag->add(['baz' => 'qux']);

$this->assertSame('bar', $bag->get('foo'), '->add() does not remove existing parameters');
$this->assertSame('qux', $bag->get('baz'), '->add() adds new parameters');
}

public function testReplace()
{
$bag = new InputBag(['foo' => 'bar']);
$bag->replace(['baz' => 'qux']);

$this->assertNull($bag->get('foo'), '->replace() removes existing parameters');
$this->assertSame('qux', $bag->get('baz'), '->replace() adds new parameters');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\RateLimiter\LimiterInterface;
use Symfony\Component\RateLimiter\Policy\NoLimiter;
use Symfony\Component\RateLimiter\RateLimit;

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

public function testConsumeWithoutLimiterAddsSpecialNoLimiter()
{
$rateLimiter = new MockAbstractRequestRateLimiter([]);

try {
$this->assertSame(\PHP_INT_MAX, $rateLimiter->consume(new Request())->getLimit());
} catch (\TypeError $error) {
if (str_contains($error->getMessage(), 'RateLimit::__construct(): Argument #1 ($availableTokens) must be of type int, float given')) {
$this->markTestSkipped('This test cannot be run on a version of the RateLimiter component that uses \INF instead of \PHP_INT_MAX in NoLimiter.');
}

throw $error;
}
}

public function testResetLimiters()
{
$rateLimiter = new MockAbstractRequestRateLimiter([
$limiter1 = $this->createMock(LimiterInterface::class),
$limiter2 = $this->createMock(LimiterInterface::class),
]);

$limiter1->expects($this->once())->method('reset');
$limiter2->expects($this->once())->method('reset');

$rateLimiter->reset(new Request());
}

public static function provideRateLimits()
{
$now = new \DateTimeImmutable();
Expand Down