aboutsummaryrefslogtreecommitdiffstats
path: root/tests/Core/Command/Maintenance
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Core/Command/Maintenance')
-rw-r--r--tests/Core/Command/Maintenance/DataFingerprintTest.php5
-rw-r--r--tests/Core/Command/Maintenance/Mimetype/UpdateDBTest.php64
-rw-r--r--tests/Core/Command/Maintenance/ModeTest.php11
-rw-r--r--tests/Core/Command/Maintenance/UpdateTheme.php3
4 files changed, 47 insertions, 36 deletions
diff --git a/tests/Core/Command/Maintenance/DataFingerprintTest.php b/tests/Core/Command/Maintenance/DataFingerprintTest.php
index 03cf37b8f48..99004a7a5f5 100644
--- a/tests/Core/Command/Maintenance/DataFingerprintTest.php
+++ b/tests/Core/Command/Maintenance/DataFingerprintTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -35,11 +36,11 @@ class DataFingerprintTest extends TestCase {
$this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
$this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
- /** @var \OCP\IConfig $config */
+ /** @var IConfig $config */
$this->command = new DataFingerprint($this->config, $this->timeFactory);
}
- public function testSetFingerPrint() {
+ public function testSetFingerPrint(): void {
$this->timeFactory->expects($this->once())
->method('getTime')
->willReturn(42);
diff --git a/tests/Core/Command/Maintenance/Mimetype/UpdateDBTest.php b/tests/Core/Command/Maintenance/Mimetype/UpdateDBTest.php
index a4169907167..b85dcf87bbc 100644
--- a/tests/Core/Command/Maintenance/Mimetype/UpdateDBTest.php
+++ b/tests/Core/Command/Maintenance/Mimetype/UpdateDBTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -33,20 +34,15 @@ class UpdateDBTest extends TestCase {
protected function setUp(): void {
parent::setUp();
- $this->detector = $this->getMockBuilder(Detection::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->loader = $this->getMockBuilder(Loader::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
- $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
+ $this->detector = $this->createMock(Detection::class);
+ $this->loader = $this->createMock(Loader::class);
+ $this->consoleInput = $this->createMock(InputInterface::class);
+ $this->consoleOutput = $this->createMock(OutputInterface::class);
$this->command = new UpdateDB($this->detector, $this->loader);
}
- public function testNoop() {
+ public function testNoop(): void {
$this->consoleInput->method('getOption')
->with('repair-filecache')
->willReturn(false);
@@ -64,17 +60,21 @@ class UpdateDBTest extends TestCase {
$this->loader->expects($this->never())
->method('updateFilecache');
+ $calls = [
+ 'Added 0 new mimetypes',
+ 'Updated 0 filecache rows',
+ ];
$this->consoleOutput->expects($this->exactly(2))
->method('writeln')
- ->withConsecutive(
- ['Added 0 new mimetypes'],
- ['Updated 0 filecache rows'],
- );
+ ->willReturnCallback(function ($message) use (&$calls): void {
+ $expected = array_shift($calls);
+ $this->assertStringContainsString($expected, $message);
+ });
self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
}
- public function testAddMimetype() {
+ public function testAddMimetype(): void {
$this->consoleInput->method('getOption')
->with('repair-filecache')
->willReturn(false);
@@ -103,19 +103,23 @@ class UpdateDBTest extends TestCase {
->with('new', 2)
->willReturn(3);
+ $calls = [
+ 'Added mimetype "testing/newmimetype" to database',
+ 'Updated 3 filecache rows for mimetype "testing/newmimetype"',
+ 'Added 1 new mimetypes',
+ 'Updated 3 filecache rows',
+ ];
$this->consoleOutput->expects($this->exactly(4))
->method('writeln')
- ->withConsecutive(
- ['Added mimetype "testing/newmimetype" to database'],
- ['Updated 3 filecache rows for mimetype "testing/newmimetype"'],
- ['Added 1 new mimetypes'],
- ['Updated 3 filecache rows'],
- );
+ ->willReturnCallback(function ($message) use (&$calls): void {
+ $expected = array_shift($calls);
+ $this->assertStringContainsString($expected, $message);
+ });
self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
}
- public function testSkipComments() {
+ public function testSkipComments(): void {
$this->detector->expects($this->once())
->method('getAllMappings')
->willReturn([
@@ -127,7 +131,7 @@ class UpdateDBTest extends TestCase {
self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
}
- public function testRepairFilecache() {
+ public function testRepairFilecache(): void {
$this->consoleInput->method('getOption')
->with('repair-filecache')
->willReturn(true);
@@ -153,13 +157,17 @@ class UpdateDBTest extends TestCase {
->with('ext', 1)
->willReturn(3);
+ $calls = [
+ 'Updated 3 filecache rows for mimetype "testing/existingmimetype"',
+ 'Added 0 new mimetypes',
+ 'Updated 3 filecache rows',
+ ];
$this->consoleOutput->expects($this->exactly(3))
->method('writeln')
- ->withConsecutive(
- ['Updated 3 filecache rows for mimetype "testing/existingmimetype"'],
- ['Added 0 new mimetypes'],
- ['Updated 3 filecache rows'],
- );
+ ->willReturnCallback(function ($message) use (&$calls): void {
+ $expected = array_shift($calls);
+ $this->assertStringContainsString($expected, $message);
+ });
self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
}
diff --git a/tests/Core/Command/Maintenance/ModeTest.php b/tests/Core/Command/Maintenance/ModeTest.php
index 458699649b2..5a9a90b0197 100644
--- a/tests/Core/Command/Maintenance/ModeTest.php
+++ b/tests/Core/Command/Maintenance/ModeTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -67,7 +68,7 @@ class ModeTest extends TestCase {
*
* @return array
*/
- public function getExecuteTestData(): array {
+ public static function getExecuteTestData(): array {
return [
'off -> on' => [
'on', // command option
@@ -111,20 +112,20 @@ class ModeTest extends TestCase {
/**
* Asserts that execute works as expected.
*
- * @dataProvider getExecuteTestData
* @param string $option The command option.
* @param bool $currentMaintenanceState The current maintenance state.
* @param null|bool $expectedMaintenanceState
- * The expected maintenance state. Null for no change.
+ * The expected maintenance state. Null for no change.
* @param string $expectedOutput The expected command output.
* @throws \Exception
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('getExecuteTestData')]
public function testExecute(
string $option,
bool $currentMaintenanceState,
$expectedMaintenanceState,
- string $expectedOutput
- ) {
+ string $expectedOutput,
+ ): void {
$this->config->expects($this->any())
->method('getSystemValueBool')
->willReturn($currentMaintenanceState);
diff --git a/tests/Core/Command/Maintenance/UpdateTheme.php b/tests/Core/Command/Maintenance/UpdateTheme.php
index 25229b8997a..9c9a2b903a7 100644
--- a/tests/Core/Command/Maintenance/UpdateTheme.php
+++ b/tests/Core/Command/Maintenance/UpdateTheme.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -42,7 +43,7 @@ class UpdateThemeTest extends TestCase {
$this->command = new UpdateTheme($this->detector, $this->cacheFactory);
}
- public function testThemeUpdate() {
+ public function testThemeUpdate(): void {
$this->consoleInput->method('getOption')
->with('maintenance:theme:update')
->willReturn(true);