Andreas Braun пре 10 година
родитељ
комит
46167529ed

+ 1 - 9
lib/Alcaeus/MongoDbAdapter/ExceptionConverter.php

@@ -28,7 +28,7 @@ class ExceptionConverter
      *
      * @return \MongoException
      */
-    public static function convertException(Exception\Exception $e, $fallbackClass = 'MongoException')
+    public static function toLegacy(Exception\Exception $e, $fallbackClass = 'MongoException')
     {
         switch (get_class($e)) {
             case Exception\AuthenticationException::class:
@@ -57,12 +57,4 @@ class ExceptionConverter
 
         return new $class($e->getMessage(), $e->getCode(), $e);
     }
-
-    /**
-     * @throws \MongoException
-     */
-    public static function toLegacy(Exception\Exception $e, $fallbackClass = 'MongoException')
-    {
-        throw self::convertException($e, $fallbackClass);
-    }
 }

+ 2 - 2
lib/Mongo/MongoClient.php

@@ -191,7 +191,7 @@ class MongoClient
         try {
             $servers = $this->manager->getServers();
         } catch (\MongoDB\Driver\Exception\Exception $e) {
-            ExceptionConverter::toLegacy($e);
+            throw ExceptionConverter::toLegacy($e);
         }
 
         foreach ($servers as $server) {
@@ -246,7 +246,7 @@ class MongoClient
         try {
             $databaseInfoIterator = $this->client->listDatabases();
         } catch (\MongoDB\Driver\Exception\Exception $e) {
-            ExceptionConverter::toLegacy($e);
+            throw ExceptionConverter::toLegacy($e);
         }
 
         $databases = [

+ 8 - 8
lib/Mongo/MongoCollection.php

@@ -286,7 +286,7 @@ class MongoCollection
                 'errmsg' => $writeError->getMessage(),
             ];
         } catch (\MongoDB\Driver\Exception\Exception $e) {
-            ExceptionConverter::toLegacy($e);
+            throw ExceptionConverter::toLegacy($e);
         }
 
         if (! $result->isAcknowledged()) {
@@ -341,7 +341,7 @@ class MongoCollection
                 $this->convertWriteConcernOptions($options)
             );
         } catch (\MongoDB\Driver\Exception\Exception $e) {
-            ExceptionConverter::toLegacy($e);
+            throw ExceptionConverter::toLegacy($e);
         }
 
         if (! $result->isAcknowledged()) {
@@ -393,7 +393,7 @@ class MongoCollection
                 'updatedExisting' => $writeResult->getUpsertedCount() == 0,
             ];
         } catch (\MongoDB\Driver\Exception\Exception $e) {
-            ExceptionConverter::toLegacy($e);
+            throw ExceptionConverter::toLegacy($e);
         }
 
         if (! $result->isAcknowledged()) {
@@ -433,7 +433,7 @@ class MongoCollection
                 $this->convertWriteConcernOptions($options)
             );
         } catch (\MongoDB\Driver\Exception\Exception $e) {
-            ExceptionConverter::toLegacy($e);
+            throw ExceptionConverter::toLegacy($e);
         }
 
         if (! $result->isAcknowledged()) {
@@ -513,7 +513,7 @@ class MongoCollection
         } catch (\MongoDB\Driver\Exception\ConnectionException $e) {
             throw new MongoResultException($e->getMessage(), $e->getCode(), $e);
         } catch (\MongoDB\Driver\Exception\Exception $e) {
-            ExceptionConverter::toLegacy($e, 'MongoResultException');
+            throw ExceptionConverter::toLegacy($e, 'MongoResultException');
         }
 
         if ($document) {
@@ -538,7 +538,7 @@ class MongoCollection
         try {
             $document = $this->collection->findOne(TypeConverter::fromLegacy($query), $options);
         } catch (\MongoDB\Driver\Exception\Exception $e) {
-            ExceptionConverter::toLegacy($e);
+            throw ExceptionConverter::toLegacy($e);
         }
 
         if ($document !== null) {
@@ -606,7 +606,7 @@ class MongoCollection
         try {
             $this->collection->createIndex($keys, $this->convertWriteConcernOptions($options));
         } catch (\MongoDB\Driver\Exception\Exception $e) {
-            ExceptionConverter::toLegacy($e);
+            throw ExceptionConverter::toLegacy($e);
         }
 
         return [
@@ -697,7 +697,7 @@ class MongoCollection
         try {
             return $this->collection->count(TypeConverter::fromLegacy($query), $options);
         } catch (\MongoDB\Driver\Exception\Exception $e) {
-            ExceptionConverter::toLegacy($e);
+            throw ExceptionConverter::toLegacy($e);
         }
     }
 

+ 2 - 2
lib/Mongo/MongoCursor.php

@@ -146,7 +146,7 @@ class MongoCursor extends AbstractCursor implements Iterator
         } catch (\MongoDB\Driver\Exception\ExecutionTimeoutException $e) {
             throw new MongoCursorTimeoutException($e->getMessage(), $e->getCode(), $e);
         } catch (\MongoDB\Driver\Exception\Exception $e) {
-            ExceptionConverter::toLegacy($e);
+            throw ExceptionConverter::toLegacy($e);
         }
 
         return $count;
@@ -167,7 +167,7 @@ class MongoCursor extends AbstractCursor implements Iterator
         } catch (\MongoDB\Driver\Exception\ExecutionTimeoutException $e) {
             throw new MongoCursorTimeoutException($e->getMessage(), $e->getCode(), $e);
         } catch (\MongoDB\Driver\Exception\Exception $e) {
-            ExceptionConverter::toLegacy($e);
+            throw ExceptionConverter::toLegacy($e);
         }
     }
 

+ 4 - 4
lib/Mongo/MongoDB.php

@@ -134,7 +134,7 @@ class MongoDB
         try {
             $collections = $this->db->listCollections($options);
         } catch (\MongoDB\Driver\Exception\Exception $e) {
-            ExceptionConverter::toLegacy($e);
+            throw ExceptionConverter::toLegacy($e);
         }
 
         $getCollectionInfo = function (CollectionInfo $collectionInfo) {
@@ -164,7 +164,7 @@ class MongoDB
         try {
             $collections = $this->db->listCollections($options);
         } catch (\MongoDB\Driver\Exception\Exception $e) {
-            ExceptionConverter::toLegacy($e);
+            throw ExceptionConverter::toLegacy($e);
         }
 
         $getCollectionName = function (CollectionInfo $collectionInfo) {
@@ -388,8 +388,8 @@ class MongoDB
                 'errmsg' => $e->getMessage(),
                 'code' => $e->getCode(),
             ];
-        } catch (\MongoDB\Driver\Exception\Excepiton $e) {
-            ExceptionConverter::toLegacy($e);
+        } catch (\MongoDB\Driver\Exception\Exception $e) {
+            throw ExceptionConverter::toLegacy($e);
         }
     }
 

+ 1 - 7
tests/Alcaeus/MongoDbAdapter/ExceptionConverterTest.php

@@ -7,18 +7,12 @@ use Alcaeus\MongoDbAdapter\ExceptionConverter;
 
 class ExceptionConverterTest extends \PHPUnit_Framework_TestCase
 {
-    public function testThrowException()
-    {
-        $this->setExpectedException('MongoException');
-        ExceptionConverter::toLegacy(new Exception\InvalidArgumentException());
-    }
-
     /**
      * @dataProvider exceptionProvider
      */
     public function testConvertException($e, $expectedClass)
     {
-        $exception = ExceptionConverter::convertException($e);
+        $exception = ExceptionConverter::toLegacy($e);
         $this->assertInstanceOf($expectedClass, $exception);
         $this->assertSame($e->getMessage(), $exception->getMessage());
         $this->assertSame($e->getCode(), $exception->getCode());