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

Fix cron jobs #3689

Merged
merged 1 commit into from
Apr 8, 2022
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
4 changes: 3 additions & 1 deletion lib/Cron/CardDescriptionActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

namespace OCA\Deck\Cron;

use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\Job;
use OCA\Deck\Activity\ActivityManager;
use OCA\Deck\Db\CardMapper;
Expand All @@ -35,7 +36,8 @@ class CardDescriptionActivity extends Job {
/** @var CardMapper */
private $cardMapper;

public function __construct(ActivityManager $activityManager, CardMapper $cardMapper) {
public function __construct(ITimeFactory $time, ActivityManager $activityManager, CardMapper $cardMapper) {
parent::__construct($time);
$this->activityManager = $activityManager;
$this->cardMapper = $cardMapper;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/Cron/DeleteCron.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

namespace OCA\Deck\Cron;

use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
use OCA\Deck\Db\AttachmentMapper;
use OCA\Deck\Db\BoardMapper;
Expand All @@ -40,7 +41,8 @@ class DeleteCron extends TimedJob {
/** @var AttachmentMapper */
private $attachmentMapper;

public function __construct(BoardMapper $boardMapper, AttachmentService $attachmentService, AttachmentMapper $attachmentMapper) {
public function __construct(ITimeFactory $time, BoardMapper $boardMapper, AttachmentService $attachmentService, AttachmentMapper $attachmentMapper) {
parent::__construct($time);
$this->boardMapper = $boardMapper;
$this->attachmentService = $attachmentService;
$this->attachmentMapper = $attachmentMapper;
Expand Down
3 changes: 3 additions & 0 deletions lib/Cron/ScheduledNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace OCA\Deck\Cron;

use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\Job;
use OCA\Deck\Db\Card;
use OCA\Deck\Db\CardMapper;
Expand All @@ -40,10 +41,12 @@ class ScheduledNotifications extends Job {
protected $logger;

public function __construct(
ITimeFactory $time,
CardMapper $cardMapper,
NotificationHelper $notificationHelper,
ILogger $logger
) {
parent::__construct($time);
$this->cardMapper = $cardMapper;
$this->notificationHelper = $notificationHelper;
$this->logger = $logger;
Expand Down
16 changes: 11 additions & 5 deletions tests/unit/Cron/DeleteCronTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,30 @@
use OCA\Deck\InvalidAttachmentType;
use OCA\Deck\Service\AttachmentService;
use OCA\Deck\Service\IAttachmentService;
use OCP\AppFramework\Utility\ITimeFactory;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

class DeleteCronTest extends \Test\TestCase {
class DeleteCronTest extends TestCase {

/** @var BoardMapper|\PHPUnit\Framework\MockObject\MockObject */
/** @var ITimeFactory|MockObject */
private $timeFactory;
/** @var BoardMapper|MockObject */
protected $boardMapper;
/** @var AttachmentService|\PHPUnit\Framework\MockObject\MockObject */
/** @var AttachmentService|MockObject */
private $attachmentService;
/** @var AttachmentMapper|\PHPUnit\Framework\MockObject\MockObject */
/** @var AttachmentMapper|MockObject */
private $attachmentMapper;
/** @var DeleteCron */
protected $deleteCron;

public function setUp(): void {
parent::setUp();
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->boardMapper = $this->createMock(BoardMapper::class);
$this->attachmentService = $this->createMock(AttachmentService::class);
$this->attachmentMapper = $this->createMock(AttachmentMapper::class);
$this->deleteCron = new DeleteCron($this->boardMapper, $this->attachmentService, $this->attachmentMapper);
$this->deleteCron = new DeleteCron($this->timeFactory, $this->boardMapper, $this->attachmentService, $this->attachmentMapper);
}

protected function getBoard($id) {
Expand Down
18 changes: 12 additions & 6 deletions tests/unit/Cron/ScheduledNoificationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,34 @@
use OCA\Deck\Db\Card;
use OCA\Deck\Db\CardMapper;
use OCA\Deck\Notification\NotificationHelper;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\ILogger;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

class ScheduledNoificationsTest extends \Test\TestCase {
class ScheduledNoificationsTest extends TestCase {

/** @var CardMapper|\PHPUnit\Framework\MockObject\MockObject */
/** @var ITimeFactory|MockObject */
protected $timeFactory;
/** @var CardMapper|MockObject */
protected $cardMapper;
/** @var NotificationHelper|\PHPUnit\Framework\MockObject\MockObject */
/** @var NotificationHelper|MockObject */
protected $notificationHelper;
/** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */
/** @var ILogger|MockObject */
protected $logger;
/** @var ScheduledNotifications */
protected $scheduledNotifications;

public function setUp(): void {
parent::setUp();
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->cardMapper = $this->createMock(CardMapper::class);
$this->notificationHelper = $this->createMock(NotificationHelper::class);
$this->logger = $this->createMock(ILogger::class);
$this->scheduledNotifications = new ScheduledNotifications($this->cardMapper, $this->notificationHelper, $this->logger);
$this->scheduledNotifications = new ScheduledNotifications($this->timeFactory, $this->cardMapper, $this->notificationHelper, $this->logger);
}

public function testDeleteCron() {
public function testScheduledCron() {
$c1 = new Card();
$c2 = new Card();
$cards = [$c1, $c2];
Expand Down