Commit 2ae7980f authored by Jens Segers's avatar Jens Segers

Adding tests for connection

parent 3c0edb03
......@@ -180,7 +180,7 @@ class Connection extends \Illuminate\Database\Connection {
*/
public function getDriverName()
{
return '';
return 'mongodb';
}
/**
......
......@@ -20,6 +20,9 @@ class ConnectionTest extends TestCase {
{
$connection = DB::connection('mongodb');
$this->assertInstanceOf('MongoDB', $connection->getMongoDB());
$connection = DB::connection('mongodb');
$this->assertInstanceOf('MongoClient', $connection->getMongoClient());
}
public function testCollection()
......@@ -81,4 +84,33 @@ class ConnectionTest extends TestCase {
$this->assertInstanceOf('Jenssegers\Mongodb\Schema\Builder', $schema);
}
public function testDriverName()
{
$driver = DB::connection('mongodb')->getDriverName();
$this->assertEquals('mongodb', $driver);
}
public function testAuth()
{
Config::set('database.connections.mongodb.username', 'foo');
Config::set('database.connections.mongodb.password', 'bar');
$host = Config::get('database.connections.mongodb.host');
$port = Config::get('database.connections.mongodb.port', 27017);
$database = Config::get('database.connections.mongodb.database');
$this->setExpectedException('MongoConnectionException', "Failed to connect to: $host:$port: Authentication failed on database '$database' with username 'foo': auth fails");
$connection = DB::connection('mongodb');
}
public function testCustomPort()
{
$port = 27000;
Config::set('database.connections.mongodb.port', $port);
$host = Config::get('database.connections.mongodb.host');
$database = Config::get('database.connections.mongodb.database');
$this->setExpectedException('MongoConnectionException', "Failed to connect to: $host:$port: Connection refused");
$connection = DB::connection('mongodb');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment