Skip to content

Commit

Permalink
Merge pull request #2813 from samsonasik/fix-missing-invalidargumente…
Browse files Browse the repository at this point in the history
…xception-basebuilder

Fix missing InvalidArgumentException in Database\BaseBuilder
  • Loading branch information
MGatner authored Apr 9, 2020
2 parents 3ededb0 + 227f2d0 commit 895f1e6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
4 changes: 2 additions & 2 deletions system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ protected function _whereIn(string $key = null, $values = null, bool $not = fals
{
if (CI_DEBUG)
{
throw new InvalidArgumentException(sprintf('%s() expects $key to be a non-empty string', debug_backtrace(0, 2)[1]['function']));
throw new \InvalidArgumentException(sprintf('%s() expects $key to be a non-empty string', debug_backtrace(0, 2)[1]['function']));
}
// @codeCoverageIgnoreStart
return $this;
Expand All @@ -1008,7 +1008,7 @@ protected function _whereIn(string $key = null, $values = null, bool $not = fals
{
if (CI_DEBUG)
{
throw new InvalidArgumentException(sprintf('%s() expects $values to be of type array or closure', debug_backtrace(0, 2)[1]['function']));
throw new \InvalidArgumentException(sprintf('%s() expects $values to be of type array or closure', debug_backtrace(0, 2)[1]['function']));
}
// @codeCoverageIgnoreStart
return $this;
Expand Down
43 changes: 43 additions & 0 deletions tests/system/Database/Builder/WhereTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,49 @@ public function testWhereInClosure()

//--------------------------------------------------------------------

public function provideInvalidKeys()
{
return [
'null' => [null],
'empty string' => [''],
];
}

/**
* @dataProvider provideInvalidKeys
*/
public function testWhereInvalidKeyThrowInvalidArgumentException($key)
{
$this->expectException(\InvalidArgumentException::class);
$builder = $this->db->table('jobs');

$builder->whereIn($key, ['Politician', 'Accountant']);
}

//--------------------------------------------------------------------

public function provideInvalidValues()
{
return [
'null' => [null],
'not array' => ['not array'],
'not instanceof \Closure' => [new \stdClass],
];
}

/**
* @dataProvider provideInvalidValues
*/
public function testWhereInEmptyValuesThrowInvalidArgumentException($values)
{
$this->expectException(\InvalidArgumentException::class);
$builder = $this->db->table('jobs');

$builder->whereIn('name', $values);
}

//--------------------------------------------------------------------

public function testWhereNotIn()
{
$builder = $this->db->table('jobs');
Expand Down

0 comments on commit 895f1e6

Please sign in to comment.