Commit 76781d79 authored by Jens Segers's avatar Jens Segers

Fixed insert return type and tweaked some tests

parent 9f601636
......@@ -338,7 +338,7 @@ class Builder extends \Illuminate\Database\Query\Builder {
$this->from . '.batchInsert(' . json_encode($values) . ')',
array(), $this->connection->getElapsedTime($start));
return $result;
return (1 == (int) $result['ok']);
}
/**
......
......@@ -274,22 +274,11 @@ class ModelTest extends PHPUnit_Framework_TestCase {
public function testToArray()
{
$original = array(
array('name' => 'knife', 'type' => 'sharp'),
array('name' => 'spoon', 'type' => 'round')
);
Item::insert($original);
$items = Item::all();
$this->assertEquals($original, $items->toArray());
$this->assertEquals($original[0], $items[0]->toArray());
// with date
$item = Item::create(array('name' => 'fork', 'type' => 'sharp'));
$array = $item->toArray();
$this->assertTrue(array_key_exists('created_at', $array));
$this->assertTrue(array_key_exists('updated_at', $array));
$keys = array_keys($array); sort($keys);
$this->assertEquals(array('_id', 'created_at', 'name', 'type', 'updated_at'), $keys);
$this->assertTrue(is_string($array['created_at']));
$this->assertTrue(is_string($array['updated_at']));
}
......
......@@ -271,11 +271,13 @@ class QueryBuilderTest extends PHPUnit_Framework_TestCase {
array('name' => 'spoon', 'type' => 'round')
));
$items = DB::collection('items')->distinct('name')->get();
$this->assertEquals(array('knife', 'fork', 'spoon'), $items);
$items = DB::collection('items')->distinct('name')->get(); sort($items);
$this->assertEquals(3, count($items));
$this->assertEquals(array('fork', 'knife', 'spoon'), $items);
$types = DB::collection('items')->distinct('type')->get();
$this->assertEquals(array('sharp', 'round'), $types);
$types = DB::collection('items')->distinct('type')->get(); sort($types);
$this->assertEquals(2, count($types));
$this->assertEquals(array('round', 'sharp'), $types);
}
public function testCustomId()
......@@ -350,9 +352,11 @@ class QueryBuilderTest extends PHPUnit_Framework_TestCase {
));
$list = DB::collection('items')->lists('name');
$this->assertEquals(4, count($list));
$this->assertEquals(array('knife', 'fork', 'spoon', 'spoon'), $list);
$list = DB::collection('items')->lists('type', 'name');
$this->assertEquals(3, count($list));
$this->assertEquals(array('knife' => 'sharp', 'fork' => 'sharp', 'spoon' => 'round'), $list);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment