summaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2015-02-20 20:15:22 +0100
committerLukas Reschke <lukas@owncloud.com>2015-02-20 20:15:22 +0100
commitfcc5f5a4f498d41f806607c06ac1a3e4a0997702 (patch)
tree5bdf228f48b140d47dcd2e98bbf7f9caab367edb /tests/lib
parent3a6b11d018e693b61cf201232bf5566f1a540b77 (diff)
parent84a47645b9d6eef678be6a33eafff2e290e4a782 (diff)
downloadnextcloud-server-fcc5f5a4f498d41f806607c06ac1a3e4a0997702.tar.gz
nextcloud-server-fcc5f5a4f498d41f806607c06ac1a3e4a0997702.zip
Merge pull request #13777 from owncloud/close-cursor
Close cursor for appframework and manipulation queries if applicable
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/appframework/db/mappertest.php14
-rw-r--r--tests/lib/appframework/db/mappertestutility.php24
2 files changed, 22 insertions, 16 deletions
diff --git a/tests/lib/appframework/db/mappertest.php b/tests/lib/appframework/db/mappertest.php
index 6ad8cd86bff..9cbc01883e3 100644
--- a/tests/lib/appframework/db/mappertest.php
+++ b/tests/lib/appframework/db/mappertest.php
@@ -74,7 +74,7 @@ class MapperTest extends MapperTestUtility {
$rows = array(
array('hi')
);
- $this->setMapperResult($sql, $params, $rows);
+ $this->setMapperResult($sql, $params, $rows);
$this->mapper->find($sql, $params);
}
@@ -84,7 +84,7 @@ class MapperTest extends MapperTestUtility {
$rows = array(
array('pre_name' => 'hi')
);
- $this->setMapperResult($sql, $params, $rows);
+ $this->setMapperResult($sql, $params, $rows, null, null, true);
$this->mapper->findOneEntity($sql, $params);
}
@@ -92,7 +92,7 @@ class MapperTest extends MapperTestUtility {
$sql = 'hi';
$params = array('jo');
$rows = array();
- $this->setMapperResult($sql, $params, $rows);
+ $this->setMapperResult($sql, $params, $rows);
$this->setExpectedException(
'\OCP\AppFramework\Db\DoesNotExistException');
$this->mapper->find($sql, $params);
@@ -102,7 +102,7 @@ class MapperTest extends MapperTestUtility {
$sql = 'hi';
$params = array('jo');
$rows = array();
- $this->setMapperResult($sql, $params, $rows);
+ $this->setMapperResult($sql, $params, $rows, null, null, true);
$this->setExpectedException(
'\OCP\AppFramework\Db\DoesNotExistException');
$this->mapper->findOneEntity($sql, $params);
@@ -114,7 +114,7 @@ class MapperTest extends MapperTestUtility {
$rows = array(
array('jo'), array('ho')
);
- $this->setMapperResult($sql, $params, $rows);
+ $this->setMapperResult($sql, $params, $rows, null, null, true);
$this->setExpectedException(
'\OCP\AppFramework\Db\MultipleObjectsReturnedException');
$this->mapper->find($sql, $params);
@@ -126,7 +126,7 @@ class MapperTest extends MapperTestUtility {
$rows = array(
array('jo'), array('ho')
);
- $this->setMapperResult($sql, $params, $rows);
+ $this->setMapperResult($sql, $params, $rows, null, null, true);
$this->setExpectedException(
'\OCP\AppFramework\Db\MultipleObjectsReturnedException');
$this->mapper->findOneEntity($sql, $params);
@@ -249,7 +249,7 @@ class MapperTest extends MapperTestUtility {
$entity = new Example();
$entity->setPreName('hi');
$entity->resetUpdatedFields();
- $this->setMapperResult($sql, array(), $rows);
+ $this->setMapperResult($sql, array(), $rows, null, null, true);
$result = $this->mapper->findAllEntities($sql);
$this->assertEquals(array($entity), $result);
}
diff --git a/tests/lib/appframework/db/mappertestutility.php b/tests/lib/appframework/db/mappertestutility.php
index ad7a67a96b1..0053b2c682d 100644
--- a/tests/lib/appframework/db/mappertestutility.php
+++ b/tests/lib/appframework/db/mappertestutility.php
@@ -36,7 +36,7 @@ abstract class MapperTestUtility extends \Test\TestCase {
private $prepareAt;
private $fetchAt;
private $iterators;
-
+
/**
* Run this function before the actual test to either set or initialize the
@@ -51,7 +51,7 @@ abstract class MapperTestUtility extends \Test\TestCase {
->getMock();
$this->query = $this->getMock('Query', array('execute', 'bindValue'));
- $this->pdoResult = $this->getMock('Result', array('fetch'));
+ $this->pdoResult = $this->getMock('Result', array('fetch', 'closeCursor'));
$this->queryAt = 0;
$this->prepareAt = 0;
$this->iterators = array();
@@ -69,7 +69,7 @@ abstract class MapperTestUtility extends \Test\TestCase {
* will be called on the result
*/
protected function setMapperResult($sql, $arguments=array(), $returnRows=array(),
- $limit=null, $offset=null){
+ $limit=null, $offset=null, $expectClose=false){
$this->iterators[] = new ArgumentIterator($returnRows);
@@ -88,8 +88,14 @@ abstract class MapperTestUtility extends \Test\TestCase {
}
return $result;
- }
+ }
));
+ if ($expectClose) {
+ $closing = $this->once();
+ } else {
+ $closing = $this->any();
+ }
+ $this->pdoResult->expects($closing)->method('closeCursor');
$index = 1;
foreach($arguments as $argument) {
@@ -105,7 +111,7 @@ abstract class MapperTestUtility extends \Test\TestCase {
case 'boolean':
$pdoConstant = \PDO::PARAM_BOOL;
break;
-
+
default:
$pdoConstant = \PDO::PARAM_STR;
break;
@@ -138,14 +144,14 @@ abstract class MapperTestUtility extends \Test\TestCase {
} elseif($limit === null && $offset !== null) {
$this->db->expects($this->at($this->prepareAt))
->method('prepareQuery')
- ->with($this->equalTo($sql),
+ ->with($this->equalTo($sql),
$this->equalTo(null),
$this->equalTo($offset))
->will(($this->returnValue($this->query)));
} else {
$this->db->expects($this->at($this->prepareAt))
->method('prepareQuery')
- ->with($this->equalTo($sql),
+ ->with($this->equalTo($sql),
$this->equalTo($limit),
$this->equalTo($offset))
->will(($this->returnValue($this->query)));
@@ -162,11 +168,11 @@ abstract class MapperTestUtility extends \Test\TestCase {
class ArgumentIterator {
private $arguments;
-
+
public function __construct($arguments){
$this->arguments = $arguments;
}
-
+
public function next(){
$result = array_shift($this->arguments);
if($result === null){