From 46f2d448abcd8dc2e914bcca638dfe4332087e9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Thu, 24 Feb 2022 16:43:37 +0100 Subject: [PATCH 1/5] Add typing to jsonSerialize MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- .github/workflows/lint.yml | 2 +- .github/workflows/phpunit.yml | 2 +- lib/Activity/ChangeSet.php | 10 +--------- lib/Db/Board.php | 2 +- lib/Db/Card.php | 6 +++--- lib/Db/RelationalEntity.php | 2 +- lib/Db/RelationalObject.php | 10 ++++++---- lib/Db/Stack.php | 2 +- 8 files changed, 15 insertions(+), 21 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index f7cb8bfad..62ca06748 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -13,7 +13,7 @@ jobs: strategy: matrix: - php-versions: ['7.4', '8.0', "8.1"] + php-versions: ['7.4', '8.0', '8.1'] name: php${{ matrix.php-versions }} lint steps: diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index bedac65bf..402263327 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -18,7 +18,7 @@ jobs: strategy: fail-fast: false matrix: - php-versions: ['7.4', '8.0', "8.1"] + php-versions: ['7.4', '8.0', '8.1'] databases: ['sqlite', 'mysql', 'pgsql'] server-versions: ['master'] diff --git a/lib/Activity/ChangeSet.php b/lib/Activity/ChangeSet.php index c4519c375..f491ecd1f 100644 --- a/lib/Activity/ChangeSet.php +++ b/lib/Activity/ChangeSet.php @@ -69,15 +69,7 @@ class ChangeSet implements \JsonSerializable { return $this->after; } - /** - * Specify data which should be serialized to JSON - * - * @link http://php.net/manual/en/jsonserializable.jsonserialize.php - * @return mixed data which can be serialized by json_encode, - * which is a value of any type other than a resource. - * @since 5.4.0 - */ - public function jsonSerialize() { + public function jsonSerialize(): array { return [ 'before' => $this->getBefore(), 'after' => $this->getAfter(), diff --git a/lib/Db/Board.php b/lib/Db/Board.php index 6cf3c3206..3b5bea9fe 100644 --- a/lib/Db/Board.php +++ b/lib/Db/Board.php @@ -58,7 +58,7 @@ class Board extends RelationalEntity { $this->shared = -1; } - public function jsonSerialize() { + public function jsonSerialize(): array { $json = parent::jsonSerialize(); if ($this->shared === -1) { unset($json['shared']); diff --git a/lib/Db/Card.php b/lib/Db/Card.php index af2c665c5..caf97aae9 100644 --- a/lib/Db/Card.php +++ b/lib/Db/Card.php @@ -50,7 +50,7 @@ class Card extends RelationalEntity { protected $deletedAt = 0; protected $commentsUnread = 0; protected $commentsCount = 0; - + protected $relatedStack = null; protected $relatedBoard = null; @@ -78,7 +78,7 @@ class Card extends RelationalEntity { $this->addRelation('commentsUnread'); $this->addRelation('commentsCount'); $this->addResolvable('owner'); - + $this->addRelation('relatedStack'); $this->addRelation('relatedBoard'); } @@ -98,7 +98,7 @@ class Card extends RelationalEntity { return $dt->format('c'); } - public function jsonSerialize() { + public function jsonSerialize(): array { $json = parent::jsonSerialize(); $json['overdue'] = self::DUEDATE_FUTURE; $due = strtotime($this->duedate); diff --git a/lib/Db/RelationalEntity.php b/lib/Db/RelationalEntity.php index c0b180c62..6e2a19ef5 100644 --- a/lib/Db/RelationalEntity.php +++ b/lib/Db/RelationalEntity.php @@ -63,7 +63,7 @@ class RelationalEntity extends Entity implements \JsonSerializable { * @return array serialized data * @throws \ReflectionException */ - public function jsonSerialize() { + public function jsonSerialize(): array { $properties = get_object_vars($this); $reflection = new \ReflectionClass($this); $json = []; diff --git a/lib/Db/RelationalObject.php b/lib/Db/RelationalObject.php index e9f0ed667..bd176e1b8 100644 --- a/lib/Db/RelationalObject.php +++ b/lib/Db/RelationalObject.php @@ -23,7 +23,9 @@ namespace OCA\Deck\Db; -class RelationalObject implements \JsonSerializable { +use JsonSerializable; + +class RelationalObject implements JsonSerializable { protected $primaryKey; protected $object; @@ -38,7 +40,7 @@ class RelationalObject implements \JsonSerializable { $this->object = $object; } - public function jsonSerialize() { + public function jsonSerialize(): array { return array_merge( ['primaryKey' => $this->primaryKey], $this->getObjectSerialization() @@ -51,8 +53,8 @@ class RelationalObject implements \JsonSerializable { * @throws \Exception */ public function getObjectSerialization() { - if ($this->object instanceof \JsonSerializable) { - $this->object->jsonSerialize(); + if ($this->object instanceof JsonSerializable) { + return $this->object->jsonSerialize(); } else { throw new \Exception('jsonSerialize is not implemented on ' . get_class($this)); } diff --git a/lib/Db/Stack.php b/lib/Db/Stack.php index c414f52a8..63e85ca03 100644 --- a/lib/Db/Stack.php +++ b/lib/Db/Stack.php @@ -45,7 +45,7 @@ class Stack extends RelationalEntity { $this->cards = $cards; } - public function jsonSerialize() { + public function jsonSerialize(): array { $json = parent::jsonSerialize(); if (empty($this->cards)) { unset($json['cards']); From 9dd8408c34648c98825675026d9fc2bacf2d0efc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 25 Feb 2022 14:03:50 +0100 Subject: [PATCH 2/5] Bump phpunit for integration tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- tests/integration/composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/composer.json b/tests/integration/composer.json index 2f8d1b789..db50584b2 100644 --- a/tests/integration/composer.json +++ b/tests/integration/composer.json @@ -1,6 +1,6 @@ { "require-dev": { - "phpunit/phpunit": "~6.5", + "phpunit/phpunit": "~9", "behat/behat": "~3.8.0", "guzzlehttp/guzzle": "6.5.2", "jarnaiz/behat-junit-formatter": "^1.3", From aff242c8fbd51b882b0c60e2c0ae52adf7c00b03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 25 Feb 2022 14:05:12 +0100 Subject: [PATCH 3/5] Update dependabot to cover integration test dependencies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- .github/dependabot.yml | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index fef83c6a8..64cfb513f 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -11,19 +11,6 @@ updates: open-pull-requests-limit: 10 reviewers: - juliushaertl - - jakobroehrl -#- package-ecosystem: npm -# directory: "/" -# target-branch: "stable1.1" -# schedule: -# interval: weekly -# day: saturday -# time: "03:00" -# timezone: Europe/Paris -# open-pull-requests-limit: 10 -# reviewers: -# - juliushaertl -# - jakobroehrl - package-ecosystem: composer directory: "/" schedule: @@ -34,11 +21,16 @@ updates: open-pull-requests-limit: 10 reviewers: - juliushaertl - ignore: - - dependency-name: christophwurst/nextcloud - versions: - - "< 16" - - ">= 15.a" +- package-ecosystem: composer + directory: "/tests/integration" + schedule: + interval: weekly + day: saturday + time: "03:00" + timezone: Europe/Paris + open-pull-requests-limit: 10 + reviewers: + - juliushaertl - package-ecosystem: github-actions directory: "/" schedule: 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 4/5] 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); } } } From 9d4938ec606998c56b13b501b2b5f2f9e8caf91e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Mon, 14 Mar 2022 20:10:15 +0100 Subject: [PATCH 5/5] Ping server integration test dependencies to phpunit 8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- .github/workflows/integration.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 2ba5edc2c..fd7068b28 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -54,6 +54,7 @@ jobs: auth_header="$(git config --local --get http.https://github.com/.extraheader)" git submodule sync --recursive git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1 + cd build/integration && composer require --dev phpunit/phpunit:~8 - name: Checkout app uses: actions/checkout@v3