1111use Illuminate \Support \LazyCollection ;
1212use Illuminate \Testing \Assert ;
1313use Jenssegers \Mongodb \Collection ;
14- use Jenssegers \Mongodb \Connection ;
1514use Jenssegers \Mongodb \Query \Builder ;
16- use Jenssegers \Mongodb \Query \Processor ;
1715use Jenssegers \Mongodb \Tests \Models \Item ;
1816use Jenssegers \Mongodb \Tests \Models \User ;
19- use Mockery as m ;
2017use MongoDB \BSON \ObjectId ;
2118use MongoDB \BSON \Regex ;
2219use MongoDB \BSON \UTCDateTime ;
@@ -34,73 +31,13 @@ public function tearDown(): void
3431 DB ::collection ('items ' )->truncate ();
3532 }
3633
37- /**
38- * @dataProvider provideQueryBuilderToMql
39- */
40- public function testMql (array $ expected , \Closure $ build ): void
41- {
42- $ builder = $ build (self ::getBuilder ());
43- $ this ->assertInstanceOf (Builder::class, $ builder );
44- $ mql = $ builder ->toMql ();
45-
46- // Operations that return a Cursor expect a "typeMap" option.
47- if (isset ($ expected ['find ' ][1 ])) {
48- $ expected ['find ' ][1 ]['typeMap ' ] = ['root ' => 'array ' , 'document ' => 'array ' ];
49- }
50- if (isset ($ expected ['aggregate ' ][1 ])) {
51- $ expected ['aggregate ' ][1 ]['typeMap ' ] = ['root ' => 'array ' , 'document ' => 'array ' ];
52- }
53-
54- // Compare with assertEquals because the query can contain BSON objects.
55- $ this ->assertEquals ($ expected , $ mql , var_export ($ mql , true ));
56- }
57-
58- public static function provideQueryBuilderToMql (): iterable
59- {
60- /**
61- * Builder::aggregate() and Builder::count() cannot be tested because they return the result,
62- * without modifying the builder.
63- */
64- $ date = new DateTimeImmutable ('2016-07-12 15:30:00 ' );
65-
66- yield [
67- ['find ' => [['foo ' => 'bar ' ], []]],
68- fn (Builder $ builder ) => $ builder ->where ('foo ' , 'bar ' ),
69- ];
70-
71- yield [
72- ['find ' => [['foo ' => ['$gt ' => new UTCDateTime ($ date )]], []]],
73- fn (Builder $ builder ) => $ builder ->where ('foo ' , '> ' , $ date ),
74- ];
75-
76- yield [
77- ['find ' => [['foo ' => ['$in ' => ['bar ' , 'baz ' ]]], []]],
78- fn (Builder $ builder ) => $ builder ->whereIn ('foo ' , ['bar ' , 'baz ' ]),
79- ];
80-
81- yield [
82- ['find ' => [[], ['limit ' => 10 , 'skip ' => 5 , 'projection ' => ['foo ' => 1 , 'bar ' => 1 ]]]],
83- fn (Builder $ builder ) => $ builder ->limit (10 )->offset (5 )->select ('foo ' , 'bar ' ),
84- ];
85-
86- yield [
87- ['distinct ' => ['foo ' , [], []]],
88- fn (Builder $ builder ) => $ builder ->distinct ('foo ' ),
89- ];
90-
91- yield [
92- ['aggregate ' => [[['$group ' => ['_id ' => ['foo ' => '$foo ' ], 'foo ' => ['$last ' => '$foo ' ]]]], []]],
93- fn (Builder $ builder ) => $ builder ->groupBy ('foo ' ),
94- ];
95- }
96-
9734 public function testDeleteWithId ()
9835 {
9936 $ user = DB ::collection ('users ' )->insertGetId ([
10037 ['name ' => 'Jane Doe ' , 'age ' => 20 ],
10138 ]);
10239
103- $ user_id = (string ) $ user ;
40+ $ user_id = (string )$ user ;
10441
10542 DB ::collection ('items ' )->insert ([
10643 ['name ' => 'one thing ' , 'user_id ' => $ user_id ],
@@ -111,7 +48,7 @@ public function testDeleteWithId()
11148
11249 $ product = DB ::collection ('items ' )->first ();
11350
114- $ pid = (string ) ($ product ['_id ' ]);
51+ $ pid = (string )($ product ['_id ' ]);
11552
11653 DB ::collection ('items ' )->where ('user_id ' , $ user_id )->delete ($ pid );
11754
@@ -892,7 +829,7 @@ public function testValue()
892829 public function testHintOptions ()
893830 {
894831 DB ::collection ('items ' )->insert ([
895- ['name ' => 'fork ' , 'tags ' => ['sharp ' , 'pointy ' ]],
832+ ['name ' => 'fork ' , 'tags ' => ['sharp ' , 'pointy ' ]],
896833 ['name ' => 'spork ' , 'tags ' => ['sharp ' , 'pointy ' , 'round ' , 'bowl ' ]],
897834 ['name ' => 'spoon ' , 'tags ' => ['round ' , 'bowl ' ]],
898835 ]);
@@ -926,13 +863,4 @@ public function testCursor()
926863 $ this ->assertEquals ($ data [$ i ]['name ' ], $ result ['name ' ]);
927864 }
928865 }
929-
930- private static function getBuilder (): Builder
931- {
932- $ connection = m::mock (Connection::class);
933- $ processor = m::mock (Processor::class);
934- $ connection ->shouldReceive ('getSession ' )->andReturn (null );
935-
936- return new Builder ($ connection , $ processor );
937- }
938866}
0 commit comments