Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Migrate to OCP version of QueuedJob #1090

Merged
merged 3 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions lib/Notification/BackgroundJob.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
*
Expand All @@ -21,25 +24,21 @@

namespace OCA\FirstRunWizard\Notification;

use OC\BackgroundJob\QueuedJob;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\QueuedJob;
use OCP\Notification\IManager as INotificationManager;

class BackgroundJob extends QueuedJob {

/** @var INotificationManager */
protected $notificationManager;

/**
* BackgroundJob constructor.
*
* @param INotificationManager $notificationManager
*/
public function __construct(INotificationManager $notificationManager) {
$this->notificationManager = $notificationManager;
public function __construct(
come-nc marked this conversation as resolved.
Show resolved Hide resolved
ITimeFactory $time,
protected INotificationManager $notificationManager,
) {
parent::__construct($time);
}

/**
* @param array $argument
* @return void
*/
protected function run($argument) {
$notification = $this->notificationManager->createNotification();
Expand All @@ -49,7 +48,7 @@ protected function run($argument) {
->setUser($argument['uid']);

if ($this->notificationManager->getCount($notification) === 0) {
$notification->setDateTime(new \DateTime());
$notification->setDateTime($this->time->getDateTime());
$this->notificationManager->notify($notification);
}
}
Expand Down
13 changes: 7 additions & 6 deletions tests/Notification/BackgroundJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
namespace OCA\FirstRunWizard\Tests\Notification;

use OCA\FirstRunWizard\Notification\BackgroundJob;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Notification\IManager;
use OCP\Notification\INotification;
use Test\TestCase;
Expand All @@ -35,17 +36,17 @@
* @group DB
*/
class BackgroundJobTest extends TestCase {
/** @var IManager|\PHPUnit_Framework_MockObject_MockObject */
protected $notificationManager;

/** @var BackgroundJob */
protected $job;
protected ITimeFactory $timeFactory;
protected IManager $notificationManager;
protected BackgroundJob $job;

protected function setUp(): void {
parent::setUp();
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->notificationManager = $this->createMock(IManager::class);
$this->job = new BackgroundJob(
$this->notificationManager
$this->timeFactory,
$this->notificationManager,
);
}

Expand Down
Loading