summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2015-02-24 17:05:50 +0100
committerBernhard Posselt <dev@bernhard-posselt.com>2015-03-21 13:36:50 +0100
commit03ce3af3a51f51852cd0a3f06872fc36d7f62dfb (patch)
tree698e8fac495cacd1975e3bce8ffc6c0c5df9d527 /tests
parent92bfd77cdee76e8cf117fc41c360eb700ba84fb9 (diff)
cleanup db stuff
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/db/FolderMapperTest.php8
-rw-r--r--tests/unit/db/mappertestutility.php87
2 files changed, 47 insertions, 48 deletions
diff --git a/tests/unit/db/FolderMapperTest.php b/tests/unit/db/FolderMapperTest.php
index e9df37195..00ad2127d 100644
--- a/tests/unit/db/FolderMapperTest.php
+++ b/tests/unit/db/FolderMapperTest.php
@@ -125,14 +125,14 @@ class FolderMapperTest extends \OCA\News\Tests\Unit\Db\MapperTestUtility {
$arguments = [$folder->getId()];
$sql2 = 'DELETE FROM `*PREFIX*news_feeds` WHERE `folder_id` = ?';
+ $arguments2 = [$folder->getId()];
$sql3 = 'DELETE FROM `*PREFIX*news_items` WHERE `feed_id` NOT IN '.
'(SELECT `feeds`.`id` FROM `*PREFIX*news_feeds` `feeds`)';
- $arguments2 = [$folder->getId()];
- $this->setMapperResult($sql, $arguments);
- $this->setMapperResult($sql2, $arguments2);
- $this->setMapperResult($sql3);
+ $this->setMapperResult($sql, $arguments, [], null, null, true);
+ $this->setMapperResult($sql2, $arguments2, [], null, null, true);
+ $this->setMapperResult($sql3, [], [], null, null, true);
$this->folderMapper->delete($folder);
}
diff --git a/tests/unit/db/mappertestutility.php b/tests/unit/db/mappertestutility.php
index 278cbc475..cba2aadd6 100644
--- a/tests/unit/db/mappertestutility.php
+++ b/tests/unit/db/mappertestutility.php
@@ -31,7 +31,6 @@ namespace OCA\News\Tests\Unit\Db;
abstract class MapperTestUtility extends \PHPUnit_Framework_TestCase {
protected $db;
private $query;
- private $pdoResult;
private $queryAt;
private $prepareAt;
private $fetchAt;
@@ -50,11 +49,10 @@ abstract class MapperTestUtility extends \PHPUnit_Framework_TestCase {
->disableOriginalConstructor()
->getMock();
- $this->query = $this->getMock('Query', array('execute', 'bindValue'));
- $this->pdoResult = $this->getMock('Result', array('fetch', 'closeCursor'));
+ $this->query = $this->getMock('\PDOStatement');
$this->queryAt = 0;
$this->prepareAt = 0;
- $this->iterators = array();
+ $this->iterators = [];
$this->fetchAt = 0;
}
@@ -68,15 +66,40 @@ abstract class MapperTestUtility extends \PHPUnit_Framework_TestCase {
* of the database query. If not provided, it wont be assumed that fetch
* will be called on the result
*/
- protected function setMapperResult($sql, $arguments=[], $returnRows=[],
+ protected function setMapperResult($sql, $arguments=array(), $returnRows=array(),
$limit=null, $offset=null, $expectClose=false){
+ if($limit === null && $offset === null) {
+ $this->db->expects($this->at($this->prepareAt))
+ ->method('prepare')
+ ->with($this->equalTo($sql))
+ ->will(($this->returnValue($this->query)));
+ } elseif($limit !== null && $offset === null) {
+ $this->db->expects($this->at($this->prepareAt))
+ ->method('prepare')
+ ->with($this->equalTo($sql), $this->equalTo($limit))
+ ->will(($this->returnValue($this->query)));
+ } elseif($limit === null && $offset !== null) {
+ $this->db->expects($this->at($this->prepareAt))
+ ->method('prepare')
+ ->with($this->equalTo($sql),
+ $this->equalTo(null),
+ $this->equalTo($offset))
+ ->will(($this->returnValue($this->query)));
+ } else {
+ $this->db->expects($this->at($this->prepareAt))
+ ->method('prepare')
+ ->with($this->equalTo($sql),
+ $this->equalTo($limit),
+ $this->equalTo($offset))
+ ->will(($this->returnValue($this->query)));
+ }
$this->iterators[] = new ArgumentIterator($returnRows);
$iterators = $this->iterators;
$fetchAt = $this->fetchAt;
- $this->pdoResult->expects($this->any())
+ $this->query->expects($this->any())
->method('fetch')
->will($this->returnCallback(
function() use ($iterators, $fetchAt){
@@ -87,16 +110,11 @@ abstract class MapperTestUtility extends \PHPUnit_Framework_TestCase {
$fetchAt++;
}
+ $this->queryAt++;
+
return $result;
}
));
- if ($expectClose) {
- $closing = $this->once();
- } else {
- $closing = $this->any();
- }
- $this->pdoResult->expects($closing)
- ->method('closeCursor');
$index = 1;
foreach($arguments as $argument) {
@@ -128,42 +146,23 @@ abstract class MapperTestUtility extends \PHPUnit_Framework_TestCase {
$this->query->expects($this->at($this->queryAt))
->method('execute')
- ->with()
- ->will($this->returnValue($this->pdoResult));
+ ->will($this->returnCallback(function($sql, $p=null, $o=null, $s=null) {
+
+ }));
$this->queryAt++;
- if($limit === null && $offset === null) {
- $this->db->expects($this->at($this->prepareAt))
- ->method('prepareQuery')
- ->with($this->equalTo($sql),
- $this->equalTo(null),
- $this->equalTo(null))
- ->will(($this->returnValue($this->query)));
- } elseif($limit !== null && $offset === null) {
- $this->db->expects($this->at($this->prepareAt))
- ->method('prepareQuery')
- ->with($this->equalTo($sql),
- $this->equalTo($limit),
- $this->equalTo(null))
- ->will(($this->returnValue($this->query)));
- } elseif($limit === null && $offset !== null) {
- $this->db->expects($this->at($this->prepareAt))
- ->method('prepareQuery')
- ->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),
- $this->equalTo($limit),
- $this->equalTo($offset))
- ->will(($this->returnValue($this->query)));
+
+
+ if ($expectClose) {
+ $closing = $this->at($this->queryAt);
+ } else {
+ $closing = $this->any();
}
+ $this->query->expects($closing)->method('closeCursor');
+ $this->queryAt++;
+
$this->prepareAt++;
$this->fetchAt++;
-
}