@@ -196,7 +196,8 @@ public function testPush()
196
196
{
197
197
$ id = DB ::collection ('users ' )->insertGetId (array (
198
198
'name ' => 'John Doe ' ,
199
- 'tags ' => array ()
199
+ 'tags ' => array (),
200
+ 'messages ' => array (),
200
201
));
201
202
202
203
DB ::collection ('users ' )->where ('_id ' , $ id )->push ('tags ' , 'tag1 ' );
@@ -213,19 +214,22 @@ public function testPush()
213
214
$ this ->assertEquals (2 , count ($ user ['tags ' ]));
214
215
$ this ->assertEquals ('tag2 ' , $ user ['tags ' ][1 ]);
215
216
216
- DB ::collection ('users ' )->where ('_id ' , $ id )->push ('tags ' , array ('tag3 ' , 'tag4 ' ));
217
-
217
+ $ message = array ('from ' => 'Jane ' , 'body ' => 'Hi John ' );
218
+ DB ::collection ('users ' )->where ('_id ' , $ id )->push ('messages ' , $ message );
219
+
218
220
$ user = DB ::collection ('users ' )->find ($ id );
219
- $ this ->assertTrue (is_array ($ user ['tags ' ]));
220
- $ this ->assertEquals (4 , count ($ user ['tags ' ]));
221
- $ this ->assertEquals ('tag4 ' , $ user ['tags ' ][3 ]);
221
+ $ this ->assertTrue (is_array ($ user ['messages ' ]));
222
+ $ this ->assertEquals ($ message , $ user ['messages ' ][0 ]);
222
223
}
223
224
224
225
public function testPull ()
225
226
{
227
+ $ message = array ('from ' => 'Jane ' , 'body ' => 'Hi John ' );
228
+
226
229
$ id = DB ::collection ('users ' )->insertGetId (array (
227
230
'name ' => 'John Doe ' ,
228
- 'tags ' => array ('tag1 ' , 'tag2 ' , 'tag3 ' , 'tag4 ' )
231
+ 'tags ' => array ('tag1 ' , 'tag2 ' , 'tag3 ' , 'tag4 ' ),
232
+ 'messages ' => array ($ message )
229
233
));
230
234
231
235
DB ::collection ('users ' )->where ('_id ' , $ id )->pull ('tags ' , 'tag3 ' );
@@ -235,12 +239,11 @@ public function testPull()
235
239
$ this ->assertEquals (3 , count ($ user ['tags ' ]));
236
240
$ this ->assertEquals ('tag4 ' , $ user ['tags ' ][2 ]);
237
241
238
- DB ::collection ('users ' )->where ('_id ' , $ id )->pull ('tags ' , array ( ' tag2 ' , ' tag4 ' ) );
239
-
242
+ DB ::collection ('users ' )->where ('_id ' , $ id )->pull ('messages ' , $ message );
243
+
240
244
$ user = DB ::collection ('users ' )->find ($ id );
241
- $ this ->assertTrue (is_array ($ user ['tags ' ]));
242
- $ this ->assertEquals (1 , count ($ user ['tags ' ]));
243
- $ this ->assertEquals ('tag1 ' , $ user ['tags ' ][0 ]);
245
+ $ this ->assertTrue (is_array ($ user ['messages ' ]));
246
+ $ this ->assertEquals (0 , count ($ user ['messages ' ]));
244
247
}
245
248
246
249
public function testDistinct ()
0 commit comments