aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDaniel Kesselberg <mail@danielkesselberg.de>2024-06-27 22:09:09 +0200
committerDaniel Kesselberg <mail@danielkesselberg.de>2024-07-01 12:52:06 +0200
commita773a8b915aafcb9fb6727384add9a5d01378932 (patch)
treee61904cee848752880e7c2edddad992770b4e124 /tests
parent3b75c5b98cd0356e99c07d9696c49732f195b3f6 (diff)
downloadnextcloud-server-a773a8b915aafcb9fb6727384add9a5d01378932.tar.gz
nextcloud-server-a773a8b915aafcb9fb6727384add9a5d01378932.zip
refactor: simplify background commands
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Command/BackgroundJobsTest.php38
-rw-r--r--tests/lib/Command/BackgroundModeTest.php59
2 files changed, 59 insertions, 38 deletions
diff --git a/tests/lib/Command/BackgroundJobsTest.php b/tests/lib/Command/BackgroundJobsTest.php
deleted file mode 100644
index f066cb5b28a..00000000000
--- a/tests/lib/Command/BackgroundJobsTest.php
+++ /dev/null
@@ -1,38 +0,0 @@
-<?php
-/**
- * SPDX-FileCopyrightText: 2016-2023 Nextcloud GmbH and Nextcloud contributors
- * SPDX-FileCopyrightText: 2015 Christian Kampka <christian@kampka.net>
- * SPDX-License-Identifier: MIT
- */
-namespace Test\Command;
-
-use OC\Core\Command\Background\Ajax;
-use OC\Core\Command\Background\Cron;
-use OC\Core\Command\Background\WebCron;
-use OCP\IAppConfig;
-use Symfony\Component\Console\Input\StringInput;
-use Symfony\Component\Console\Output\NullOutput;
-use Test\TestCase;
-
-class BackgroundJobsTest extends TestCase {
- public function testCronCommand() {
- $appConfig = \OCP\Server::get(IAppConfig::class);
- $job = new Cron($appConfig);
- $job->run(new StringInput(''), new NullOutput());
- $this->assertEquals('cron', $appConfig->getValueString('core', 'backgroundjobs_mode'));
- }
-
- public function testAjaxCommand() {
- $appConfig = \OCP\Server::get(IAppConfig::class);
- $job = new Ajax($appConfig);
- $job->run(new StringInput(''), new NullOutput());
- $this->assertEquals('ajax', $appConfig->getValueString('core', 'backgroundjobs_mode'));
- }
-
- public function testWebCronCommand() {
- $appConfig = \OCP\Server::get(IAppConfig::class);
- $job = new WebCron($appConfig);
- $job->run(new StringInput(''), new NullOutput());
- $this->assertEquals('webcron', $appConfig->getValueString('core', 'backgroundjobs_mode'));
- }
-}
diff --git a/tests/lib/Command/BackgroundModeTest.php b/tests/lib/Command/BackgroundModeTest.php
new file mode 100644
index 00000000000..941449c98bb
--- /dev/null
+++ b/tests/lib/Command/BackgroundModeTest.php
@@ -0,0 +1,59 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2016-2023 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2015 Christian Kampka <christian@kampka.net>
+ * SPDX-License-Identifier: MIT
+ */
+namespace Test\Command;
+
+use OC\Core\Command\Background\Mode;
+use OCP\IAppConfig;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputDefinition;
+use Symfony\Component\Console\Tester\CommandTester;
+use Test\TestCase;
+
+class BackgroundModeTest extends TestCase {
+ private IAppConfig $appConfig;
+
+ private Mode $command;
+
+ public function setUp(): void {
+ $this->appConfig = $this->createMock(IAppConfig::class);
+
+ $inputDefinition = new InputDefinition([
+ new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'),
+ ]);
+
+ $this->command = new Mode($this->appConfig);
+ $this->command->setDefinition($inputDefinition);
+ }
+
+ /**
+ * @dataProvider dataModeCommand
+ */
+ public function testModeCommand(string $mode): void {
+ $this->appConfig->expects($this->once())
+ ->method('setValueString')
+ ->with('core', 'backgroundjobs_mode', $mode);
+
+ $commandTester = new CommandTester($this->command);
+ $commandTester->execute(['command' => 'background:' . $mode]);
+
+ $commandTester->assertCommandIsSuccessful();
+
+ $output = $commandTester->getDisplay();
+ $this->assertStringContainsString($mode, $output);
+ }
+
+ public function dataModeCommand(): array {
+ return [
+ 'ajax' => ['ajax'],
+ 'cron' => ['cron'],
+ 'webcron' => ['webcron'],
+ ];
+ }
+}