Browse Source

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

Add tests for authentication options
Andreas 8 years ago
parent
commit
69d66a5992
1 changed files with 26 additions and 0 deletions
  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