-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpFoundation] Adds various return-typed getters to ParameterBag #49972
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
Changes from all commits
8843e8b
8afc924
22ff96e
b236f36
206e0b3
de83b1c
e083887
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -378,6 +378,30 @@ public function testGetEnumThrowsExceptionWithInvalidValueType() | |
|
||
$this->assertNull($bag->getEnum('invalid-value', FooEnum::class)); | ||
} | ||
|
||
public function testGetStringOrNull(): void | ||
{ | ||
$bag = new ParameterBag(['valid-value' => 'foo']); | ||
|
||
$this->assertSame('foo', $bag->getStringOrNull('valid-value')); | ||
$this->assertNull($bag->getStringOrNull('missing-key')); | ||
} | ||
|
||
public function testGetIntOrNull(): void | ||
{ | ||
$bag = new ParameterBag(['valid-value' => 1]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An assertion with an invalid value is necessary, i.e. with a value that cannot be converted to int. Same for Boolean. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've changed it to using native |
||
|
||
$this->assertSame(1, $bag->getIntOrNull('valid-value')); | ||
$this->assertNull($bag->getIntOrNull('missing-key')); | ||
} | ||
|
||
public function testGetBooleanOrNull(): void | ||
{ | ||
$bag = new ParameterBag(['valid-value' => true]); | ||
|
||
$this->assertTrue($bag->getBooleanOrNull('valid-value')); | ||
$this->assertNull($bag->getBooleanOrNull('missing-key')); | ||
} | ||
} | ||
|
||
class InputStringable | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking if the value is set is not necessary:
filter_var(null, \FILTER_VALIDATE_INT, \FILTER_NULL_ON_FAILURE)
returnsnull
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed it to use
getInt
implementation instead.