Skip to content

Commit 895f1e6

Browse files
authored
Merge pull request #2813 from samsonasik/fix-missing-invalidargumentexception-basebuilder
Fix missing InvalidArgumentException in Database\BaseBuilder
2 parents 3ededb0 + 227f2d0 commit 895f1e6

2 files changed

Lines changed: 45 additions & 2 deletions

File tree

system/Database/BaseBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ protected function _whereIn(string $key = null, $values = null, bool $not = fals
997997
{
998998
if (CI_DEBUG)
999999
{
1000-
throw new InvalidArgumentException(sprintf('%s() expects $key to be a non-empty string', debug_backtrace(0, 2)[1]['function']));
1000+
throw new \InvalidArgumentException(sprintf('%s() expects $key to be a non-empty string', debug_backtrace(0, 2)[1]['function']));
10011001
}
10021002
// @codeCoverageIgnoreStart
10031003
return $this;
@@ -1008,7 +1008,7 @@ protected function _whereIn(string $key = null, $values = null, bool $not = fals
10081008
{
10091009
if (CI_DEBUG)
10101010
{
1011-
throw new InvalidArgumentException(sprintf('%s() expects $values to be of type array or closure', debug_backtrace(0, 2)[1]['function']));
1011+
throw new \InvalidArgumentException(sprintf('%s() expects $values to be of type array or closure', debug_backtrace(0, 2)[1]['function']));
10121012
}
10131013
// @codeCoverageIgnoreStart
10141014
return $this;

tests/system/Database/Builder/WhereTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,49 @@ public function testWhereInClosure()
221221

222222
//--------------------------------------------------------------------
223223

224+
public function provideInvalidKeys()
225+
{
226+
return [
227+
'null' => [null],
228+
'empty string' => [''],
229+
];
230+
}
231+
232+
/**
233+
* @dataProvider provideInvalidKeys
234+
*/
235+
public function testWhereInvalidKeyThrowInvalidArgumentException($key)
236+
{
237+
$this->expectException(\InvalidArgumentException::class);
238+
$builder = $this->db->table('jobs');
239+
240+
$builder->whereIn($key, ['Politician', 'Accountant']);
241+
}
242+
243+
//--------------------------------------------------------------------
244+
245+
public function provideInvalidValues()
246+
{
247+
return [
248+
'null' => [null],
249+
'not array' => ['not array'],
250+
'not instanceof \Closure' => [new \stdClass],
251+
];
252+
}
253+
254+
/**
255+
* @dataProvider provideInvalidValues
256+
*/
257+
public function testWhereInEmptyValuesThrowInvalidArgumentException($values)
258+
{
259+
$this->expectException(\InvalidArgumentException::class);
260+
$builder = $this->db->table('jobs');
261+
262+
$builder->whereIn('name', $values);
263+
}
264+
265+
//--------------------------------------------------------------------
266+
224267
public function testWhereNotIn()
225268
{
226269
$builder = $this->db->table('jobs');

0 commit comments

Comments
 (0)