File tree 3 files changed +37
-10
lines changed
src/Jenssegers/Mongodb/Schema
3 files changed +37
-10
lines changed Original file line number Diff line number Diff line change @@ -78,11 +78,21 @@ public function dropIndex($columns = null)
78
78
{
79
79
$ columns = $ this ->fluent ($ columns );
80
80
81
- foreach ($ columns as $ column )
81
+ // Columns are passed as a default array
82
+ if (is_array ($ columns ) && is_int (key ($ columns )))
82
83
{
83
- $ this ->collection ->deleteIndex ($ column );
84
+ // Transform the columns to the required array format
85
+ $ transform = array ();
86
+ foreach ($ columns as $ column )
87
+ {
88
+ $ transform [$ column ] = 1 ;
89
+ }
90
+
91
+ $ columns = $ transform ;
84
92
}
85
93
94
+ $ this ->collection ->deleteIndex ($ columns );
95
+
86
96
return $ this ;
87
97
}
88
98
Original file line number Diff line number Diff line change @@ -34,6 +34,14 @@ public function testIndex()
34
34
35
35
$ index = $ this ->getIndex ('newcollection ' , 'mykey ' );
36
36
$ this ->assertEquals (1 , $ index ['key ' ]['mykey ' ]);
37
+
38
+ Schema::collection ('newcollection ' , function ($ collection )
39
+ {
40
+ $ collection ->index (array ('mykey ' ));
41
+ });
42
+
43
+ $ index = $ this ->getIndex ('newcollection ' , 'mykey ' );
44
+ $ this ->assertEquals (1 , $ index ['key ' ]['mykey ' ]);
37
45
}
38
46
39
47
public function testUnique ()
@@ -57,6 +65,15 @@ public function testDropIndex()
57
65
58
66
$ index = $ this ->getIndex ('newcollection ' , 'uniquekey ' );
59
67
$ this ->assertEquals (null , $ index );
68
+
69
+ Schema::collection ('newcollection ' , function ($ collection )
70
+ {
71
+ $ collection ->unique ('uniquekey ' );
72
+ $ collection ->dropIndex (array ('uniquekey ' ));
73
+ });
74
+
75
+ $ index = $ this ->getIndex ('newcollection ' , 'uniquekey ' );
76
+ $ this ->assertEquals (null , $ index );
60
77
}
61
78
62
79
public function testBackground ()
Original file line number Diff line number Diff line change 9
9
use Illuminate \Database \DatabaseManager ;
10
10
use Illuminate \Database \Connectors \ConnectionFactory ;
11
11
use Illuminate \Events \Dispatcher ;
12
- use Illuminate \Cache \ArrayStore ;
13
- use Illuminate \Cache \Repository ;
12
+ use Illuminate \Cache \CacheManager ;
14
13
15
14
# Fake app class
16
15
class App extends ArrayObject {
@@ -20,19 +19,20 @@ function bound() {}
20
19
# Fake app
21
20
$ app = new App ;
22
21
23
- # Event dispatcher
24
- $ app ['events ' ] = new Dispatcher ;
25
-
26
- # Cache driver
27
- $ app ['cache ' ] = new Repository (new ArrayStore );
28
-
29
22
# Load database configuration
30
23
$ config = require 'config/database.php ' ;
31
24
foreach ($ config as $ key => $ value )
32
25
{
33
26
$ app ['config ' ]["database. $ key " ] = $ value ;
34
27
}
35
28
29
+ # Event dispatcher
30
+ $ app ['events ' ] = new Dispatcher ;
31
+
32
+ # Cache driver
33
+ $ app ['config ' ]['cache.driver ' ] = 'array ' ;
34
+ $ app ['cache ' ] = new CacheManager ($ app );
35
+
36
36
# Initialize database manager
37
37
$ app ['db.factory ' ] = new ConnectionFactory (new Container );
38
38
$ app ['db ' ] = new DatabaseManager ($ app , $ app ['db.factory ' ]);
You can’t perform that action at this time.
0 commit comments