11<?php
22
3- use Illuminate \Support \Facades \DB ;
4-
5- class QueryBuilderTest extends PHPUnit_Framework_TestCase {
6-
7- public function setUp () {}
3+ class QueryBuilderTest extends TestCase {
84
95 public function tearDown ()
106 {
@@ -238,17 +234,25 @@ public function testPush()
238234 DB ::collection ('users ' )->where ('_id ' , $ id )->push ('messages ' , $ message );
239235 $ user = DB ::collection ('users ' )->find ($ id );
240236 $ this ->assertTrue (is_array ($ user ['messages ' ]));
237+ $ this ->assertEquals (1 , count ($ user ['messages ' ]));
241238 $ 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 ' ]));
242245 }
243246
244247 public function testPull ()
245248 {
246- $ message = array ('from ' => 'Jane ' , 'body ' => 'Hi John ' );
249+ $ message1 = array ('from ' => 'Jane ' , 'body ' => 'Hi John ' );
250+ $ message2 = array ('from ' => 'Mark ' , 'body ' => 'Hi John ' );
247251
248252 $ id = DB ::collection ('users ' )->insertGetId (array (
249253 'name ' => 'John Doe ' ,
250254 'tags ' => array ('tag1 ' , 'tag2 ' , 'tag3 ' , 'tag4 ' ),
251- 'messages ' => array ($ message )
255+ 'messages ' => array ($ message1 , $ message2 )
252256 ));
253257
254258 DB ::collection ('users ' )->where ('_id ' , $ id )->pull ('tags ' , 'tag3 ' );
@@ -258,10 +262,16 @@ public function testPull()
258262 $ this ->assertEquals (3 , count ($ user ['tags ' ]));
259263 $ this ->assertEquals ('tag4 ' , $ user ['tags ' ][2 ]);
260264
261- DB ::collection ('users ' )->where ('_id ' , $ id )->pull ('messages ' , $ message );
265+ DB ::collection ('users ' )->where ('_id ' , $ id )->pull ('messages ' , $ message1 );
262266
263267 $ user = DB ::collection ('users ' )->find ($ id );
264268 $ 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 ' ]));
265275 $ this ->assertEquals (0 , count ($ user ['messages ' ]));
266276 }
267277
0 commit comments