Skip to content

Commit 209b301

Browse files
committed
Tweaked tests and fixed pluck bug
1 parent 03cee24 commit 209b301

File tree

5 files changed

+535
-497
lines changed

5 files changed

+535
-497
lines changed

src/Jenssegers/Mongodb/Builder.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,26 @@ public function decrement($column, $amount = 1, array $extra = array())
359359
return $this->increment($column, -1 * $amount, $extra);
360360
}
361361

362+
/**
363+
* Pluck a single column from the database.
364+
*
365+
* @param string $column
366+
* @return mixed
367+
*/
368+
public function pluck($column)
369+
{
370+
$result = (array) $this->first(array($column));
371+
372+
// MongoDB returns the _id field even if you did not ask for it, so we need to
373+
// remove this from the result.
374+
if (array_key_exists('_id', $result))
375+
{
376+
unset($result['_id']);
377+
}
378+
379+
return count($result) > 0 ? reset($result) : null;
380+
}
381+
362382
/**
363383
* Delete a record from the database.
364384
*

tests/CacheTest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@
55

66
class CacheTest extends PHPUnit_Framework_TestCase {
77

8+
protected $cache;
9+
810
public function setUp()
911
{
10-
// test data
12+
# clear cache
13+
global $app;
14+
$this->cache = $app['cache'];
15+
1116
User::create(array('name' => 'John Doe', 'age' => 35, 'title' => 'admin'));
1217
User::create(array('name' => 'Jane Doe', 'age' => 33, 'title' => 'admin'));
1318
User::create(array('name' => 'Harry Hoe', 'age' => 13, 'title' => 'user'));
@@ -16,15 +21,11 @@ public function setUp()
1621
public function tearDown()
1722
{
1823
User::truncate();
24+
$this->cache->forget('db.users');
1925
}
2026

2127
public function testCache()
2228
{
23-
# get from cache driver
24-
global $app;
25-
$cache = $app['cache'];
26-
$cache->forget('db.users');
27-
2829
# auto generate cache key
2930
$users = DB::collection('users')->where('age', '>', 10)->remember(10)->get();
3031
$this->assertEquals(3, count($users));
@@ -36,7 +37,7 @@ public function testCache()
3637
$users = User::where('age', '>', 10)->remember(10, 'db.users')->get();
3738
$this->assertEquals(3, count($users));
3839

39-
$users = $cache->get('db.users');
40+
$users = $this->cache->get('db.users');
4041
$this->assertEquals(3, count($users));
4142
}
4243

tests/ModelQueryTest.php

Lines changed: 0 additions & 328 deletions
This file was deleted.

0 commit comments

Comments
 (0)