Przeglądaj źródła

Fix failing test

Andreas Braun 10 lat temu
rodzic
commit
d8cacca496

+ 7 - 4
lib/Alcaeus/MongoDbAdapter/ExceptionConverter.php

@@ -23,9 +23,12 @@ use MongoDB\Driver\Exception;
 class ExceptionConverter
 {
     /**
+     * @param Exception\Exception $e
+     * @param string $fallbackClass
+     *
      * @return \MongoException
      */
-    public static function convertException(Exception\Exception $e)
+    public static function convertException(Exception\Exception $e, $fallbackClass = 'MongoException')
     {
         switch (get_class($e)) {
             case Exception\AuthenticationException::class:
@@ -45,7 +48,7 @@ class ExceptionConverter
                 break;
 
             default:
-                $class = 'MongoException';
+                $class = $fallbackClass;
         }
 
         if (strpos($e->getMessage(), 'No suitable servers found') !== false) {
@@ -58,8 +61,8 @@ class ExceptionConverter
     /**
      * @throws \MongoException
      */
-    public static function toLegacy(Exception\Exception $e)
+    public static function toLegacy(Exception\Exception $e, $fallbackClass = 'MongoException')
     {
-        throw self::convertException($e);
+        throw self::convertException($e, $fallbackClass);
     }
 }

+ 1 - 3
lib/Mongo/MongoCollection.php

@@ -513,10 +513,8 @@ class MongoCollection
             }
         } catch (\MongoDB\Driver\Exception\ConnectionException $e) {
             throw new MongoResultException($e->getMessage(), $e->getCode(), $e);
-        } catch (\MongoDB\Driver\Exception\RuntimeException $e) {
-            throw new MongoResultException($e->getMessage(), $e->getCode(), $e);
         } catch (\MongoDB\Driver\Exception\Exception $e) {
-            ExceptionConverter::toLegacy($e);
+            ExceptionConverter::toLegacy($e, 'MongoResultException');
         }
 
         if ($document) {