From a08f1936ec2634e6926fc183535836311f76210e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 11 Mar 2022 15:22:58 +0100 Subject: [PATCH] Fix test warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Db/Card.php | 23 ++++++++++----------- lib/Db/CardMapper.php | 2 +- lib/Db/LabelMapper.php | 4 ++-- lib/Service/CardService.php | 8 +++---- lib/StatusException.php | 2 +- tests/unit/Activity/ActivityManagerTest.php | 6 ++---- 6 files changed, 21 insertions(+), 24 deletions(-) diff --git a/lib/Db/Card.php b/lib/Db/Card.php index caf97aae9..91bc6ab08 100644 --- a/lib/Db/Card.php +++ b/lib/Db/Card.php @@ -101,19 +101,18 @@ class Card extends RelationalEntity { public function jsonSerialize(): array { $json = parent::jsonSerialize(); $json['overdue'] = self::DUEDATE_FUTURE; - $due = strtotime($this->duedate); - - $today = new DateTime(); - $today->setTime(0, 0); - - $match_date = new DateTime($this->duedate); - - $match_date->setTime(0, 0); - - $diff = $today->diff($match_date); - $diffDays = (integer) $diff->format('%R%a'); // Extract days count in interval - + $due = $this->duedate ? strtotime($this->duedate) : false; if ($due !== false) { + $today = new DateTime(); + $today->setTime(0, 0); + + $match_date = new DateTime($this->duedate); + + $match_date->setTime(0, 0); + + $diff = $today->diff($match_date); + $diffDays = (integer) $diff->format('%R%a'); // Extract days count in interval + if ($diffDays === 1) { $json['overdue'] = self::DUEDATE_NEXT; } diff --git a/lib/Db/CardMapper.php b/lib/Db/CardMapper.php index 973a544f1..219588f81 100644 --- a/lib/Db/CardMapper.php +++ b/lib/Db/CardMapper.php @@ -551,7 +551,7 @@ class CardMapper extends QBMapper implements IPermissionMapper { public function isOwner($userId, $cardId): bool { $sql = 'SELECT owner FROM `*PREFIX*deck_boards` WHERE `id` IN (SELECT board_id FROM `*PREFIX*deck_stacks` WHERE id IN (SELECT stack_id FROM `*PREFIX*deck_cards` WHERE id = ?))'; $stmt = $this->db->prepare($sql); - $stmt->bindParam(1, $cardId, \PDO::PARAM_INT); + $stmt->bindParam(1, $cardId, \PDO::PARAM_INT, 0); $stmt->execute(); $row = $stmt->fetch(); return ($row['owner'] === $userId); diff --git a/lib/Db/LabelMapper.php b/lib/Db/LabelMapper.php index 1aa2bc98f..cc0b9b553 100644 --- a/lib/Db/LabelMapper.php +++ b/lib/Db/LabelMapper.php @@ -83,14 +83,14 @@ class LabelMapper extends DeckMapper implements IPermissionMapper { public function deleteLabelAssignments($labelId) { $sql = 'DELETE FROM `*PREFIX*deck_assigned_labels` WHERE label_id = ?'; $stmt = $this->db->prepare($sql); - $stmt->bindParam(1, $labelId, \PDO::PARAM_INT); + $stmt->bindParam(1, $labelId, \PDO::PARAM_INT, 0); $stmt->execute(); } public function deleteLabelAssignmentsForCard($cardId) { $sql = 'DELETE FROM `*PREFIX*deck_assigned_labels` WHERE card_id = ?'; $stmt = $this->db->prepare($sql); - $stmt->bindParam(1, $cardId, \PDO::PARAM_INT); + $stmt->bindParam(1, $cardId, \PDO::PARAM_INT, 0); $stmt->execute(); } diff --git a/lib/Service/CardService.php b/lib/Service/CardService.php index d925f67d9..8b5f9a652 100644 --- a/lib/Service/CardService.php +++ b/lib/Service/CardService.php @@ -114,7 +114,7 @@ class CardService { $countComments = $this->commentsManager->getNumberOfCommentsForObject('deckCard', (string)$card->getId()); $card->setCommentsUnread($countUnreadComments); $card->setCommentsCount($countComments); - + $stack = $this->stackMapper->find($card->getStackId()); $board = $this->boardService->find($stack->getBoardId()); $card->setRelatedStack($stack); @@ -224,7 +224,7 @@ class CardService { $card->setDescription($description); $card->setDuedate($duedate); $card = $this->cardMapper->insert($card); - + $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_CREATE); $this->changeHelper->cardChanged($card->getId(), false); $this->eventDispatcher->dispatchTyped(new CardCreatedEvent($card)); @@ -253,7 +253,7 @@ class CardService { $card = $this->cardMapper->find($id); $card->setDeletedAt(time()); $this->cardMapper->update($card); - + $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_DELETE); $this->notificationHelper->markDuedateAsRead($card); $this->changeHelper->cardChanged($card->getId(), false); @@ -338,7 +338,7 @@ class CardService { $resetDuedateNotification = false; if ( $card->getDuedate() === null || - (new \DateTime($card->getDuedate())) != (new \DateTime($changes->getBefore()->getDuedate())) + (new \DateTime($card->getDuedate())) != (new \DateTime($changes->getBefore()->getDuedate() ?? '')) ) { $card->setNotified(false); $resetDuedateNotification = true; diff --git a/lib/StatusException.php b/lib/StatusException.php index 0c0ce00ef..153238eb9 100644 --- a/lib/StatusException.php +++ b/lib/StatusException.php @@ -31,7 +31,7 @@ namespace OCA\Deck; */ class StatusException extends \Exception { public function __construct($message) { - parent::__construct($message); + parent::__construct($message ?? ''); } public function getStatus() { diff --git a/tests/unit/Activity/ActivityManagerTest.php b/tests/unit/Activity/ActivityManagerTest.php index 8727820b9..700d72b19 100644 --- a/tests/unit/Activity/ActivityManagerTest.php +++ b/tests/unit/Activity/ActivityManagerTest.php @@ -103,15 +103,13 @@ class ActivityManagerTest extends TestCase { if ($format !== '') { $this->assertStringContainsString('{user}', $format); } else { - /** @noinspection ForgottenDebugOutputInspection */ - print_r('No activity string found for '. $constant . PHP_EOL); + self::addWarning('No activity string found for '. $constant); } $format = $this->activityManager->getActivityFormat('cz', $value, [], true); if ($format !== '') { $this->assertStringStartsWith('You', $format); } else { - /** @noinspection ForgottenDebugOutputInspection */ - print_r('No own activity string found for '. $constant . PHP_EOL); + self::addWarning('No own activity string found for '. $constant); } } }