rebuild Model package for NoSQL drivers
This commit is contained in:
65
tests/model/MongoDriverTest.php
Normal file
65
tests/model/MongoDriverTest.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?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());
|
||||
}
|
||||
|
||||
}
|
@ -14,6 +14,7 @@ require_once dirname(__FILE__) . '/../../model/Db.php';
|
||||
require_once dirname(__FILE__) . '/../../model/DbStatement.php';
|
||||
require_once dirname(__FILE__) . '/../../model/MySQLiStatement.php';
|
||||
require_once dirname(__FILE__) . '/../../model/DbDriver.php';
|
||||
require_once dirname(__FILE__) . '/../../model/SqlDbDriver.php';
|
||||
require_once dirname(__FILE__) . '/../../model/MySQLiDriver.php';
|
||||
|
||||
class MySQLiDriverTest extends PHPUnit_Extensions_Database_TestCase
|
||||
|
@ -13,8 +13,9 @@
|
||||
require_once dirname(__FILE__) . '/../../model/DbExpr.php';
|
||||
require_once dirname(__FILE__) . '/../../model/Db.php';
|
||||
require_once dirname(__FILE__) . '/../../model/DbDriver.php';
|
||||
require_once dirname(__FILE__) . '/../../model/SqlDbDriver.php';
|
||||
|
||||
class DbDriverTest extends PHPUnit_Framework_TestCase
|
||||
class SqlDbDriverTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
private $driver;
|
||||
@ -22,13 +23,13 @@ class DbDriverTest extends PHPUnit_Framework_TestCase
|
||||
public function setUp()
|
||||
{
|
||||
$conf = array('hostname' => 'localhost', 'database' => 'db', 'username' => 'test', 'password' => '1234');
|
||||
$this->driver = $this->getMockForAbstractClass('DbDriver', array($conf));
|
||||
$this->driver = $this->getMockForAbstractClass('SqlDbDriver', array($conf));
|
||||
}
|
||||
|
||||
public function testConstruct()
|
||||
{
|
||||
$conf = array('hostname' => 'localhost', 'database' => 'db', 'username' => 'test', 'password' => '1234');
|
||||
$this->driver = $this->getMockForAbstractClass('DbDriver', array($conf));
|
||||
$this->driver = $this->getMockForAbstractClass('SqlDbDriver', array($conf));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -38,7 +39,7 @@ class DbDriverTest extends PHPUnit_Framework_TestCase
|
||||
public function testConstructWrongConfig()
|
||||
{
|
||||
$conf = array('hostname' => 'localhost', 'database' => 'db');
|
||||
$this->getMockForAbstractClass('DbDriver', array($conf));
|
||||
$this->getMockForAbstractClass('SqlDbDriver', array($conf));
|
||||
}
|
||||
|
||||
public function testGetConnection()
|
@ -17,8 +17,9 @@ require_once dirname(__FILE__) . '/../../model/DbExpr.php';
|
||||
require_once dirname(__FILE__) . '/../../model/Db.php';
|
||||
require_once dirname(__FILE__) . '/../../model/DbDriver.php';
|
||||
require_once dirname(__FILE__) . '/../../model/Model.php';
|
||||
require_once dirname(__FILE__) . '/../../model/SqlModel.php';
|
||||
|
||||
class ModelTest extends PHPUnit_Framework_TestCase
|
||||
class SqlModelTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
private $model;
|
||||
@ -32,7 +33,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
Config::set('Db', $conf);
|
||||
if (!class_exists('MockModel')) {
|
||||
$this->model = $this->getMockForAbstractClass('Model', array(), 'MockModel');
|
||||
$this->model = $this->getMockForAbstractClass('SqlModel', array(), 'MockModel');
|
||||
} else {
|
||||
$this->model = new MockModel();
|
||||
}
|
||||
@ -41,7 +42,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function testModel()
|
||||
{
|
||||
$this->assertInstanceOf('Model', $this->model);
|
||||
$this->assertInstanceOf('SqlModel', $this->model);
|
||||
}
|
||||
|
||||
public function testGetInsertId()
|
||||
@ -83,7 +84,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function testOrder()
|
||||
{
|
||||
$model = new ReflectionClass('Model');
|
||||
$model = new ReflectionClass('SqlModel');
|
||||
$method = $model->getMethod('order');
|
||||
$method->setAccessible(true);
|
||||
$this->assertEquals(' ORDER BY id DESC', $method->invoke($this->model, array('sort' => 'id', 'order' => 'desc')));
|
||||
@ -98,7 +99,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function testSearch()
|
||||
{
|
||||
$model = new ReflectionClass('Model');
|
||||
$model = new ReflectionClass('SqlModel');
|
||||
$method = $model->getMethod('search');
|
||||
$method->setAccessible(true);
|
||||
$this->assertEmpty($method->invoke($this->model, array()));
|
||||
@ -108,7 +109,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function testFetch()
|
||||
{
|
||||
$model = new ReflectionClass('Model');
|
||||
$model = new ReflectionClass('SqlModel');
|
||||
$method = $model->getMethod('fetch');
|
||||
$method->setAccessible(true);
|
||||
|
||||
@ -118,7 +119,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function testFetchField()
|
||||
{
|
||||
$model = new ReflectionClass('Model');
|
||||
$model = new ReflectionClass('SqlModel');
|
||||
$method = $model->getMethod('fetchField');
|
||||
$method->setAccessible(true);
|
||||
|
||||
@ -128,7 +129,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function testFetchAll()
|
||||
{
|
||||
$model = new ReflectionClass('Model');
|
||||
$model = new ReflectionClass('SqlModel');
|
||||
$method = $model->getMethod('fetchAll');
|
||||
$method->setAccessible(true);
|
||||
|
||||
@ -167,7 +168,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function testAddCleanCache()
|
||||
{
|
||||
$model = new ReflectionClass('Model');
|
||||
$model = new ReflectionClass('SqlModel');
|
||||
$method = $model->getMethod('addCleanCache');
|
||||
$method->setAccessible(true);
|
||||
|
||||
@ -180,7 +181,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function testCleanCaches()
|
||||
{
|
||||
$model = new ReflectionClass('Model');
|
||||
$model = new ReflectionClass('SqlModel');
|
||||
$method = $model->getMethod('addCleanCache');
|
||||
$method->setAccessible(true);
|
||||
|
||||
@ -190,7 +191,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
||||
$method->invoke($this->model, $key);
|
||||
$this->assertAttributeEquals(array($key, $key, $key), 'caches_clean', $this->model);
|
||||
|
||||
$model = new ReflectionClass('Model');
|
||||
$model = new ReflectionClass('SqlModel');
|
||||
$method = $model->getMethod('cleanCaches');
|
||||
$method->setAccessible(true);
|
||||
|
Reference in New Issue
Block a user