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

Fix missing InvalidArgumentException in Database\BaseBuilder #2813

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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']));
}

return $this;
Expand All @@ -1007,7 +1007,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']));
}

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