diff options
Diffstat (limited to 'tests/lib/appframework/db/mappertestutility.php')
-rw-r--r-- | tests/lib/appframework/db/mappertestutility.php | 81 |
1 files changed, 41 insertions, 40 deletions
diff --git a/tests/lib/appframework/db/mappertestutility.php b/tests/lib/appframework/db/mappertestutility.php index 0053b2c682d..e99a7617d9f 100644 --- a/tests/lib/appframework/db/mappertestutility.php +++ b/tests/lib/appframework/db/mappertestutility.php @@ -31,7 +31,6 @@ namespace Test\AppFramework\Db; abstract class MapperTestUtility extends \Test\TestCase { protected $db; private $query; - private $pdoResult; private $queryAt; private $prepareAt; private $fetchAt; @@ -46,15 +45,14 @@ abstract class MapperTestUtility extends \Test\TestCase { parent::setUp(); $this->db = $this->getMockBuilder( - '\OCP\IDb') + '\OCP\IDBConnection') ->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; } @@ -70,13 +68,38 @@ abstract class MapperTestUtility extends \Test\TestCase { */ 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,15 +110,11 @@ abstract class MapperTestUtility extends \Test\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) { @@ -126,39 +145,21 @@ abstract class MapperTestUtility extends \Test\TestCase { } $this->query->expects($this->at($this->queryAt)) - ->method('execute') - ->with() - ->will($this->returnValue($this->pdoResult)); + ->method('execute'); $this->queryAt++; - if($limit === null && $offset === null) { - $this->db->expects($this->at($this->prepareAt)) - ->method('prepareQuery') - ->with($this->equalTo($sql)) - ->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)) - ->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->once(); + } else { + $closing = $this->any(); } + $this->query->expects($closing)->method('closeCursor'); + $this->queryAt++; + $this->prepareAt++; $this->fetchAt++; - } |