diff --git a/core/Command/Db/DbIndexUsage.php b/core/Command/Db/DbIndexUsage.php
index 7df5f40e24c..24cd41cc682 100644
--- a/core/Command/Db/DbIndexUsage.php
+++ b/core/Command/Db/DbIndexUsage.php
@@ -8,14 +8,14 @@ declare(strict_types=1);
*/
namespace OC\Core\Command\Db;
+use Doctrine\DBAL\Platforms\MySQLPlatform;
+use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use OC\DB\Connection;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
-use Doctrine\DBAL\Platforms\MySQLPlatform;
-use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
class DbIndexUsage extends Command {
diff --git a/core/Command/Db/DbInfo.php b/core/Command/Db/DbInfo.php
index 19d22049e77..93fc02bea8d 100644
--- a/core/Command/Db/DbInfo.php
+++ b/core/Command/Db/DbInfo.php
@@ -8,15 +8,15 @@ declare(strict_types=1);
*/
namespace OC\Core\Command\Db;
+use Doctrine\DBAL\Platforms\MySQLPlatform;
+use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
+use Doctrine\DBAL\Platforms\SqlitePlatform;
use OC\DB\Connection;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
-use Doctrine\DBAL\Platforms\MySQLPlatform;
-use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
-use Doctrine\DBAL\Platforms\SqlitePlatform;
class DbInfo extends Command {
@@ -37,7 +37,7 @@ class DbInfo extends Command {
#[\Override]
protected function execute(InputInterface $input, OutputInterface $output): int {
$platform = $this->connection->getDatabasePlatform();
- $asJson = $input->getOption('json');
+ $asJson = $input->getOption('json');
if ($platform instanceof MySQLPlatform) {
$rows = $this->getMySQLInfo();
@@ -76,9 +76,9 @@ class DbInfo extends Command {
private function getMySQLInfo(): array {
$result = $this->connection->executeQuery(
- "SELECT VERSION() AS version, @@innodb_buffer_pool_size AS buffer_pool,
+ 'SELECT VERSION() AS version, @@innodb_buffer_pool_size AS buffer_pool,
@@max_connections AS max_conn, @@character_set_database AS charset,
- @@transaction_isolation AS tx_isolation"
+ @@transaction_isolation AS tx_isolation'
);
$info = $result->fetchAssociative();
@@ -114,7 +114,7 @@ class DbInfo extends Command {
private function getSQLiteInfo(): array {
$result = $this->connection->executeQuery('SELECT sqlite_version() AS version');
- $info = $result->fetchAssociative();
+ $info = $result->fetchAssociative();
return [
['setting' => 'Engine', 'value' => 'SQLite'],
['setting' => 'Version', 'value' => $info['version']],
diff --git a/core/Command/Db/DbLocks.php b/core/Command/Db/DbLocks.php
index 8ecd6b130ed..29fe615250c 100644
--- a/core/Command/Db/DbLocks.php
+++ b/core/Command/Db/DbLocks.php
@@ -8,14 +8,14 @@ declare(strict_types=1);
*/
namespace OC\Core\Command\Db;
+use Doctrine\DBAL\Platforms\MySQLPlatform;
+use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use OC\DB\Connection;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
-use Doctrine\DBAL\Platforms\MySQLPlatform;
-use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
class DbLocks extends Command {
@@ -39,7 +39,7 @@ class DbLocks extends Command {
$asJson = $input->getOption('json');
if ($platform instanceof MySQLPlatform) {
- $sql = "SELECT r.trx_id AS waiting_trx_id,
+ $sql = 'SELECT r.trx_id AS waiting_trx_id,
r.trx_mysql_thread_id AS waiting_thread,
r.trx_query AS waiting_query,
b.trx_id AS blocking_trx_id,
@@ -47,11 +47,11 @@ class DbLocks extends Command {
b.trx_query AS blocking_query
FROM information_schema.innodb_lock_waits w
JOIN information_schema.innodb_trx b ON b.trx_id = w.blocking_trx_id
- JOIN information_schema.innodb_trx r ON r.trx_id = w.requesting_trx_id";
+ JOIN information_schema.innodb_trx r ON r.trx_id = w.requesting_trx_id';
$headers = ['Waiting TRX', 'Waiting Thread', 'Waiting Query', 'Blocking TRX', 'Blocking Thread', 'Blocking Query'];
$cols = ['waiting_trx_id', 'waiting_thread', 'waiting_query', 'blocking_trx_id', 'blocking_thread', 'blocking_query'];
} elseif ($platform instanceof PostgreSQLPlatform) {
- $sql = "SELECT blocked_locks.pid AS blocked_pid,
+ $sql = 'SELECT blocked_locks.pid AS blocked_pid,
blocked_activity.usename AS blocked_user,
blocking_locks.pid AS blocking_pid,
blocking_activity.usename AS blocking_user,
@@ -65,9 +65,9 @@ class DbLocks extends Command {
AND blocking_locks.relation IS NOT DISTINCT FROM blocked_locks.relation
AND blocking_locks.pid != blocked_locks.pid
JOIN pg_catalog.pg_stat_activity blocking_activity ON blocking_activity.pid = blocking_locks.pid
- WHERE NOT blocked_locks.granted";
+ WHERE NOT blocked_locks.granted';
$headers = ['Blocked PID', 'Blocked User', 'Blocking PID', 'Blocking User', 'Blocked Query', 'Duration'];
- $cols = ['blocked_pid', 'blocked_user', 'blocking_pid', 'blocking_user', 'blocked_query', 'blocked_duration'];
+ $cols = ['blocked_pid', 'blocked_user', 'blocking_pid', 'blocking_user', 'blocked_query', 'blocked_duration'];
} else {
$output->writeln('db:locks is not supported for SQLite and Oracle (SQLite uses file-level locking).');
return Command::SUCCESS;
@@ -92,7 +92,7 @@ class DbLocks extends Command {
$table->setHeaders($headers);
foreach ($rows as $row) {
- $table->addRow(array_map(fn($col) => $row[$col] ?? '—', $cols));
+ $table->addRow(array_map(fn ($col) => $row[$col] ?? '—', $cols));
}
$table->render();
diff --git a/core/Command/Db/DbSize.php b/core/Command/Db/DbSize.php
index f402dd62182..36187b57e4f 100644
--- a/core/Command/Db/DbSize.php
+++ b/core/Command/Db/DbSize.php
@@ -8,14 +8,14 @@ declare(strict_types=1);
*/
namespace OC\Core\Command\Db;
+use Doctrine\DBAL\Platforms\MySQLPlatform;
+use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use OC\DB\Connection;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
-use Doctrine\DBAL\Platforms\MySQLPlatform;
-use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
class DbSize extends Command {
@@ -36,10 +36,10 @@ class DbSize extends Command {
#[\Override]
protected function execute(InputInterface $input, OutputInterface $output): int {
$platform = $this->connection->getDatabasePlatform();
- $asJson = $input->getOption('json');
+ $asJson = $input->getOption('json');
if ($platform instanceof MySQLPlatform) {
- $sql = "
+ $sql = '
SELECT table_name AS `table`,
ROUND((data_length + index_length) / 1024 / 1024, 2) AS total_mb,
ROUND(data_length / 1024 / 1024, 2) AS data_mb,
@@ -49,9 +49,9 @@ class DbSize extends Command {
FROM information_schema.tables
WHERE table_schema = DATABASE()
ORDER BY (data_length + index_length) DESC
- ";
+ ';
$headers = ['Table', 'Total (MB)', 'Data (MB)', 'Index (MB)', 'Rows', 'Avg Row (bytes)'];
- $cols = ['table', 'total_mb', 'data_mb', 'index_mb', 'rows', 'avg_row_bytes'];
+ $cols = ['table', 'total_mb', 'data_mb', 'index_mb', 'rows', 'avg_row_bytes'];
} elseif ($platform instanceof PostgreSQLPlatform) {
$sql = "
SELECT relname AS table,
@@ -66,7 +66,7 @@ class DbSize extends Command {
ORDER BY pg_total_relation_size(c.oid) DESC
";
$headers = ['Table', 'Total (MB)', 'Data (MB)', 'Index (MB)', 'Rows (est.)', 'Avg Row (bytes)'];
- $cols = ['table', 'total_mb', 'data_mb', 'index_mb', 'rows', 'avg_row_bytes'];
+ $cols = ['table', 'total_mb', 'data_mb', 'index_mb', 'rows', 'avg_row_bytes'];
} else {
$output->writeln('db:size is not supported for SQLite and Oracle.');
return Command::SUCCESS;
@@ -83,7 +83,7 @@ class DbSize extends Command {
$table->setHeaders($headers);
foreach ($rows as $row) {
- $table->addRow(array_map(fn($col) => $row[$col], $cols));
+ $table->addRow(array_map(fn ($col) => $row[$col], $cols));
}
$table->render();
diff --git a/tests/Core/Command/Db/DbIndexUsageTest.php b/tests/Core/Command/Db/DbIndexUsageTest.php
index ea5c311c214..c5520499a90 100644
--- a/tests/Core/Command/Db/DbIndexUsageTest.php
+++ b/tests/Core/Command/Db/DbIndexUsageTest.php
@@ -22,148 +22,148 @@ use Test\TestCase;
class DbIndexUsageTest extends TestCase {
- private Connection&MockObject $connection;
- private InputInterface&MockObject $input;
- private DbIndexUsage $command;
+ private Connection&MockObject $connection;
+ private InputInterface&MockObject $input;
+ private DbIndexUsage $command;
- protected function setUp(): void {
- parent::setUp();
- $this->connection = $this->createMock(Connection::class);
- $this->input = $this->createMock(InputInterface::class);
- $this->command = new DbIndexUsage($this->connection);
- }
+ protected function setUp(): void {
+ parent::setUp();
+ $this->connection = $this->createMock(Connection::class);
+ $this->input = $this->createMock(InputInterface::class);
+ $this->command = new DbIndexUsage($this->connection);
+ }
- private function mockMySQLRows(): array {
- return [
- ['table' => 'oc_filecache', 'index' => 'idx_fc_name', 'reads' => 0, 'writes' => 150],
- ['table' => 'oc_share', 'index' => 'idx_sh_par', 'reads' => 0, 'writes' => 42],
- ];
- }
+ private function mockMySQLRows(): array {
+ return [
+ ['table' => 'oc_filecache', 'index' => 'idx_fc_name', 'reads' => 0, 'writes' => 150],
+ ['table' => 'oc_share', 'index' => 'idx_sh_par', 'reads' => 0, 'writes' => 42],
+ ];
+ }
- private function mockPostgreSQLRows(): array {
- return [
- ['table' => 'oc_filecache', 'index' => 'idx_fc_name', 'reads' => 0, 'tuples_read' => 0, 'tuples_fetched' => 0],
- ];
- }
+ private function mockPostgreSQLRows(): array {
+ return [
+ ['table' => 'oc_filecache', 'index' => 'idx_fc_name', 'reads' => 0, 'tuples_read' => 0, 'tuples_fetched' => 0],
+ ];
+ }
- private function mockResult(array $rows): Result&MockObject {
- $result = $this->createMock(Result::class);
- $result->method('fetchAllAssociative')->willReturn($rows);
- return $result;
- }
+ private function mockResult(array $rows): Result&MockObject {
+ $result = $this->createMock(Result::class);
+ $result->method('fetchAllAssociative')->willReturn($rows);
+ return $result;
+ }
- public function testNoUnusedIndexesPrintsSuccessMessage(): void {
- $this->connection->method('getDatabasePlatform')
- ->willReturn($this->createMock(MySQLPlatform::class));
- $this->connection->method('executeQuery')
- ->willReturn($this->mockResult([]));
- $this->input->method('getOption')->willReturnMap([['json', false], ['all', false]]);
+ public function testNoUnusedIndexesPrintsSuccessMessage(): void {
+ $this->connection->method('getDatabasePlatform')
+ ->willReturn($this->createMock(MySQLPlatform::class));
+ $this->connection->method('executeQuery')
+ ->willReturn($this->mockResult([]));
+ $this->input->method('getOption')->willReturnMap([['json', false], ['all', false]]);
- $output = new BufferedOutput();
- $exit = self::invokePrivate($this->command, 'execute', [$this->input, $output]);
+ $output = new BufferedOutput();
+ $exit = self::invokePrivate($this->command, 'execute', [$this->input, $output]);
- $this->assertSame(0, $exit);
- $this->assertStringContainsString('No unused indexes found', $output->fetch());
- }
+ $this->assertSame(0, $exit);
+ $this->assertStringContainsString('No unused indexes found', $output->fetch());
+ }
- public function testMySQLUnusedIndexesRendersTable(): void {
- $this->connection->method('getDatabasePlatform')
- ->willReturn($this->createMock(MySQLPlatform::class));
- $this->connection->method('executeQuery')
- ->willReturn($this->mockResult($this->mockMySQLRows()));
- $this->input->method('getOption')->willReturnMap([['json', false], ['all', false]]);
+ public function testMySQLUnusedIndexesRendersTable(): void {
+ $this->connection->method('getDatabasePlatform')
+ ->willReturn($this->createMock(MySQLPlatform::class));
+ $this->connection->method('executeQuery')
+ ->willReturn($this->mockResult($this->mockMySQLRows()));
+ $this->input->method('getOption')->willReturnMap([['json', false], ['all', false]]);
- $output = new BufferedOutput();
- $exit = self::invokePrivate($this->command, 'execute', [$this->input, $output]);
+ $output = new BufferedOutput();
+ $exit = self::invokePrivate($this->command, 'execute', [$this->input, $output]);
- $this->assertSame(0, $exit);
- $content = $output->fetch();
- $this->assertStringContainsString('Reads', $content);
- $this->assertStringContainsString('Writes', $content);
- $this->assertStringContainsString('idx_fc_name', $content);
- $this->assertStringContainsString('Found 2 unused index(es)', $content);
- }
+ $this->assertSame(0, $exit);
+ $content = $output->fetch();
+ $this->assertStringContainsString('Reads', $content);
+ $this->assertStringContainsString('Writes', $content);
+ $this->assertStringContainsString('idx_fc_name', $content);
+ $this->assertStringContainsString('Found 2 unused index(es)', $content);
+ }
- public function testPostgreSQLUnusedIndexesRendersTable(): void {
- $this->connection->method('getDatabasePlatform')
- ->willReturn($this->createMock(PostgreSQLPlatform::class));
- $this->connection->method('executeQuery')
- ->willReturn($this->mockResult($this->mockPostgreSQLRows()));
- $this->input->method('getOption')->willReturnMap([['json', false], ['all', false]]);
+ public function testPostgreSQLUnusedIndexesRendersTable(): void {
+ $this->connection->method('getDatabasePlatform')
+ ->willReturn($this->createMock(PostgreSQLPlatform::class));
+ $this->connection->method('executeQuery')
+ ->willReturn($this->mockResult($this->mockPostgreSQLRows()));
+ $this->input->method('getOption')->willReturnMap([['json', false], ['all', false]]);
- $output = new BufferedOutput();
- $exit = self::invokePrivate($this->command, 'execute', [$this->input, $output]);
+ $output = new BufferedOutput();
+ $exit = self::invokePrivate($this->command, 'execute', [$this->input, $output]);
- $this->assertSame(0, $exit);
- $content = $output->fetch();
- $this->assertStringContainsString('Tuples Read', $content);
- $this->assertStringContainsString('Tuples Fetched', $content);
- }
+ $this->assertSame(0, $exit);
+ $content = $output->fetch();
+ $this->assertStringContainsString('Tuples Read', $content);
+ $this->assertStringContainsString('Tuples Fetched', $content);
+ }
- public function testAllFlagSuppressesCountMessage(): void {
- $this->connection->method('getDatabasePlatform')
- ->willReturn($this->createMock(MySQLPlatform::class));
- $this->connection->method('executeQuery')
- ->willReturn($this->mockResult($this->mockMySQLRows()));
- $this->input->method('getOption')->willReturnMap([['json', false], ['all', true]]);
+ public function testAllFlagSuppressesCountMessage(): void {
+ $this->connection->method('getDatabasePlatform')
+ ->willReturn($this->createMock(MySQLPlatform::class));
+ $this->connection->method('executeQuery')
+ ->willReturn($this->mockResult($this->mockMySQLRows()));
+ $this->input->method('getOption')->willReturnMap([['json', false], ['all', true]]);
- $output = new BufferedOutput();
- self::invokePrivate($this->command, 'execute', [$this->input, $output]);
+ $output = new BufferedOutput();
+ self::invokePrivate($this->command, 'execute', [$this->input, $output]);
- $this->assertStringNotContainsString('Found', $output->fetch());
- }
+ $this->assertStringNotContainsString('Found', $output->fetch());
+ }
- public function testDefaultFilterIncludedInQuery(): void {
- $this->connection->method('getDatabasePlatform')
- ->willReturn($this->createMock(MySQLPlatform::class));
- $this->connection->expects($this->once())
- ->method('executeQuery')
- ->with($this->stringContains('count_read = 0'))
- ->willReturn($this->mockResult([]));
- $this->input->method('getOption')->willReturnMap([['json', false], ['all', false]]);
+ public function testDefaultFilterIncludedInQuery(): void {
+ $this->connection->method('getDatabasePlatform')
+ ->willReturn($this->createMock(MySQLPlatform::class));
+ $this->connection->expects($this->once())
+ ->method('executeQuery')
+ ->with($this->stringContains('count_read = 0'))
+ ->willReturn($this->mockResult([]));
+ $this->input->method('getOption')->willReturnMap([['json', false], ['all', false]]);
- self::invokePrivate($this->command, 'execute', [$this->input, new BufferedOutput()]);
- }
+ self::invokePrivate($this->command, 'execute', [$this->input, new BufferedOutput()]);
+ }
- public function testAllFlagRemovesFilterFromQuery(): void {
- $this->connection->method('getDatabasePlatform')
- ->willReturn($this->createMock(MySQLPlatform::class));
- $this->connection->expects($this->once())
- ->method('executeQuery')
- ->with($this->logicalNot($this->stringContains('count_read = 0')))
- ->willReturn($this->mockResult([]));
- $this->input->method('getOption')->willReturnMap([['json', false], ['all', true]]);
+ public function testAllFlagRemovesFilterFromQuery(): void {
+ $this->connection->method('getDatabasePlatform')
+ ->willReturn($this->createMock(MySQLPlatform::class));
+ $this->connection->expects($this->once())
+ ->method('executeQuery')
+ ->with($this->logicalNot($this->stringContains('count_read = 0')))
+ ->willReturn($this->mockResult([]));
+ $this->input->method('getOption')->willReturnMap([['json', false], ['all', true]]);
- self::invokePrivate($this->command, 'execute', [$this->input, new BufferedOutput()]);
- }
+ self::invokePrivate($this->command, 'execute', [$this->input, new BufferedOutput()]);
+ }
- public function testJsonOutputWhenRowsExist(): void {
- $this->connection->method('getDatabasePlatform')
- ->willReturn($this->createMock(MySQLPlatform::class));
- $this->connection->method('executeQuery')
- ->willReturn($this->mockResult($this->mockMySQLRows()));
- $this->input->method('getOption')->willReturnMap([['json', true], ['all', false]]);
+ public function testJsonOutputWhenRowsExist(): void {
+ $this->connection->method('getDatabasePlatform')
+ ->willReturn($this->createMock(MySQLPlatform::class));
+ $this->connection->method('executeQuery')
+ ->willReturn($this->mockResult($this->mockMySQLRows()));
+ $this->input->method('getOption')->willReturnMap([['json', true], ['all', false]]);
- $output = new BufferedOutput();
- $exit = self::invokePrivate($this->command, 'execute', [$this->input, $output]);
+ $output = new BufferedOutput();
+ $exit = self::invokePrivate($this->command, 'execute', [$this->input, $output]);
- $this->assertSame(0, $exit);
- $data = json_decode($output->fetch(), true);
- $this->assertIsArray($data);
- $this->assertCount(2, $data);
- $this->assertArrayHasKey('table', $data[0]);
- $this->assertArrayHasKey('index', $data[0]);
- }
+ $this->assertSame(0, $exit);
+ $data = json_decode($output->fetch(), true);
+ $this->assertIsArray($data);
+ $this->assertCount(2, $data);
+ $this->assertArrayHasKey('table', $data[0]);
+ $this->assertArrayHasKey('index', $data[0]);
+ }
- public function testSQLiteReturnsSuccessWithMessage(): void {
- $this->connection->method('getDatabasePlatform')
- ->willReturn($this->createMock(SqlitePlatform::class));
- $this->input->method('getOption')->willReturnMap([['json', false], ['all', false]]);
+ public function testSQLiteReturnsSuccessWithMessage(): void {
+ $this->connection->method('getDatabasePlatform')
+ ->willReturn($this->createMock(SqlitePlatform::class));
+ $this->input->method('getOption')->willReturnMap([['json', false], ['all', false]]);
- $output = new BufferedOutput();
- $exit = self::invokePrivate($this->command, 'execute', [$this->input, $output]);
+ $output = new BufferedOutput();
+ $exit = self::invokePrivate($this->command, 'execute', [$this->input, $output]);
- $this->assertSame(0, $exit);
- $this->assertStringContainsString('not supported for SQLite', $output->fetch());
- }
+ $this->assertSame(0, $exit);
+ $this->assertStringContainsString('not supported for SQLite', $output->fetch());
+ }
}
diff --git a/tests/Core/Command/Db/DbInfoTest.php b/tests/Core/Command/Db/DbInfoTest.php
index bdcc2fbcd74..bf5d5be492b 100644
--- a/tests/Core/Command/Db/DbInfoTest.php
+++ b/tests/Core/Command/Db/DbInfoTest.php
@@ -30,17 +30,17 @@ class DbInfoTest extends TestCase {
protected function setUp(): void {
parent::setUp();
$this->connection = $this->createMock(Connection::class);
- $this->input = $this->createMock(InputInterface::class);
- $this->command = new DbInfo($this->connection);
+ $this->input = $this->createMock(InputInterface::class);
+ $this->command = new DbInfo($this->connection);
}
private function mockMySQLResult(array $overrides = []): Result&MockObject {
$result = $this->createMock(Result::class);
$result->method('fetchAssociative')->willReturn(array_merge([
- 'version' => '8.0.30',
- 'buffer_pool' => 1073741824, // 1 GB
- 'max_conn' => '200',
- 'charset' => 'utf8mb4',
+ 'version' => '8.0.30',
+ 'buffer_pool' => 1073741824, // 1 GB
+ 'max_conn' => '200',
+ 'charset' => 'utf8mb4',
'tx_isolation' => 'READ-COMMITTED',
], $overrides));
return $result;
@@ -49,10 +49,10 @@ class DbInfoTest extends TestCase {
private function mockPostgreSQLResult(): Result&MockObject {
$result = $this->createMock(Result::class);
$result->method('fetchAssociative')->willReturn([
- 'version' => 'PostgreSQL 15.2 on x86_64',
- 'max_conn' => '100',
+ 'version' => 'PostgreSQL 15.2 on x86_64',
+ 'max_conn' => '100',
'shared_buffers' => '128MB',
- 'work_mem' => '4MB',
+ 'work_mem' => '4MB',
]);
return $result;
}
@@ -128,17 +128,17 @@ class DbInfoTest extends TestCase {
$data = json_decode($output->fetch(), true);
$this->assertIsArray($data);
$this->assertArrayHasKey('setting', $data[0]);
- $this->assertArrayHasKey('value', $data[0]);
+ $this->assertArrayHasKey('value', $data[0]);
}
public static function dataMySQLHealthChecks(): array {
return [
- 'charset utf8mb4 → OK' => ['charset', 'utf8mb4', true, 'Character Set'],
- 'charset latin1 → CHECK' => ['charset', 'latin1', false, 'Character Set'],
- 'max_conn 200 → OK' => ['max_conn', '200', true, 'Max Connections'],
- 'max_conn 50 → CHECK' => ['max_conn', '50', false, 'Max Connections'],
- 'tx_isolation READ-COMMITTED → OK' => ['tx_isolation', 'READ-COMMITTED', true, 'Transaction Isolation'],
- 'tx_isolation REPEATABLE-READ → CHECK' => ['tx_isolation', 'REPEATABLE-READ', false, 'Transaction Isolation'],
+ 'charset utf8mb4 → OK' => ['charset', 'utf8mb4', true, 'Character Set'],
+ 'charset latin1 → CHECK' => ['charset', 'latin1', false, 'Character Set'],
+ 'max_conn 200 → OK' => ['max_conn', '200', true, 'Max Connections'],
+ 'max_conn 50 → CHECK' => ['max_conn', '50', false, 'Max Connections'],
+ 'tx_isolation READ-COMMITTED → OK' => ['tx_isolation', 'READ-COMMITTED', true, 'Transaction Isolation'],
+ 'tx_isolation REPEATABLE-READ → CHECK' => ['tx_isolation', 'REPEATABLE-READ', false, 'Transaction Isolation'],
];
}
@@ -159,7 +159,7 @@ class DbInfoTest extends TestCase {
self::invokePrivate($this->command, 'execute', [$this->input, $output]);
$data = json_decode($output->fetch(), true);
- $rows = array_values(array_filter($data, fn($r) => $r['setting'] === $settingLabel));
+ $rows = array_values(array_filter($data, fn ($r) => $r['setting'] === $settingLabel));
$this->assertNotEmpty($rows, "Setting '{$settingLabel}' not found in JSON output");
$this->assertSame($expectedOk, $rows[0]['ok']);
}
diff --git a/tests/Core/Command/Db/DbLocksTest.php b/tests/Core/Command/Db/DbLocksTest.php
index 5987f49cfcd..c0621141c98 100644
--- a/tests/Core/Command/Db/DbLocksTest.php
+++ b/tests/Core/Command/Db/DbLocksTest.php
@@ -22,140 +22,140 @@ use Test\TestCase;
class DbLocksTest extends TestCase {
- private Connection&MockObject $connection;
- private InputInterface&MockObject $input;
- private DbLocks $command;
+ private Connection&MockObject $connection;
+ private InputInterface&MockObject $input;
+ private DbLocks $command;
- protected function setUp(): void {
- parent::setUp();
- $this->connection = $this->createMock(Connection::class);
- $this->input = $this->createMock(InputInterface::class);
- $this->command = new DbLocks($this->connection);
- }
+ protected function setUp(): void {
+ parent::setUp();
+ $this->connection = $this->createMock(Connection::class);
+ $this->input = $this->createMock(InputInterface::class);
+ $this->command = new DbLocks($this->connection);
+ }
- private function mockMySQLLocks(): array {
- return [[
- 'waiting_trx_id' => '12345',
- 'waiting_thread' => '42',
- 'waiting_query' => 'UPDATE oc_filecache SET path_hash = ?',
- 'blocking_trx_id' => '12344',
- 'blocking_thread' => '41',
- 'blocking_query' => null, // NULL — deve ser renderizado como '—'
- ]];
- }
+ private function mockMySQLLocks(): array {
+ return [[
+ 'waiting_trx_id' => '12345',
+ 'waiting_thread' => '42',
+ 'waiting_query' => 'UPDATE oc_filecache SET path_hash = ?',
+ 'blocking_trx_id' => '12344',
+ 'blocking_thread' => '41',
+ 'blocking_query' => null, // NULL — deve ser renderizado como '—'
+ ]];
+ }
- private function mockPostgreSQLLocks(): array {
- return [[
- 'blocked_pid' => 1234,
- 'blocked_user' => 'nextcloud',
- 'blocking_pid' => 1233,
- 'blocking_user' => 'nextcloud',
- 'blocked_query' => 'SELECT * FROM oc_filecache WHERE parent = ?',
- 'blocked_duration' => '00:00:05.123456',
- ]];
- }
+ private function mockPostgreSQLLocks(): array {
+ return [[
+ 'blocked_pid' => 1234,
+ 'blocked_user' => 'nextcloud',
+ 'blocking_pid' => 1233,
+ 'blocking_user' => 'nextcloud',
+ 'blocked_query' => 'SELECT * FROM oc_filecache WHERE parent = ?',
+ 'blocked_duration' => '00:00:05.123456',
+ ]];
+ }
- private function mockResult(array $rows): Result&MockObject {
- $result = $this->createMock(Result::class);
- $result->method('fetchAllAssociative')->willReturn($rows);
- return $result;
- }
+ private function mockResult(array $rows): Result&MockObject {
+ $result = $this->createMock(Result::class);
+ $result->method('fetchAllAssociative')->willReturn($rows);
+ return $result;
+ }
- public function testMySQLNoLocksShowsInfoMessage(): void {
- $this->connection->method('getDatabasePlatform')
- ->willReturn($this->createMock(MySQLPlatform::class));
- $this->connection->method('executeQuery')
- ->willReturn($this->mockResult([]));
- $this->input->method('getOption')->willReturnMap([['json', false]]);
+ public function testMySQLNoLocksShowsInfoMessage(): void {
+ $this->connection->method('getDatabasePlatform')
+ ->willReturn($this->createMock(MySQLPlatform::class));
+ $this->connection->method('executeQuery')
+ ->willReturn($this->mockResult([]));
+ $this->input->method('getOption')->willReturnMap([['json', false]]);
- $output = new BufferedOutput();
- $exit = self::invokePrivate($this->command, 'execute', [$this->input, $output]);
+ $output = new BufferedOutput();
+ $exit = self::invokePrivate($this->command, 'execute', [$this->input, $output]);
- $this->assertSame(0, $exit);
- $this->assertStringContainsString('No active locks', $output->fetch());
- }
+ $this->assertSame(0, $exit);
+ $this->assertStringContainsString('No active locks', $output->fetch());
+ }
- public function testPostgreSQLNoLocksShowsInfoMessage(): void {
- $this->connection->method('getDatabasePlatform')
- ->willReturn($this->createMock(PostgreSQLPlatform::class));
- $this->connection->method('executeQuery')
- ->willReturn($this->mockResult([]));
- $this->input->method('getOption')->willReturnMap([['json', false]]);
+ public function testPostgreSQLNoLocksShowsInfoMessage(): void {
+ $this->connection->method('getDatabasePlatform')
+ ->willReturn($this->createMock(PostgreSQLPlatform::class));
+ $this->connection->method('executeQuery')
+ ->willReturn($this->mockResult([]));
+ $this->input->method('getOption')->willReturnMap([['json', false]]);
- $output = new BufferedOutput();
- $exit = self::invokePrivate($this->command, 'execute', [$this->input, $output]);
+ $output = new BufferedOutput();
+ $exit = self::invokePrivate($this->command, 'execute', [$this->input, $output]);
- $this->assertSame(0, $exit);
- $this->assertStringContainsString('No active locks', $output->fetch());
- }
+ $this->assertSame(0, $exit);
+ $this->assertStringContainsString('No active locks', $output->fetch());
+ }
- public function testMySQLLocksFoundShowsErrorMessage(): void {
- $this->connection->method('getDatabasePlatform')
- ->willReturn($this->createMock(MySQLPlatform::class));
- $this->connection->method('executeQuery')
- ->willReturn($this->mockResult($this->mockMySQLLocks()));
- $this->input->method('getOption')->willReturnMap([['json', false]]);
+ public function testMySQLLocksFoundShowsErrorMessage(): void {
+ $this->connection->method('getDatabasePlatform')
+ ->willReturn($this->createMock(MySQLPlatform::class));
+ $this->connection->method('executeQuery')
+ ->willReturn($this->mockResult($this->mockMySQLLocks()));
+ $this->input->method('getOption')->willReturnMap([['json', false]]);
- $output = new BufferedOutput();
- $exit = self::invokePrivate($this->command, 'execute', [$this->input, $output]);
+ $output = new BufferedOutput();
+ $exit = self::invokePrivate($this->command, 'execute', [$this->input, $output]);
- $this->assertSame(0, $exit);
- $this->assertStringContainsString('Found 1 blocking transaction(s)', $output->fetch());
- }
+ $this->assertSame(0, $exit);
+ $this->assertStringContainsString('Found 1 blocking transaction(s)', $output->fetch());
+ }
- public function testPostgreSQLLocksFoundShowsErrorMessage(): void {
- $this->connection->method('getDatabasePlatform')
- ->willReturn($this->createMock(PostgreSQLPlatform::class));
- $this->connection->method('executeQuery')
- ->willReturn($this->mockResult($this->mockPostgreSQLLocks()));
- $this->input->method('getOption')->willReturnMap([['json', false]]);
+ public function testPostgreSQLLocksFoundShowsErrorMessage(): void {
+ $this->connection->method('getDatabasePlatform')
+ ->willReturn($this->createMock(PostgreSQLPlatform::class));
+ $this->connection->method('executeQuery')
+ ->willReturn($this->mockResult($this->mockPostgreSQLLocks()));
+ $this->input->method('getOption')->willReturnMap([['json', false]]);
- $output = new BufferedOutput();
- $exit = self::invokePrivate($this->command, 'execute', [$this->input, $output]);
+ $output = new BufferedOutput();
+ $exit = self::invokePrivate($this->command, 'execute', [$this->input, $output]);
- $this->assertSame(0, $exit);
- $this->assertStringContainsString('Found 1 blocking transaction(s)', $output->fetch());
- }
+ $this->assertSame(0, $exit);
+ $this->assertStringContainsString('Found 1 blocking transaction(s)', $output->fetch());
+ }
- public function testJsonOutputWhenLocksExist(): void {
- $this->connection->method('getDatabasePlatform')
- ->willReturn($this->createMock(MySQLPlatform::class));
- $this->connection->method('executeQuery')
- ->willReturn($this->mockResult($this->mockMySQLLocks()));
- $this->input->method('getOption')->willReturnMap([['json', true]]);
+ public function testJsonOutputWhenLocksExist(): void {
+ $this->connection->method('getDatabasePlatform')
+ ->willReturn($this->createMock(MySQLPlatform::class));
+ $this->connection->method('executeQuery')
+ ->willReturn($this->mockResult($this->mockMySQLLocks()));
+ $this->input->method('getOption')->willReturnMap([['json', true]]);
- $output = new BufferedOutput();
- $exit = self::invokePrivate($this->command, 'execute', [$this->input, $output]);
+ $output = new BufferedOutput();
+ $exit = self::invokePrivate($this->command, 'execute', [$this->input, $output]);
- $this->assertSame(0, $exit);
- $data = json_decode($output->fetch(), true);
- $this->assertIsArray($data);
- $this->assertCount(1, $data);
- $this->assertArrayHasKey('waiting_trx_id', $data[0]);
- }
+ $this->assertSame(0, $exit);
+ $data = json_decode($output->fetch(), true);
+ $this->assertIsArray($data);
+ $this->assertCount(1, $data);
+ $this->assertArrayHasKey('waiting_trx_id', $data[0]);
+ }
- public function testSQLiteReturnsSuccessWithMessage(): void {
- $this->connection->method('getDatabasePlatform')
- ->willReturn($this->createMock(SqlitePlatform::class));
- $this->input->method('getOption')->willReturnMap([['json', false]]);
+ public function testSQLiteReturnsSuccessWithMessage(): void {
+ $this->connection->method('getDatabasePlatform')
+ ->willReturn($this->createMock(SqlitePlatform::class));
+ $this->input->method('getOption')->willReturnMap([['json', false]]);
- $output = new BufferedOutput();
- $exit = self::invokePrivate($this->command, 'execute', [$this->input, $output]);
+ $output = new BufferedOutput();
+ $exit = self::invokePrivate($this->command, 'execute', [$this->input, $output]);
- $this->assertSame(0, $exit);
- $this->assertStringContainsString('file-level locking', $output->fetch());
- }
+ $this->assertSame(0, $exit);
+ $this->assertStringContainsString('file-level locking', $output->fetch());
+ }
- public function testNullColumnRenderedAsDash(): void {
- $this->connection->method('getDatabasePlatform')
- ->willReturn($this->createMock(MySQLPlatform::class));
- $this->connection->method('executeQuery')
- ->willReturn($this->mockResult($this->mockMySQLLocks())); // blocking_query = null
- $this->input->method('getOption')->willReturnMap([['json', false]]);
+ public function testNullColumnRenderedAsDash(): void {
+ $this->connection->method('getDatabasePlatform')
+ ->willReturn($this->createMock(MySQLPlatform::class));
+ $this->connection->method('executeQuery')
+ ->willReturn($this->mockResult($this->mockMySQLLocks())); // blocking_query = null
+ $this->input->method('getOption')->willReturnMap([['json', false]]);
- $output = new BufferedOutput();
- self::invokePrivate($this->command, 'execute', [$this->input, $output]);
+ $output = new BufferedOutput();
+ self::invokePrivate($this->command, 'execute', [$this->input, $output]);
- $this->assertStringContainsString('—', $output->fetch());
- }
+ $this->assertStringContainsString('—', $output->fetch());
+ }
}
diff --git a/tests/Core/Command/Db/DbSizeTest.php b/tests/Core/Command/Db/DbSizeTest.php
index b6c430e9fd9..17aadb9b5a9 100644
--- a/tests/Core/Command/Db/DbSizeTest.php
+++ b/tests/Core/Command/Db/DbSizeTest.php
@@ -22,101 +22,101 @@ use Test\TestCase;
class DbSizeTest extends TestCase {
- private Connection&MockObject $connection;
- private InputInterface&MockObject $input;
- private DbSize $command;
+ private Connection&MockObject $connection;
+ private InputInterface&MockObject $input;
+ private DbSize $command;
- protected function setUp(): void {
- parent::setUp();
- $this->connection = $this->createMock(Connection::class);
- $this->input = $this->createMock(InputInterface::class);
- $this->command = new DbSize($this->connection);
- }
+ protected function setUp(): void {
+ parent::setUp();
+ $this->connection = $this->createMock(Connection::class);
+ $this->input = $this->createMock(InputInterface::class);
+ $this->command = new DbSize($this->connection);
+ }
- private function mockRows(): array {
- return [
- ['table' => 'oc_filecache', 'total_mb' => 12.50, 'data_mb' => 10.00, 'index_mb' => 2.50, 'rows' => 5000, 'avg_row_bytes' => 2560],
- ['table' => 'oc_share', 'total_mb' => 3.25, 'data_mb' => 2.00, 'index_mb' => 1.25, 'rows' => 200, 'avg_row_bytes' => 16384],
- ];
- }
+ private function mockRows(): array {
+ return [
+ ['table' => 'oc_filecache', 'total_mb' => 12.50, 'data_mb' => 10.00, 'index_mb' => 2.50, 'rows' => 5000, 'avg_row_bytes' => 2560],
+ ['table' => 'oc_share', 'total_mb' => 3.25, 'data_mb' => 2.00, 'index_mb' => 1.25, 'rows' => 200, 'avg_row_bytes' => 16384],
+ ];
+ }
- private function mockResult(array $rows): Result&MockObject {
- $result = $this->createMock(Result::class);
- $result->method('fetchAllAssociative')->willReturn($rows);
- return $result;
- }
+ private function mockResult(array $rows): Result&MockObject {
+ $result = $this->createMock(Result::class);
+ $result->method('fetchAllAssociative')->willReturn($rows);
+ return $result;
+ }
- public function testMySQLOutputContainsTableAndTotal(): void {
- $this->connection->method('getDatabasePlatform')
- ->willReturn($this->createMock(MySQLPlatform::class));
- $this->connection->method('executeQuery')
- ->willReturn($this->mockResult($this->mockRows()));
- $this->input->method('getOption')->willReturnMap([['json', false]]);
+ public function testMySQLOutputContainsTableAndTotal(): void {
+ $this->connection->method('getDatabasePlatform')
+ ->willReturn($this->createMock(MySQLPlatform::class));
+ $this->connection->method('executeQuery')
+ ->willReturn($this->mockResult($this->mockRows()));
+ $this->input->method('getOption')->willReturnMap([['json', false]]);
- $output = new BufferedOutput();
- $exit = self::invokePrivate($this->command, 'execute', [$this->input, $output]);
+ $output = new BufferedOutput();
+ $exit = self::invokePrivate($this->command, 'execute', [$this->input, $output]);
- $this->assertSame(0, $exit);
- $content = $output->fetch();
- $this->assertStringContainsString('oc_filecache', $content);
- $this->assertStringContainsString('Total database size', $content);
- }
+ $this->assertSame(0, $exit);
+ $content = $output->fetch();
+ $this->assertStringContainsString('oc_filecache', $content);
+ $this->assertStringContainsString('Total database size', $content);
+ }
- public function testPostgreSQLOutputContainsTableAndTotal(): void {
- $this->connection->method('getDatabasePlatform')
- ->willReturn($this->createMock(PostgreSQLPlatform::class));
- $this->connection->method('executeQuery')
- ->willReturn($this->mockResult($this->mockRows()));
- $this->input->method('getOption')->willReturnMap([['json', false]]);
+ public function testPostgreSQLOutputContainsTableAndTotal(): void {
+ $this->connection->method('getDatabasePlatform')
+ ->willReturn($this->createMock(PostgreSQLPlatform::class));
+ $this->connection->method('executeQuery')
+ ->willReturn($this->mockResult($this->mockRows()));
+ $this->input->method('getOption')->willReturnMap([['json', false]]);
- $output = new BufferedOutput();
- $exit = self::invokePrivate($this->command, 'execute', [$this->input, $output]);
+ $output = new BufferedOutput();
+ $exit = self::invokePrivate($this->command, 'execute', [$this->input, $output]);
- $this->assertSame(0, $exit);
- $this->assertStringContainsString('Total database size', $output->fetch());
- }
+ $this->assertSame(0, $exit);
+ $this->assertStringContainsString('Total database size', $output->fetch());
+ }
- public function testSQLiteReturnsSuccessWithMessage(): void {
- $this->connection->method('getDatabasePlatform')
- ->willReturn($this->createMock(SqlitePlatform::class));
- $this->input->method('getOption')->willReturnMap([['json', false]]);
+ public function testSQLiteReturnsSuccessWithMessage(): void {
+ $this->connection->method('getDatabasePlatform')
+ ->willReturn($this->createMock(SqlitePlatform::class));
+ $this->input->method('getOption')->willReturnMap([['json', false]]);
- $output = new BufferedOutput();
- $exit = self::invokePrivate($this->command, 'execute', [$this->input, $output]);
+ $output = new BufferedOutput();
+ $exit = self::invokePrivate($this->command, 'execute', [$this->input, $output]);
- $this->assertSame(0, $exit);
- $this->assertStringContainsString('not supported for SQLite', $output->fetch());
- }
+ $this->assertSame(0, $exit);
+ $this->assertStringContainsString('not supported for SQLite', $output->fetch());
+ }
- public function testJsonOutputIsValidArray(): void {
- $this->connection->method('getDatabasePlatform')
- ->willReturn($this->createMock(MySQLPlatform::class));
- $this->connection->method('executeQuery')
- ->willReturn($this->mockResult($this->mockRows()));
- $this->input->method('getOption')->willReturnMap([['json', true]]);
+ public function testJsonOutputIsValidArray(): void {
+ $this->connection->method('getDatabasePlatform')
+ ->willReturn($this->createMock(MySQLPlatform::class));
+ $this->connection->method('executeQuery')
+ ->willReturn($this->mockResult($this->mockRows()));
+ $this->input->method('getOption')->willReturnMap([['json', true]]);
- $output = new BufferedOutput();
- $exit = self::invokePrivate($this->command, 'execute', [$this->input, $output]);
+ $output = new BufferedOutput();
+ $exit = self::invokePrivate($this->command, 'execute', [$this->input, $output]);
- $this->assertSame(0, $exit);
- $data = json_decode($output->fetch(), true);
- $this->assertIsArray($data);
- $this->assertCount(2, $data);
- $this->assertArrayHasKey('table', $data[0]);
- $this->assertArrayHasKey('total_mb', $data[0]);
- }
+ $this->assertSame(0, $exit);
+ $data = json_decode($output->fetch(), true);
+ $this->assertIsArray($data);
+ $this->assertCount(2, $data);
+ $this->assertArrayHasKey('table', $data[0]);
+ $this->assertArrayHasKey('total_mb', $data[0]);
+ }
- public function testTotalSizeCalculation(): void {
- $this->connection->method('getDatabasePlatform')
- ->willReturn($this->createMock(MySQLPlatform::class));
- $this->connection->method('executeQuery')
- ->willReturn($this->mockResult($this->mockRows()));
- $this->input->method('getOption')->willReturnMap([['json', false]]);
+ public function testTotalSizeCalculation(): void {
+ $this->connection->method('getDatabasePlatform')
+ ->willReturn($this->createMock(MySQLPlatform::class));
+ $this->connection->method('executeQuery')
+ ->willReturn($this->mockResult($this->mockRows()));
+ $this->input->method('getOption')->willReturnMap([['json', false]]);
- $output = new BufferedOutput();
- self::invokePrivate($this->command, 'execute', [$this->input, $output]);
+ $output = new BufferedOutput();
+ self::invokePrivate($this->command, 'execute', [$this->input, $output]);
- // 12.50 + 3.25 = 15.75
- $this->assertStringContainsString('15.75', $output->fetch());
- }
+ // 12.50 + 3.25 = 15.75
+ $this->assertStringContainsString('15.75', $output->fetch());
+ }
}