forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow request input to be retrieved as a collection (laravel#38832)
* Allow request input to be retrieved as a collection * Fix docblock spacing -- styleci * Remove default input value when collecting key
- Loading branch information
1 parent
7d954a1
commit 33e4655
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
use Illuminate\Http\UploadedFile; | ||
use Illuminate\Routing\Route; | ||
use Illuminate\Session\Store; | ||
use Illuminate\Support\Collection; | ||
use Mockery as m; | ||
use PHPUnit\Framework\TestCase; | ||
use RuntimeException; | ||
|
@@ -502,6 +503,26 @@ public function testBooleanMethod() | |
$this->assertFalse($request->boolean('some_undefined_key')); | ||
} | ||
|
||
public function testCollectMethod() | ||
{ | ||
$request = Request::create('/', 'GET', ['users' => [1, 2, 3]]); | ||
|
||
$this->assertInstanceOf(Collection::class, $request->collect('users')); | ||
$this->assertTrue($request->collect('developers')->isEmpty()); | ||
$this->assertEquals([1, 2, 3], $request->collect('users')->all()); | ||
$this->assertEquals(['users' => [1, 2, 3]], $request->collect()->all()); | ||
|
||
$request = Request::create('/', 'GET', ['text-payload']); | ||
$this->assertEquals(['text-payload'], $request->collect()->all()); | ||
|
||
$request = Request::create('/', 'GET', ['email' => '[email protected]']); | ||
$this->assertEquals(['[email protected]'], $request->collect('email')->all()); | ||
|
||
$request = Request::create('/', 'GET', []); | ||
$this->assertInstanceOf(Collection::class, $request->collect()); | ||
$this->assertTrue($request->collect()->isEmpty()); | ||
} | ||
|
||
public function testArrayAccess() | ||
{ | ||
$request = Request::create('/', 'GET', ['name' => null, 'foo' => ['bar' => null, 'baz' => '']]); | ||
|