diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2021-01-03 15:28:31 +0100 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2021-01-08 11:45:19 +0100 |
commit | 8b64e92b9262d2a2eec6345685ce421050f95c66 (patch) | |
tree | dd51490b8a184b2643414d11867a9fa450aa5065 /tests/lib/DB | |
parent | 84e6e9f7cf19207041925eaa237d24e1c12c2c2d (diff) | |
download | nextcloud-server-8b64e92b9262d2a2eec6345685ce421050f95c66.tar.gz nextcloud-server-8b64e92b9262d2a2eec6345685ce421050f95c66.zip |
Bump doctrine/dbal from 2.12.0 to 3.0.0
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'tests/lib/DB')
-rw-r--r-- | tests/lib/DB/ConnectionTest.php | 14 | ||||
-rw-r--r-- | tests/lib/DB/DBSchemaTest.php | 9 | ||||
-rw-r--r-- | tests/lib/DB/MDB2SchemaManagerTest.php | 2 | ||||
-rw-r--r-- | tests/lib/DB/MDB2SchemaReaderTest.php | 4 | ||||
-rw-r--r-- | tests/lib/DB/MigratorTest.php | 27 | ||||
-rw-r--r-- | tests/lib/DB/MySqlMigrationTest.php | 2 | ||||
-rw-r--r-- | tests/lib/DB/OCPostgreSqlPlatformTest.php | 4 | ||||
-rw-r--r-- | tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php | 4 | ||||
-rw-r--r-- | tests/lib/DB/QueryBuilder/ExpressionBuilderTest.php | 8 | ||||
-rw-r--r-- | tests/lib/DB/QueryBuilder/FunctionBuilderTest.php | 28 | ||||
-rw-r--r-- | tests/lib/DB/SchemaDiffTest.php | 14 | ||||
-rw-r--r-- | tests/lib/DB/SqliteMigrationTest.php | 4 |
12 files changed, 58 insertions, 62 deletions
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 { |