modified model classes with tests

This commit is contained in:
Anton Grebnev
2011-11-17 15:12:47 +04:00
parent e740ae7000
commit 7e8fe0f94d
10 changed files with 212 additions and 85 deletions

View File

@ -48,7 +48,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
->getMock();
$this->request = $this->getMockBuilder('MongoDbCommandMock')
->disableOriginalConstructor()
->setMethods(array('execute', 'bindParam'))
->setMethods(array('execute', 'bindParam', 'getInsertId'))
->getMock();
$this->stmt = new MongoStatement($this->driver, $this->request);
}
@ -84,13 +84,42 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
}
$this->setDriverGetConnectionMethod();
$this->request
->expects($this->any())
->expects($this->once())
->method('execute')
->will($this->returnValue(array('n' => 20, 'ok' => 1)));
$this->stmt->execute();
$this->assertEquals(20, $this->stmt->affectedRows());
}
/**
* @runInSeparateProcess
*/
public function testGetInsertId()
{
if (!defined('DEBUG')) {
define('DEBUG', false);
}
$this->setDriverGetConnectionMethod();
$this->request = $this->getMockBuilder('InsertMongoCommand')
->disableOriginalConstructor()
->setMethods(array('execute', 'bindParam', 'getInsertId'))
->getMock();
$this->request
->expects($this->once())
->method('execute')
->will($this->returnValue(array('n' => 20, 'ok' => 1)));
$this->request
->expects($this->once())
->method('getInsertId')
->will($this->returnValue('4b0rrs'));
$this->stmt = new MongoStatement($this->driver, $this->request);
$this->stmt->execute();
$this->assertEquals('4b0rrs', $this->stmt->getInsertId());
}
/**
* @runInSeparateProcess
@ -286,6 +315,8 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
$this->stmt->execute();
$this->assertInstanceOf('MongoStatement', $this->stmt->order(array('id' => 1)));
$this->assertInstanceOf('MongoStatement', $this->stmt->limit(10));
$this->assertInstanceOf('MongoStatement', $this->stmt->skip(1));
$this->stmt->fetch();
$this->stmt->fetch();
@ -368,7 +399,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
->setMethods(array('count'))
->disableOriginalConstructor()
->getMock();
$resultMock
->expects($this->any())
->method('count')
@ -381,7 +412,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
return $this;
}
public function setRequestForFetch()
{
$resultMock = $this->getMockBuilder('MongoCursor')