Преглед изворни кода

Add tests for authentication options

Andreas Braun пре 8 година
родитељ
комит
2abe45a344
1 измењених фајлова са 26 додато и 0 уклоњено
  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