Skip to content

Commit

Permalink
fireInput will unset empty array.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhichao-poper committed Jun 3, 2020
1 parent 18a9949 commit 11ef4d4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/ConditionsGeneratorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ public function getInputArgs($key = null, $default = null)
protected function isVaildInput($requestKey)
{
return Arr::has($this->inputArgs, $requestKey)
&& Arr::get($this->inputArgs, $requestKey) !== []
&& Arr::get($this->inputArgs, $requestKey) !== null
&& Arr::get($this->inputArgs, $requestKey) !== '';
}
Expand Down
13 changes: 13 additions & 0 deletions tests/Unit/ConditionGeneratorTrait/HandlePaginate.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,17 @@ public function test_order()
'id' => 'asc',
], Arr::get($conditions, 'order'));
}

public function test_fireInput()
{
$fakeRequest = new FakeRequest();

$conditions = $fakeRequest->getConditions([
'empty_array_field' => []
]);

$this->assertEquals([
'id' => 'asc',
], Arr::get($conditions, 'order'));
}
}
9 changes: 9 additions & 0 deletions tests/Utils/FakeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ class FakeRequest
{
use ConditionsGeneratorTrait;

protected function wheres()
{
return [
'empty_array_field' => $this->fireInput('empty_array_field', function($value) {
return $value.'%';
}),
];
}

protected function order()
{
return '+id';
Expand Down

0 comments on commit 11ef4d4

Please sign in to comment.