From 32cb30cb8400032d334873a3205e68bea7f909f5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 16 Jul 2015 10:38:12 +0200 Subject: Correctly count the number of items (rowCount is Update/Insert/Delete only) --- tests/lib/db/querybuilder/querybuildertest.php | 35 ++++++++++++++++---------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'tests') diff --git a/tests/lib/db/querybuilder/querybuildertest.php b/tests/lib/db/querybuilder/querybuildertest.php index 4ee44bb8dd7..8be0c5d17e7 100644 --- a/tests/lib/db/querybuilder/querybuildertest.php +++ b/tests/lib/db/querybuilder/querybuildertest.php @@ -25,17 +25,20 @@ use Doctrine\DBAL\Query\Expression\CompositeExpression; use OC\DB\QueryBuilder\Literal; use OC\DB\QueryBuilder\Parameter; use OC\DB\QueryBuilder\QueryBuilder; +use OCP\IDBConnection; class QueryBuilderTest extends \Test\TestCase { /** @var QueryBuilder */ protected $queryBuilder; + /** @var IDBConnection */ + protected $connection; + protected function setUp() { parent::setUp(); - $connection = \OC::$server->getDatabaseConnection(); - - $this->queryBuilder = new QueryBuilder($connection); + $this->connection = \OC::$server->getDatabaseConnection(); + $this->queryBuilder = new QueryBuilder($this->connection); } public function dataFirstResult() { @@ -54,18 +57,18 @@ class QueryBuilderTest extends \Test\TestCase { * @param array $expectedSet */ public function testFirstResult($firstResult, $expectedSet) { - $eB = $this->queryBuilder->expr(); + $qB = $this->connection->getQueryBuilder(); + $eB = $qB->expr(); for ($i = 1; $i < 10; $i++) { - $this->queryBuilder->insert('*PREFIX*appconfig') + $qB->insert('*PREFIX*appconfig') ->values([ 'appid' => $eB->literal('testFirstResult'), 'configkey' => $eB->literal('testing' . $i), 'configvalue' => $eB->literal(100 - $i), - ]); - $this->queryBuilder->execute(); + ]) + ->execute(); } - $this->queryBuilder->resetQueryParts(); if ($firstResult !== null) { $this->queryBuilder->setFirstResult($firstResult); @@ -82,13 +85,19 @@ class QueryBuilderTest extends \Test\TestCase { ->orderBy('configkey', 'ASC'); $query = $this->queryBuilder->execute(); - $this->assertSame(sizeof($expectedSet), $query->rowCount()); - $this->assertEquals($expectedSet, $query->fetchAll()); + $rows = []; + while ($row = $query->fetch()) { + $rows[] = $row; + } + $query->closeCursor(); - $this->queryBuilder->delete('*PREFIX*appconfig') - ->where($eB->eq('appid', $eB->literal('testFirstResult'))); + $this->assertCount(sizeof($expectedSet), $rows); + $this->assertEquals($expectedSet, $rows); - $query = $this->queryBuilder->execute(); + $qB = $this->connection->getQueryBuilder(); + $qB->delete('*PREFIX*appconfig') + ->where($eB->eq('appid', $eB->literal('testFirstResult'))) + ->execute(); } public function dataMaxResults() { -- cgit v1.2.3