diff options
author | Joas Schilling <coding@schilljs.com> | 2020-11-05 10:50:53 +0100 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2020-11-09 12:28:17 +0100 |
commit | 8027dcbc6f6b1653f5ebcf04b1862ac1e1f51d32 (patch) | |
tree | 1bf182f477bfbead7b75ae14a8cd0fce5bb38ada /tests | |
parent | 72545ffd07a07f142c9c18b3e4afc9ae1b5c8da2 (diff) | |
download | nextcloud-server-8027dcbc6f6b1653f5ebcf04b1862ac1e1f51d32.tar.gz nextcloud-server-8027dcbc6f6b1653f5ebcf04b1862ac1e1f51d32.zip |
Don't leave cursors open when tests fail
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Accounts/AccountsManagerTest.php | 5 | ||||
-rw-r--r-- | tests/lib/DB/ConnectionTest.php | 4 | ||||
-rw-r--r-- | tests/lib/DB/LegacyDBTest.php | 28 | ||||
-rw-r--r-- | tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php | 10 | ||||
-rw-r--r-- | tests/lib/DB/QueryBuilder/FunctionBuilderTest.php | 70 | ||||
-rw-r--r-- | tests/lib/Files/Cache/QuerySearchHelperTest.php | 7 | ||||
-rw-r--r-- | tests/lib/Files/Type/LoaderTest.php | 4 | ||||
-rw-r--r-- | tests/lib/Lock/DBLockingProviderTest.php | 7 |
8 files changed, 111 insertions, 24 deletions
diff --git a/tests/lib/Accounts/AccountsManagerTest.php b/tests/lib/Accounts/AccountsManagerTest.php index de9cc706b6a..ff75b51d008 100644 --- a/tests/lib/Accounts/AccountsManagerTest.php +++ b/tests/lib/Accounts/AccountsManagerTest.php @@ -248,7 +248,10 @@ class AccountsManagerTest extends TestCase { ->where($query->expr()->eq('uid', $query->createParameter('uid'))) ->setParameter('uid', $uid); $query->execute(); - $result = $query->execute()->fetchAll(); + + $qResult = $query->execute(); + $result = $qResult->fetchAll(); + $qResult->closeCursor(); if (!empty($result)) { return json_decode($result[0]['data'], true); diff --git a/tests/lib/DB/ConnectionTest.php b/tests/lib/DB/ConnectionTest.php index c8b2b7ee13e..be84cb81cb3 100644 --- a/tests/lib/DB/ConnectionTest.php +++ b/tests/lib/DB/ConnectionTest.php @@ -157,7 +157,7 @@ class ConnectionTest extends \Test\TestCase { $this->assertEquals('bar', $this->getTextValueByIntergerField(1)); } - + public function testSetValuesOverWritePreconditionFailed() { $this->expectException(\OCP\PreConditionNotMetException::class); @@ -335,7 +335,7 @@ class ConnectionTest extends \Test\TestCase { $this->assertEquals(0, $result); } - + public function testUniqueConstraintViolating() { $this->expectException(\Doctrine\DBAL\Exception\UniqueConstraintViolationException::class); diff --git a/tests/lib/DB/LegacyDBTest.php b/tests/lib/DB/LegacyDBTest.php index cf4c746a4dd..d4913cbe6f5 100644 --- a/tests/lib/DB/LegacyDBTest.php +++ b/tests/lib/DB/LegacyDBTest.php @@ -89,6 +89,8 @@ class LegacyDBTest extends \Test\TestCase { $this->assertTrue((bool)$result); $row = $result->fetchRow(); $this->assertFalse($row); + $result->closeCursor(); + $query = OC_DB::prepare('INSERT INTO `*PREFIX*'.$this->table2.'` (`fullname`,`uri`) VALUES (?,?)'); $result = $query->execute(['fullname test', 'uri_1']); $this->assertEquals(1, $result); @@ -100,6 +102,7 @@ class LegacyDBTest extends \Test\TestCase { $this->assertEquals($row['fullname'], 'fullname test'); $row = $result->fetchRow(); $this->assertFalse((bool)$row); //PDO returns false, MDB2 returns null + $result->closeCursor(); } /** @@ -112,6 +115,7 @@ class LegacyDBTest extends \Test\TestCase { $query = OC_DB::prepare('SELECT `fullname`,`uri` FROM `*PREFIX*'.$this->table2.'` WHERE `uri` = ?'); $result = $query->execute(['uri_2']); $this->assertTrue((bool)$result); + $result->closeCursor(); } public function testUNIX_TIMESTAMP() { @@ -121,6 +125,7 @@ class LegacyDBTest extends \Test\TestCase { $query = OC_DB::prepare('SELECT `fullname`,`uri` FROM `*PREFIX*'.$this->table2.'` WHERE `uri` = ?'); $result = $query->execute(['uri_3']); $this->assertTrue((bool)$result); + $result->closeCursor(); } public function testLastInsertId() { @@ -143,7 +148,12 @@ class LegacyDBTest extends \Test\TestCase { $result = $query->execute([$expected, 'uri_1', 'This is a vCard']); $this->assertEquals(1, $result); - $actual = OC_DB::prepare("SELECT `fullname` FROM `$table`")->execute()->fetchOne(); + $query = OC_DB::prepare("SELECT `fullname` FROM `$table`"); + + $result = $query->execute(); + $actual = $result->fetchOne(); + $result->closeCursor(); + $this->assertSame($expected, $actual); } @@ -162,6 +172,7 @@ class LegacyDBTest extends \Test\TestCase { $result = $query->execute(); $this->assertTrue((bool)$result); $row = $result->fetchRow(); + $result->closeCursor(); $this->assertArrayHasKey($rowname, $row); $this->assertEquals($expect, $row[$rowname]); $query = OC_DB::prepare('DELETE FROM `' . $table . '`'); @@ -227,14 +238,17 @@ class LegacyDBTest extends \Test\TestCase { $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` LIKE ?"); $result = $query->execute(['foobar']); $this->assertCount(0, $result->fetchAll()); + $result->closeCursor(); $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` ILIKE ?"); $result = $query->execute(['foobar']); $this->assertCount(1, $result->fetchAll()); + $result->closeCursor(); $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` ILIKE ?"); $result = $query->execute(['foo']); $this->assertCount(0, $result->fetchAll()); + $result->closeCursor(); } public function testILIKEWildcard() { @@ -246,26 +260,32 @@ class LegacyDBTest extends \Test\TestCase { $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` LIKE ?"); $result = $query->execute(['%bar']); $this->assertCount(0, $result->fetchAll()); + $result->closeCursor(); $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` LIKE ?"); $result = $query->execute(['foo%']); $this->assertCount(0, $result->fetchAll()); + $result->closeCursor(); $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` LIKE ?"); $result = $query->execute(['%ba%']); $this->assertCount(0, $result->fetchAll()); + $result->closeCursor(); $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` ILIKE ?"); $result = $query->execute(['%bar']); $this->assertCount(1, $result->fetchAll()); + $result->closeCursor(); $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` ILIKE ?"); $result = $query->execute(['foo%']); $this->assertCount(1, $result->fetchAll()); + $result->closeCursor(); $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` ILIKE ?"); $result = $query->execute(['%ba%']); $this->assertCount(1, $result->fetchAll()); + $result->closeCursor(); } /** @@ -282,7 +302,11 @@ class LegacyDBTest extends \Test\TestCase { $result = $query->execute([$expected]); $this->assertEquals(1, $result); - $actual = OC_DB::prepare("SELECT `textfield` FROM `$table`")->execute()->fetchOne(); + $query = OC_DB::prepare("SELECT `textfield` FROM `$table`"); + + $result = $query->execute(); + $actual = $result->fetchOne(); + $result->closeCursor(); $this->assertSame($expected, $actual); } diff --git a/tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php b/tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php index 8e0ce2fe934..8fd86a638fe 100644 --- a/tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php +++ b/tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php @@ -67,7 +67,10 @@ class ExpressionBuilderDBTest extends TestCase { ->from('users') ->where($query->expr()->like($query->createNamedParameter($param1), $query->createNamedParameter($param2))); - $this->assertEquals($match, $query->execute()->fetchColumn()); + $result = $query->execute(); + $column = $result->fetchColumn(); + $result->closeCursor(); + $this->assertEquals($match, $column); } public function ilikeProvider() { @@ -101,6 +104,9 @@ class ExpressionBuilderDBTest extends TestCase { ->from('users') ->where($query->expr()->iLike($query->createNamedParameter($param1), $query->createNamedParameter($param2))); - $this->assertEquals($match, $query->execute()->fetchColumn()); + $result = $query->execute(); + $column = $result->fetchColumn(); + $result->closeCursor(); + $this->assertEquals($match, $column); } } diff --git a/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php b/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php index 3d9baf35b1c..fad991bfa90 100644 --- a/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php +++ b/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php @@ -48,7 +48,10 @@ class FunctionBuilderTest extends TestCase { $query->from('appconfig') ->setMaxResults(1); - $this->assertEquals('foobar', $query->execute()->fetchColumn()); + $result = $query->execute(); + $column = $result->fetchColumn(); + $result->closeCursor(); + $this->assertEquals('foobar', $column); } public function testMd5() { @@ -58,7 +61,10 @@ class FunctionBuilderTest extends TestCase { $query->from('appconfig') ->setMaxResults(1); - $this->assertEquals(md5('foobar'), $query->execute()->fetchColumn()); + $result = $query->execute(); + $column = $result->fetchColumn(); + $result->closeCursor(); + $this->assertEquals(md5('foobar'), $column); } public function testSubstring() { @@ -68,7 +74,10 @@ class FunctionBuilderTest extends TestCase { $query->from('appconfig') ->setMaxResults(1); - $this->assertEquals('oo', $query->execute()->fetchColumn()); + $result = $query->execute(); + $column = $result->fetchColumn(); + $result->closeCursor(); + $this->assertEquals('oo', $column); } public function testSubstringNoLength() { @@ -78,7 +87,10 @@ class FunctionBuilderTest extends TestCase { $query->from('appconfig') ->setMaxResults(1); - $this->assertEquals('oobar', $query->execute()->fetchColumn()); + $result = $query->execute(); + $column = $result->fetchColumn(); + $result->closeCursor(); + $this->assertEquals('oobar', $column); } public function testLower() { @@ -88,7 +100,10 @@ class FunctionBuilderTest extends TestCase { $query->from('appconfig') ->setMaxResults(1); - $this->assertEquals('foobar', $query->execute()->fetchColumn()); + $result = $query->execute(); + $column = $result->fetchColumn(); + $result->closeCursor(); + $this->assertEquals('foobar', $column); } public function testAdd() { @@ -98,7 +113,10 @@ class FunctionBuilderTest extends TestCase { $query->from('appconfig') ->setMaxResults(1); - $this->assertEquals(3, $query->execute()->fetchColumn()); + $result = $query->execute(); + $column = $result->fetchColumn(); + $result->closeCursor(); + $this->assertEquals(3, $column); } public function testSubtract() { @@ -108,7 +126,10 @@ class FunctionBuilderTest extends TestCase { $query->from('appconfig') ->setMaxResults(1); - $this->assertEquals(1, $query->execute()->fetchColumn()); + $result = $query->execute(); + $column = $result->fetchColumn(); + $result->closeCursor(); + $this->assertEquals(1, $column); } public function testCount() { @@ -118,7 +139,10 @@ class FunctionBuilderTest extends TestCase { $query->from('appconfig') ->setMaxResults(1); - $this->assertGreaterThan(1, $query->execute()->fetchColumn()); + $result = $query->execute(); + $column = $result->fetchColumn(); + $result->closeCursor(); + $this->assertGreaterThan(1, $column); } private function setUpMinMax($value) { @@ -151,7 +175,10 @@ class FunctionBuilderTest extends TestCase { ->where($query->expr()->eq('appid', $query->createNamedParameter('minmax'))) ->setMaxResults(1); - $this->assertEquals(null, $query->execute()->fetchColumn()); + $result = $query->execute(); + $row = $result->fetchColumn(); + $result->closeCursor(); + $this->assertEquals(null, $row); } public function testMinEmpty() { @@ -164,7 +191,10 @@ class FunctionBuilderTest extends TestCase { ->where($query->expr()->eq('appid', $query->createNamedParameter('minmax'))) ->setMaxResults(1); - $this->assertEquals(null, $query->execute()->fetchColumn()); + $result = $query->execute(); + $row = $result->fetchColumn(); + $result->closeCursor(); + $this->assertEquals(null, $row); } public function testMax() { @@ -180,7 +210,10 @@ class FunctionBuilderTest extends TestCase { ->where($query->expr()->eq('appid', $query->createNamedParameter('minmax'))) ->setMaxResults(1); - $this->assertEquals(20, $query->execute()->fetchColumn()); + $result = $query->execute(); + $row = $result->fetchColumn(); + $result->closeCursor(); + $this->assertEquals(20, $row); } public function testMin() { @@ -196,7 +229,10 @@ class FunctionBuilderTest extends TestCase { ->where($query->expr()->eq('appid', $query->createNamedParameter('minmax'))) ->setMaxResults(1); - $this->assertEquals(10, $query->execute()->fetchColumn()); + $result = $query->execute(); + $row = $result->fetchColumn(); + $result->closeCursor(); + $this->assertEquals(10, $row); } public function testGreatest() { @@ -206,7 +242,10 @@ class FunctionBuilderTest extends TestCase { $query->from('appconfig') ->setMaxResults(1); - $this->assertEquals(2, $query->execute()->fetchColumn()); + $result = $query->execute(); + $row = $result->fetchColumn(); + $result->closeCursor(); + $this->assertEquals(2, $row); } public function testLeast() { @@ -216,6 +255,9 @@ class FunctionBuilderTest extends TestCase { $query->from('appconfig') ->setMaxResults(1); - $this->assertEquals(1, $query->execute()->fetchColumn()); + $result = $query->execute(); + $row = $result->fetchColumn(); + $result->closeCursor(); + $this->assertEquals(1, $row); } } diff --git a/tests/lib/Files/Cache/QuerySearchHelperTest.php b/tests/lib/Files/Cache/QuerySearchHelperTest.php index 8f97e0158fe..8344460f757 100644 --- a/tests/lib/Files/Cache/QuerySearchHelperTest.php +++ b/tests/lib/Files/Cache/QuerySearchHelperTest.php @@ -136,7 +136,12 @@ class QuerySearchHelperTest extends TestCase { private function search(ISearchOperator $operator) { $dbOperator = $this->querySearchHelper->searchOperatorToDBExpr($this->builder, $operator); $this->builder->andWhere($dbOperator); - return $this->builder->execute()->fetchAll(\PDO::FETCH_COLUMN); + + $result = $this->builder->execute(); + $rows = $result->fetchAll(\PDO::FETCH_COLUMN); + $result->closeCursor(); + + return $rows; } public function comparisonProvider() { diff --git a/tests/lib/Files/Type/LoaderTest.php b/tests/lib/Files/Type/LoaderTest.php index ccd37cbb655..fd3ec552dd2 100644 --- a/tests/lib/Files/Type/LoaderTest.php +++ b/tests/lib/Files/Type/LoaderTest.php @@ -76,7 +76,9 @@ class LoaderTest extends \Test\TestCase { ->from('mimetypes') ->where($qb->expr()->eq('id', $qb->createPositionalParameter($mimetypeId))); - $mimetype = $qb->execute()->fetch(); + $result = $qb->execute(); + $mimetype = $result->fetch(); + $result->closeCursor(); $this->assertEquals('testing/mymimetype', $mimetype['mimetype']); $this->assertEquals('testing/mymimetype', $this->loader->getMimetypeById($mimetypeId)); diff --git a/tests/lib/Lock/DBLockingProviderTest.php b/tests/lib/Lock/DBLockingProviderTest.php index ac58538284c..3f53589d8f1 100644 --- a/tests/lib/Lock/DBLockingProviderTest.php +++ b/tests/lib/Lock/DBLockingProviderTest.php @@ -102,7 +102,12 @@ class DBLockingProviderTest extends LockingProvider { $query->select('lock') ->from('file_locks') ->where($query->expr()->eq('key', $query->createNamedParameter($key))); - return $query->execute()->fetchColumn(); + + $result = $query->execute(); + $rows = $result->fetchColumn(); + $result->closeCursor(); + + return $rows; } public function testDoubleShared() { |