Skip to content

Commit f602d5c

Browse files
Merge branch '7.0' into 7.1
* 7.0: [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 move adding detailed JSON error messages to the validate phase [Profiler] Add word wrap in tables in dialog to see all the text [Core] Fix & Enhance security arabic translation. [HttpFoundation] Add tests for `MethodRequestMatcher` and `SchemeRequestMatcher`
2 parents e7487bc + e7bb762 commit f602d5c

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

Tests/InputBagTest.php

+18
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,24 @@ public function testFilterArrayWithoutArrayFlag()
154154
$bag->filter('foo', \FILTER_VALIDATE_INT);
155155
}
156156

157+
public function testAdd()
158+
{
159+
$bag = new InputBag(['foo' => 'bar']);
160+
$bag->add(['baz' => 'qux']);
161+
162+
$this->assertSame('bar', $bag->get('foo'), '->add() does not remove existing parameters');
163+
$this->assertSame('qux', $bag->get('baz'), '->add() adds new parameters');
164+
}
165+
166+
public function testReplace()
167+
{
168+
$bag = new InputBag(['foo' => 'bar']);
169+
$bag->replace(['baz' => 'qux']);
170+
171+
$this->assertNull($bag->get('foo'), '->replace() removes existing parameters');
172+
$this->assertSame('qux', $bag->get('baz'), '->replace() adds new parameters');
173+
}
174+
157175
public function testGetEnum()
158176
{
159177
$bag = new InputBag(['valid-value' => 1]);

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();

Tests/RequestMatcher/MethodRequestMatcherTest.php

+7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ public function test(string $requestMethod, array|string $matcherMethod, bool $i
2727
$this->assertSame($isMatch, $matcher->matches($request));
2828
}
2929

30+
public function testAlwaysMatchesOnEmptyMethod()
31+
{
32+
$matcher = new MethodRequestMatcher([]);
33+
$request = Request::create('https://example.com', 'POST');
34+
$this->assertTrue($matcher->matches($request));
35+
}
36+
3037
public static function getData()
3138
{
3239
return [

Tests/RequestMatcher/SchemeRequestMatcherTest.php

+7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ public function test(string $requestScheme, array|string $matcherScheme, bool $i
4242
}
4343
}
4444

45+
public function testAlwaysMatchesOnParamsHeaders()
46+
{
47+
$matcher = new SchemeRequestMatcher([]);
48+
$request = Request::create('sftp://example.com');
49+
$this->assertTrue($matcher->matches($request));
50+
}
51+
4552
public static function getData()
4653
{
4754
return [

0 commit comments

Comments
 (0)