Skip to content

Commit

Permalink
Merge branch '5.4' into 6.4
Browse files Browse the repository at this point in the history
* 5.4:
  [Console][PhpUnitBridge][VarDumper] Fix `NO_COLOR` empty value handling
  [Translation] Fix CSV escape char in `CsvFileLoader` on PHP >= 7.4
  [DoctrineBridge] fix messenger bus dispatch inside an active transaction
  [HttpFoundation] Add tests for uncovered sections
  treat uninitialized properties referenced by property paths as null
  properly set up constraint options
  [ErrorHandler][VarDumper] Remove PHP 8.4 deprecations
  [Core] Fix & Enhance security arabic translation.
  • Loading branch information
nicolas-grekas committed Jul 26, 2024
2 parents e36a71e + 9c375b2 commit c3fa5c0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Tests/InputBagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,24 @@ public function testFilterArrayWithoutArrayFlag()
$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');
}

public function testGetEnum()
{
$bag = new InputBag(['valid-value' => 1]);
Expand Down
29 changes: 29 additions & 0 deletions Tests/RateLimiter/AbstractRequestRateLimiterTest.php
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

0 comments on commit c3fa5c0

Please sign in to comment.