-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Expand file tree
/
Copy pathTaskProcessingWorkerIsRunningTest.php
More file actions
78 lines (66 loc) · 2.77 KB
/
TaskProcessingWorkerIsRunningTest.php
File metadata and controls
78 lines (66 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Settings\Tests;
use OCA\Settings\SetupChecks\TaskProcessingWorkerIsRunning;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IAppConfig;
use OCP\IL10N;
use OCP\SetupCheck\SetupResult;
use OCP\TaskProcessing\IManager;
use OCP\TaskProcessing\Task;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class TaskProcessingWorkerIsRunningTest extends TestCase {
private IL10N&MockObject $l10n;
private ITimeFactory&MockObject $timeFactory;
private IManager&MockObject $taskProcessingManager;
private IAppConfig&MockObject $appConfig;
private TaskProcessingWorkerIsRunning $check;
protected function setUp(): void {
parent::setUp();
$this->l10n = $this->getMockBuilder(IL10N::class)->getMock();
$this->timeFactory = $this->getMockBuilder(ITimeFactory::class)->getMock();
$this->taskProcessingManager = $this->getMockBuilder(IManager::class)->getMock();
$this->appConfig = $this->getMockBuilder(IAppConfig::class)->getMock();
$this->check = new TaskProcessingWorkerIsRunning(
$this->l10n,
$this->taskProcessingManager,
$this->timeFactory,
$this->appConfig
);
}
public function testPass(): void {
$tasks = [];
for ($i = 0; $i < 10; $i++) {
$task = new Task('test', ['test' => 'test'], 'settings', 'user' . $i);
$task->setStartedAt($this->timeFactory->now()->getTimestamp());
$task->setScheduledAt($this->timeFactory->now()->getTimestamp());
$task->setEndedAt($this->timeFactory->now()->getTimestamp());
$task->setStatus(Task::STATUS_SUCCESSFUL);
$tasks[] = $task;
}
$this->taskProcessingManager->method('getTasks')->willReturn($tasks);
$this->timeFactory->method('now')->willReturn(new \DateTimeImmutable());
$this->appConfig->method('getValueString')->willReturn((string)$this->timeFactory->now()->getTimestamp());
$this->assertEquals(SetupResult::SUCCESS, $this->check->run()->getSeverity());
}
public function testFail(): void {
$tasks = [];
for ($i = 0; $i < 10; $i++) {
$task = new Task('test', ['test' => 'test'], 'settings', 'user' . $i);
$task->setStartedAt($this->timeFactory->now()->getTimestamp());
$task->setScheduledAt($this->timeFactory->now()->getTimestamp());
$task->setEndedAt($this->timeFactory->now()->getTimestamp());
$task->setStatus(Task::STATUS_SUCCESSFUL);
$tasks[] = $task;
}
$this->taskProcessingManager->method('getTasks')->willReturn($tasks);
$this->timeFactory->method('now')->willReturn(new \DateTimeImmutable());
$this->appConfig->method('getValueString')->willReturn((string)($this->timeFactory->now()->getTimestamp() - 60 * 10));
$this->assertEquals(SetupResult::WARNING, $this->check->run()->getSeverity());
}
}