Skip to content

Commit 76781d7

Browse files
committed
Fixed insert return type and tweaked some tests
1 parent 9f60163 commit 76781d7

File tree

3 files changed

+12
-19
lines changed

3 files changed

+12
-19
lines changed

src/Jenssegers/Mongodb/Query/Builder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ public function insert(array $values)
338338
$this->from . '.batchInsert(' . json_encode($values) . ')',
339339
array(), $this->connection->getElapsedTime($start));
340340

341-
return $result;
341+
return (1 == (int) $result['ok']);
342342
}
343343

344344
/**

tests/ModelTest.php

+3-14
Original file line numberDiff line numberDiff line change
@@ -274,22 +274,11 @@ public function testScope()
274274

275275
public function testToArray()
276276
{
277-
$original = array(
278-
array('name' => 'knife', 'type' => 'sharp'),
279-
array('name' => 'spoon', 'type' => 'round')
280-
);
281-
282-
Item::insert($original);
283-
284-
$items = Item::all();
285-
$this->assertEquals($original, $items->toArray());
286-
$this->assertEquals($original[0], $items[0]->toArray());
287-
288-
// with date
289277
$item = Item::create(array('name' => 'fork', 'type' => 'sharp'));
278+
290279
$array = $item->toArray();
291-
$this->assertTrue(array_key_exists('created_at', $array));
292-
$this->assertTrue(array_key_exists('updated_at', $array));
280+
$keys = array_keys($array); sort($keys);
281+
$this->assertEquals(array('_id', 'created_at', 'name', 'type', 'updated_at'), $keys);
293282
$this->assertTrue(is_string($array['created_at']));
294283
$this->assertTrue(is_string($array['updated_at']));
295284
}

tests/QueryBuilderTest.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,13 @@ public function testDistinct()
271271
array('name' => 'spoon', 'type' => 'round')
272272
));
273273

274-
$items = DB::collection('items')->distinct('name')->get();
275-
$this->assertEquals(array('knife', 'fork', 'spoon'), $items);
274+
$items = DB::collection('items')->distinct('name')->get(); sort($items);
275+
$this->assertEquals(3, count($items));
276+
$this->assertEquals(array('fork', 'knife', 'spoon'), $items);
276277

277-
$types = DB::collection('items')->distinct('type')->get();
278-
$this->assertEquals(array('sharp', 'round'), $types);
278+
$types = DB::collection('items')->distinct('type')->get(); sort($types);
279+
$this->assertEquals(2, count($types));
280+
$this->assertEquals(array('round', 'sharp'), $types);
279281
}
280282

281283
public function testCustomId()
@@ -350,9 +352,11 @@ public function testList()
350352
));
351353

352354
$list = DB::collection('items')->lists('name');
355+
$this->assertEquals(4, count($list));
353356
$this->assertEquals(array('knife', 'fork', 'spoon', 'spoon'), $list);
354357

355358
$list = DB::collection('items')->lists('type', 'name');
359+
$this->assertEquals(3, count($list));
356360
$this->assertEquals(array('knife' => 'sharp', 'fork' => 'sharp', 'spoon' => 'round'), $list);
357361
}
358362

0 commit comments

Comments
 (0)