diff options
Diffstat (limited to 'apps/dav/tests/unit/Comments/EntityCollectionTest.php')
-rw-r--r-- | apps/dav/tests/unit/Comments/EntityCollectionTest.php | 97 |
1 files changed, 34 insertions, 63 deletions
diff --git a/apps/dav/tests/unit/Comments/EntityCollectionTest.php b/apps/dav/tests/unit/Comments/EntityCollectionTest.php index f8f3990fbac..29ebde7d602 100644 --- a/apps/dav/tests/unit/Comments/EntityCollectionTest.php +++ b/apps/dav/tests/unit/Comments/EntityCollectionTest.php @@ -1,68 +1,39 @@ <?php + +declare(strict_types=1); /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ - namespace OCA\DAV\Tests\unit\Comments; +use OCA\DAV\Comments\CommentNode; use OCA\DAV\Comments\EntityCollection; use OCP\Comments\IComment; use OCP\Comments\ICommentsManager; -use OCP\ILogger; +use OCP\Comments\NotFoundException; use OCP\IUserManager; use OCP\IUserSession; +use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; class EntityCollectionTest extends \Test\TestCase { - - /** @var \OCP\Comments\ICommentsManager|\PHPUnit\Framework\MockObject\MockObject */ - protected $commentsManager; - /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */ - protected $userManager; - /** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */ - protected $logger; - /** @var EntityCollection */ - protected $collection; - /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */ - protected $userSession; + protected ICommentsManager&MockObject $commentsManager; + protected IUserManager&MockObject $userManager; + protected LoggerInterface&MockObject $logger; + protected IUserSession&MockObject $userSession; + protected EntityCollection $collection; protected function setUp(): void { parent::setUp(); - $this->commentsManager = $this->getMockBuilder(ICommentsManager::class) - ->disableOriginalConstructor() - ->getMock(); - $this->userManager = $this->getMockBuilder(IUserManager::class) - ->disableOriginalConstructor() - ->getMock(); - $this->userSession = $this->getMockBuilder(IUserSession::class) - ->disableOriginalConstructor() - ->getMock(); - $this->logger = $this->getMockBuilder(ILogger::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->collection = new \OCA\DAV\Comments\EntityCollection( + $this->commentsManager = $this->createMock(ICommentsManager::class); + $this->userManager = $this->createMock(IUserManager::class); + $this->userSession = $this->createMock(IUserSession::class); + $this->logger = $this->createMock(LoggerInterface::class); + + $this->collection = new EntityCollection( '19', 'files', $this->commentsManager, @@ -72,11 +43,11 @@ class EntityCollectionTest extends \Test\TestCase { ); } - public function testGetId() { + public function testGetId(): void { $this->assertSame($this->collection->getId(), '19'); } - public function testGetChild() { + public function testGetChild(): void { $this->commentsManager->expects($this->once()) ->method('get') ->with('55') @@ -87,22 +58,22 @@ class EntityCollectionTest extends \Test\TestCase { ); $node = $this->collection->getChild('55'); - $this->assertTrue($node instanceof \OCA\DAV\Comments\CommentNode); + $this->assertInstanceOf(CommentNode::class, $node); } - public function testGetChildException() { + public function testGetChildException(): void { $this->expectException(\Sabre\DAV\Exception\NotFound::class); $this->commentsManager->expects($this->once()) ->method('get') ->with('55') - ->will($this->throwException(new \OCP\Comments\NotFoundException())); + ->willThrowException(new NotFoundException()); $this->collection->getChild('55'); } - public function testGetChildren() { + public function testGetChildren(): void { $this->commentsManager->expects($this->once()) ->method('getForObject') ->with('files', '19') @@ -114,11 +85,11 @@ class EntityCollectionTest extends \Test\TestCase { $result = $this->collection->getChildren(); - $this->assertSame(count($result), 1); - $this->assertTrue($result[0] instanceof \OCA\DAV\Comments\CommentNode); + $this->assertCount(1, $result); + $this->assertInstanceOf(CommentNode::class, $result[0]); } - public function testFindChildren() { + public function testFindChildren(): void { $dt = new \DateTime('2016-01-10 18:48:00'); $this->commentsManager->expects($this->once()) ->method('getForObject') @@ -131,19 +102,19 @@ class EntityCollectionTest extends \Test\TestCase { $result = $this->collection->findChildren(5, 15, $dt); - $this->assertSame(count($result), 1); - $this->assertTrue($result[0] instanceof \OCA\DAV\Comments\CommentNode); + $this->assertCount(1, $result); + $this->assertInstanceOf(CommentNode::class, $result[0]); } - public function testChildExistsTrue() { + public function testChildExistsTrue(): void { $this->assertTrue($this->collection->childExists('44')); } - public function testChildExistsFalse() { + public function testChildExistsFalse(): void { $this->commentsManager->expects($this->once()) ->method('get') ->with('44') - ->will($this->throwException(new \OCP\Comments\NotFoundException())); + ->willThrowException(new NotFoundException()); $this->assertFalse($this->collection->childExists('44')); } |