Skip to content
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

[6.x] Add "missing" method to Request class #30320

Merged
merged 4 commits into from Oct 18, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -150,6 +150,19 @@ public function anyFilled($keys)
return false;
}
/**
* Determine if the request is missing a given input item key.
*
* @param string|array $key
* @return bool
*/
public function missing($key)
{
$keys = is_array($key) ? $key : func_get_args();
return ! $this->has($keys);
}
/**
* Determine if the given input key is an empty string for "has".
*
@@ -300,6 +300,31 @@ public function testHasMethod()
$this->assertTrue($request->has('foo.baz'));
}
public function testMissingMethod()
{
$request = Request::create('/', 'GET', ['name' => 'Taylor', 'age' => '', 'city' => null]);
$this->assertFalse($request->missing('name'));
$this->assertFalse($request->missing('age'));
$this->assertFalse($request->missing('city'));
$this->assertTrue($request->missing('foo'));
$this->assertTrue($request->missing('name', 'email'));
$request = Request::create('/', 'GET', ['name' => 'Taylor', 'email' => 'foo']);
$this->assertFalse($request->missing('name'));
$this->assertFalse($request->missing('name', 'email'));
$request = Request::create('/', 'GET', ['foo' => ['bar', 'bar']]);
$this->assertFalse($request->missing('foo'));
$request = Request::create('/', 'GET', ['foo' => '', 'bar' => null]);
$this->assertFalse($request->missing('foo'));
$this->assertFalse($request->missing('bar'));
$request = Request::create('/', 'GET', ['foo' => ['bar' => null, 'baz' => '']]);
$this->assertFalse($request->missing('foo.bar'));
$this->assertFalse($request->missing('foo.baz'));
}
public function testHasAnyMethod()
{
$request = Request::create('/', 'GET', ['name' => 'Taylor', 'age' => '', 'city' => null]);
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.