11
11
use Illuminate \Support \LazyCollection ;
12
12
use Illuminate \Testing \Assert ;
13
13
use Jenssegers \Mongodb \Collection ;
14
- use Jenssegers \Mongodb \Connection ;
15
14
use Jenssegers \Mongodb \Query \Builder ;
16
- use Jenssegers \Mongodb \Query \Processor ;
17
15
use Jenssegers \Mongodb \Tests \Models \Item ;
18
16
use Jenssegers \Mongodb \Tests \Models \User ;
19
- use Mockery as m ;
20
17
use MongoDB \BSON \ObjectId ;
21
18
use MongoDB \BSON \Regex ;
22
19
use MongoDB \BSON \UTCDateTime ;
@@ -34,73 +31,13 @@ public function tearDown(): void
34
31
DB ::collection ('items ' )->truncate ();
35
32
}
36
33
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
-
97
34
public function testDeleteWithId ()
98
35
{
99
36
$ user = DB ::collection ('users ' )->insertGetId ([
100
37
['name ' => 'Jane Doe ' , 'age ' => 20 ],
101
38
]);
102
39
103
- $ user_id = (string ) $ user ;
40
+ $ user_id = (string )$ user ;
104
41
105
42
DB ::collection ('items ' )->insert ([
106
43
['name ' => 'one thing ' , 'user_id ' => $ user_id ],
@@ -111,7 +48,7 @@ public function testDeleteWithId()
111
48
112
49
$ product = DB ::collection ('items ' )->first ();
113
50
114
- $ pid = (string ) ($ product ['_id ' ]);
51
+ $ pid = (string )($ product ['_id ' ]);
115
52
116
53
DB ::collection ('items ' )->where ('user_id ' , $ user_id )->delete ($ pid );
117
54
@@ -892,7 +829,7 @@ public function testValue()
892
829
public function testHintOptions ()
893
830
{
894
831
DB ::collection ('items ' )->insert ([
895
- ['name ' => 'fork ' , 'tags ' => ['sharp ' , 'pointy ' ]],
832
+ ['name ' => 'fork ' , 'tags ' => ['sharp ' , 'pointy ' ]],
896
833
['name ' => 'spork ' , 'tags ' => ['sharp ' , 'pointy ' , 'round ' , 'bowl ' ]],
897
834
['name ' => 'spoon ' , 'tags ' => ['round ' , 'bowl ' ]],
898
835
]);
@@ -926,13 +863,4 @@ public function testCursor()
926
863
$ this ->assertEquals ($ data [$ i ]['name ' ], $ result ['name ' ]);
927
864
}
928
865
}
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
- }
938
866
}
0 commit comments