diff options
Diffstat (limited to 'tests/lib/DB')
-rw-r--r-- | tests/lib/DB/LegacyDBTest.php | 52 | ||||
-rw-r--r-- | tests/lib/DB/MDB2SchemaManagerTest.php | 8 | ||||
-rw-r--r-- | tests/lib/DB/MDB2SchemaReaderTest.php | 12 | ||||
-rw-r--r-- | tests/lib/DB/MigratorTest.php | 60 |
4 files changed, 66 insertions, 66 deletions
diff --git a/tests/lib/DB/LegacyDBTest.php b/tests/lib/DB/LegacyDBTest.php index ce7ef0a3a63..cd4befdbe52 100644 --- a/tests/lib/DB/LegacyDBTest.php +++ b/tests/lib/DB/LegacyDBTest.php @@ -85,15 +85,15 @@ class LegacyDBTest extends \Test\TestCase { public function testQuotes() { $query = OC_DB::prepare('SELECT `fullname` FROM `*PREFIX*'.$this->table2.'` WHERE `uri` = ?'); - $result = $query->execute(array('uri_1')); + $result = $query->execute(['uri_1']); $this->assertTrue((bool)$result); $row = $result->fetchRow(); $this->assertFalse($row); $query = OC_DB::prepare('INSERT INTO `*PREFIX*'.$this->table2.'` (`fullname`,`uri`) VALUES (?,?)'); - $result = $query->execute(array('fullname test', 'uri_1')); + $result = $query->execute(['fullname test', 'uri_1']); $this->assertEquals(1, $result); $query = OC_DB::prepare('SELECT `fullname`,`uri` FROM `*PREFIX*'.$this->table2.'` WHERE `uri` = ?'); - $result = $query->execute(array('uri_1')); + $result = $query->execute(['uri_1']); $this->assertTrue((bool)$result); $row = $result->fetchRow(); $this->assertArrayHasKey('fullname', $row); @@ -107,29 +107,29 @@ class LegacyDBTest extends \Test\TestCase { */ public function testNOW() { $query = OC_DB::prepare('INSERT INTO `*PREFIX*'.$this->table2.'` (`fullname`,`uri`) VALUES (NOW(),?)'); - $result = $query->execute(array('uri_2')); + $result = $query->execute(['uri_2']); $this->assertEquals(1, $result); $query = OC_DB::prepare('SELECT `fullname`,`uri` FROM `*PREFIX*'.$this->table2.'` WHERE `uri` = ?'); - $result = $query->execute(array('uri_2')); + $result = $query->execute(['uri_2']); $this->assertTrue((bool)$result); } public function testUNIX_TIMESTAMP() { $query = OC_DB::prepare('INSERT INTO `*PREFIX*'.$this->table2.'` (`fullname`,`uri`) VALUES (UNIX_TIMESTAMP(),?)'); - $result = $query->execute(array('uri_3')); + $result = $query->execute(['uri_3']); $this->assertEquals(1, $result); $query = OC_DB::prepare('SELECT `fullname`,`uri` FROM `*PREFIX*'.$this->table2.'` WHERE `uri` = ?'); - $result = $query->execute(array('uri_3')); + $result = $query->execute(['uri_3']); $this->assertTrue((bool)$result); } public function testLastInsertId() { $query = OC_DB::prepare('INSERT INTO `*PREFIX*'.$this->table2.'` (`fullname`,`uri`) VALUES (?,?)'); - $result1 = OC_DB::executeAudited($query, array('insertid 1','uri_1')); + $result1 = OC_DB::executeAudited($query, ['insertid 1','uri_1']); $id1 = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*'.$this->table2); // we don't know the id we should expect, so insert another row - $result2 = OC_DB::executeAudited($query, array('insertid 2','uri_2')); + $result2 = OC_DB::executeAudited($query, ['insertid 2','uri_2']); $id2 = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*'.$this->table2); // now we can check if the two ids are in correct order $this->assertGreaterThan($id1, $id2); @@ -140,7 +140,7 @@ class LegacyDBTest extends \Test\TestCase { $expected = "ะรถ้ๅ\xE2\x80\xA2"; $query = OC_DB::prepare("INSERT INTO `$table` (`fullname`, `uri`, `carddata`) VALUES (?, ?, ?)"); - $result = $query->execute(array($expected, 'uri_1', 'This is a vCard')); + $result = $query->execute([$expected, 'uri_1', 'This is a vCard']); $this->assertEquals(1, $result); $actual = OC_DB::prepare("SELECT `fullname` FROM `$table`")->execute()->fetchOne(); @@ -156,7 +156,7 @@ class LegacyDBTest extends \Test\TestCase { $rowname = 'decimaltest'; $query = OC_DB::prepare('INSERT INTO `' . $table . '` (`' . $rowname . '`) VALUES (?)'); - $result = $query->execute(array($insert)); + $result = $query->execute([$insert]); $this->assertEquals(1, $result); $query = OC_DB::prepare('SELECT `' . $rowname . '` FROM `' . $table . '`'); $result = $query->execute(); @@ -205,35 +205,35 @@ class LegacyDBTest extends \Test\TestCase { // updating to. MySQL reports 1 here when the PDO::MYSQL_ATTR_FOUND_ROWS // flag is not specified. $query = OC_DB::prepare("UPDATE `*PREFIX*{$this->table2}` SET `uri` = ?"); - $this->assertSame(2, $query->execute(array('uri1'))); + $this->assertSame(2, $query->execute(['uri1'])); } protected function insertCardData($fullname, $uri) { $query = OC_DB::prepare("INSERT INTO `*PREFIX*{$this->table2}` (`fullname`, `uri`, `carddata`) VALUES (?, ?, ?)"); - $this->assertSame(1, $query->execute(array($fullname, $uri, $this->getUniqueID()))); + $this->assertSame(1, $query->execute([$fullname, $uri, $this->getUniqueID()])); } protected function updateCardData($fullname, $uri) { $query = OC_DB::prepare("UPDATE `*PREFIX*{$this->table2}` SET `uri` = ? WHERE `fullname` = ?"); - return $query->execute(array($uri, $fullname)); + return $query->execute([$uri, $fullname]); } public function testILIKE() { $table = "*PREFIX*{$this->table2}"; $query = OC_DB::prepare("INSERT INTO `$table` (`fullname`, `uri`, `carddata`) VALUES (?, ?, ?)"); - $query->execute(array('fooBAR', 'foo', 'bar')); + $query->execute(['fooBAR', 'foo', 'bar']); $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` LIKE ?"); - $result = $query->execute(array('foobar')); + $result = $query->execute(['foobar']); $this->assertCount(0, $result->fetchAll()); $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` ILIKE ?"); - $result = $query->execute(array('foobar')); + $result = $query->execute(['foobar']); $this->assertCount(1, $result->fetchAll()); $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` ILIKE ?"); - $result = $query->execute(array('foo')); + $result = $query->execute(['foo']); $this->assertCount(0, $result->fetchAll()); } @@ -241,30 +241,30 @@ class LegacyDBTest extends \Test\TestCase { $table = "*PREFIX*{$this->table2}"; $query = OC_DB::prepare("INSERT INTO `$table` (`fullname`, `uri`, `carddata`) VALUES (?, ?, ?)"); - $query->execute(array('FooBAR', 'foo', 'bar')); + $query->execute(['FooBAR', 'foo', 'bar']); $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` LIKE ?"); - $result = $query->execute(array('%bar')); + $result = $query->execute(['%bar']); $this->assertCount(0, $result->fetchAll()); $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` LIKE ?"); - $result = $query->execute(array('foo%')); + $result = $query->execute(['foo%']); $this->assertCount(0, $result->fetchAll()); $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` LIKE ?"); - $result = $query->execute(array('%ba%')); + $result = $query->execute(['%ba%']); $this->assertCount(0, $result->fetchAll()); $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` ILIKE ?"); - $result = $query->execute(array('%bar')); + $result = $query->execute(['%bar']); $this->assertCount(1, $result->fetchAll()); $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` ILIKE ?"); - $result = $query->execute(array('foo%')); + $result = $query->execute(['foo%']); $this->assertCount(1, $result->fetchAll()); $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` ILIKE ?"); - $result = $query->execute(array('%ba%')); + $result = $query->execute(['%ba%']); $this->assertCount(1, $result->fetchAll()); } @@ -279,7 +279,7 @@ class LegacyDBTest extends \Test\TestCase { if ($throwsOnMysqlWithoutUTF8MB4 && $config->getSystemValue('dbtype', 'sqlite') === 'mysql' && $config->getSystemValue('mysql.utf8mb4', false) === false) { $this->markTestSkipped('MySQL requires UTF8mb4 to store value: ' . $expected); } - $result = $query->execute(array($expected)); + $result = $query->execute([$expected]); $this->assertEquals(1, $result); $actual = OC_DB::prepare("SELECT `textfield` FROM `$table`")->execute()->fetchOne(); diff --git a/tests/lib/DB/MDB2SchemaManagerTest.php b/tests/lib/DB/MDB2SchemaManagerTest.php index 8c9290c56b4..d83131a685f 100644 --- a/tests/lib/DB/MDB2SchemaManagerTest.php +++ b/tests/lib/DB/MDB2SchemaManagerTest.php @@ -40,10 +40,10 @@ class MDB2SchemaManagerTest extends \Test\TestCase { $manager = new \OC\DB\MDB2SchemaManager($connection); $manager->createDbFromStructure(__DIR__ . '/ts-autoincrement-before.xml'); - $connection->executeUpdate('insert into `*PREFIX*table` values (?)', array('abc')); - $connection->executeUpdate('insert into `*PREFIX*table` values (?)', array('abc')); - $connection->executeUpdate('insert into `*PREFIX*table` values (?)', array('123')); - $connection->executeUpdate('insert into `*PREFIX*table` values (?)', array('123')); + $connection->executeUpdate('insert into `*PREFIX*table` values (?)', ['abc']); + $connection->executeUpdate('insert into `*PREFIX*table` values (?)', ['abc']); + $connection->executeUpdate('insert into `*PREFIX*table` values (?)', ['123']); + $connection->executeUpdate('insert into `*PREFIX*table` values (?)', ['123']); $manager->updateDbFromStructure(__DIR__ . '/ts-autoincrement-after.xml'); $this->addToAssertionCount(1); diff --git a/tests/lib/DB/MDB2SchemaReaderTest.php b/tests/lib/DB/MDB2SchemaReaderTest.php index 5698ad966f1..2f987adb290 100644 --- a/tests/lib/DB/MDB2SchemaReaderTest.php +++ b/tests/lib/DB/MDB2SchemaReaderTest.php @@ -38,10 +38,10 @@ class MDB2SchemaReaderTest extends TestCase { ->getMock(); $config->expects($this->any()) ->method('getSystemValue') - ->willReturnMap(array( - array('dbname', 'owncloud', 'testDB'), - array('dbtableprefix', 'oc_', 'test_') - )); + ->willReturnMap([ + ['dbname', 'owncloud', 'testDB'], + ['dbtableprefix', 'oc_', 'test_'] + ]); return $config; } @@ -85,10 +85,10 @@ class MDB2SchemaReaderTest extends TestCase { $this->assertEquals(2, $table->getColumn('decimalfield_precision_scale')->getScale()); $this->assertCount(2, $table->getIndexes()); - $this->assertEquals(array('integerfield'), $table->getIndex('primary')->getUnquotedColumns()); + $this->assertEquals(['integerfield'], $table->getIndex('primary')->getUnquotedColumns()); $this->assertTrue($table->getIndex('primary')->isPrimary()); $this->assertTrue($table->getIndex('primary')->isUnique()); - $this->assertEquals(array('booleanfield'), $table->getIndex('index_boolean')->getUnquotedColumns()); + $this->assertEquals(['booleanfield'], $table->getIndex('index_boolean')->getUnquotedColumns()); $this->assertFalse($table->getIndex('index_boolean')->isPrimary()); $this->assertFalse($table->getIndex('index_boolean')->isUnique()); } diff --git a/tests/lib/DB/MigratorTest.php b/tests/lib/DB/MigratorTest.php index e5cc28654e4..a438d0189df 100644 --- a/tests/lib/DB/MigratorTest.php +++ b/tests/lib/DB/MigratorTest.php @@ -77,19 +77,19 @@ class MigratorTest extends \Test\TestCase { * @return \Doctrine\DBAL\Schema\Schema[] */ private function getDuplicateKeySchemas() { - $startSchema = new Schema(array(), array(), $this->getSchemaConfig()); + $startSchema = new Schema([], [], $this->getSchemaConfig()); $table = $startSchema->createTable($this->tableName); $table->addColumn('id', 'integer'); $table->addColumn('name', 'string'); - $table->addIndex(array('id'), $this->tableName . '_id'); + $table->addIndex(['id'], $this->tableName . '_id'); - $endSchema = new Schema(array(), array(), $this->getSchemaConfig()); + $endSchema = new Schema([], [], $this->getSchemaConfig()); $table = $endSchema->createTable($this->tableName); $table->addColumn('id', 'integer'); $table->addColumn('name', 'string'); - $table->addUniqueIndex(array('id'), $this->tableName . '_id'); + $table->addUniqueIndex(['id'], $this->tableName . '_id'); - return array($startSchema, $endSchema); + return [$startSchema, $endSchema]; } private function getSchemaConfig() { @@ -113,9 +113,9 @@ class MigratorTest extends \Test\TestCase { $migrator = $this->manager->getMigrator(); $migrator->migrate($startSchema); - $this->connection->insert($this->tableName, array('id' => 1, 'name' => 'foo')); - $this->connection->insert($this->tableName, array('id' => 2, 'name' => 'bar')); - $this->connection->insert($this->tableName, array('id' => 2, 'name' => 'qwerty')); + $this->connection->insert($this->tableName, ['id' => 1, 'name' => 'foo']); + $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'); @@ -126,9 +126,9 @@ class MigratorTest extends \Test\TestCase { $migrator = $this->manager->getMigrator(); $migrator->migrate($startSchema); - $this->connection->insert($this->tableName, array('id' => 1, 'name' => 'foo')); - $this->connection->insert($this->tableName, array('id' => 2, 'name' => 'bar')); - $this->connection->insert($this->tableName, array('id' => 3, 'name' => 'qwerty')); + $this->connection->insert($this->tableName, ['id' => 1, 'name' => 'foo']); + $this->connection->insert($this->tableName, ['id' => 2, 'name' => 'bar']); + $this->connection->insert($this->tableName, ['id' => 3, 'name' => 'qwerty']); $migrator->checkMigrate($endSchema); $migrator->migrate($endSchema); @@ -145,9 +145,9 @@ class MigratorTest extends \Test\TestCase { $migrator = $this->manager->getMigrator(); $migrator->migrate($startSchema); - $this->connection->insert($this->tableName, array('id' => 1, 'name' => 'foo')); - $this->connection->insert($this->tableName, array('id' => 2, 'name' => 'bar')); - $this->connection->insert($this->tableName, array('id' => 3, 'name' => 'qwerty')); + $this->connection->insert($this->tableName, ['id' => 1, 'name' => 'foo']); + $this->connection->insert($this->tableName, ['id' => 2, 'name' => 'bar']); + $this->connection->insert($this->tableName, ['id' => 3, 'name' => 'qwerty']); $migrator->checkMigrate($endSchema); $migrator->migrate($endSchema); @@ -163,10 +163,10 @@ class MigratorTest extends \Test\TestCase { $migrator->migrate($endSchema); - $this->connection->insert($this->tableName, array('id' => 1, 'name' => 'foo')); - $this->connection->insert($this->tableName, array('id' => 2, 'name' => 'bar')); + $this->connection->insert($this->tableName, ['id' => 1, 'name' => 'foo']); + $this->connection->insert($this->tableName, ['id' => 2, 'name' => 'bar']); try { - $this->connection->insert($this->tableName, array('id' => 2, 'name' => 'qwerty')); + $this->connection->insert($this->tableName, ['id' => 2, 'name' => 'qwerty']); $this->fail('Expected duplicate key insert to fail'); } catch (DBALException $e) { $this->addToAssertionCount(1); @@ -174,16 +174,16 @@ class MigratorTest extends \Test\TestCase { } public function testAddingPrimaryKeyWithAutoIncrement() { - $startSchema = new Schema(array(), array(), $this->getSchemaConfig()); + $startSchema = new Schema([], [], $this->getSchemaConfig()); $table = $startSchema->createTable($this->tableName); $table->addColumn('id', 'integer'); $table->addColumn('name', 'string'); - $endSchema = new Schema(array(), array(), $this->getSchemaConfig()); + $endSchema = new Schema([], [], $this->getSchemaConfig()); $table = $endSchema->createTable($this->tableName); - $table->addColumn('id', 'integer', array('autoincrement' => true)); + $table->addColumn('id', 'integer', ['autoincrement' => true]); $table->addColumn('name', 'string'); - $table->setPrimaryKey(array('id')); + $table->setPrimaryKey(['id']); $migrator = $this->manager->getMigrator(); $migrator->migrate($startSchema); @@ -195,17 +195,17 @@ class MigratorTest extends \Test\TestCase { } public function testReservedKeywords() { - $startSchema = new Schema(array(), array(), $this->getSchemaConfig()); + $startSchema = new Schema([], [], $this->getSchemaConfig()); $table = $startSchema->createTable($this->tableName); - $table->addColumn('id', 'integer', array('autoincrement' => true)); - $table->addColumn('user', 'string', array('length' => 255)); - $table->setPrimaryKey(array('id')); + $table->addColumn('id', 'integer', ['autoincrement' => true]); + $table->addColumn('user', 'string', ['length' => 255]); + $table->setPrimaryKey(['id']); - $endSchema = new Schema(array(), array(), $this->getSchemaConfig()); + $endSchema = new Schema([], [], $this->getSchemaConfig()); $table = $endSchema->createTable($this->tableName); - $table->addColumn('id', 'integer', array('autoincrement' => true)); - $table->addColumn('user', 'string', array('length' => 64)); - $table->setPrimaryKey(array('id')); + $table->addColumn('id', 'integer', ['autoincrement' => true]); + $table->addColumn('user', 'string', ['length' => 64]); + $table->setPrimaryKey(['id']); $migrator = $this->manager->getMigrator(); $migrator->migrate($startSchema); @@ -227,7 +227,7 @@ class MigratorTest extends \Test\TestCase { $tableFk = $startSchema->createTable($this->tableNameTmp); $tableFk->addColumn('fk_id', 'integer'); $tableFk->addColumn('name', 'string'); - $tableFk->addForeignKeyConstraint($this->tableName, array('fk_id'), array('id'), array(), $fkName); + $tableFk->addForeignKeyConstraint($this->tableName, ['fk_id'], ['id'], [], $fkName); $migrator = $this->manager->getMigrator(); $migrator->migrate($startSchema); |