Skip to content

Commit 620e5b3

Browse files
committed
Adding tests for issue mongodb#27
1 parent c02ad8d commit 620e5b3

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

tests/ModelTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,19 @@ public function testFirst()
146146
$this->assertEquals('John Doe', $user->name);
147147
}
148148

149+
public function testNoDocument()
150+
{
151+
$items = Item::where('name', 'nothing')->get();
152+
$this->assertInstanceOf('Illuminate\Database\Eloquent\Collection', $items);
153+
$this->assertEquals(0, $items->count());
154+
155+
$item =Item::where('name', 'nothing')->first();
156+
$this->assertEquals(null, $item);
157+
158+
$item = Item::find('51c33d8981fec6813e00000a');
159+
$this->assertEquals(null, $item);
160+
}
161+
149162
/**
150163
* @expectedException Illuminate\Database\Eloquent\ModelNotFoundException
151164
*/

tests/QueryBuilderTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ public function testGet()
2929
$this->assertEquals(1, count($users));
3030
}
3131

32+
public function testNoDocument()
33+
{
34+
$items = DB::collection('items')->where('name', 'nothing')->get();
35+
$this->assertEquals(array(), $items);
36+
37+
$item = DB::collection('items')->where('name', 'nothing')->first();
38+
$this->assertEquals(null, $item);
39+
40+
$item = DB::collection('items')->where('_id', '51c33d8981fec6813e00000a')->first();
41+
$this->assertEquals(null, $item);
42+
}
43+
3244
public function testInsert()
3345
{
3446
DB::collection('users')->insert(array(

0 commit comments

Comments
 (0)