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()); } }