1
1
<?php
2
2
3
- use Illuminate \Support \Facades \DB ;
4
-
5
- class QueryBuilderTest extends PHPUnit_Framework_TestCase {
6
-
7
- public function setUp () {}
3
+ class QueryBuilderTest extends TestCase {
8
4
9
5
public function tearDown ()
10
6
{
@@ -238,17 +234,25 @@ public function testPush()
238
234
DB ::collection ('users ' )->where ('_id ' , $ id )->push ('messages ' , $ message );
239
235
$ user = DB ::collection ('users ' )->find ($ id );
240
236
$ this ->assertTrue (is_array ($ user ['messages ' ]));
237
+ $ this ->assertEquals (1 , count ($ user ['messages ' ]));
241
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 ' ]));
242
245
}
243
246
244
247
public function testPull ()
245
248
{
246
- $ message = array ('from ' => 'Jane ' , 'body ' => 'Hi John ' );
249
+ $ message1 = array ('from ' => 'Jane ' , 'body ' => 'Hi John ' );
250
+ $ message2 = array ('from ' => 'Mark ' , 'body ' => 'Hi John ' );
247
251
248
252
$ id = DB ::collection ('users ' )->insertGetId (array (
249
253
'name ' => 'John Doe ' ,
250
254
'tags ' => array ('tag1 ' , 'tag2 ' , 'tag3 ' , 'tag4 ' ),
251
- 'messages ' => array ($ message )
255
+ 'messages ' => array ($ message1 , $ message2 )
252
256
));
253
257
254
258
DB ::collection ('users ' )->where ('_id ' , $ id )->pull ('tags ' , 'tag3 ' );
@@ -258,10 +262,16 @@ public function testPull()
258
262
$ this ->assertEquals (3 , count ($ user ['tags ' ]));
259
263
$ this ->assertEquals ('tag4 ' , $ user ['tags ' ][2 ]);
260
264
261
- DB ::collection ('users ' )->where ('_id ' , $ id )->pull ('messages ' , $ message );
265
+ DB ::collection ('users ' )->where ('_id ' , $ id )->pull ('messages ' , $ message1 );
262
266
263
267
$ user = DB ::collection ('users ' )->find ($ id );
264
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 ' ]));
265
275
$ this ->assertEquals (0 , count ($ user ['messages ' ]));
266
276
}
267
277
0 commit comments