Skip to content

Commit 152e223

Browse files
authored
add testStringMethod to HttpRequestTest.php (#46088)
1 parent dd3abef commit 152e223

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/Http/HttpRequestTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Session\Store;
99
use Illuminate\Support\Carbon;
1010
use Illuminate\Support\Collection;
11+
use Illuminate\Support\Stringable;
1112
use Illuminate\Tests\Database\Fixtures\Models\Money\Price;
1213
use InvalidArgumentException;
1314
use Mockery as m;
@@ -585,6 +586,32 @@ public function testInputMethod()
585586
$this->assertInstanceOf(SymfonyUploadedFile::class, $request['file']);
586587
}
587588

589+
public function testStringMethod()
590+
{
591+
$request = Request::create('/', 'GET', [
592+
'int' => 123,
593+
'int_str' => '456',
594+
'float' => 123.456,
595+
'float_str' => '123.456',
596+
'float_zero' => 0.000,
597+
'float_str_zero' => '0.000',
598+
'str' => 'abc',
599+
'empty_str' => '',
600+
'null' => null,
601+
]);
602+
$this->assertTrue($request->string('int') instanceof Stringable);
603+
$this->assertTrue($request->string('unknown_key') instanceof Stringable);
604+
$this->assertSame('123', $request->string('int')->value());
605+
$this->assertSame('456', $request->string('int_str')->value());
606+
$this->assertSame('123.456', $request->string('float')->value());
607+
$this->assertSame('123.456', $request->string('float_str')->value());
608+
$this->assertSame('0', $request->string('float_zero')->value());
609+
$this->assertSame('0.000', $request->string('float_str_zero')->value());
610+
$this->assertSame('', $request->string('empty_str')->value());
611+
$this->assertSame('', $request->string('null')->value());
612+
$this->assertSame('', $request->string('unknown_key')->value());
613+
}
614+
588615
public function testBooleanMethod()
589616
{
590617
$request = Request::create('/', 'GET', ['with_trashed' => 'false', 'download' => true, 'checked' => 1, 'unchecked' => '0', 'with_on' => 'on', 'with_yes' => 'yes']);

0 commit comments

Comments
 (0)