@@ -18,11 +18,22 @@ public function testCollection()
18
18
$ this ->assertInstanceOf ('Jenssegers\Mongodb\Builder ' , DB ::collection ('users ' ));
19
19
}
20
20
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
+
21
32
public function testInsert ()
22
33
{
23
34
$ user = array (
35
+ 'tags ' => array ('tag1 ' , 'tag2 ' ),
24
36
'name ' => 'John Doe ' ,
25
- 'tags ' => array ('tag1 ' , 'tag2 ' )
26
37
);
27
38
DB ::collection ('users ' )->insert ($ user );
28
39
@@ -38,12 +49,12 @@ public function testBatchInsert()
38
49
{
39
50
$ users = array (
40
51
array (
41
- 'name ' => ' Jane Doe ' ,
42
- 'tags ' => array ( ' tag1 ' , ' tag2 ' )
52
+ 'tags ' => array ( ' tag1 ' , ' tag2 ' ) ,
53
+ 'name ' => ' Jane Doe ' ,
43
54
),
44
55
array (
56
+ 'tags ' => array ('tag3 ' ),
45
57
'name ' => 'John Doe ' ,
46
- 'tags ' => array ('tag3 ' )
47
58
),
48
59
);
49
60
DB ::collection ('users ' )->insert ($ users );
@@ -68,6 +79,33 @@ public function testFind()
68
79
$ this ->assertEquals ('John Doe ' , $ user ['name ' ]);
69
80
}
70
81
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
+
71
109
public function testSubKey ()
72
110
{
73
111
$ user1 = array (
@@ -97,11 +135,11 @@ public function testInArray()
97
135
{
98
136
$ item1 = array (
99
137
'tags ' => array ('tag1 ' , 'tag2 ' , 'tag3 ' , 'tag4 ' )
100
- );
138
+ );
101
139
102
140
$ item2 = array (
103
141
'tags ' => array ('tag2 ' )
104
- );
142
+ );
105
143
106
144
DB ::collection ('items ' )->insert (array ($ item1 , $ item2 ));
107
145
0 commit comments