Skip to content

Commit 2ae7980

Browse files
committed
Adding tests for connection
1 parent 3c0edb0 commit 2ae7980

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/Jenssegers/Mongodb/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public function getElapsedTime($start)
180180
*/
181181
public function getDriverName()
182182
{
183-
return '';
183+
return 'mongodb';
184184
}
185185

186186
/**

tests/ConnectionTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ public function testDb()
2020
{
2121
$connection = DB::connection('mongodb');
2222
$this->assertInstanceOf('MongoDB', $connection->getMongoDB());
23+
24+
$connection = DB::connection('mongodb');
25+
$this->assertInstanceOf('MongoClient', $connection->getMongoClient());
2326
}
2427

2528
public function testCollection()
@@ -81,4 +84,33 @@ public function testSchemaBuilder()
8184
$this->assertInstanceOf('Jenssegers\Mongodb\Schema\Builder', $schema);
8285
}
8386

87+
public function testDriverName()
88+
{
89+
$driver = DB::connection('mongodb')->getDriverName();
90+
$this->assertEquals('mongodb', $driver);
91+
}
92+
93+
public function testAuth()
94+
{
95+
Config::set('database.connections.mongodb.username', 'foo');
96+
Config::set('database.connections.mongodb.password', 'bar');
97+
$host = Config::get('database.connections.mongodb.host');
98+
$port = Config::get('database.connections.mongodb.port', 27017);
99+
$database = Config::get('database.connections.mongodb.database');
100+
101+
$this->setExpectedException('MongoConnectionException', "Failed to connect to: $host:$port: Authentication failed on database '$database' with username 'foo': auth fails");
102+
$connection = DB::connection('mongodb');
103+
}
104+
105+
public function testCustomPort()
106+
{
107+
$port = 27000;
108+
Config::set('database.connections.mongodb.port', $port);
109+
$host = Config::get('database.connections.mongodb.host');
110+
$database = Config::get('database.connections.mongodb.database');
111+
112+
$this->setExpectedException('MongoConnectionException', "Failed to connect to: $host:$port: Connection refused");
113+
$connection = DB::connection('mongodb');
114+
}
115+
84116
}

0 commit comments

Comments
 (0)