BackgroundModeTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2016-2023 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-FileCopyrightText: 2015 Christian Kampka <christian@kampka.net>
  6. * SPDX-License-Identifier: MIT
  7. */
  8. namespace Test\Command;
  9. use OC\Core\Command\Background\Mode;
  10. use OCP\IAppConfig;
  11. use Symfony\Component\Console\Input\InputArgument;
  12. use Symfony\Component\Console\Input\InputDefinition;
  13. use Symfony\Component\Console\Tester\CommandTester;
  14. use Test\TestCase;
  15. class BackgroundModeTest extends TestCase {
  16. private IAppConfig $appConfig;
  17. private Mode $command;
  18. public function setUp(): void {
  19. $this->appConfig = $this->createMock(IAppConfig::class);
  20. $inputDefinition = new InputDefinition([
  21. new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'),
  22. ]);
  23. $this->command = new Mode($this->appConfig);
  24. $this->command->setDefinition($inputDefinition);
  25. }
  26. /**
  27. * @dataProvider dataModeCommand
  28. */
  29. public function testModeCommand(string $mode): void {
  30. $this->appConfig->expects($this->once())
  31. ->method('setValueString')
  32. ->with('core', 'backgroundjobs_mode', $mode);
  33. $commandTester = new CommandTester($this->command);
  34. $commandTester->execute(['command' => 'background:' . $mode]);
  35. $commandTester->assertCommandIsSuccessful();
  36. $output = $commandTester->getDisplay();
  37. $this->assertStringContainsString($mode, $output);
  38. }
  39. public function dataModeCommand(): array {
  40. return [
  41. 'ajax' => ['ajax'],
  42. 'cron' => ['cron'],
  43. 'webcron' => ['webcron'],
  44. ];
  45. }
  46. }