@@ -18,11 +18,22 @@ public function testCollection()
1818 $ this ->assertInstanceOf ('Jenssegers\Mongodb\Builder ' , DB ::collection ('users ' ));
1919 }
2020
21+ public function testGet ()
22+ {
23+ $ users = DB ::collection ('users ' )->get ();
24+ $ this ->assertEquals (0 , count ($ users ));
25+
26+ DB ::collection ('users ' )->insert (array ('name ' => 'John Doe ' ));
27+
28+ $ users = DB ::collection ('users ' )->get ();
29+ $ this ->assertEquals (1 , count ($ users ));
30+ }
31+
2132 public function testInsert ()
2233 {
2334 $ user = array (
35+ 'tags ' => array ('tag1 ' , 'tag2 ' ),
2436 'name ' => 'John Doe ' ,
25- 'tags ' => array ('tag1 ' , 'tag2 ' )
2637 );
2738 DB ::collection ('users ' )->insert ($ user );
2839
@@ -38,12 +49,12 @@ public function testBatchInsert()
3849 {
3950 $ users = array (
4051 array (
41- 'name ' => ' Jane Doe ' ,
42- 'tags ' => array ( ' tag1 ' , ' tag2 ' )
52+ 'tags ' => array ( ' tag1 ' , ' tag2 ' ) ,
53+ 'name ' => ' Jane Doe ' ,
4354 ),
4455 array (
56+ 'tags ' => array ('tag3 ' ),
4557 'name ' => 'John Doe ' ,
46- 'tags ' => array ('tag3 ' )
4758 ),
4859 );
4960 DB ::collection ('users ' )->insert ($ users );
@@ -68,6 +79,33 @@ public function testFind()
6879 $ this ->assertEquals ('John Doe ' , $ user ['name ' ]);
6980 }
7081
82+ public function testUpdate ()
83+ {
84+ DB ::collection ('users ' )->insert (array ('name ' => 'John Doe ' , 'age ' => 10 ));
85+ DB ::collection ('users ' )->where ('name ' , 'John Doe ' )->update (array ('age ' => 100 ));
86+
87+ $ user = User::where ('name ' , 'John Doe ' )->first ();
88+ $ this ->assertEquals (100 , $ user ->age );
89+ }
90+
91+ public function testDelete ()
92+ {
93+ DB ::collection ('users ' )->insert (array ('name ' => 'John Doe ' , 'age ' => 100 ));
94+
95+ DB ::collection ('users ' )->where ('age ' , '< ' , 30 )->delete ();
96+ $ this ->assertEquals (1 , DB ::collection ('users ' )->count ());
97+
98+ DB ::collection ('users ' )->where ('age ' , '> ' , 30 )->delete ();
99+ $ this ->assertEquals (0 , DB ::collection ('users ' )->count ());
100+ }
101+
102+ public function testTruncate ()
103+ {
104+ DB ::collection ('users ' )->insert (array ('name ' => 'John Doe ' , 'age ' => 100 ));
105+ DB ::collection ('users ' )->truncate ();
106+ $ this ->assertEquals (0 , DB ::collection ('users ' )->count ());
107+ }
108+
71109 public function testSubKey ()
72110 {
73111 $ user1 = array (
@@ -97,11 +135,11 @@ public function testInArray()
97135 {
98136 $ item1 = array (
99137 'tags ' => array ('tag1 ' , 'tag2 ' , 'tag3 ' , 'tag4 ' )
100- );
138+ );
101139
102140 $ item2 = array (
103141 'tags ' => array ('tag2 ' )
104- );
142+ );
105143
106144 DB ::collection ('items ' )->insert (array ($ item1 , $ item2 ));
107145
0 commit comments