소스 검색

Add WriteConcernException to exceptionconverter.

Olivier Lechevalier 10 년 전
부모
커밋
2bcb1f74d9
2개의 변경된 파일6개의 추가작업 그리고 2개의 파일을 삭제
  1. 4 0
      lib/Alcaeus/MongoDbAdapter/ExceptionConverter.php
  2. 2 2
      tests/Alcaeus/MongoDbAdapter/MongoCollectionTest.php

+ 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]);
     }