Skip to content

Commit cddb4f3

Browse files
authored
[10.x] Extended pluck() testcases (#48657)
* Update QueryBuilderTest.php * style
1 parent fcceb52 commit cddb4f3

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/Integration/Database/QueryBuilderTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,4 +398,42 @@ public function testChunkMap()
398398
$this->assertSame('Bar Post', $results[1]);
399399
$this->assertCount(3, DB::getQueryLog());
400400
}
401+
402+
public function testPluck()
403+
{
404+
// Test SELECT override, since pluck will take the first column.
405+
$this->assertSame([
406+
'Foo Post',
407+
'Bar Post',
408+
], DB::table('posts')->select(['content', 'id', 'title'])->pluck('title')->toArray());
409+
410+
// Test without SELECT override.
411+
$this->assertSame([
412+
'Foo Post',
413+
'Bar Post',
414+
], DB::table('posts')->pluck('title')->toArray());
415+
416+
// Test specific key.
417+
$this->assertSame([
418+
1 => 'Foo Post',
419+
2 => 'Bar Post',
420+
], DB::table('posts')->pluck('title', 'id')->toArray());
421+
422+
$results = DB::table('posts')->pluck('title', 'created_at');
423+
424+
// Test timestamps (truncates RDBMS differences).
425+
$this->assertSame([
426+
'2017-11-12 13:14:15',
427+
'2018-01-02 03:04:05',
428+
], $results->keys()->map(fn ($v) => substr($v, 0, 19))->toArray());
429+
$this->assertSame([
430+
'Foo Post',
431+
'Bar Post',
432+
], $results->values()->toArray());
433+
434+
// Test duplicate keys (a match will override a previous match).
435+
$this->assertSame([
436+
'Lorem Ipsum.' => 'Bar Post',
437+
], DB::table('posts')->pluck('title', 'content')->toArray());
438+
}
401439
}

0 commit comments

Comments
 (0)