Skip to content

Commit

Permalink
Adding tests for raw push and pull
Browse files Browse the repository at this point in the history
  • Loading branch information
jenssegers committed Apr 5, 2014
1 parent e7769af commit 11f0f83
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
20 changes: 17 additions & 3 deletions tests/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,25 @@ public function testPush()
DB::collection('users')->where('_id', $id)->push('messages', $message);
$user = DB::collection('users')->find($id);
$this->assertTrue(is_array($user['messages']));
$this->assertEquals(1, count($user['messages']));
$this->assertEquals($message, $user['messages'][0]);

// Raw
DB::collection('users')->where('_id', $id)->push(array('tags' => 'tag3', 'messages' => array('from' => 'Mark', 'body' => 'Hi John')));
$user = DB::collection('users')->find($id);
$this->assertEquals(4, count($user['tags']));
$this->assertEquals(2, count($user['messages']));
}

public function testPull()
{
$message = array('from' => 'Jane', 'body' => 'Hi John');
$message1 = array('from' => 'Jane', 'body' => 'Hi John');
$message2 = array('from' => 'Mark', 'body' => 'Hi John');

$id = DB::collection('users')->insertGetId(array(
'name' => 'John Doe',
'tags' => array('tag1', 'tag2', 'tag3', 'tag4'),
'messages' => array($message)
'messages' => array($message1, $message2)
));

DB::collection('users')->where('_id', $id)->pull('tags', 'tag3');
Expand All @@ -254,10 +262,16 @@ public function testPull()
$this->assertEquals(3, count($user['tags']));
$this->assertEquals('tag4', $user['tags'][2]);

DB::collection('users')->where('_id', $id)->pull('messages', $message);
DB::collection('users')->where('_id', $id)->pull('messages', $message1);

$user = DB::collection('users')->find($id);
$this->assertTrue(is_array($user['messages']));
$this->assertEquals(1, count($user['messages']));

// Raw
DB::collection('users')->where('_id', $id)->pull(array('tags' => 'tag2', 'messages' => $message2));
$user = DB::collection('users')->find($id);
$this->assertEquals(2, count($user['tags']));
$this->assertEquals(0, count($user['messages']));
}

Expand Down
6 changes: 6 additions & 0 deletions tests/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,14 @@ public function testGroupBy()
$this->assertEquals(33, $users[2]->age);

$users = User::groupBy('age')->skip(1)->take(2)->orderBy('age', 'desc')->get();
$this->assertEquals(2, count($users));
$this->assertEquals(35, $users[0]->age);
$this->assertEquals(33, $users[1]->age);
$this->assertNull($users[0]->name);

$users = User::select('name')->groupBy('age')->skip(1)->take(2)->orderBy('age', 'desc')->get();
$this->assertEquals(2, count($users));
$this->assertNotNull($users[0]->name);
}

public function testCount()
Expand Down

0 comments on commit 11f0f83

Please sign in to comment.