File tree 2 files changed +22
-2
lines changed
tests/Alcaeus/MongoDbAdapter
2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change 14
14
*/
15
15
16
16
use Alcaeus \MongoDbAdapter \AbstractCursor ;
17
+ use Alcaeus \MongoDbAdapter \ExceptionConverter ;
17
18
use MongoDB \Driver \Cursor ;
18
19
use MongoDB \Driver \ReadPreference ;
19
20
use MongoDB \Operation \Find ;
@@ -139,8 +140,12 @@ public function count($foundOnly = false)
139
140
}
140
141
141
142
$ options = $ this ->getOptions ($ optionNames ) + $ this ->options ;
143
+ try {
144
+ $ count = $ this ->collection ->count ($ this ->query , $ options );
145
+ } catch (\MongoDB \Driver \Exception \Exception $ e ) {
146
+ ExceptionConverter::toLegacy ($ e );
147
+ }
142
148
143
- $ count = $ this ->collection ->count ($ this ->query , $ options );
144
149
return $ count ;
145
150
}
146
151
@@ -154,7 +159,12 @@ protected function doQuery()
154
159
{
155
160
$ options = $ this ->getOptions () + $ this ->options ;
156
161
157
- $ this ->cursor = $ this ->collection ->find ($ this ->query , $ options );
162
+ try {
163
+ $ this ->cursor = $ this ->collection ->find ($ this ->query , $ options );
164
+ } catch (\MongoDB \Driver \Exception \Exception $ e ) {
165
+ ExceptionConverter::toLegacy ($ e );
166
+ }
167
+
158
168
}
159
169
160
170
/**
Original file line number Diff line number Diff line change @@ -38,6 +38,16 @@ public function testCount()
38
38
$ this ->assertSame (1 , $ cursor ->count (true ));
39
39
}
40
40
41
+ public function testCountCannotConnect ()
42
+ {
43
+ $ client = $ this ->getClient ([], 'mongodb://localhost:28888 ' );
44
+ $ cursor = $ client ->selectCollection ('mongo-php-adapter ' , 'test ' )->find ();
45
+
46
+ $ this ->setExpectedException ('MongoConnectionException ' );
47
+
48
+ $ cursor ->count ();
49
+ }
50
+
41
51
/**
42
52
* @dataProvider getCursorOptions
43
53
*/
You can’t perform that action at this time.
0 commit comments