Explorar el Código

Merge pull request #173 from alcaeus/add-auth-tests

Add tests for authentication options
Andreas hace 8 años
padre
commit
69d66a5992
Se han modificado 1 ficheros con 26 adiciones y 0 borrados
  1. 26 0
      tests/Alcaeus/MongoDbAdapter/Mongo/MongoClientTest.php

+ 26 - 0
tests/Alcaeus/MongoDbAdapter/Mongo/MongoClientTest.php

@@ -225,6 +225,32 @@ class MongoClientTest extends TestCase
         ];
     }
 
+    public function testConnectWithUsernameAndPassword()
+    {
+        $this->expectException(\MongoConnectionException::class);
+        $this->expectExceptionMessage('Authentication failed');
+
+        $client = $this->getClient(['username' => 'alcaeus', 'password' => 'mySuperSecurePassword']);
+        $collection = $client->selectCollection('test', 'foo');
+
+        $document = ['foo' => 'bar'];
+
+        $collection->insert($document);
+    }
+    
+    public function testConnectWithUsernameAndPasswordInConnectionUrl()
+    {
+        $this->expectException(\MongoConnectionException::class);
+        $this->expectExceptionMessage('Authentication failed');
+
+        $client = $this->getClient([], 'mongodb://alcaeus:mySuperSecurePassword@localhost');
+        $collection = $client->selectCollection('test', 'foo');
+
+        $document = ['foo' => 'bar'];
+
+        $collection->insert($document);
+    }
+
     /**
      * @param array $options
      * @return string