aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/DB
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/DB')
-rw-r--r--tests/lib/DB/AdapterTest.php7
-rw-r--r--tests/lib/DB/ConnectionFactoryTest.php5
-rw-r--r--tests/lib/DB/Exception/DbalExceptionTest.php4
-rw-r--r--tests/lib/DB/MigrationsTest.php52
-rw-r--r--tests/lib/DB/MigratorTest.php12
-rw-r--r--tests/lib/DB/OCPostgreSqlPlatformTest.php1
-rw-r--r--tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php18
-rw-r--r--tests/lib/DB/QueryBuilder/ExpressionBuilderTest.php49
-rw-r--r--tests/lib/DB/QueryBuilder/FunctionBuilderTest.php58
-rw-r--r--tests/lib/DB/QueryBuilder/Partitioned/JoinConditionTest.php10
-rw-r--r--tests/lib/DB/QueryBuilder/Partitioned/PartitionedQueryBuilderTest.php1
-rw-r--r--tests/lib/DB/QueryBuilder/QueryBuilderTest.php124
-rw-r--r--tests/lib/DB/QueryBuilder/QuoteHelperTest.php9
13 files changed, 185 insertions, 165 deletions
diff --git a/tests/lib/DB/AdapterTest.php b/tests/lib/DB/AdapterTest.php
index 99b7cf4e099..394428337f1 100644
--- a/tests/lib/DB/AdapterTest.php
+++ b/tests/lib/DB/AdapterTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -6,6 +7,8 @@
namespace Test\DB;
+use OCP\IDBConnection;
+use OCP\Server;
use Test\TestCase;
class AdapterTest extends TestCase {
@@ -13,8 +16,8 @@ class AdapterTest extends TestCase {
private $connection;
public function setUp(): void {
- $this->connection = \OC::$server->getDatabaseConnection();
- $this->appId = uniqid('test_db_adapter', true);
+ $this->connection = Server::get(IDBConnection::class);
+ $this->appId = substr(uniqid('test_db_adapter', true), 0, 32);
}
public function tearDown(): void {
diff --git a/tests/lib/DB/ConnectionFactoryTest.php b/tests/lib/DB/ConnectionFactoryTest.php
index 23bde34a8fb..d09a83ca856 100644
--- a/tests/lib/DB/ConnectionFactoryTest.php
+++ b/tests/lib/DB/ConnectionFactoryTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -12,7 +13,7 @@ use OCP\ICacheFactory;
use Test\TestCase;
class ConnectionFactoryTest extends TestCase {
- public function splitHostFromPortAndSocketData() {
+ public static function splitHostFromPortAndSocketData(): array {
return [
['127.0.0.1', ['host' => '127.0.0.1']],
['db.example.org', ['host' => 'db.example.org']],
@@ -27,10 +28,10 @@ class ConnectionFactoryTest extends TestCase {
}
/**
- * @dataProvider splitHostFromPortAndSocketData
* @param string $host
* @param array $expected
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('splitHostFromPortAndSocketData')]
public function testSplitHostFromPortAndSocket($host, array $expected): void {
/** @var SystemConfig $config */
$config = $this->createMock(SystemConfig::class);
diff --git a/tests/lib/DB/Exception/DbalExceptionTest.php b/tests/lib/DB/Exception/DbalExceptionTest.php
index 470beff9080..eac74291749 100644
--- a/tests/lib/DB/Exception/DbalExceptionTest.php
+++ b/tests/lib/DB/Exception/DbalExceptionTest.php
@@ -35,16 +35,16 @@ class DbalExceptionTest extends \Test\TestCase {
}
/**
- * @dataProvider dataDriverException
* @param string $class
* @param int $reason
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataDriverException')]
public function testDriverException(string $class, int $reason): void {
$result = DbalException::wrap(new $class($this->driverException, null));
$this->assertSame($reason, $result->getReason());
}
- public function dataDriverException(): array {
+ public static function dataDriverException(): array {
return [
[LockWaitTimeoutException::class, DbalException::REASON_LOCK_WAIT_TIMEOUT],
[ForeignKeyConstraintViolationException::class, DbalException::REASON_FOREIGN_KEY_VIOLATION],
diff --git a/tests/lib/DB/MigrationsTest.php b/tests/lib/DB/MigrationsTest.php
index 531e0a3805a..2b39b26d852 100644
--- a/tests/lib/DB/MigrationsTest.php
+++ b/tests/lib/DB/MigrationsTest.php
@@ -93,7 +93,7 @@ class MigrationsTest extends \Test\TestCase {
$this->expectExceptionMessage('Migration step \'X\' is unknown');
$this->migrationService = $this->getMockBuilder(MigrationService::class)
- ->setMethods(['findMigrations'])
+ ->onlyMethods(['findMigrations'])
->setConstructorArgs(['testing', $this->db])
->getMock();
$this->migrationService->expects($this->any())->method('findMigrations')->willReturn(
@@ -134,7 +134,7 @@ class MigrationsTest extends \Test\TestCase {
->method('postSchemaChange');
$this->migrationService = $this->getMockBuilder(MigrationService::class)
- ->setMethods(['createInstance'])
+ ->onlyMethods(['createInstance'])
->setConstructorArgs(['testing', $this->db])
->getMock();
@@ -164,7 +164,7 @@ class MigrationsTest extends \Test\TestCase {
->method('postSchemaChange');
$this->migrationService = $this->getMockBuilder(MigrationService::class)
- ->setMethods(['createInstance'])
+ ->onlyMethods(['createInstance'])
->setConstructorArgs(['testing', $this->db])
->getMock();
@@ -175,7 +175,7 @@ class MigrationsTest extends \Test\TestCase {
$this->migrationService->executeStep('20170130180000');
}
- public function dataGetMigration() {
+ public static function dataGetMigration(): array {
return [
['current', '20170130180001'],
['prev', '20170130180000'],
@@ -185,13 +185,13 @@ class MigrationsTest extends \Test\TestCase {
}
/**
- * @dataProvider dataGetMigration
* @param string $alias
* @param string $expected
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetMigration')]
public function testGetMigration($alias, $expected): void {
$this->migrationService = $this->getMockBuilder(MigrationService::class)
- ->setMethods(['getMigratedVersions', 'findMigrations'])
+ ->onlyMethods(['getMigratedVersions', 'findMigrations'])
->setConstructorArgs(['testing', $this->db])
->getMock();
$this->migrationService->expects($this->any())->method('getMigratedVersions')->willReturn(
@@ -211,22 +211,33 @@ class MigrationsTest extends \Test\TestCase {
public function testMigrate(): void {
$this->migrationService = $this->getMockBuilder(MigrationService::class)
- ->setMethods(['getMigratedVersions', 'findMigrations', 'executeStep'])
+ ->onlyMethods(['getMigratedVersions', 'findMigrations', 'executeStep'])
->setConstructorArgs(['testing', $this->db])
->getMock();
- $this->migrationService->expects($this->any())->method('getMigratedVersions')->willReturn(
- ['20170130180000', '20170130180001']
- );
- $this->migrationService->expects($this->any())->method('findMigrations')->willReturn(
- ['20170130180000' => 'X', '20170130180001' => 'Y', '20170130180002' => 'Z', '20170130180003' => 'A']
- );
+ $this->migrationService->method('getMigratedVersions')
+ ->willReturn(
+ ['20170130180000', '20170130180001']
+ );
+ $this->migrationService->method('findMigrations')
+ ->willReturn(
+ ['20170130180000' => 'X', '20170130180001' => 'Y', '20170130180002' => 'Z', '20170130180003' => 'A']
+ );
$this->assertEquals(
['20170130180000', '20170130180001', '20170130180002', '20170130180003'],
- $this->migrationService->getAvailableVersions());
+ $this->migrationService->getAvailableVersions()
+ );
- $this->migrationService->expects($this->exactly(2))->method('executeStep')
- ->withConsecutive(['20170130180002'], ['20170130180003']);
+ $calls = [
+ ['20170130180002', false],
+ ['20170130180003', false],
+ ];
+ $this->migrationService->expects($this->exactly(2))
+ ->method('executeStep')
+ ->willReturnCallback(function () use (&$calls): void {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, func_get_args());
+ });
$this->migrationService->migrate();
}
@@ -833,11 +844,10 @@ class MigrationsTest extends \Test\TestCase {
'class' => 'OCP\\Migration\\Attributes\\CreateTable',
'table' => 'new_table',
'description' => 'Table is used to store things, but also to get more things',
- 'notes' =>
- [
- 'this is a notice',
- 'and another one, if really needed'
- ],
+ 'notes' => [
+ 'this is a notice',
+ 'and another one, if really needed'
+ ],
'columns' => []
],
[
diff --git a/tests/lib/DB/MigratorTest.php b/tests/lib/DB/MigratorTest.php
index c6afe5a053a..9d8ee6791a9 100644
--- a/tests/lib/DB/MigratorTest.php
+++ b/tests/lib/DB/MigratorTest.php
@@ -16,8 +16,10 @@ use OC\DB\Migrator;
use OC\DB\OracleMigrator;
use OC\DB\SQLiteMigrator;
use OCP\DB\Types;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IDBConnection;
+use OCP\Server;
/**
* Class MigratorTest
@@ -46,15 +48,15 @@ class MigratorTest extends \Test\TestCase {
protected function setUp(): void {
parent::setUp();
- $this->config = \OC::$server->getConfig();
- $this->connection = \OC::$server->get(\OC\DB\Connection::class);
+ $this->config = Server::get(IConfig::class);
+ $this->connection = Server::get(\OC\DB\Connection::class);
$this->tableName = $this->getUniqueTableName();
$this->tableNameTmp = $this->getUniqueTableName();
}
private function getMigrator(): Migrator {
- $dispatcher = \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class);
+ $dispatcher = Server::get(IEventDispatcher::class);
if ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_SQLITE) {
return new SQLiteMigrator($this->connection, $this->config, $dispatcher);
} elseif ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_ORACLE) {
@@ -261,7 +263,7 @@ class MigratorTest extends \Test\TestCase {
$this->assertTrue($startSchema->getTable($this->tableNameTmp)->hasForeignKey($fkName));
}
- public function dataNotNullEmptyValuesFailOracle(): array {
+ public static function dataNotNullEmptyValuesFailOracle(): array {
return [
[ParameterType::BOOLEAN, true, Types::BOOLEAN, false],
[ParameterType::BOOLEAN, false, Types::BOOLEAN, true],
@@ -277,13 +279,13 @@ class MigratorTest extends \Test\TestCase {
}
/**
- * @dataProvider dataNotNullEmptyValuesFailOracle
*
* @param int $parameterType
* @param bool|int|string $value
* @param string $columnType
* @param bool $oracleThrows
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataNotNullEmptyValuesFailOracle')]
public function testNotNullEmptyValuesFailOracle(int $parameterType, $value, string $columnType, bool $oracleThrows): void {
$startSchema = new Schema([], [], $this->getSchemaConfig());
$table = $startSchema->createTable($this->tableName);
diff --git a/tests/lib/DB/OCPostgreSqlPlatformTest.php b/tests/lib/DB/OCPostgreSqlPlatformTest.php
index bea3adf29a4..af17b01fc13 100644
--- a/tests/lib/DB/OCPostgreSqlPlatformTest.php
+++ b/tests/lib/DB/OCPostgreSqlPlatformTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2017 ownCloud, Inc.
diff --git a/tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php b/tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php
index 392fe9ff937..153993f396e 100644
--- a/tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php
+++ b/tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -11,6 +12,7 @@ use OC\DB\QueryBuilder\Literal;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\DB\Types;
use OCP\IConfig;
+use OCP\IDBConnection;
use OCP\Server;
use Test\TestCase;
@@ -18,19 +20,19 @@ use Test\TestCase;
* @group DB
*/
class ExpressionBuilderDBTest extends TestCase {
- /** @var \Doctrine\DBAL\Connection|\OCP\IDBConnection */
+ /** @var \Doctrine\DBAL\Connection|IDBConnection */
protected $connection;
protected $schemaSetup = false;
protected function setUp(): void {
parent::setUp();
- $this->connection = \OC::$server->getDatabaseConnection();
+ $this->connection = Server::get(IDBConnection::class);
$this->prepareTestingTable();
}
- public function likeProvider() {
- $connection = \OC::$server->getDatabaseConnection();
+ public static function likeProvider(): array {
+ $connection = Server::get(IDBConnection::class);
return [
['foo', 'bar', false],
@@ -46,12 +48,12 @@ class ExpressionBuilderDBTest extends TestCase {
}
/**
- * @dataProvider likeProvider
*
* @param string $param1
* @param string $param2
* @param boolean $match
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('likeProvider')]
public function testLike($param1, $param2, $match): void {
$query = $this->connection->getQueryBuilder();
@@ -65,8 +67,8 @@ class ExpressionBuilderDBTest extends TestCase {
$this->assertEquals($match, $column);
}
- public function ilikeProvider() {
- $connection = \OC::$server->getDatabaseConnection();
+ public static function ilikeProvider(): array {
+ $connection = Server::get(IDBConnection::class);
return [
['foo', 'bar', false],
@@ -83,12 +85,12 @@ class ExpressionBuilderDBTest extends TestCase {
}
/**
- * @dataProvider ilikeProvider
*
* @param string $param1
* @param string $param2
* @param boolean $match
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('ilikeProvider')]
public function testILike($param1, $param2, $match): void {
$query = $this->connection->getQueryBuilder();
diff --git a/tests/lib/DB/QueryBuilder/ExpressionBuilderTest.php b/tests/lib/DB/QueryBuilder/ExpressionBuilderTest.php
index c14c55e6d02..1f84ebfbec1 100644
--- a/tests/lib/DB/QueryBuilder/ExpressionBuilderTest.php
+++ b/tests/lib/DB/QueryBuilder/ExpressionBuilderTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -10,6 +11,8 @@ namespace Test\DB\QueryBuilder;
use Doctrine\DBAL\Query\Expression\ExpressionBuilder as DoctrineExpressionBuilder;
use OC\DB\QueryBuilder\ExpressionBuilder\ExpressionBuilder;
use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\IDBConnection;
+use OCP\Server;
use Psr\Log\LoggerInterface;
use Test\TestCase;
@@ -27,7 +30,7 @@ class ExpressionBuilderTest extends TestCase {
/** @var DoctrineExpressionBuilder */
protected $doctrineExpressionBuilder;
- /** @var \OCP\IDBConnection */
+ /** @var IDBConnection */
protected $connection;
/** @var \Doctrine\DBAL\Connection */
@@ -39,8 +42,8 @@ class ExpressionBuilderTest extends TestCase {
protected function setUp(): void {
parent::setUp();
- $this->connection = \OC::$server->getDatabaseConnection();
- $this->internalConnection = \OC::$server->get(\OC\DB\Connection::class);
+ $this->connection = Server::get(IDBConnection::class);
+ $this->internalConnection = Server::get(\OC\DB\Connection::class);
$this->logger = $this->createMock(LoggerInterface::class);
$queryBuilder = $this->createMock(IQueryBuilder::class);
@@ -50,8 +53,8 @@ class ExpressionBuilderTest extends TestCase {
$this->doctrineExpressionBuilder = new DoctrineExpressionBuilder($this->internalConnection);
}
- public function dataComparison() {
- $valueSets = $this->dataComparisons();
+ public static function dataComparison(): array {
+ $valueSets = self::dataComparisons();
$comparisonOperators = ['=', '<>', '<', '>', '<=', '>='];
$testSets = [];
@@ -64,7 +67,6 @@ class ExpressionBuilderTest extends TestCase {
}
/**
- * @dataProvider dataComparison
*
* @param string $comparison
* @param mixed $input1
@@ -72,6 +74,7 @@ class ExpressionBuilderTest extends TestCase {
* @param mixed $input2
* @param bool $isInput2Literal
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataComparison')]
public function testComparison($comparison, $input1, $isInput1Literal, $input2, $isInput2Literal): void {
[$doctrineInput1, $ocInput1] = $this->helpWithLiteral($input1, $isInput1Literal);
[$doctrineInput2, $ocInput2] = $this->helpWithLiteral($input2, $isInput2Literal);
@@ -82,7 +85,7 @@ class ExpressionBuilderTest extends TestCase {
);
}
- public function dataComparisons() {
+ public static function dataComparisons(): array {
return [
['value', false, 'value', false],
['value', false, 'value', true],
@@ -92,13 +95,13 @@ class ExpressionBuilderTest extends TestCase {
}
/**
- * @dataProvider dataComparisons
*
* @param mixed $input1
* @param bool $isInput1Literal
* @param mixed $input2
* @param bool $isInput2Literal
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataComparisons')]
public function testEquals($input1, $isInput1Literal, $input2, $isInput2Literal): void {
[$doctrineInput1, $ocInput1] = $this->helpWithLiteral($input1, $isInput1Literal);
[$doctrineInput2, $ocInput2] = $this->helpWithLiteral($input2, $isInput2Literal);
@@ -110,13 +113,13 @@ class ExpressionBuilderTest extends TestCase {
}
/**
- * @dataProvider dataComparisons
*
* @param mixed $input1
* @param bool $isInput1Literal
* @param mixed $input2
* @param bool $isInput2Literal
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataComparisons')]
public function testNotEquals($input1, $isInput1Literal, $input2, $isInput2Literal): void {
[$doctrineInput1, $ocInput1] = $this->helpWithLiteral($input1, $isInput1Literal);
[$doctrineInput2, $ocInput2] = $this->helpWithLiteral($input2, $isInput2Literal);
@@ -128,13 +131,13 @@ class ExpressionBuilderTest extends TestCase {
}
/**
- * @dataProvider dataComparisons
*
* @param mixed $input1
* @param bool $isInput1Literal
* @param mixed $input2
* @param bool $isInput2Literal
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataComparisons')]
public function testLowerThan($input1, $isInput1Literal, $input2, $isInput2Literal): void {
[$doctrineInput1, $ocInput1] = $this->helpWithLiteral($input1, $isInput1Literal);
[$doctrineInput2, $ocInput2] = $this->helpWithLiteral($input2, $isInput2Literal);
@@ -146,13 +149,13 @@ class ExpressionBuilderTest extends TestCase {
}
/**
- * @dataProvider dataComparisons
*
* @param mixed $input1
* @param bool $isInput1Literal
* @param mixed $input2
* @param bool $isInput2Literal
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataComparisons')]
public function testLowerThanEquals($input1, $isInput1Literal, $input2, $isInput2Literal): void {
[$doctrineInput1, $ocInput1] = $this->helpWithLiteral($input1, $isInput1Literal);
[$doctrineInput2, $ocInput2] = $this->helpWithLiteral($input2, $isInput2Literal);
@@ -164,13 +167,13 @@ class ExpressionBuilderTest extends TestCase {
}
/**
- * @dataProvider dataComparisons
*
* @param mixed $input1
* @param bool $isInput1Literal
* @param mixed $input2
* @param bool $isInput2Literal
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataComparisons')]
public function testGreaterThan($input1, $isInput1Literal, $input2, $isInput2Literal): void {
[$doctrineInput1, $ocInput1] = $this->helpWithLiteral($input1, $isInput1Literal);
[$doctrineInput2, $ocInput2] = $this->helpWithLiteral($input2, $isInput2Literal);
@@ -182,13 +185,13 @@ class ExpressionBuilderTest extends TestCase {
}
/**
- * @dataProvider dataComparisons
*
* @param mixed $input1
* @param bool $isInput1Literal
* @param mixed $input2
* @param bool $isInput2Literal
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataComparisons')]
public function testGreaterThanEquals($input1, $isInput1Literal, $input2, $isInput2Literal): void {
[$doctrineInput1, $ocInput1] = $this->helpWithLiteral($input1, $isInput1Literal);
[$doctrineInput2, $ocInput2] = $this->helpWithLiteral($input2, $isInput2Literal);
@@ -213,7 +216,7 @@ class ExpressionBuilderTest extends TestCase {
);
}
- public function dataLike() {
+ public static function dataLike(): array {
return [
['value', false],
['value', true],
@@ -221,11 +224,11 @@ class ExpressionBuilderTest extends TestCase {
}
/**
- * @dataProvider dataLike
*
* @param mixed $input
* @param bool $isLiteral
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataLike')]
public function testLike($input, $isLiteral): void {
[$doctrineInput, $ocInput] = $this->helpWithLiteral($input, $isLiteral);
@@ -236,11 +239,11 @@ class ExpressionBuilderTest extends TestCase {
}
/**
- * @dataProvider dataLike
*
* @param mixed $input
* @param bool $isLiteral
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataLike')]
public function testNotLike($input, $isLiteral): void {
[$doctrineInput, $ocInput] = $this->helpWithLiteral($input, $isLiteral);
@@ -250,7 +253,7 @@ class ExpressionBuilderTest extends TestCase {
);
}
- public function dataIn() {
+ public static function dataIn(): array {
return [
['value', false],
['value', true],
@@ -260,11 +263,11 @@ class ExpressionBuilderTest extends TestCase {
}
/**
- * @dataProvider dataIn
*
* @param mixed $input
* @param bool $isLiteral
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataIn')]
public function testIn($input, $isLiteral): void {
[$doctrineInput, $ocInput] = $this->helpWithLiteral($input, $isLiteral);
@@ -275,11 +278,11 @@ class ExpressionBuilderTest extends TestCase {
}
/**
- * @dataProvider dataIn
*
* @param mixed $input
* @param bool $isLiteral
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataIn')]
public function testNotIn($input, $isLiteral): void {
[$doctrineInput, $ocInput] = $this->helpWithLiteral($input, $isLiteral);
@@ -317,7 +320,7 @@ class ExpressionBuilderTest extends TestCase {
return [$doctrineInput, $ocInput];
}
- public function dataLiteral() {
+ public static function dataLiteral(): array {
return [
['value', null],
['1', null],
@@ -329,11 +332,11 @@ class ExpressionBuilderTest extends TestCase {
}
/**
- * @dataProvider dataLiteral
*
* @param mixed $input
* @param string|null $type
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataLiteral')]
public function testLiteral($input, $type): void {
/** @var \OC\DB\QueryBuilder\Literal $actual */
$actual = $this->expressionBuilder->literal($input, $type);
@@ -345,7 +348,7 @@ class ExpressionBuilderTest extends TestCase {
);
}
- public function dataClobComparisons() {
+ public static function dataClobComparisons(): array {
return [
['eq', '5', IQueryBuilder::PARAM_STR, false, 3],
['eq', '5', IQueryBuilder::PARAM_STR, true, 1],
@@ -373,13 +376,13 @@ class ExpressionBuilderTest extends TestCase {
}
/**
- * @dataProvider dataClobComparisons
* @param string $function
* @param mixed $value
* @param mixed $type
* @param bool $compareKeyToValue
* @param int $expected
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataClobComparisons')]
public function testClobComparisons($function, $value, $type, $compareKeyToValue, $expected): void {
$appId = $this->getUniqueID('testing');
$this->createConfig($appId, 1, 4);
diff --git a/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php b/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php
index f3007ace85c..5a111c91aa7 100644
--- a/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php
+++ b/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-only
@@ -8,6 +9,8 @@ namespace Test\DB\QueryBuilder;
use OC\DB\QueryBuilder\Literal;
use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\IDBConnection;
+use OCP\Server;
use Test\TestCase;
/**
@@ -18,18 +21,16 @@ use Test\TestCase;
* @package Test\DB\QueryBuilder
*/
class FunctionBuilderTest extends TestCase {
- /** @var \Doctrine\DBAL\Connection|\OCP\IDBConnection */
+ /** @var \Doctrine\DBAL\Connection|IDBConnection */
protected $connection;
protected function setUp(): void {
parent::setUp();
- $this->connection = \OC::$server->getDatabaseConnection();
+ $this->connection = Server::get(IDBConnection::class);
}
- /**
- * @dataProvider providerTestConcatString
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerTestConcatString')]
public function testConcatString($closure): void {
$query = $this->connection->getQueryBuilder();
[$real, $arguments, $return] = $closure($query);
@@ -49,38 +50,38 @@ class FunctionBuilderTest extends TestCase {
$this->assertEquals($return, $column);
}
- public function providerTestConcatString(): array {
+ public static function providerTestConcatString(): array {
return [
- '1 column: string param unicode' =>
- [function ($q) {
+ '1 column: string param unicode'
+ => [function ($q) {
return [false, [$q->createNamedParameter('👍')], '👍'];
}],
- '2 columns: string param and string param' =>
- [function ($q) {
+ '2 columns: string param and string param'
+ => [function ($q) {
return [false, [$q->createNamedParameter('foo'), $q->createNamedParameter('bar')], 'foobar'];
}],
- '2 columns: string param and int literal' =>
- [function ($q) {
+ '2 columns: string param and int literal'
+ => [function ($q) {
return [false, [$q->createNamedParameter('foo'), $q->expr()->literal(1)], 'foo1'];
}],
- '2 columns: string param and string literal' =>
- [function ($q) {
+ '2 columns: string param and string literal'
+ => [function ($q) {
return [false, [$q->createNamedParameter('foo'), $q->expr()->literal('bar')], 'foobar'];
}],
- '2 columns: string real and int literal' =>
- [function ($q) {
+ '2 columns: string real and int literal'
+ => [function ($q) {
return [true, ['configkey', $q->expr()->literal(2)], '12'];
}],
- '4 columns: string literal' =>
- [function ($q) {
+ '4 columns: string literal'
+ => [function ($q) {
return [false, [$q->expr()->literal('foo'), $q->expr()->literal('bar'), $q->expr()->literal('foo'), $q->expr()->literal('bar')], 'foobarfoobar'];
}],
- '4 columns: int literal' =>
- [function ($q) {
+ '4 columns: int literal'
+ => [function ($q) {
return [false, [$q->expr()->literal(1), $q->expr()->literal(2), $q->expr()->literal(3), $q->expr()->literal(4)], '1234'];
}],
- '5 columns: string param with special chars used in the function' =>
- [function ($q) {
+ '5 columns: string param with special chars used in the function'
+ => [function ($q) {
return [false, [$q->createNamedParameter('b'), $q->createNamedParameter("'"), $q->createNamedParameter('||'), $q->createNamedParameter(','), $q->createNamedParameter('a')], "b'||,a"];
}],
];
@@ -323,7 +324,7 @@ class FunctionBuilderTest extends TestCase {
$this->assertGreaterThan(1, $column);
}
- public function octetLengthProvider() {
+ public static function octetLengthProvider(): array {
return [
['', 0],
['foobar', 6],
@@ -332,9 +333,7 @@ class FunctionBuilderTest extends TestCase {
];
}
- /**
- * @dataProvider octetLengthProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('octetLengthProvider')]
public function testOctetLength(string $str, int $bytes): void {
$query = $this->connection->getQueryBuilder();
@@ -348,7 +347,7 @@ class FunctionBuilderTest extends TestCase {
$this->assertEquals($bytes, $column);
}
- public function charLengthProvider() {
+ public static function charLengthProvider(): array {
return [
['', 0],
['foobar', 6],
@@ -357,9 +356,7 @@ class FunctionBuilderTest extends TestCase {
];
}
- /**
- * @dataProvider charLengthProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('charLengthProvider')]
public function testCharLength(string $str, int $bytes): void {
$query = $this->connection->getQueryBuilder();
@@ -370,6 +367,7 @@ class FunctionBuilderTest extends TestCase {
$result = $query->execute();
$column = $result->fetchOne();
$result->closeCursor();
+ $this->assertNotNull($column);
$this->assertEquals($bytes, $column);
}
diff --git a/tests/lib/DB/QueryBuilder/Partitioned/JoinConditionTest.php b/tests/lib/DB/QueryBuilder/Partitioned/JoinConditionTest.php
index a8ebf11c2c2..8f84d6a0d2c 100644
--- a/tests/lib/DB/QueryBuilder/Partitioned/JoinConditionTest.php
+++ b/tests/lib/DB/QueryBuilder/Partitioned/JoinConditionTest.php
@@ -22,7 +22,7 @@ class JoinConditionTest extends TestCase {
parent::setUp();
}
- public function platformProvider(): array {
+ public static function platformProvider(): array {
return [
[IDBConnection::PLATFORM_SQLITE],
[IDBConnection::PLATFORM_POSTGRES],
@@ -41,9 +41,7 @@ class JoinConditionTest extends TestCase {
);
}
- /**
- * @dataProvider platformProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('platformProvider')]
public function testParseCondition(string $platform): void {
$query = $this->getBuilder($platform);
$param1 = $query->createNamedParameter('files');
@@ -63,9 +61,7 @@ class JoinConditionTest extends TestCase {
], $parsed->toConditions);
}
- /**
- * @dataProvider platformProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('platformProvider')]
public function testParseCastCondition(string $platform): void {
$query = $this->getBuilder($platform);
diff --git a/tests/lib/DB/QueryBuilder/Partitioned/PartitionedQueryBuilderTest.php b/tests/lib/DB/QueryBuilder/Partitioned/PartitionedQueryBuilderTest.php
index 697b3ab92c9..f99adc73aa8 100644
--- a/tests/lib/DB/QueryBuilder/Partitioned/PartitionedQueryBuilderTest.php
+++ b/tests/lib/DB/QueryBuilder/Partitioned/PartitionedQueryBuilderTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
diff --git a/tests/lib/DB/QueryBuilder/QueryBuilderTest.php b/tests/lib/DB/QueryBuilder/QueryBuilderTest.php
index 508748f13b2..990191a9ff5 100644
--- a/tests/lib/DB/QueryBuilder/QueryBuilderTest.php
+++ b/tests/lib/DB/QueryBuilder/QueryBuilderTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -17,6 +18,7 @@ use OCP\DB\IResult;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\DB\QueryBuilder\IQueryFunction;
use OCP\IDBConnection;
+use OCP\Server;
use Psr\Log\LoggerInterface;
/**
@@ -42,7 +44,7 @@ class QueryBuilderTest extends \Test\TestCase {
protected function setUp(): void {
parent::setUp();
- $this->connection = \OC::$server->getDatabaseConnection();
+ $this->connection = Server::get(IDBConnection::class);
$this->config = $this->createMock(SystemConfig::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->queryBuilder = new QueryBuilder($this->connection, $this->config, $this->logger);
@@ -88,7 +90,7 @@ class QueryBuilderTest extends \Test\TestCase {
->execute();
}
- public function dataFirstResult() {
+ public static function dataFirstResult(): array {
return [
[0, [99, 98, 97, 96, 95, 94, 93, 92, 91]],
[0, [99, 98, 97, 96, 95, 94, 93, 92, 91]],
@@ -98,11 +100,11 @@ class QueryBuilderTest extends \Test\TestCase {
}
/**
- * @dataProvider dataFirstResult
*
* @param int|null $firstResult
* @param array $expectedSet
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataFirstResult')]
public function testFirstResult($firstResult, $expectedSet): void {
$this->deleteTestingRows();
$this->createTestingRows();
@@ -124,7 +126,7 @@ class QueryBuilderTest extends \Test\TestCase {
$this->deleteTestingRows();
}
- public function dataMaxResults() {
+ public static function dataMaxResults(): array {
return [
[null, [99, 98, 97, 96, 95, 94, 93, 92, 91]],
// Limit 0 gives mixed results: either all entries or none is returned
@@ -135,11 +137,11 @@ class QueryBuilderTest extends \Test\TestCase {
}
/**
- * @dataProvider dataMaxResults
*
* @param int $maxResult
* @param array $expectedSet
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataMaxResults')]
public function testMaxResults($maxResult, $expectedSet): void {
$this->deleteTestingRows();
$this->createTestingRows();
@@ -161,10 +163,10 @@ class QueryBuilderTest extends \Test\TestCase {
$this->deleteTestingRows();
}
- public function dataSelect() {
+ public function dataSelect(): array {
$config = $this->createMock(SystemConfig::class);
$logger = $this->createMock(LoggerInterface::class);
- $queryBuilder = new QueryBuilder(\OC::$server->getDatabaseConnection(), $config, $logger);
+ $queryBuilder = new QueryBuilder(Server::get(IDBConnection::class), $config, $logger);
return [
// select('column1')
[['configvalue'], ['configvalue' => '99']],
@@ -187,12 +189,12 @@ class QueryBuilderTest extends \Test\TestCase {
}
/**
- * @dataProvider dataSelect
*
* @param array $selectArguments
* @param array $expected
* @param string $expectedLiteral
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataSelect')]
public function testSelect($selectArguments, $expected, $expectedLiteral = ''): void {
$this->deleteTestingRows();
$this->createTestingRows();
@@ -229,10 +231,10 @@ class QueryBuilderTest extends \Test\TestCase {
$this->deleteTestingRows();
}
- public function dataSelectAlias() {
+ public function dataSelectAlias(): array {
$config = $this->createMock(SystemConfig::class);
$logger = $this->createMock(LoggerInterface::class);
- $queryBuilder = new QueryBuilder(\OC::$server->getDatabaseConnection(), $config, $logger);
+ $queryBuilder = new QueryBuilder(Server::get(IDBConnection::class), $config, $logger);
return [
['configvalue', 'cv', ['cv' => '99']],
[$queryBuilder->expr()->literal('column1'), 'thing', ['thing' => 'column1']],
@@ -240,12 +242,12 @@ class QueryBuilderTest extends \Test\TestCase {
}
/**
- * @dataProvider dataSelectAlias
*
* @param mixed $select
* @param array $alias
* @param array $expected
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataSelectAlias')]
public function testSelectAlias($select, $alias, $expected): void {
$this->deleteTestingRows();
$this->createTestingRows();
@@ -338,10 +340,10 @@ class QueryBuilderTest extends \Test\TestCase {
$this->deleteTestingRows('testFirstResult2');
}
- public function dataAddSelect() {
+ public function dataAddSelect(): array {
$config = $this->createMock(SystemConfig::class);
$logger = $this->createMock(LoggerInterface::class);
- $queryBuilder = new QueryBuilder(\OC::$server->getDatabaseConnection(), $config, $logger);
+ $queryBuilder = new QueryBuilder(Server::get(IDBConnection::class), $config, $logger);
return [
// addSelect('column1')
[['configvalue'], ['appid' => 'testFirstResult', 'configvalue' => '99']],
@@ -364,12 +366,12 @@ class QueryBuilderTest extends \Test\TestCase {
}
/**
- * @dataProvider dataAddSelect
*
* @param array $selectArguments
* @param array $expected
* @param string $expectedLiteral
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataAddSelect')]
public function testAddSelect($selectArguments, $expected, $expectedLiteral = ''): void {
$this->deleteTestingRows();
$this->createTestingRows();
@@ -408,7 +410,7 @@ class QueryBuilderTest extends \Test\TestCase {
$this->deleteTestingRows();
}
- public function dataDelete() {
+ public static function dataDelete(): array {
return [
['data', null, ['table' => '`*PREFIX*data`', 'alias' => null], '`*PREFIX*data`'],
['data', 't', ['table' => '`*PREFIX*data`', 'alias' => 't'], '`*PREFIX*data` t'],
@@ -416,13 +418,13 @@ class QueryBuilderTest extends \Test\TestCase {
}
/**
- * @dataProvider dataDelete
*
* @param string $tableName
* @param string $tableAlias
* @param array $expectedQueryPart
* @param string $expectedQuery
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataDelete')]
public function testDelete($tableName, $tableAlias, $expectedQueryPart, $expectedQuery): void {
$this->queryBuilder->delete($tableName, $tableAlias);
@@ -437,7 +439,7 @@ class QueryBuilderTest extends \Test\TestCase {
);
}
- public function dataUpdate() {
+ public static function dataUpdate(): array {
return [
['data', null, ['table' => '`*PREFIX*data`', 'alias' => null], '`*PREFIX*data`'],
['data', 't', ['table' => '`*PREFIX*data`', 'alias' => 't'], '`*PREFIX*data` t'],
@@ -445,13 +447,13 @@ class QueryBuilderTest extends \Test\TestCase {
}
/**
- * @dataProvider dataUpdate
*
* @param string $tableName
* @param string $tableAlias
* @param array $expectedQueryPart
* @param string $expectedQuery
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataUpdate')]
public function testUpdate($tableName, $tableAlias, $expectedQueryPart, $expectedQuery): void {
$this->queryBuilder->update($tableName, $tableAlias);
@@ -466,19 +468,19 @@ class QueryBuilderTest extends \Test\TestCase {
);
}
- public function dataInsert() {
+ public static function dataInsert(): array {
return [
['data', ['table' => '`*PREFIX*data`'], '`*PREFIX*data`'],
];
}
/**
- * @dataProvider dataInsert
*
* @param string $tableName
* @param array $expectedQueryPart
* @param string $expectedQuery
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataInsert')]
public function testInsert($tableName, $expectedQueryPart, $expectedQuery): void {
$this->queryBuilder->insert($tableName);
@@ -493,10 +495,10 @@ class QueryBuilderTest extends \Test\TestCase {
);
}
- public function dataFrom() {
+ public function dataFrom(): array {
$config = $this->createMock(SystemConfig::class);
$logger = $this->createMock(LoggerInterface::class);
- $qb = new QueryBuilder(\OC::$server->getDatabaseConnection(), $config, $logger);
+ $qb = new QueryBuilder(Server::get(IDBConnection::class), $config, $logger);
return [
[$qb->createFunction('(' . $qb->select('*')->from('test')->getSQL() . ')'), 'q', null, null, [
['table' => '(SELECT * FROM `*PREFIX*test`)', 'alias' => '`q`']
@@ -515,7 +517,6 @@ class QueryBuilderTest extends \Test\TestCase {
}
/**
- * @dataProvider dataFrom
*
* @param string|IQueryFunction $table1Name
* @param string $table1Alias
@@ -524,6 +525,7 @@ class QueryBuilderTest extends \Test\TestCase {
* @param array $expectedQueryPart
* @param string $expectedQuery
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataFrom')]
public function testFrom($table1Name, $table1Alias, $table2Name, $table2Alias, $expectedQueryPart, $expectedQuery): void {
$this->queryBuilder->from($table1Name, $table1Alias);
if ($table2Name !== null) {
@@ -541,7 +543,7 @@ class QueryBuilderTest extends \Test\TestCase {
);
}
- public function dataJoin() {
+ public static function dataJoin(): array {
return [
[
'd1', 'data2', null, null,
@@ -563,7 +565,6 @@ class QueryBuilderTest extends \Test\TestCase {
}
/**
- * @dataProvider dataJoin
*
* @param string $fromAlias
* @param string $tableName
@@ -572,6 +573,7 @@ class QueryBuilderTest extends \Test\TestCase {
* @param array $expectedQueryPart
* @param string $expectedQuery
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataJoin')]
public function testJoin($fromAlias, $tableName, $tableAlias, $condition, $expectedQueryPart, $expectedQuery): void {
$this->queryBuilder->from('data1', 'd1');
$this->queryBuilder->join(
@@ -593,7 +595,6 @@ class QueryBuilderTest extends \Test\TestCase {
}
/**
- * @dataProvider dataJoin
*
* @param string $fromAlias
* @param string $tableName
@@ -602,6 +603,7 @@ class QueryBuilderTest extends \Test\TestCase {
* @param array $expectedQueryPart
* @param string $expectedQuery
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataJoin')]
public function testInnerJoin($fromAlias, $tableName, $tableAlias, $condition, $expectedQueryPart, $expectedQuery): void {
$this->queryBuilder->from('data1', 'd1');
$this->queryBuilder->innerJoin(
@@ -622,7 +624,7 @@ class QueryBuilderTest extends \Test\TestCase {
);
}
- public function dataLeftJoin() {
+ public static function dataLeftJoin(): array {
return [
[
'd1', 'data2', null, null,
@@ -643,7 +645,6 @@ class QueryBuilderTest extends \Test\TestCase {
}
/**
- * @dataProvider dataLeftJoin
*
* @param string $fromAlias
* @param string $tableName
@@ -652,6 +653,7 @@ class QueryBuilderTest extends \Test\TestCase {
* @param array $expectedQueryPart
* @param string $expectedQuery
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataLeftJoin')]
public function testLeftJoin($fromAlias, $tableName, $tableAlias, $condition, $expectedQueryPart, $expectedQuery): void {
$this->queryBuilder->from('data1', 'd1');
$this->queryBuilder->leftJoin(
@@ -672,7 +674,7 @@ class QueryBuilderTest extends \Test\TestCase {
);
}
- public function dataRightJoin() {
+ public static function dataRightJoin(): array {
return [
[
'd1', 'data2', null, null,
@@ -693,7 +695,6 @@ class QueryBuilderTest extends \Test\TestCase {
}
/**
- * @dataProvider dataRightJoin
*
* @param string $fromAlias
* @param string $tableName
@@ -702,6 +703,7 @@ class QueryBuilderTest extends \Test\TestCase {
* @param array $expectedQueryPart
* @param string $expectedQuery
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataRightJoin')]
public function testRightJoin($fromAlias, $tableName, $tableAlias, $condition, $expectedQueryPart, $expectedQuery): void {
$this->queryBuilder->from('data1', 'd1');
$this->queryBuilder->rightJoin(
@@ -722,7 +724,7 @@ class QueryBuilderTest extends \Test\TestCase {
);
}
- public function dataSet() {
+ public static function dataSet(): array {
return [
['column1', new Literal('value'), null, null, ['`column1` = value'], '`column1` = value'],
['column1', new Parameter(':param'), null, null, ['`column1` = :param'], '`column1` = :param'],
@@ -732,7 +734,6 @@ class QueryBuilderTest extends \Test\TestCase {
}
/**
- * @dataProvider dataSet
*
* @param string $partOne1
* @param string $partOne2
@@ -741,6 +742,7 @@ class QueryBuilderTest extends \Test\TestCase {
* @param array $expectedQueryPart
* @param string $expectedQuery
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataSet')]
public function testSet($partOne1, $partOne2, $partTwo1, $partTwo2, $expectedQueryPart, $expectedQuery): void {
$this->queryBuilder->update('data');
$this->queryBuilder->set($partOne1, $partOne2);
@@ -759,7 +761,7 @@ class QueryBuilderTest extends \Test\TestCase {
);
}
- public function dataWhere() {
+ public static function dataWhere(): array {
return [
[['where1'], new CompositeExpression('AND', ['where1']), 'where1'],
[['where1', 'where2'], new CompositeExpression('AND', ['where1', 'where2']), '(where1) AND (where2)'],
@@ -767,12 +769,12 @@ class QueryBuilderTest extends \Test\TestCase {
}
/**
- * @dataProvider dataWhere
*
* @param array $whereArguments
* @param array $expectedQueryPart
* @param string $expectedQuery
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataWhere')]
public function testWhere($whereArguments, $expectedQueryPart, $expectedQuery): void {
$this->queryBuilder->select('column');
call_user_func_array(
@@ -792,12 +794,12 @@ class QueryBuilderTest extends \Test\TestCase {
}
/**
- * @dataProvider dataWhere
*
* @param array $whereArguments
* @param array $expectedQueryPart
* @param string $expectedQuery
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataWhere')]
public function testAndWhere($whereArguments, $expectedQueryPart, $expectedQuery): void {
$this->queryBuilder->select('column');
call_user_func_array(
@@ -816,7 +818,7 @@ class QueryBuilderTest extends \Test\TestCase {
);
}
- public function dataOrWhere() {
+ public static function dataOrWhere(): array {
return [
[['where1'], new CompositeExpression('OR', ['where1']), 'where1'],
[['where1', 'where2'], new CompositeExpression('OR', ['where1', 'where2']), '(where1) OR (where2)'],
@@ -824,12 +826,12 @@ class QueryBuilderTest extends \Test\TestCase {
}
/**
- * @dataProvider dataOrWhere
*
* @param array $whereArguments
* @param array $expectedQueryPart
* @param string $expectedQuery
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataOrWhere')]
public function testOrWhere($whereArguments, $expectedQueryPart, $expectedQuery): void {
$this->queryBuilder->select('column');
call_user_func_array(
@@ -848,7 +850,7 @@ class QueryBuilderTest extends \Test\TestCase {
);
}
- public function dataGroupBy() {
+ public static function dataGroupBy(): array {
return [
[['column1'], ['`column1`'], '`column1`'],
[['column1', 'column2'], ['`column1`', '`column2`'], '`column1`, `column2`'],
@@ -856,12 +858,12 @@ class QueryBuilderTest extends \Test\TestCase {
}
/**
- * @dataProvider dataGroupBy
*
* @param array $groupByArguments
* @param array $expectedQueryPart
* @param string $expectedQuery
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGroupBy')]
public function testGroupBy($groupByArguments, $expectedQueryPart, $expectedQuery): void {
$this->queryBuilder->select('column');
call_user_func_array(
@@ -880,7 +882,7 @@ class QueryBuilderTest extends \Test\TestCase {
);
}
- public function dataAddGroupBy() {
+ public static function dataAddGroupBy(): array {
return [
[['column2'], ['`column1`', '`column2`'], '`column1`, `column2`'],
[['column2', 'column3'], ['`column1`', '`column2`', '`column3`'], '`column1`, `column2`, `column3`'],
@@ -888,12 +890,12 @@ class QueryBuilderTest extends \Test\TestCase {
}
/**
- * @dataProvider dataAddGroupBy
*
* @param array $groupByArguments
* @param array $expectedQueryPart
* @param string $expectedQuery
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataAddGroupBy')]
public function testAddGroupBy($groupByArguments, $expectedQueryPart, $expectedQuery): void {
$this->queryBuilder->select('column');
$this->queryBuilder->groupBy('column1');
@@ -913,20 +915,20 @@ class QueryBuilderTest extends \Test\TestCase {
);
}
- public function dataSetValue() {
+ public static function dataSetValue(): array {
return [
['column', 'value', ['`column`' => 'value'], '(`column`) VALUES(value)'],
];
}
/**
- * @dataProvider dataSetValue
*
* @param string $column
* @param string $value
* @param array $expectedQueryPart
* @param string $expectedQuery
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataSetValue')]
public function testSetValue($column, $value, $expectedQueryPart, $expectedQuery): void {
$this->queryBuilder->insert('data');
$this->queryBuilder->setValue($column, $value);
@@ -943,13 +945,13 @@ class QueryBuilderTest extends \Test\TestCase {
}
/**
- * @dataProvider dataSetValue
*
* @param string $column
* @param string $value
* @param array $expectedQueryPart
* @param string $expectedQuery
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataSetValue')]
public function testValues($column, $value, $expectedQueryPart, $expectedQuery): void {
$this->queryBuilder->insert('data');
$this->queryBuilder->values([
@@ -967,7 +969,7 @@ class QueryBuilderTest extends \Test\TestCase {
);
}
- public function dataHaving() {
+ public static function dataHaving(): array {
return [
[['condition1'], new CompositeExpression('AND', ['condition1']), 'HAVING condition1'],
[['condition1', 'condition2'], new CompositeExpression('AND', ['condition1', 'condition2']), 'HAVING (condition1) AND (condition2)'],
@@ -985,12 +987,12 @@ class QueryBuilderTest extends \Test\TestCase {
}
/**
- * @dataProvider dataHaving
*
* @param array $havingArguments
* @param array $expectedQueryPart
* @param string $expectedQuery
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataHaving')]
public function testHaving($havingArguments, $expectedQueryPart, $expectedQuery): void {
call_user_func_array(
[$this->queryBuilder, 'having'],
@@ -1008,7 +1010,7 @@ class QueryBuilderTest extends \Test\TestCase {
);
}
- public function dataAndHaving() {
+ public static function dataAndHaving(): array {
return [
[['condition2'], new CompositeExpression('AND', ['condition1', 'condition2']), 'HAVING (condition1) AND (condition2)'],
[['condition2', 'condition3'], new CompositeExpression('AND', ['condition1', 'condition2', 'condition3']), 'HAVING (condition1) AND (condition2) AND (condition3)'],
@@ -1026,12 +1028,12 @@ class QueryBuilderTest extends \Test\TestCase {
}
/**
- * @dataProvider dataAndHaving
*
* @param array $havingArguments
* @param array $expectedQueryPart
* @param string $expectedQuery
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataAndHaving')]
public function testAndHaving($havingArguments, $expectedQueryPart, $expectedQuery): void {
$this->queryBuilder->having('condition1');
call_user_func_array(
@@ -1050,7 +1052,7 @@ class QueryBuilderTest extends \Test\TestCase {
);
}
- public function dataOrHaving() {
+ public static function dataOrHaving(): array {
return [
[['condition2'], new CompositeExpression('OR', ['condition1', 'condition2']), 'HAVING (condition1) OR (condition2)'],
[['condition2', 'condition3'], new CompositeExpression('OR', ['condition1', 'condition2', 'condition3']), 'HAVING (condition1) OR (condition2) OR (condition3)'],
@@ -1068,12 +1070,12 @@ class QueryBuilderTest extends \Test\TestCase {
}
/**
- * @dataProvider dataOrHaving
*
* @param array $havingArguments
* @param array $expectedQueryPart
* @param string $expectedQuery
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataOrHaving')]
public function testOrHaving($havingArguments, $expectedQueryPart, $expectedQuery): void {
$this->queryBuilder->having('condition1');
call_user_func_array(
@@ -1092,7 +1094,7 @@ class QueryBuilderTest extends \Test\TestCase {
);
}
- public function dataOrderBy() {
+ public static function dataOrderBy(): array {
return [
['column', null, ['`column` ASC'], 'ORDER BY `column` ASC'],
['column', 'ASC', ['`column` ASC'], 'ORDER BY `column` ASC'],
@@ -1101,13 +1103,13 @@ class QueryBuilderTest extends \Test\TestCase {
}
/**
- * @dataProvider dataOrderBy
*
* @param string $sort
* @param string $order
* @param array $expectedQueryPart
* @param string $expectedQuery
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataOrderBy')]
public function testOrderBy($sort, $order, $expectedQueryPart, $expectedQuery): void {
$this->queryBuilder->orderBy($sort, $order);
@@ -1122,7 +1124,7 @@ class QueryBuilderTest extends \Test\TestCase {
);
}
- public function dataAddOrderBy() {
+ public static function dataAddOrderBy(): array {
return [
['column2', null, null, ['`column1` ASC', '`column2` ASC'], 'ORDER BY `column1` ASC, `column2` ASC'],
['column2', null, 'ASC', ['`column1` ASC', '`column2` ASC'], 'ORDER BY `column1` ASC, `column2` ASC'],
@@ -1137,7 +1139,6 @@ class QueryBuilderTest extends \Test\TestCase {
}
/**
- * @dataProvider dataAddOrderBy
*
* @param string $sort2
* @param string $order2
@@ -1145,6 +1146,7 @@ class QueryBuilderTest extends \Test\TestCase {
* @param array $expectedQueryPart
* @param string $expectedQuery
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataAddOrderBy')]
public function testAddOrderBy($sort2, $order2, $order1, $expectedQueryPart, $expectedQuery): void {
$this->queryBuilder->orderBy('column1', $order1);
$this->queryBuilder->addOrderBy($sort2, $order2);
@@ -1197,10 +1199,10 @@ class QueryBuilderTest extends \Test\TestCase {
}
}
- public function dataGetTableName() {
+ public function dataGetTableName(): array {
$config = $this->createMock(SystemConfig::class);
$logger = $this->createMock(LoggerInterface::class);
- $qb = new QueryBuilder(\OC::$server->getDatabaseConnection(), $config, $logger);
+ $qb = new QueryBuilder(Server::get(IDBConnection::class), $config, $logger);
return [
['*PREFIX*table', null, '`*PREFIX*table`'],
['*PREFIX*table', true, '`*PREFIX*table`'],
@@ -1217,12 +1219,12 @@ class QueryBuilderTest extends \Test\TestCase {
}
/**
- * @dataProvider dataGetTableName
*
* @param string|IQueryFunction $tableName
* @param bool $automatic
* @param string $expected
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetTableName')]
public function testGetTableName($tableName, $automatic, $expected): void {
if ($automatic !== null) {
$this->queryBuilder->automaticTablePrefix($automatic);
@@ -1234,7 +1236,7 @@ class QueryBuilderTest extends \Test\TestCase {
);
}
- public function dataGetColumnName() {
+ public static function dataGetColumnName(): array {
return [
['column', '', '`column`'],
['column', 'a', '`a`.`column`'],
@@ -1242,11 +1244,11 @@ class QueryBuilderTest extends \Test\TestCase {
}
/**
- * @dataProvider dataGetColumnName
* @param string $column
* @param string $prefix
* @param string $expected
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetColumnName')]
public function testGetColumnName($column, $prefix, $expected): void {
$this->assertSame(
$expected,
@@ -1427,7 +1429,7 @@ class QueryBuilderTest extends \Test\TestCase {
$this->logger
->expects($this->once())
->method('error')
- ->willReturnCallback(function ($message, $parameters) {
+ ->willReturnCallback(function ($message, $parameters): void {
$this->assertInstanceOf(QueryException::class, $parameters['exception']);
$this->assertSame(
'More than 1000 expressions in a list are not allowed on Oracle.',
@@ -1462,7 +1464,7 @@ class QueryBuilderTest extends \Test\TestCase {
$this->logger
->expects($this->once())
->method('error')
- ->willReturnCallback(function ($message, $parameters) {
+ ->willReturnCallback(function ($message, $parameters): void {
$this->assertInstanceOf(QueryException::class, $parameters['exception']);
$this->assertSame(
'The number of parameters must not exceed 65535. Restriction by PostgreSQL.',
diff --git a/tests/lib/DB/QueryBuilder/QuoteHelperTest.php b/tests/lib/DB/QueryBuilder/QuoteHelperTest.php
index 3c2e33c28ea..6efb55708a1 100644
--- a/tests/lib/DB/QueryBuilder/QuoteHelperTest.php
+++ b/tests/lib/DB/QueryBuilder/QuoteHelperTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -23,7 +24,7 @@ class QuoteHelperTest extends \Test\TestCase {
$this->helper = new QuoteHelper();
}
- public function dataQuoteColumnName() {
+ public static function dataQuoteColumnName(): array {
return [
['column', '`column`'],
[new Literal('literal'), 'literal'],
@@ -37,10 +38,10 @@ class QuoteHelperTest extends \Test\TestCase {
}
/**
- * @dataProvider dataQuoteColumnName
* @param mixed $input
* @param string $expected
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataQuoteColumnName')]
public function testQuoteColumnName($input, $expected): void {
$this->assertSame(
$expected,
@@ -48,7 +49,7 @@ class QuoteHelperTest extends \Test\TestCase {
);
}
- public function dataQuoteColumnNames() {
+ public static function dataQuoteColumnNames(): array {
return [
// Single case
['d.column', '`d`.`column`'],
@@ -72,10 +73,10 @@ class QuoteHelperTest extends \Test\TestCase {
}
/**
- * @dataProvider dataQuoteColumnNames
* @param mixed $input
* @param string $expected
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataQuoteColumnNames')]
public function testQuoteColumnNames($input, $expected): void {
$this->assertSame(
$expected,