@@ -234,17 +234,25 @@ public function testPush()
234
234
DB ::collection ('users ' )->where ('_id ' , $ id )->push ('messages ' , $ message );
235
235
$ user = DB ::collection ('users ' )->find ($ id );
236
236
$ this ->assertTrue (is_array ($ user ['messages ' ]));
237
+ $ this ->assertEquals (1 , count ($ user ['messages ' ]));
237
238
$ this ->assertEquals ($ message , $ user ['messages ' ][0 ]);
239
+
240
+ // Raw
241
+ DB ::collection ('users ' )->where ('_id ' , $ id )->push (array ('tags ' => 'tag3 ' , 'messages ' => array ('from ' => 'Mark ' , 'body ' => 'Hi John ' )));
242
+ $ user = DB ::collection ('users ' )->find ($ id );
243
+ $ this ->assertEquals (4 , count ($ user ['tags ' ]));
244
+ $ this ->assertEquals (2 , count ($ user ['messages ' ]));
238
245
}
239
246
240
247
public function testPull ()
241
248
{
242
- $ message = array ('from ' => 'Jane ' , 'body ' => 'Hi John ' );
249
+ $ message1 = array ('from ' => 'Jane ' , 'body ' => 'Hi John ' );
250
+ $ message2 = array ('from ' => 'Mark ' , 'body ' => 'Hi John ' );
243
251
244
252
$ id = DB ::collection ('users ' )->insertGetId (array (
245
253
'name ' => 'John Doe ' ,
246
254
'tags ' => array ('tag1 ' , 'tag2 ' , 'tag3 ' , 'tag4 ' ),
247
- 'messages ' => array ($ message )
255
+ 'messages ' => array ($ message1 , $ message2 )
248
256
));
249
257
250
258
DB ::collection ('users ' )->where ('_id ' , $ id )->pull ('tags ' , 'tag3 ' );
@@ -254,10 +262,16 @@ public function testPull()
254
262
$ this ->assertEquals (3 , count ($ user ['tags ' ]));
255
263
$ this ->assertEquals ('tag4 ' , $ user ['tags ' ][2 ]);
256
264
257
- DB ::collection ('users ' )->where ('_id ' , $ id )->pull ('messages ' , $ message );
265
+ DB ::collection ('users ' )->where ('_id ' , $ id )->pull ('messages ' , $ message1 );
258
266
259
267
$ user = DB ::collection ('users ' )->find ($ id );
260
268
$ this ->assertTrue (is_array ($ user ['messages ' ]));
269
+ $ this ->assertEquals (1 , count ($ user ['messages ' ]));
270
+
271
+ // Raw
272
+ DB ::collection ('users ' )->where ('_id ' , $ id )->pull (array ('tags ' => 'tag2 ' , 'messages ' => $ message2 ));
273
+ $ user = DB ::collection ('users ' )->find ($ id );
274
+ $ this ->assertEquals (2 , count ($ user ['tags ' ]));
261
275
$ this ->assertEquals (0 , count ($ user ['messages ' ]));
262
276
}
263
277
0 commit comments