diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2021-01-03 17:28:31 +0300 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2021-01-08 13:45:19 +0300 |
commit | 8b64e92b9262d2a2eec6345685ce421050f95c66 (patch) | |
tree | dd51490b8a184b2643414d11867a9fa450aa5065 /tests | |
parent | 84e6e9f7cf19207041925eaa237d24e1c12c2c2d (diff) |
Bump doctrine/dbal from 2.12.0 to 3.0.0
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'tests')
22 files changed, 116 insertions, 108 deletions
diff --git a/tests/lib/AppConfigTest.php b/tests/lib/AppConfigTest.php index d2643d599f3..d4ae66cb2f1 100644 --- a/tests/lib/AppConfigTest.php +++ b/tests/lib/AppConfigTest.php @@ -10,6 +10,7 @@ namespace Test; use OC\AppConfig; +use OC\DB\Connection; use OCP\IConfig; /** @@ -23,7 +24,7 @@ class AppConfigTest extends TestCase { /** @var \OCP\IAppConfig */ protected $appConfig; - /** @var \OCP\IDBConnection */ + /** @var Connection */ protected $connection; protected $originalConfig; @@ -31,7 +32,7 @@ class AppConfigTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OC::$server->get(Connection::class); $sql = $this->connection->getQueryBuilder(); $sql->select('*') ->from('appconfig'); @@ -138,7 +139,7 @@ class AppConfigTest extends TestCase { } public function testGetApps() { - $config = new \OC\AppConfig(\OC::$server->getDatabaseConnection()); + $config = new \OC\AppConfig(\OC::$server->get(Connection::class)); $this->assertEqualsCanonicalizing([ 'anotherapp', @@ -149,7 +150,7 @@ class AppConfigTest extends TestCase { } public function testGetKeys() { - $config = new \OC\AppConfig(\OC::$server->getDatabaseConnection()); + $config = new \OC\AppConfig(\OC::$server->get(Connection::class)); $keys = $config->getKeys('testapp'); $this->assertEqualsCanonicalizing([ @@ -162,7 +163,7 @@ class AppConfigTest extends TestCase { } public function testGetValue() { - $config = new \OC\AppConfig(\OC::$server->getDatabaseConnection()); + $config = new \OC\AppConfig(\OC::$server->get(Connection::class)); $value = $config->getValue('testapp', 'installed_version'); $this->assertConfigKey('testapp', 'installed_version', $value); @@ -175,7 +176,7 @@ class AppConfigTest extends TestCase { } public function testHasKey() { - $config = new \OC\AppConfig(\OC::$server->getDatabaseConnection()); + $config = new \OC\AppConfig(\OC::$server->get(Connection::class)); $this->assertTrue($config->hasKey('testapp', 'installed_version')); $this->assertFalse($config->hasKey('testapp', 'nonexistant')); @@ -183,13 +184,13 @@ class AppConfigTest extends TestCase { } public function testSetValueUpdate() { - $config = new \OC\AppConfig(\OC::$server->getDatabaseConnection()); + $config = new \OC\AppConfig(\OC::$server->get(Connection::class)); $this->assertEquals('1.2.3', $config->getValue('testapp', 'installed_version')); $this->assertConfigKey('testapp', 'installed_version', '1.2.3'); $wasModified = $config->setValue('testapp', 'installed_version', '1.2.3'); - if (!(\OC::$server->getDatabaseConnection() instanceof \OC\DB\OracleConnection)) { + if (!(\OC::$server->get(Connection::class) instanceof \OC\DB\OracleConnection)) { $this->assertFalse($wasModified); } @@ -207,7 +208,7 @@ class AppConfigTest extends TestCase { } public function testSetValueInsert() { - $config = new \OC\AppConfig(\OC::$server->getDatabaseConnection()); + $config = new \OC\AppConfig(\OC::$server->get(Connection::class)); $this->assertFalse($config->hasKey('someapp', 'somekey')); $this->assertNull($config->getValue('someapp', 'somekey')); @@ -219,13 +220,13 @@ class AppConfigTest extends TestCase { $this->assertConfigKey('someapp', 'somekey', 'somevalue'); $wasInserted = $config->setValue('someapp', 'somekey', 'somevalue'); - if (!(\OC::$server->getDatabaseConnection() instanceof \OC\DB\OracleConnection)) { + if (!(\OC::$server->get(Connection::class) instanceof \OC\DB\OracleConnection)) { $this->assertFalse($wasInserted); } } public function testDeleteKey() { - $config = new \OC\AppConfig(\OC::$server->getDatabaseConnection()); + $config = new \OC\AppConfig(\OC::$server->get(Connection::class)); $this->assertTrue($config->hasKey('testapp', 'deletethis')); @@ -247,7 +248,7 @@ class AppConfigTest extends TestCase { } public function testDeleteApp() { - $config = new \OC\AppConfig(\OC::$server->getDatabaseConnection()); + $config = new \OC\AppConfig(\OC::$server->get(Connection::class)); $this->assertTrue($config->hasKey('someapp', 'otherkey')); @@ -267,7 +268,7 @@ class AppConfigTest extends TestCase { } public function testGetValuesNotAllowed() { - $config = new \OC\AppConfig(\OC::$server->getDatabaseConnection()); + $config = new \OC\AppConfig(\OC::$server->get(Connection::class)); $this->assertFalse($config->getValues('testapp', 'enabled')); @@ -275,7 +276,7 @@ class AppConfigTest extends TestCase { } public function testGetValues() { - $config = new \OC\AppConfig(\OC::$server->getDatabaseConnection()); + $config = new \OC\AppConfig(\OC::$server->get(Connection::class)); $sql = \OC::$server->getDatabaseConnection()->getQueryBuilder(); $sql->select(['configkey', 'configvalue']) @@ -311,7 +312,7 @@ class AppConfigTest extends TestCase { public function testGetFilteredValues() { /** @var \OC\AppConfig|\PHPUnit\Framework\MockObject\MockObject $config */ $config = $this->getMockBuilder(\OC\AppConfig::class) - ->setConstructorArgs([\OC::$server->getDatabaseConnection()]) + ->setConstructorArgs([\OC::$server->get(Connection::class)]) ->setMethods(['getValues']) ->getMock(); @@ -333,8 +334,8 @@ class AppConfigTest extends TestCase { } public function testSettingConfigParallel() { - $appConfig1 = new \OC\AppConfig(\OC::$server->getDatabaseConnection()); - $appConfig2 = new \OC\AppConfig(\OC::$server->getDatabaseConnection()); + $appConfig1 = new \OC\AppConfig(\OC::$server->get(Connection::class)); + $appConfig2 = new \OC\AppConfig(\OC::$server->get(Connection::class)); $appConfig1->getValue('testapp', 'foo', 'v1'); $appConfig2->getValue('testapp', 'foo', 'v1'); diff --git a/tests/lib/AppFramework/Db/MapperTestUtility.php b/tests/lib/AppFramework/Db/MapperTestUtility.php index b25ff9f3e16..e17b875e4c4 100644 --- a/tests/lib/AppFramework/Db/MapperTestUtility.php +++ b/tests/lib/AppFramework/Db/MapperTestUtility.php @@ -23,12 +23,15 @@ namespace Test\AppFramework\Db; +use OCP\DB\IPreparedStatement; +use OCP\DB\IResult; + /** * Simple utility class for testing mappers */ abstract class MapperTestUtility extends \Test\TestCase { protected $db; - private $query; + private $statement; private $queryAt; private $prepareAt; private $fetchAt; @@ -47,7 +50,7 @@ abstract class MapperTestUtility extends \Test\TestCase { ->disableOriginalConstructor() ->getMock(); - $this->query = $this->createMock('\PDOStatement'); + $this->statement = $this->createMock(IPreparedStatement::class); $this->queryAt = 0; $this->prepareAt = 0; $this->iterators = []; @@ -94,26 +97,26 @@ abstract class MapperTestUtility extends \Test\TestCase { $this->db->expects($this->at($this->prepareAt)) ->method('prepare') ->with($this->equalTo($sql)) - ->will(($this->returnValue($this->query))); + ->will(($this->returnValue($this->statement))); } 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))); + ->will(($this->returnValue($this->statement))); } 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))); + ->will(($this->returnValue($this->statement))); } 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))); + ->will(($this->returnValue($this->statement))); } $this->iterators[] = new ArgumentIterator($returnRows); @@ -121,7 +124,7 @@ abstract class MapperTestUtility extends \Test\TestCase { $iterators = $this->iterators; $fetchAt = $this->fetchAt; - $this->query->expects($this->any()) + $this->statement->expects($this->any()) ->method('fetch') ->willReturnCallback( function () use ($iterators, $fetchAt) { @@ -141,7 +144,7 @@ abstract class MapperTestUtility extends \Test\TestCase { if ($this->isAssocArray($arguments)) { foreach ($arguments as $key => $argument) { $pdoConstant = $this->getPDOType($argument); - $this->query->expects($this->at($this->queryAt)) + $this->statement->expects($this->at($this->queryAt)) ->method('bindValue') ->with($this->equalTo($key), $this->equalTo($argument), @@ -152,7 +155,7 @@ abstract class MapperTestUtility extends \Test\TestCase { $index = 1; foreach ($arguments as $argument) { $pdoConstant = $this->getPDOType($argument); - $this->query->expects($this->at($this->queryAt)) + $this->statement->expects($this->at($this->queryAt)) ->method('bindValue') ->with($this->equalTo($index), $this->equalTo($argument), @@ -162,9 +165,10 @@ abstract class MapperTestUtility extends \Test\TestCase { } } - $this->query->expects($this->at($this->queryAt)) + $this->statement->expects($this->at($this->queryAt)) ->method('execute') ->willReturnCallback(function ($sql, $p = null, $o = null, $s = null) { + return $this->createMock(IResult::class); }); $this->queryAt++; @@ -175,7 +179,7 @@ abstract class MapperTestUtility extends \Test\TestCase { } else { $closing = $this->any(); } - $this->query->expects($closing)->method('closeCursor'); + $this->statement->expects($closing)->method('closeCursor'); $this->queryAt++; $this->prepareAt++; diff --git a/tests/lib/DB/ConnectionTest.php b/tests/lib/DB/ConnectionTest.php index cab6133c3c0..d628d9814e0 100644 --- a/tests/lib/DB/ConnectionTest.php +++ b/tests/lib/DB/ConnectionTest.php @@ -44,7 +44,7 @@ class ConnectionTest extends \Test\TestCase { protected function setUp(): void { parent::setUp(); - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OC::$server->get(\OC\DB\Connection::class); } protected function tearDown(): void { @@ -234,7 +234,7 @@ class ConnectionTest extends \Test\TestCase { $query = $this->connection->prepare('SELECT * FROM `*PREFIX*table`'); $result = $query->execute(); $this->assertTrue((bool)$result); - $this->assertEquals(7, count($query->fetchAll())); + $this->assertEquals(7, count($result->fetchAll())); } public function testInsertIfNotExistNull() { @@ -263,7 +263,7 @@ class ConnectionTest extends \Test\TestCase { $query = $this->connection->prepare('SELECT * FROM `*PREFIX*table`'); $result = $query->execute(); $this->assertTrue((bool)$result); - $this->assertEquals(2, count($query->fetchAll())); + $this->assertEquals(2, count($result->fetchAll())); } public function testInsertIfNotExistDonTOverwrite() { @@ -278,11 +278,10 @@ class ConnectionTest extends \Test\TestCase { // Normal test to have same known data inserted. $query = $this->connection->prepare('INSERT INTO `*PREFIX*table` (`textfield`, `clobfield`) VALUES (?, ?)'); $result = $query->execute([$fullName, $uri]); - $this->assertEquals(1, $result); + $this->assertEquals(1, $result->rowCount()); $query = $this->connection->prepare('SELECT `textfield`, `clobfield` FROM `*PREFIX*table` WHERE `clobfield` = ?'); $result = $query->execute([$uri]); - $this->assertTrue($result); - $rowset = $query->fetchAll(); + $rowset = $result->fetchAll(); $this->assertEquals(1, count($rowset)); $this->assertArrayHasKey('textfield', $rowset[0]); $this->assertEquals($fullName, $rowset[0]['textfield']); @@ -297,10 +296,9 @@ class ConnectionTest extends \Test\TestCase { $query = $this->connection->prepare('SELECT `textfield`, `clobfield` FROM `*PREFIX*table` WHERE `clobfield` = ?'); $result = $query->execute([$uri]); - $this->assertTrue($result); // Test that previously inserted data isn't overwritten // And that a new row hasn't been inserted. - $rowset = $query->fetchAll(); + $rowset = $result->fetchAll(); $this->assertEquals(1, count($rowset)); $this->assertArrayHasKey('textfield', $rowset[0]); $this->assertEquals($fullName, $rowset[0]['textfield']); diff --git a/tests/lib/DB/DBSchemaTest.php b/tests/lib/DB/DBSchemaTest.php index 9f575a75da6..4f24c3f67aa 100644 --- a/tests/lib/DB/DBSchemaTest.php +++ b/tests/lib/DB/DBSchemaTest.php @@ -64,7 +64,6 @@ class DBSchemaTest extends TestCase { public function testSchema() { $this->doTestSchemaCreating(); $this->doTestSchemaChanging(); - $this->doTestSchemaDumping(); $this->doTestSchemaRemoving(); } @@ -79,14 +78,6 @@ class DBSchemaTest extends TestCase { $this->assertTableExist($this->table2); } - public function doTestSchemaDumping() { - $outfile = $this->tempManager->getTemporaryFile(); - OC_DB::getDbStructure($outfile); - $content = file_get_contents($outfile); - $this->assertStringContainsString($this->table1, $content); - $this->assertStringContainsString($this->table2, $content); - } - public function doTestSchemaRemoving() { OC_DB::removeDBStructure($this->schema_file); $this->assertTableNotExist($this->table1); diff --git a/tests/lib/DB/MDB2SchemaManagerTest.php b/tests/lib/DB/MDB2SchemaManagerTest.php index 18af9716502..693de746b5e 100644 --- a/tests/lib/DB/MDB2SchemaManagerTest.php +++ b/tests/lib/DB/MDB2SchemaManagerTest.php @@ -30,7 +30,7 @@ class MDB2SchemaManagerTest extends \Test\TestCase { } public function testAutoIncrement() { - $connection = \OC::$server->getDatabaseConnection(); + $connection = \OC::$server->get(\OC\DB\Connection::class); if ($connection->getDatabasePlatform() instanceof OraclePlatform) { $this->markTestSkipped('Adding auto increment columns in Oracle is not supported.'); } diff --git a/tests/lib/DB/MDB2SchemaReaderTest.php b/tests/lib/DB/MDB2SchemaReaderTest.php index b3dd98fd6b7..1e7d3a20b7c 100644 --- a/tests/lib/DB/MDB2SchemaReaderTest.php +++ b/tests/lib/DB/MDB2SchemaReaderTest.php @@ -9,7 +9,7 @@ namespace Test\DB; -use Doctrine\DBAL\Platforms\MySqlPlatform; +use Doctrine\DBAL\Platforms\MySQLPlatform; use Doctrine\DBAL\Schema\Schema; use OC\DB\MDB2SchemaReader; use OCP\IConfig; @@ -50,7 +50,7 @@ class MDB2SchemaReaderTest extends TestCase { } public function testRead() { - $reader = new MDB2SchemaReader($this->getConfig(), new MySqlPlatform()); + $reader = new MDB2SchemaReader($this->getConfig(), new MySQLPlatform()); $schema = $reader->loadSchemaFromFile(__DIR__ . '/testschema.xml', new Schema()); $this->assertCount(1, $schema->getTables()); diff --git a/tests/lib/DB/MigratorTest.php b/tests/lib/DB/MigratorTest.php index 52b0b0ff03e..539eb404bbf 100644 --- a/tests/lib/DB/MigratorTest.php +++ b/tests/lib/DB/MigratorTest.php @@ -9,7 +9,7 @@ namespace Test\DB; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\SchemaConfig; @@ -49,7 +49,7 @@ class MigratorTest extends \Test\TestCase { parent::setUp(); $this->config = \OC::$server->getConfig(); - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OC::$server->get(\OC\DB\Connection::class); if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) { $this->markTestSkipped('DB migration tests are not supported on OCI'); } @@ -66,12 +66,12 @@ class MigratorTest extends \Test\TestCase { // Try to delete if exists (IF EXISTS NOT SUPPORTED IN ORACLE) try { $this->connection->exec('DROP TABLE ' . $this->connection->quoteIdentifier($this->tableNameTmp)); - } catch (\Doctrine\DBAL\DBALException $e) { + } catch (Exception $e) { } try { $this->connection->exec('DROP TABLE ' . $this->connection->quoteIdentifier($this->tableName)); - } catch (\Doctrine\DBAL\DBALException $e) { + } catch (Exception $e) { } parent::tearDown(); } @@ -125,9 +125,9 @@ class MigratorTest extends \Test\TestCase { return $this->connection->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver; } - + public function testDuplicateKeyUpgrade() { - $this->expectException(\OC\DB\MigrationException::class); + $this->expectException(Exception\UniqueConstraintViolationException::class); if ($this->isSQLite()) { $this->markTestSkipped('sqlite does not throw errors when creating a new key on existing data'); @@ -140,8 +140,12 @@ class MigratorTest extends \Test\TestCase { $this->connection->insert($this->tableName, ['id' => 2, 'name' => 'bar']); $this->connection->insert($this->tableName, ['id' => 2, 'name' => 'qwerty']); - $migrator->checkMigrate($endSchema); - $this->fail('checkMigrate should have failed'); + try { + $migrator->migrate($endSchema); + } catch (Exception\UniqueConstraintViolationException $e) { + $this->connection->rollBack(); + throw $e; + } } public function testChangeToString() { @@ -156,7 +160,6 @@ class MigratorTest extends \Test\TestCase { $this->connection->insert($this->tableName, ['id' => 2, 'name' => 'bar']); $this->connection->insert($this->tableName, ['id' => 3, 'name' => 'qwerty']); - $migrator->checkMigrate($endSchema); $migrator->migrate($endSchema); $this->addToAssertionCount(1); @@ -181,7 +184,6 @@ class MigratorTest extends \Test\TestCase { $this->connection->insert($this->tableName, ['id' => 2, 'name' => 'bar']); $this->connection->insert($this->tableName, ['id' => 3, 'name' => 'qwerty']); - $migrator->checkMigrate($endSchema); $migrator->migrate($endSchema); $this->addToAssertionCount(1); } @@ -200,7 +202,6 @@ class MigratorTest extends \Test\TestCase { $this->connection->insert($this->tableName, ['id' => 2, 'name' => 'bar']); $this->connection->insert($this->tableName, ['id' => 3, 'name' => 'qwerty']); - $migrator->checkMigrate($endSchema); $migrator->migrate($endSchema); $this->addToAssertionCount(1); @@ -219,7 +220,7 @@ class MigratorTest extends \Test\TestCase { try { $this->connection->insert($this->tableName, ['id' => 2, 'name' => 'qwerty']); $this->fail('Expected duplicate key insert to fail'); - } catch (DBALException $e) { + } catch (Exception $e) { $this->addToAssertionCount(1); } } @@ -239,7 +240,6 @@ class MigratorTest extends \Test\TestCase { $migrator = $this->manager->getMigrator(); $migrator->migrate($startSchema); - $migrator->checkMigrate($endSchema); $migrator->migrate($endSchema); $this->addToAssertionCount(1); @@ -261,7 +261,6 @@ class MigratorTest extends \Test\TestCase { $migrator = $this->manager->getMigrator(); $migrator->migrate($startSchema); - $migrator->checkMigrate($endSchema); $migrator->migrate($endSchema); $this->addToAssertionCount(1); diff --git a/tests/lib/DB/MySqlMigrationTest.php b/tests/lib/DB/MySqlMigrationTest.php index 36ab8ef7319..38cb64916ec 100644 --- a/tests/lib/DB/MySqlMigrationTest.php +++ b/tests/lib/DB/MySqlMigrationTest.php @@ -24,7 +24,7 @@ class MySqlMigrationTest extends \Test\TestCase { protected function setUp(): void { parent::setUp(); - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OC::$server->get(\OC\DB\Connection::class); if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform) { $this->markTestSkipped("Test only relevant on MySql"); } diff --git a/tests/lib/DB/OCPostgreSqlPlatformTest.php b/tests/lib/DB/OCPostgreSqlPlatformTest.php index 62a2fc34712..334a2ecc778 100644 --- a/tests/lib/DB/OCPostgreSqlPlatformTest.php +++ b/tests/lib/DB/OCPostgreSqlPlatformTest.php @@ -21,7 +21,7 @@ namespace Test\DB; -use Doctrine\DBAL\Platforms\PostgreSqlPlatform; +use Doctrine\DBAL\Platforms\PostgreSQL100Platform; use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Types\Types; @@ -38,7 +38,7 @@ use Doctrine\DBAL\Types\Types; */ class OCPostgreSqlPlatformTest extends \Test\TestCase { public function testAlterBigint() { - $platform = new PostgreSqlPlatform(); + $platform = new PostgreSQL100Platform(); $sourceSchema = new Schema(); $targetSchema = new Schema(); diff --git a/tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php b/tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php index 8fd86a638fe..d7f6b4ac115 100644 --- a/tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php +++ b/tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php @@ -68,7 +68,7 @@ class ExpressionBuilderDBTest extends TestCase { ->where($query->expr()->like($query->createNamedParameter($param1), $query->createNamedParameter($param2))); $result = $query->execute(); - $column = $result->fetchColumn(); + $column = $result->fetchOne(); $result->closeCursor(); $this->assertEquals($match, $column); } @@ -105,7 +105,7 @@ class ExpressionBuilderDBTest extends TestCase { ->where($query->expr()->iLike($query->createNamedParameter($param1), $query->createNamedParameter($param2))); $result = $query->execute(); - $column = $result->fetchColumn(); + $column = $result->fetchOne(); $result->closeCursor(); $this->assertEquals($match, $column); } diff --git a/tests/lib/DB/QueryBuilder/ExpressionBuilderTest.php b/tests/lib/DB/QueryBuilder/ExpressionBuilderTest.php index b3e9124e7de..2a3a4e9a9c1 100644 --- a/tests/lib/DB/QueryBuilder/ExpressionBuilderTest.php +++ b/tests/lib/DB/QueryBuilder/ExpressionBuilderTest.php @@ -40,19 +40,23 @@ class ExpressionBuilderTest extends TestCase { /** @var DoctrineExpressionBuilder */ protected $doctrineExpressionBuilder; - /** @var \Doctrine\DBAL\Connection|\OCP\IDBConnection */ + /** @var \OCP\IDBConnection */ protected $connection; + /** @var \Doctrine\DBAL\Connection */ + protected $internalConnection; + protected function setUp(): void { parent::setUp(); $this->connection = \OC::$server->getDatabaseConnection(); + $this->internalConnection = \OC::$server->get(\OC\DB\Connection::class); $queryBuilder = $this->createMock(IQueryBuilder::class); $this->expressionBuilder = new ExpressionBuilder($this->connection, $queryBuilder); - $this->doctrineExpressionBuilder = new DoctrineExpressionBuilder($this->connection); + $this->doctrineExpressionBuilder = new DoctrineExpressionBuilder($this->internalConnection); } public function dataComparison() { diff --git a/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php b/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php index fad991bfa90..71ae3d5c7f6 100644 --- a/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php +++ b/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php @@ -49,7 +49,7 @@ class FunctionBuilderTest extends TestCase { ->setMaxResults(1); $result = $query->execute(); - $column = $result->fetchColumn(); + $column = $result->fetchOne(); $result->closeCursor(); $this->assertEquals('foobar', $column); } @@ -62,7 +62,7 @@ class FunctionBuilderTest extends TestCase { ->setMaxResults(1); $result = $query->execute(); - $column = $result->fetchColumn(); + $column = $result->fetchOne(); $result->closeCursor(); $this->assertEquals(md5('foobar'), $column); } @@ -75,7 +75,7 @@ class FunctionBuilderTest extends TestCase { ->setMaxResults(1); $result = $query->execute(); - $column = $result->fetchColumn(); + $column = $result->fetchOne(); $result->closeCursor(); $this->assertEquals('oo', $column); } @@ -88,7 +88,7 @@ class FunctionBuilderTest extends TestCase { ->setMaxResults(1); $result = $query->execute(); - $column = $result->fetchColumn(); + $column = $result->fetchOne(); $result->closeCursor(); $this->assertEquals('oobar', $column); } @@ -101,7 +101,7 @@ class FunctionBuilderTest extends TestCase { ->setMaxResults(1); $result = $query->execute(); - $column = $result->fetchColumn(); + $column = $result->fetchOne(); $result->closeCursor(); $this->assertEquals('foobar', $column); } @@ -114,7 +114,7 @@ class FunctionBuilderTest extends TestCase { ->setMaxResults(1); $result = $query->execute(); - $column = $result->fetchColumn(); + $column = $result->fetchOne(); $result->closeCursor(); $this->assertEquals(3, $column); } @@ -127,7 +127,7 @@ class FunctionBuilderTest extends TestCase { ->setMaxResults(1); $result = $query->execute(); - $column = $result->fetchColumn(); + $column = $result->fetchOne(); $result->closeCursor(); $this->assertEquals(1, $column); } @@ -140,7 +140,7 @@ class FunctionBuilderTest extends TestCase { ->setMaxResults(1); $result = $query->execute(); - $column = $result->fetchColumn(); + $column = $result->fetchOne(); $result->closeCursor(); $this->assertGreaterThan(1, $column); } @@ -176,7 +176,7 @@ class FunctionBuilderTest extends TestCase { ->setMaxResults(1); $result = $query->execute(); - $row = $result->fetchColumn(); + $row = $result->fetchOne(); $result->closeCursor(); $this->assertEquals(null, $row); } @@ -192,7 +192,7 @@ class FunctionBuilderTest extends TestCase { ->setMaxResults(1); $result = $query->execute(); - $row = $result->fetchColumn(); + $row = $result->fetchOne(); $result->closeCursor(); $this->assertEquals(null, $row); } @@ -211,7 +211,7 @@ class FunctionBuilderTest extends TestCase { ->setMaxResults(1); $result = $query->execute(); - $row = $result->fetchColumn(); + $row = $result->fetchOne(); $result->closeCursor(); $this->assertEquals(20, $row); } @@ -230,7 +230,7 @@ class FunctionBuilderTest extends TestCase { ->setMaxResults(1); $result = $query->execute(); - $row = $result->fetchColumn(); + $row = $result->fetchOne(); $result->closeCursor(); $this->assertEquals(10, $row); } @@ -243,7 +243,7 @@ class FunctionBuilderTest extends TestCase { ->setMaxResults(1); $result = $query->execute(); - $row = $result->fetchColumn(); + $row = $result->fetchOne(); $result->closeCursor(); $this->assertEquals(2, $row); } @@ -256,7 +256,7 @@ class FunctionBuilderTest extends TestCase { ->setMaxResults(1); $result = $query->execute(); - $row = $result->fetchColumn(); + $row = $result->fetchOne(); $result->closeCursor(); $this->assertEquals(1, $row); } diff --git a/tests/lib/DB/SchemaDiffTest.php b/tests/lib/DB/SchemaDiffTest.php index 6394fa41b8e..0e5612e3b3b 100644 --- a/tests/lib/DB/SchemaDiffTest.php +++ b/tests/lib/DB/SchemaDiffTest.php @@ -26,6 +26,7 @@ use Doctrine\DBAL\Schema\SchemaDiff; use OC\DB\MDB2SchemaManager; use OC\DB\MDB2SchemaReader; use OCP\IConfig; +use OCP\IDBConnection; use Test\TestCase; /** @@ -36,8 +37,10 @@ use Test\TestCase; * @package Test\DB */ class SchemaDiffTest extends TestCase { - /** @var \Doctrine\DBAL\Connection $connection */ + /** @var IDBConnection $connection */ private $connection; + /** @var \Doctrine\DBAL\Connection $connection */ + private $internalConnection; /** @var MDB2SchemaManager */ private $manager; @@ -57,7 +60,8 @@ class SchemaDiffTest extends TestCase { $this->config = \OC::$server->getConfig(); $this->connection = \OC::$server->getDatabaseConnection(); - $this->manager = new MDB2SchemaManager($this->connection); + $this->internalConnection = \OC::$server->get(\OC\DB\Connection::class); + $this->manager = new MDB2SchemaManager($this->internalConnection); $this->testPrefix = strtolower($this->getUniqueID($this->config->getSystemValue('dbtableprefix', 'oc_'), 3)); } @@ -79,17 +83,17 @@ class SchemaDiffTest extends TestCase { $this->manager->createDbFromStructure($schemaFile); $schemaReader = new MDB2SchemaReader($this->config, $this->connection->getDatabasePlatform()); - $toSchema = new Schema([], [], $this->connection->getSchemaManager()->createSchemaConfig()); + $toSchema = new Schema([], [], $this->internalConnection->getSchemaManager()->createSchemaConfig()); $endSchema = $schemaReader->loadSchemaFromFile($schemaFile, $toSchema); // get the diff /** @var SchemaDiff $diff */ $migrator = $this->manager->getMigrator(); - $diff = $this->invokePrivate($migrator, 'getDiff', [$endSchema, $this->connection]); + $diff = $this->invokePrivate($migrator, 'getDiff', [$endSchema, $this->internalConnection]); // no sql statement is expected $sqls = $diff->toSql($this->connection->getDatabasePlatform()); - $this->assertEquals([], $sqls); + $this->assertEmpty($sqls); } public function providesSchemaFiles() { diff --git a/tests/lib/DB/SqliteMigrationTest.php b/tests/lib/DB/SqliteMigrationTest.php index 480a5ebe74f..b0bf39b4035 100644 --- a/tests/lib/DB/SqliteMigrationTest.php +++ b/tests/lib/DB/SqliteMigrationTest.php @@ -24,14 +24,14 @@ class SqliteMigrationTest extends \Test\TestCase { protected function setUp(): void { parent::setUp(); - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OC::$server->get(\OC\DB\Connection::class); if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) { $this->markTestSkipped("Test only relevant on Sqlite"); } $dbPrefix = \OC::$server->getConfig()->getSystemValue("dbtableprefix"); $this->tableName = $this->getUniqueID($dbPrefix . '_enum_bit_test'); - $this->connection->exec("CREATE TABLE $this->tableName(t0 tinyint unsigned, t1 tinyint)"); + $this->connection->prepare("CREATE TABLE $this->tableName(t0 tinyint unsigned, t1 tinyint)")->execute(); } protected function tearDown(): void { diff --git a/tests/lib/Files/Cache/CacheTest.php b/tests/lib/Files/Cache/CacheTest.php index a6d429798e8..d74f9cc723c 100644 --- a/tests/lib/Files/Cache/CacheTest.php +++ b/tests/lib/Files/Cache/CacheTest.php @@ -116,7 +116,7 @@ class CacheTest extends \Test\TestCase { public function testFolder($folder) { if (strpos($folder, 'F09F9890')) { // 4 byte UTF doesn't work on mysql - $params = \OC::$server->getDatabaseConnection()->getParams(); + $params = \OC::$server->get(\OC\DB\Connection::class)->getParams(); if (\OC::$server->getDatabaseConnection()->getDatabasePlatform() instanceof MySqlPlatform && $params['charset'] !== 'utf8mb4') { $this->markTestSkipped('MySQL doesn\'t support 4 byte UTF-8'); } diff --git a/tests/lib/Files/Config/UserMountCacheTest.php b/tests/lib/Files/Config/UserMountCacheTest.php index 6f347a504cb..2bea4f8389a 100644 --- a/tests/lib/Files/Config/UserMountCacheTest.php +++ b/tests/lib/Files/Config/UserMountCacheTest.php @@ -337,7 +337,7 @@ class UserMountCacheTest extends TestCase { $sql = 'SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` =?'; $query = $this->connection->prepare($sql); $query->execute([$storageId, md5($internalPath)]); - return (int)$query->fetchColumn(); + return (int)$query->fetchOne(); } return $id; } diff --git a/tests/lib/Lock/DBLockingProviderTest.php b/tests/lib/Lock/DBLockingProviderTest.php index 3f53589d8f1..31abd330fed 100644 --- a/tests/lib/Lock/DBLockingProviderTest.php +++ b/tests/lib/Lock/DBLockingProviderTest.php @@ -94,7 +94,7 @@ class DBLockingProviderTest extends LockingProvider { private function getLockEntryCount() { $query = $this->connection->prepare('SELECT count(*) FROM `*PREFIX*file_locks`'); $query->execute(); - return $query->fetchColumn(); + return $query->fetchOne(); } protected function getLockValue($key) { @@ -104,7 +104,7 @@ class DBLockingProviderTest extends LockingProvider { ->where($query->expr()->eq('key', $query->createNamedParameter($key))); $result = $query->execute(); - $rows = $result->fetchColumn(); + $rows = $result->fetchOne(); $result->closeCursor(); return $rows; diff --git a/tests/lib/Repair/CleanTagsTest.php b/tests/lib/Repair/CleanTagsTest.php index a56d79f9bc6..3f3ac0bf18d 100644 --- a/tests/lib/Repair/CleanTagsTest.php +++ b/tests/lib/Repair/CleanTagsTest.php @@ -122,7 +122,7 @@ class CleanTagsTest extends \Test\TestCase { ->from($tableName) ->execute(); - $this->assertEquals($expected, $result->fetchColumn(), $message); + $this->assertEquals($expected, $result->fetchOne(), $message); } /** diff --git a/tests/lib/Repair/RepairCollationTest.php b/tests/lib/Repair/RepairCollationTest.php index 9cba3e8e30a..35679eb8630 100644 --- a/tests/lib/Repair/RepairCollationTest.php +++ b/tests/lib/Repair/RepairCollationTest.php @@ -8,7 +8,6 @@ namespace Test\Repair; -use Doctrine\DBAL\Connection; use Doctrine\DBAL\Platforms\MySqlPlatform; use OC\Repair\Collation; use OCP\IDBConnection; @@ -41,7 +40,7 @@ class RepairCollationTest extends TestCase { private $repair; /** - * @var Connection|IDBConnection + * @var IDBConnection */ private $connection; @@ -61,7 +60,7 @@ class RepairCollationTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OC::$server->get(IDBConnection::class); $this->logger = $this->createMock(ILogger::class); $this->config = \OC::$server->getConfig(); if (!$this->connection->getDatabasePlatform() instanceof MySqlPlatform) { @@ -70,13 +69,13 @@ class RepairCollationTest extends TestCase { $dbPrefix = $this->config->getSystemValue("dbtableprefix"); $this->tableName = $this->getUniqueID($dbPrefix . "_collation_test"); - $this->connection->exec("CREATE TABLE $this->tableName(text VARCHAR(16)) COLLATE utf8_unicode_ci"); + $this->connection->prepare("CREATE TABLE $this->tableName(text VARCHAR(16)) COLLATE utf8_unicode_ci")->execute(); $this->repair = new TestCollationRepair($this->config, $this->logger, $this->connection, false); } protected function tearDown(): void { - $this->connection->getSchemaManager()->dropTable($this->tableName); + $this->connection->getInner()->getSchemaManager()->dropTable($this->tableName); parent::tearDown(); } diff --git a/tests/lib/Repair/RepairSqliteAutoincrementTest.php b/tests/lib/Repair/RepairSqliteAutoincrementTest.php index 9db0d5630aa..c03eb12b894 100644 --- a/tests/lib/Repair/RepairSqliteAutoincrementTest.php +++ b/tests/lib/Repair/RepairSqliteAutoincrementTest.php @@ -8,6 +8,7 @@ namespace Test\Repair; +use OC\DB\Connection; use OCP\Migration\IOutput; /** @@ -23,7 +24,7 @@ class RepairSqliteAutoincrementTest extends \Test\TestCase { private $repair; /** - * @var \Doctrine\DBAL\Connection + * @var Connection */ private $connection; @@ -40,7 +41,7 @@ class RepairSqliteAutoincrementTest extends \Test\TestCase { protected function setUp(): void { parent::setUp(); - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OC::$server->get(\OC\DB\Connection::class); $this->config = \OC::$server->getConfig(); if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) { $this->markTestSkipped("Test only relevant on Sqlite"); @@ -48,7 +49,7 @@ class RepairSqliteAutoincrementTest extends \Test\TestCase { $dbPrefix = $this->config->getSystemValue('dbtableprefix', 'oc_'); $this->tableName = $this->getUniqueID($dbPrefix . 'autoinc_test'); - $this->connection->exec('CREATE TABLE ' . $this->tableName . '("someid" INTEGER NOT NULL, "text" VARCHAR(16), PRIMARY KEY("someid"))'); + $this->connection->prepare('CREATE TABLE ' . $this->tableName . '("someid" INTEGER NOT NULL, "text" VARCHAR(16), PRIMARY KEY("someid"))')->execute(); $this->repair = new \OC\Repair\SqliteAutoincrement($this->connection); } diff --git a/tests/lib/Security/CredentialsManagerTest.php b/tests/lib/Security/CredentialsManagerTest.php index 9c1a0cb9291..3ce80227f44 100644 --- a/tests/lib/Security/CredentialsManagerTest.php +++ b/tests/lib/Security/CredentialsManagerTest.php @@ -21,6 +21,7 @@ namespace Test\Security; +use OC\DB\ConnectionAdapter; use OC\Security\CredentialsManager; use OC\SystemConfig; use OCP\IDBConnection; @@ -38,13 +39,19 @@ class CredentialsManagerTest extends \Test\TestCase { /** @var IDBConnection */ protected $dbConnection; + /** @var ConnectionAdapter */ + protected $dbConnectionAdapter; + /** @var CredentialsManager */ protected $manager; protected function setUp(): void { parent::setUp(); $this->crypto = $this->createMock(ICrypto::class); - $this->dbConnection = $this->getMockBuilder('\OC\DB\Connection') + $this->dbConnection = $this->getMockBuilder(IDBConnection::class) + ->disableOriginalConstructor() + ->getMock(); + $this->dbConnectionAdapter = $this->getMockBuilder(ConnectionAdapter::class) ->disableOriginalConstructor() ->getMock(); $this->manager = new CredentialsManager($this->crypto, $this->dbConnection); @@ -91,9 +98,9 @@ class CredentialsManagerTest extends \Test\TestCase { ->with('baz') ->willReturn(json_encode('bar')); - $qb = $this->getMockBuilder('\OC\DB\QueryBuilder\QueryBuilder') + $qb = $this->getMockBuilder(\OC\DB\QueryBuilder\QueryBuilder::class) ->setConstructorArgs([ - $this->dbConnection, + $this->dbConnectionAdapter, $this->createMock(SystemConfig::class), $this->createMock(ILogger::class), ]) @@ -103,7 +110,7 @@ class CredentialsManagerTest extends \Test\TestCase { ->method('execute') ->willReturn($this->getQueryResult(['credentials' => 'baz'])); - $this->dbConnection->expects($this->once()) + $this->dbConnectionAdapter->expects($this->once()) ->method('getQueryBuilder') ->willReturn($qb); diff --git a/tests/lib/ServerTest.php b/tests/lib/ServerTest.php index 1054c4195b2..8df39ca7cc9 100644 --- a/tests/lib/ServerTest.php +++ b/tests/lib/ServerTest.php @@ -72,7 +72,7 @@ class ServerTest extends \Test\TestCase { ['CryptoWrapper', '\OC\Session\CryptoWrapper'], ['CsrfTokenManager', '\OC\Security\CSRF\CsrfTokenManager'], - ['DatabaseConnection', '\OC\DB\Connection'], + ['DatabaseConnection', '\OC\DB\ConnectionAdapter'], ['DatabaseConnection', '\OCP\IDBConnection'], ['DateTimeFormatter', '\OC\DateTimeFormatter'], ['DateTimeFormatter', '\OCP\IDateTimeFormatter'], |