diff options
Diffstat (limited to 'apps/dav/tests/unit/Comments/RootCollectionTest.php')
-rw-r--r-- | apps/dav/tests/unit/Comments/RootCollectionTest.php | 126 |
1 files changed, 44 insertions, 82 deletions
diff --git a/apps/dav/tests/unit/Comments/RootCollectionTest.php b/apps/dav/tests/unit/Comments/RootCollectionTest.php index 8537eb9ab17..9a05d996c8c 100644 --- a/apps/dav/tests/unit/Comments/RootCollectionTest.php +++ b/apps/dav/tests/unit/Comments/RootCollectionTest.php @@ -1,97 +1,59 @@ <?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 OC\EventDispatcher\EventDispatcher; -use OC\EventDispatcher\SymfonyAdapter; use OCA\DAV\Comments\EntityTypeCollection as EntityTypeCollectionImplementation; +use OCA\DAV\Comments\RootCollection; use OCP\Comments\CommentsEntityEvent; use OCP\Comments\ICommentsManager; -use OCP\ILogger; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IUser; use OCP\IUserManager; use OCP\IUserSession; +use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; class RootCollectionTest extends \Test\TestCase { - - /** @var \OCP\Comments\ICommentsManager|\PHPUnit\Framework\MockObject\MockObject */ - protected $commentsManager; - /** @var \OCP\IUserManager|\PHPUnit\Framework\MockObject\MockObject */ - protected $userManager; - /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */ - protected $logger; - /** @var \OCA\DAV\Comments\RootCollection */ - protected $collection; - /** @var \OCP\IUserSession|\PHPUnit\Framework\MockObject\MockObject */ - protected $userSession; - /** @var EventDispatcherInterface */ - protected $dispatcher; - /** @var \OCP\IUser|\PHPUnit\Framework\MockObject\MockObject */ - protected $user; + protected ICommentsManager&MockObject $commentsManager; + protected IUserManager&MockObject $userManager; + protected LoggerInterface&MockObject $logger; + protected IUserSession&MockObject $userSession; + protected IEventDispatcher $dispatcher; + protected IUser&MockObject $user; + protected RootCollection $collection; protected function setUp(): void { parent::setUp(); - $this->user = $this->getMockBuilder(IUser::class) - ->disableOriginalConstructor() - ->getMock(); - - $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(LoggerInterface::class) - ->disableOriginalConstructor() - ->getMock(); - $this->dispatcher = new SymfonyAdapter( - new EventDispatcher( - new \Symfony\Component\EventDispatcher\EventDispatcher(), - \OC::$server, - $this->logger - ), + $this->user = $this->createMock(IUser::class); + + $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->dispatcher = new EventDispatcher( + new \Symfony\Component\EventDispatcher\EventDispatcher(), + \OC::$server, $this->logger ); - $this->collection = new \OCA\DAV\Comments\RootCollection( + $this->collection = new RootCollection( $this->commentsManager, $this->userManager, $this->userSession, $this->dispatcher, - $this->createMock(ILogger::class) + $this->logger ); } - protected function prepareForInitCollections() { + protected function prepareForInitCollections(): void { $this->user->expects($this->any()) ->method('getUID') ->willReturn('alice'); @@ -100,7 +62,7 @@ class RootCollectionTest extends \Test\TestCase { ->method('getUser') ->willReturn($this->user); - $this->dispatcher->addListener(CommentsEntityEvent::EVENT_ENTITY, function (CommentsEntityEvent $event) { + $this->dispatcher->addListener(CommentsEntityEvent::class, function (CommentsEntityEvent $event): void { $event->addEntityCollection('files', function () { return true; }); @@ -108,27 +70,27 @@ class RootCollectionTest extends \Test\TestCase { } - public function testCreateFile() { + public function testCreateFile(): void { $this->expectException(\Sabre\DAV\Exception\Forbidden::class); $this->collection->createFile('foo'); } - public function testCreateDirectory() { + public function testCreateDirectory(): void { $this->expectException(\Sabre\DAV\Exception\Forbidden::class); $this->collection->createDirectory('foo'); } - public function testGetChild() { + public function testGetChild(): void { $this->prepareForInitCollections(); $etc = $this->collection->getChild('files'); - $this->assertTrue($etc instanceof EntityTypeCollectionImplementation); + $this->assertInstanceOf(EntityTypeCollectionImplementation::class, $etc); } - public function testGetChildInvalid() { + public function testGetChildInvalid(): void { $this->expectException(\Sabre\DAV\Exception\NotFound::class); $this->prepareForInitCollections(); @@ -136,64 +98,64 @@ class RootCollectionTest extends \Test\TestCase { } - public function testGetChildNoAuth() { + public function testGetChildNoAuth(): void { $this->expectException(\Sabre\DAV\Exception\NotAuthenticated::class); $this->collection->getChild('files'); } - public function testGetChildren() { + public function testGetChildren(): void { $this->prepareForInitCollections(); $children = $this->collection->getChildren(); $this->assertFalse(empty($children)); foreach ($children as $child) { - $this->assertTrue($child instanceof EntityTypeCollectionImplementation); + $this->assertInstanceOf(EntityTypeCollectionImplementation::class, $child); } } - public function testGetChildrenNoAuth() { + public function testGetChildrenNoAuth(): void { $this->expectException(\Sabre\DAV\Exception\NotAuthenticated::class); $this->collection->getChildren(); } - public function testChildExistsYes() { + public function testChildExistsYes(): void { $this->prepareForInitCollections(); $this->assertTrue($this->collection->childExists('files')); } - public function testChildExistsNo() { + public function testChildExistsNo(): void { $this->prepareForInitCollections(); $this->assertFalse($this->collection->childExists('robots')); } - public function testChildExistsNoAuth() { + public function testChildExistsNoAuth(): void { $this->expectException(\Sabre\DAV\Exception\NotAuthenticated::class); $this->collection->childExists('files'); } - public function testDelete() { + public function testDelete(): void { $this->expectException(\Sabre\DAV\Exception\Forbidden::class); $this->collection->delete(); } - public function testGetName() { + public function testGetName(): void { $this->assertSame('comments', $this->collection->getName()); } - public function testSetName() { + public function testSetName(): void { $this->expectException(\Sabre\DAV\Exception\Forbidden::class); $this->collection->setName('foobar'); } - public function testGetLastModified() { + public function testGetLastModified(): void { $this->assertSame(null, $this->collection->getLastModified()); } } |