|
12 | 12 | namespace Symfony\Component\HttpFoundation\Tests;
|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase;
|
| 15 | +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; |
15 | 16 | use Symfony\Component\HttpFoundation\Exception\BadRequestException;
|
16 | 17 | use Symfony\Component\HttpFoundation\InputBag;
|
17 | 18 |
|
18 | 19 | class InputBagTest extends TestCase
|
19 | 20 | {
|
| 21 | + use ExpectDeprecationTrait; |
| 22 | + |
20 | 23 | public function testGet()
|
21 | 24 | {
|
22 |
| - $bag = new InputBag(['foo' => 'bar', 'null' => null, 'int' => 1, 'float' => 1.0, 'bool' => false, 'stringable' => new class() implements \Stringable { |
23 |
| - public function __toString(): string |
24 |
| - { |
25 |
| - return 'strval'; |
26 |
| - } |
27 |
| - }]); |
| 25 | + $bag = new InputBag(['foo' => 'bar', 'null' => null, 'int' => 1, 'float' => 1.0, 'bool' => false]); |
28 | 26 |
|
29 | 27 | $this->assertSame('bar', $bag->get('foo'), '->get() gets the value of a string parameter');
|
30 | 28 | $this->assertSame('default', $bag->get('unknown', 'default'), '->get() returns second argument as default if a parameter is not defined');
|
31 | 29 | $this->assertNull($bag->get('null', 'default'), '->get() returns null if null is set');
|
32 | 30 | $this->assertSame(1, $bag->get('int'), '->get() gets the value of an int parameter');
|
33 | 31 | $this->assertSame(1.0, $bag->get('float'), '->get() gets the value of a float parameter');
|
34 |
| - $this->assertSame('strval', $bag->get('stringable'), '->get() gets the string value of a \Stringable parameter'); |
35 | 32 | $this->assertFalse($bag->get('bool'), '->get() gets the value of a bool parameter');
|
36 | 33 | }
|
37 | 34 |
|
@@ -106,4 +103,35 @@ public function testFilterArrayWithoutArrayFlag()
|
106 | 103 | $bag = new InputBag(['foo' => ['bar', 'baz']]);
|
107 | 104 | $bag->filter('foo', \FILTER_VALIDATE_INT);
|
108 | 105 | }
|
| 106 | + |
| 107 | + /** |
| 108 | + * @group legacy |
| 109 | + */ |
| 110 | + public function testLegacyGetStringableObject() |
| 111 | + { |
| 112 | + $bag = new InputBag(['stringable' => new class() implements \Stringable { |
| 113 | + public function __toString(): string |
| 114 | + { |
| 115 | + return 'strval'; |
| 116 | + } |
| 117 | + }]); |
| 118 | + |
| 119 | + $this->expectDeprecation('Since symfony/http-foundation 6.2: Retrieving a "Stringable@anonymous" object from "Symfony\Component\HttpFoundation\InputBag::get()" is deprecated, use scalars or null instead.'); |
| 120 | + $this->assertSame('strval', $bag->get('stringable'), '->get() gets the string value of a \Stringable parameter'); |
| 121 | + } |
| 122 | + |
| 123 | + /** |
| 124 | + * @group legacy |
| 125 | + */ |
| 126 | + public function testLegacySetStringableObject() |
| 127 | + { |
| 128 | + $bag = new InputBag(); |
| 129 | + $this->expectDeprecation('Since symfony/http-foundation 6.2: Passing a "Stringable@anonymous" object as a 2nd argument ($value) to "Symfony\Component\HttpFoundation\InputBag::set()" is deprecated. Pass a scalar, an array or null instead.'); |
| 130 | + $bag->set('stringable', new class() implements \Stringable { |
| 131 | + public function __toString(): string |
| 132 | + { |
| 133 | + return 'strval'; |
| 134 | + } |
| 135 | + }); |
| 136 | + } |
109 | 137 | }
|
0 commit comments