Parcourir la source

Add WriteConcernException to exceptionconverter.

Olivier Lechevalier il y a 10 ans
Parent
commit
2bcb1f74d9

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

@@ -76,6 +76,10 @@ class ExceptionConverter
             return new \MongoConnectionException($message, $code, $e);
         }
 
+        if ($message === "cannot use 'w' > 1 when a host is not replicated") {
+            return new \MongoWriteConcernException($message, $code, $e);
+        }
+
         return new $class($message, $code, $e);
     }
 }

+ 2 - 2
tests/Alcaeus/MongoDbAdapter/MongoCollectionTest.php

@@ -105,7 +105,7 @@ class MongoCollectionTest extends TestCase
     {
         $this->setExpectedException(
             'MongoWriteConcernException',
-            "localhost:27017: cannot use 'w' > 1 when a host is not replicated"
+            "cannot use 'w' > 1 when a host is not replicated"
         );
 
         $document = ['foo' => 'bar'];
@@ -192,7 +192,7 @@ class MongoCollectionTest extends TestCase
 
     public function testUpdateWriteConcern()
     {
-        $this->setExpectedException('MongoWriteConcernException', "localhost:27017: cannot use 'w' > 1 when a host is not replicated");
+        $this->setExpectedException('MongoWriteConcernException', "cannot use 'w' > 1 when a host is not replicated");
 
         $this->getCollection()->update([], ['$set' => ['foo' => 'bar']], ['w' => 2]);
     }