Skip to content

Commit

Permalink
make Request::has work like Collection::has and exchange exists with …
Browse files Browse the repository at this point in the history
…filled
  • Loading branch information
themsaid committed Apr 7, 2017
1 parent e9c65cd commit 2d22de0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Http/Concerns/InteractsWithInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function bearerToken()
* @param string|array $key
* @return bool
*/
public function exists($key)
public function has($key)
{
$keys = is_array($key) ? $key : func_get_args();

Expand All @@ -85,7 +85,7 @@ public function exists($key)
* @param string|array $key
* @return bool
*/
public function has($key)
public function filled($key)
{
$keys = is_array($key) ? $key : func_get_args();

Expand Down
46 changes: 25 additions & 21 deletions tests/Http/HttpRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,46 +190,50 @@ public function testSecureMethod()
$this->assertTrue($request->secure());
}

public function testExistsMethod()
public function testHasMethod()
{
$request = Request::create('/', 'GET', ['name' => 'Taylor']);
$this->assertTrue($request->exists('name'));
$this->assertFalse($request->exists('foo'));
$this->assertFalse($request->exists('name', 'email'));
$request = Request::create('/', 'GET', ['name' => 'Taylor', 'age' => '', 'city' => null]);
$this->assertTrue($request->has('name'));
$this->assertTrue($request->has('age'));
$this->assertTrue($request->has('city'));
$this->assertFalse($request->has('foo'));
$this->assertFalse($request->has('name', 'email'));

$request = Request::create('/', 'GET', ['name' => 'Taylor', 'email' => 'foo']);
$this->assertTrue($request->exists('name'));
$this->assertTrue($request->exists('name', 'email'));
$this->assertTrue($request->has('name'));
$this->assertTrue($request->has('name', 'email'));

$request = Request::create('/', 'GET', ['foo' => ['bar', 'bar']]);
$this->assertTrue($request->exists('foo'));
$this->assertTrue($request->has('foo'));

$request = Request::create('/', 'GET', ['foo' => '', 'bar' => null]);
$this->assertTrue($request->exists('foo'));
$this->assertTrue($request->exists('bar'));
$this->assertTrue($request->has('foo'));
$this->assertTrue($request->has('bar'));

$request = Request::create('/', 'GET', ['foo' => ['bar' => null, 'baz' => '']]);
$this->assertTrue($request->exists('foo.bar'));
$this->assertTrue($request->exists('foo.baz'));
$this->assertTrue($request->has('foo.bar'));
$this->assertTrue($request->has('foo.baz'));
}

public function testHasMethod()
public function testFilledMethod()
{
$request = Request::create('/', 'GET', ['name' => 'Taylor']);
$this->assertTrue($request->has('name'));
$this->assertFalse($request->has('foo'));
$this->assertFalse($request->has('name', 'email'));
$request = Request::create('/', 'GET', ['name' => 'Taylor', 'age' => '', 'city' => null]);
$this->assertTrue($request->filled('name'));
$this->assertFalse($request->filled('age'));
$this->assertFalse($request->filled('city'));
$this->assertFalse($request->filled('foo'));
$this->assertFalse($request->filled('name', 'email'));

$request = Request::create('/', 'GET', ['name' => 'Taylor', 'email' => 'foo']);
$this->assertTrue($request->has('name'));
$this->assertTrue($request->has('name', 'email'));
$this->assertTrue($request->filled('name'));
$this->assertTrue($request->filled('name', 'email'));

//test arrays within query string
$request = Request::create('/', 'GET', ['foo' => ['bar', 'baz']]);
$this->assertTrue($request->has('foo'));
$this->assertTrue($request->filled('foo'));

$request = Request::create('/', 'GET', ['foo' => ['bar' => 'baz']]);
$this->assertTrue($request->has('foo.bar'));
$this->assertTrue($request->filled('foo.bar'));
}

public function testInputMethod()
Expand Down

0 comments on commit 2d22de0

Please sign in to comment.