You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.7 KiB

<?php
/*
* @copyright NetMonsters <team@netmonsters.ru>
* @link http://netmonsters.ru
* @package Majestic
* @subpackage UnitTests
* @since 2011-11-10
*
* Unit tests for MongoDriver class
*/
require_once dirname(__FILE__) . '/../../model/DbDriver.php';
require_once dirname(__FILE__) . '/../../model/NoSqlDbDriver.php';
require_once dirname(__FILE__) . '/../../model/MongoDriver.php';
class MongoDriverTest extends PHPUnit_Framework_TestCase
{
private $conf = array();
public function setUp()
{
$this->conf = array(
'hostname' => 'localhost',
'database' => 'test',
'username' => 'test',
'password' => '1234',
'port' => 27017
);
}
/**
* @expectedException Exception
* @expectedExceptionMessage Configuration must have a "hostname".
*/
public function testGetConnectionNoHostname()
{
unset($this->conf['hostname']);
$mongo = new MongoDriver($this->conf);
$mongo->getConnection();
}
/**
* @expectedException MongoConnectionException
* @expectedExceptionMessage Couldn't authenticate with database
*/
public function testGetConnectionWrongPassword()
{
$this->conf['password'] = 'nopass';
$mongo = new MongoDriver($this->conf);
$this->assertInstanceOf('Mongo', $mongo->getConnection());
}
public function testGetConnection()
{
$mongo = new MongoDriver($this->conf);
$this->assertFalse($mongo->isConnected());
$this->assertInstanceOf('Mongo', $mongo->getConnection());
$this->assertTrue($mongo->isConnected());
$mongo->disconnect();
$this->assertFalse($mongo->isConnected());
}
}