Commit e3f8c872 authored by Jens Segers's avatar Jens Segers

More tests

parent fb259e92
...@@ -284,21 +284,6 @@ class ModelQueryTest extends PHPUnit_Framework_TestCase { ...@@ -284,21 +284,6 @@ class ModelQueryTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(5, count($users)); $this->assertEquals(5, count($users));
} }
public function testUpdate()
{
User::where('name', 'John Doe')
->update(array('age' => 100));
$user = User::where('name', 'John Doe')->first();
$this->assertEquals(100, $user->age);
}
public function testDelete()
{
User::where('age', '>', 30)->delete();
$this->assertEquals(3, User::count());
}
public function testInsert() public function testInsert()
{ {
User::insert( User::insert(
......
...@@ -18,11 +18,22 @@ class QueryTest extends PHPUnit_Framework_TestCase { ...@@ -18,11 +18,22 @@ class QueryTest extends PHPUnit_Framework_TestCase {
$this->assertInstanceOf('Jenssegers\Mongodb\Builder', DB::collection('users')); $this->assertInstanceOf('Jenssegers\Mongodb\Builder', DB::collection('users'));
} }
public function testGet()
{
$users = DB::collection('users')->get();
$this->assertEquals(0, count($users));
DB::collection('users')->insert(array('name' => 'John Doe'));
$users = DB::collection('users')->get();
$this->assertEquals(1, count($users));
}
public function testInsert() public function testInsert()
{ {
$user = array( $user = array(
'tags' => array('tag1', 'tag2'),
'name' => 'John Doe', 'name' => 'John Doe',
'tags' => array('tag1', 'tag2')
); );
DB::collection('users')->insert($user); DB::collection('users')->insert($user);
...@@ -38,12 +49,12 @@ class QueryTest extends PHPUnit_Framework_TestCase { ...@@ -38,12 +49,12 @@ class QueryTest extends PHPUnit_Framework_TestCase {
{ {
$users = array( $users = array(
array( array(
'name' => 'Jane Doe', 'tags' => array('tag1', 'tag2'),
'tags' => array('tag1', 'tag2') 'name' => 'Jane Doe',
), ),
array( array(
'tags' => array('tag3'),
'name' => 'John Doe', 'name' => 'John Doe',
'tags' => array('tag3')
), ),
); );
DB::collection('users')->insert($users); DB::collection('users')->insert($users);
...@@ -68,6 +79,33 @@ class QueryTest extends PHPUnit_Framework_TestCase { ...@@ -68,6 +79,33 @@ class QueryTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('John Doe', $user['name']); $this->assertEquals('John Doe', $user['name']);
} }
public function testUpdate()
{
DB::collection('users')->insert(array('name' => 'John Doe', 'age' => 10));
DB::collection('users')->where('name', 'John Doe')->update(array('age' => 100));
$user = User::where('name', 'John Doe')->first();
$this->assertEquals(100, $user->age);
}
public function testDelete()
{
DB::collection('users')->insert(array('name' => 'John Doe', 'age' => 100));
DB::collection('users')->where('age', '<', 30)->delete();
$this->assertEquals(1, DB::collection('users')->count());
DB::collection('users')->where('age', '>', 30)->delete();
$this->assertEquals(0, DB::collection('users')->count());
}
public function testTruncate()
{
DB::collection('users')->insert(array('name' => 'John Doe', 'age' => 100));
DB::collection('users')->truncate();
$this->assertEquals(0, DB::collection('users')->count());
}
public function testSubKey() public function testSubKey()
{ {
$user1 = array( $user1 = array(
...@@ -97,11 +135,11 @@ class QueryTest extends PHPUnit_Framework_TestCase { ...@@ -97,11 +135,11 @@ class QueryTest extends PHPUnit_Framework_TestCase {
{ {
$item1 = array( $item1 = array(
'tags' => array('tag1', 'tag2', 'tag3', 'tag4') 'tags' => array('tag1', 'tag2', 'tag3', 'tag4')
); );
$item2 = array( $item2 = array(
'tags' => array('tag2') 'tags' => array('tag2')
); );
DB::collection('items')->insert(array($item1, $item2)); DB::collection('items')->insert(array($item1, $item2));
......
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