diff --git a/tests/php/Activity/Provider/BaseTest.php b/tests/php/Activity/Provider/BaseTest.php index b80824bcb3b..71b9ccd70d0 100644 --- a/tests/php/Activity/Provider/BaseTest.php +++ b/tests/php/Activity/Provider/BaseTest.php @@ -1,4 +1,6 @@ * @@ -41,20 +43,13 @@ * @package OCA\Talk\Tests\php\Activity */ class BaseTest extends TestCase { - /** @var IFactory|MockObject */ - protected $l10nFactory; - /** @var IURLGenerator|MockObject */ - protected $url; - /** @var Config|MockObject */ - protected $config; - /** @var IManager|MockObject */ - protected $activityManager; - /** @var IUserManager|MockObject */ - protected $userManager; - /** @var AvatarService|MockObject */ - protected $avatarService; - /** @var Manager|MockObject */ - protected $manager; + protected IFactory&MockObject $l10nFactory; + protected IURLGenerator&MockObject $url; + protected Config&MockObject $config; + protected IManager&MockObject $activityManager; + protected IUserManager&MockObject $userManager; + protected AvatarService&MockObject $avatarService; + protected Manager&MockObject $manager; public function setUp(): void { parent::setUp(); @@ -104,7 +99,7 @@ public static function dataPreParse(): array { public function testPreParse(string $appId, bool $hasUser, bool $disabledForUser, bool $willThrowException): void { $user = $hasUser ? $this->createMock(IUser::class) : null; - /** @var IEvent|MockObject $event */ + /** @var IEvent&MockObject $event */ $event = $this->createMock(IEvent::class); $event->expects($this->once()) ->method('getApp') @@ -135,8 +130,8 @@ public function testPreParse(string $appId, bool $hasUser, bool $disabledForUser static::invokePrivate($provider, 'preParse', [$event]); } - public function testPreParseThrows() { - /** @var IEvent|MockObject $event */ + public function testPreParseThrows(): void { + /** @var IEvent&MockObject $event */ $event = $this->createMock(IEvent::class); $event->expects($this->once()) ->method('getApp') @@ -146,7 +141,7 @@ public function testPreParseThrows() { static::invokePrivate($provider, 'preParse', [$event]); } - public static function dataSetSubject() { + public static function dataSetSubject(): array { return [ ['No placeholder', [], 'No placeholder'], ['This has one {placeholder}', ['placeholder' => ['name' => 'foobar']], 'This has one foobar'], @@ -156,12 +151,8 @@ public static function dataSetSubject() { /** * @dataProvider dataSetSubject - * - * @param string $subject - * @param array $parameters - * @param string $parsedSubject */ - public function testSetSubject($subject, array $parameters, $parsedSubject) { + public function testSetSubject(string $subject, array $parameters, string $parsedSubject): void { $provider = $this->getProvider(); $event = $this->createMock(IEvent::class); @@ -177,7 +168,7 @@ public function testSetSubject($subject, array $parameters, $parsedSubject) { self::invokePrivate($provider, 'setSubjects', [$event, $subject, $parameters]); } - public static function dataGetRoom() { + public static function dataGetRoom(): array { return [ [Room::TYPE_ONE_TO_ONE, 23, 'private-call', 'private-call', 'one2one'], [Room::TYPE_GROUP, 42, 'group-call', 'group-call', 'group'], @@ -190,14 +181,8 @@ public static function dataGetRoom() { /** * @dataProvider dataGetRoom - * - * @param int $type - * @param int $id - * @param string $name - * @param string $expectedName - * @param string $expectedType */ - public function testGetRoom($type, $id, $name, $expectedName, $expectedType) { + public function testGetRoom(int $type, int $id, string $name, string $expectedName, string $expectedType): void { $provider = $this->getProvider(); $room = $this->createMock(Room::class); @@ -239,10 +224,6 @@ public static function dataGetUser(): array { /** * @dataProvider dataGetUser - * - * @param string $uid - * @param bool $validUser - * @param string $name */ public function testGetUser(string $uid, bool $validUser, string $name): void { $provider = $this->getProvider(); diff --git a/tests/php/Activity/Provider/InvitationTest.php b/tests/php/Activity/Provider/InvitationTest.php index f6edb1c18bd..2d9a44e5a5c 100644 --- a/tests/php/Activity/Provider/InvitationTest.php +++ b/tests/php/Activity/Provider/InvitationTest.php @@ -1,4 +1,6 @@ * @@ -43,20 +45,13 @@ * @package OCA\Talk\Tests\php\Activity */ class InvitationTest extends TestCase { - /** @var IFactory|MockObject */ - protected $l10nFactory; - /** @var IURLGenerator|MockObject */ - protected $url; - /** @var Config|MockObject */ - protected $config; - /** @var IManager|MockObject */ - protected $activityManager; - /** @var IUserManager|MockObject */ - protected $userManager; - /** @var AvatarService|MockObject */ - protected $avatarService; - /** @var Manager|MockObject */ - protected $manager; + protected IFactory&MockObject $l10nFactory; + protected IURLGenerator&MockObject $url; + protected Config&MockObject $config; + protected IManager&MockObject $activityManager; + protected IUserManager&MockObject $userManager; + protected AvatarService&MockObject $avatarService; + protected Manager&MockObject $manager; public function setUp(): void { parent::setUp(); @@ -100,8 +95,8 @@ protected function getProvider(array $methods = []) { ); } - public function testParseThrowsWrongSubject() { - /** @var IEvent|MockObject $event */ + public function testParseThrowsWrongSubject(): void { + /** @var IEvent&MockObject $event */ $event = $this->createMock(IEvent::class); $event->expects($this->once()) ->method('getApp') @@ -128,7 +123,7 @@ public function testParseThrowsWrongSubject() { $provider->parse('en', $event); } - public static function dataParse() { + public static function dataParse(): array { return [ ['en', true, ['room' => 23, 'user' => 'test1'], ['actor' => ['actor-data'], 'call' => ['call-data']]], ['de', false, ['room' => 42, 'user' => 'test2'], ['actor' => ['actor-data'], 'call' => ['call-unknown']]], @@ -137,16 +132,11 @@ public static function dataParse() { /** * @dataProvider dataParse - * - * @param string $lang - * @param bool $roomExists - * @param array $params - * @param array $expectedParams */ - public function testParse($lang, $roomExists, array $params, array $expectedParams) { + public function testParse(string $lang, bool $roomExists, array $params, array $expectedParams): void { $provider = $this->getProvider(['setSubjects', 'getUser', 'getRoom', 'getFormerRoom']); - /** @var IL10N|MockObject $l */ + /** @var IL10N&MockObject $l */ $l = $this->createMock(IL10N::class); $l->expects($this->any()) ->method('t') @@ -154,7 +144,7 @@ public function testParse($lang, $roomExists, array $params, array $expectedPara return vsprintf($text, $parameters); }); - /** @var IEvent|MockObject $event */ + /** @var IEvent&MockObject $event */ $event = $this->createMock(IEvent::class); $event->expects($this->once()) ->method('getApp') @@ -180,7 +170,7 @@ public function testParse($lang, $roomExists, array $params, array $expectedPara ->willReturn(false); if ($roomExists) { - /** @var Room|MockObject $room */ + /** @var Room&MockObject $room */ $room = $this->createMock(Room::class); $this->manager->expects($this->once()) diff --git a/tests/php/Activity/SettingTest.php b/tests/php/Activity/SettingTest.php index 22df7e1e2d0..ec06893b062 100644 --- a/tests/php/Activity/SettingTest.php +++ b/tests/php/Activity/SettingTest.php @@ -1,4 +1,6 @@ * @@ -26,7 +28,7 @@ use Test\TestCase; class SettingTest extends TestCase { - public static function dataSettings() { + public static function dataSettings(): array { return [ [Setting::class], ]; @@ -34,40 +36,36 @@ public static function dataSettings() { /** * @dataProvider dataSettings - * @param string $settingClass */ - public function testImplementsInterface($settingClass) { - $setting = \OC::$server->get($settingClass); + public function testImplementsInterface(string $settingClass): void { + $setting = \OCP\Server::get($settingClass); $this->assertInstanceOf(ISetting::class, $setting); } /** * @dataProvider dataSettings - * @param string $settingClass */ - public function testGetIdentifier($settingClass) { + public function testGetIdentifier(string $settingClass): void { /** @var ISetting $setting */ - $setting = \OC::$server->get($settingClass); + $setting = \OCP\Server::get($settingClass); $this->assertIsString($setting->getIdentifier()); } /** * @dataProvider dataSettings - * @param string $settingClass */ - public function testGetName($settingClass) { + public function testGetName(string $settingClass): void { /** @var ISetting $setting */ - $setting = \OC::$server->get($settingClass); + $setting = \OCP\Server::get($settingClass); $this->assertIsString($setting->getName()); } /** * @dataProvider dataSettings - * @param string $settingClass */ - public function testGetPriority($settingClass) { + public function testGetPriority(string $settingClass): void { /** @var ISetting $setting */ - $setting = \OC::$server->get($settingClass); + $setting = \OCP\Server::get($settingClass); $priority = $setting->getPriority(); $this->assertIsInt($setting->getPriority()); $this->assertGreaterThanOrEqual(0, $priority); @@ -76,41 +74,37 @@ public function testGetPriority($settingClass) { /** * @dataProvider dataSettings - * @param string $settingClass */ - public function testCanChangeStream($settingClass) { + public function testCanChangeStream(string $settingClass): void { /** @var ISetting $setting */ - $setting = \OC::$server->get($settingClass); + $setting = \OCP\Server::get($settingClass); $this->assertIsBool($setting->canChangeStream()); } /** * @dataProvider dataSettings - * @param string $settingClass */ - public function testIsDefaultEnabledStream($settingClass) { + public function testIsDefaultEnabledStream(string $settingClass): void { /** @var ISetting $setting */ - $setting = \OC::$server->get($settingClass); + $setting = \OCP\Server::get($settingClass); $this->assertIsBool($setting->isDefaultEnabledStream()); } /** * @dataProvider dataSettings - * @param string $settingClass */ - public function testCanChangeMail($settingClass) { + public function testCanChangeMail(string $settingClass): void { /** @var ISetting $setting */ - $setting = \OC::$server->get($settingClass); + $setting = \OCP\Server::get($settingClass); $this->assertIsBool($setting->canChangeMail()); } /** * @dataProvider dataSettings - * @param string $settingClass */ - public function testIsDefaultEnabledMail($settingClass) { + public function testIsDefaultEnabledMail(string $settingClass): void { /** @var ISetting $setting */ - $setting = \OC::$server->get($settingClass); + $setting = \OCP\Server::get($settingClass); $this->assertIsBool($setting->isDefaultEnabledMail()); } } diff --git a/tests/php/BackgroundJob/CheckHostedSignalingServerTest.php b/tests/php/BackgroundJob/CheckHostedSignalingServerTest.php index eba49ff9198..538a5e4f3f4 100644 --- a/tests/php/BackgroundJob/CheckHostedSignalingServerTest.php +++ b/tests/php/BackgroundJob/CheckHostedSignalingServerTest.php @@ -39,20 +39,13 @@ use Test\TestCase; class CheckHostedSignalingServerTest extends TestCase { - /** @var ITimeFactory|MockObject */ - protected $timeFactory; - /** @var HostedSignalingServerService|MockObject */ - protected $hostedSignalingServerService; - /** @var IConfig|MockObject */ - protected $config; - /** @var IManager|MockObject */ - protected $notificationManager; - /** @var IGroupManager|MockObject */ - protected $groupManager; - /** @var IURLGenerator|MockObject */ - protected $urlGenerator; - /** @var LoggerInterface|MockObject */ - protected $logger; + protected ITimeFactory&MockObject $timeFactory; + protected HostedSignalingServerService&MockObject $hostedSignalingServerService; + protected IConfig&MockObject $config; + protected IManager&MockObject $notificationManager; + protected IGroupManager&MockObject $groupManager; + protected IURLGenerator&MockObject $urlGenerator; + protected LoggerInterface&MockObject $logger; public function setUp(): void { parent::setUp(); @@ -78,7 +71,7 @@ public function getBackgroundJob(): CheckHostedSignalingServer { ); } - public function testRunWithNoChange() { + public function testRunWithNoChange(): void { $backgroundJob = $this->getBackgroundJob(); $this->config @@ -92,10 +85,10 @@ public function testRunWithNoChange() { ->method('fetchAccountInfo') ->willReturn(['status' => 'pending']); - $this->invokePrivate($backgroundJob, 'run', ['']); + self::invokePrivate($backgroundJob, 'run', ['']); } - public function testRunWithPendingToActiveChange() { + public function testRunWithPendingToActiveChange(): void { $backgroundJob = $this->getBackgroundJob(); $newStatus = [ 'status' => 'active', @@ -142,6 +135,6 @@ public function testRunWithPendingToActiveChange() { ->method('fetchAccountInfo') ->willReturn($newStatus); - $this->invokePrivate($backgroundJob, 'run', ['']); + self::invokePrivate($backgroundJob, 'run', ['']); } } diff --git a/tests/php/BackgroundJob/RemoveEmptyRoomsTest.php b/tests/php/BackgroundJob/RemoveEmptyRoomsTest.php index 52bcb26d706..51ff06d4ea3 100644 --- a/tests/php/BackgroundJob/RemoveEmptyRoomsTest.php +++ b/tests/php/BackgroundJob/RemoveEmptyRoomsTest.php @@ -33,24 +33,18 @@ use OCA\Talk\Service\RoomService; use OCP\AppFramework\Utility\ITimeFactory; use OCP\Files\Config\IUserMountCache; +use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; use Test\TestCase; class RemoveEmptyRoomsTest extends TestCase { - /** @var ITimeFactory|MockObject */ - protected $timeFactory; - /** @var Manager|MockObject */ - protected $manager; - /** @var RoomService|MockObject */ - protected $roomService; - /** @var ParticipantService|MockObject */ - protected $participantService; - /** @var ParticipantService|MockObject */ - protected $federationManager; - /** @var LoggerInterface|MockObject */ - protected $loggerInterface; - /** @var IUserMountCache|MockObject */ - protected $userMountCache; + protected ITimeFactory&MockObject $timeFactory; + protected Manager&MockObject $manager; + protected RoomService&MockObject $roomService; + protected ParticipantService&MockObject $participantService; + protected FederationManager&MockObject $federationManager; + protected LoggerInterface&MockObject $loggerInterface; + protected IUserMountCache&MockObject $userMountCache; public function setUp(): void { parent::setUp(); @@ -91,6 +85,15 @@ public function testDoDeleteRoom(): void { $this->assertEquals(1, $numDeletedRooms, 'Invalid final quantity of rooms'); } + public static function dataDeleteIfFileIsRemoved(): array { + return [ + ['', [], 0], + ['email', [], 0], + ['file', ['fileExists'], 0], + ['file', [], 1], + ]; + } + /** * @dataProvider dataDeleteIfFileIsRemoved */ @@ -116,12 +119,14 @@ public function testDeleteIfFileIsRemoved(string $objectType, array $fileList, i $this->assertEquals($numDeletedRoomsExpected, $numDeletedRoomsActual, 'Invalid final quantity of rooms'); } - public static function dataDeleteIfFileIsRemoved(): array { + public static function dataDeleteIfIsEmpty(): array { return [ - ['', [], 0], - ['email', [], 0], - ['file', ['fileExists'], 0], - ['file', [], 1], + 'room with user' => ['', 1, 0, 0], + 'room with fed invite' => ['', 0, 1, 0], + 'room to delete' => ['', 0, 0, 1], + 'file room with user' => ['file', 1, 0, 0], + 'email room with user' => ['email', 1, 0, 0], + 'email room without user' => ['email', 0, 0, 1] ]; } @@ -156,17 +161,6 @@ public function testDeleteIfIsEmpty(string $objectType, int $actorsCount, int $i $this->assertEquals($numDeletedRoomsExpected, $numDeletedRoomsActual, 'Invalid final quantity of rooms'); } - public static function dataDeleteIfIsEmpty(): array { - return [ - 'room with user' => ['', 1, 0, 0], - 'room with fed invite' => ['', 0, 1, 0], - 'room to delete' => ['', 0, 0, 1], - 'file room with user' => ['file', 1, 0, 0], - 'email room with user' => ['email', 1, 0, 0], - 'email room without user' => ['email', 0, 0, 1] - ]; - } - /** * @dataProvider dataCallback */ diff --git a/tests/php/CapabilitiesTest.php b/tests/php/CapabilitiesTest.php index d62e84353a3..60411c1ea0a 100644 --- a/tests/php/CapabilitiesTest.php +++ b/tests/php/CapabilitiesTest.php @@ -43,15 +43,15 @@ use Test\TestCase; class CapabilitiesTest extends TestCase { - protected IConfig|MockObject $serverConfig; - protected Config|MockObject $talkConfig; - protected IAppConfig|MockObject $appConfig; - protected CommentsManager|MockObject $commentsManager; - protected IUserSession|MockObject $userSession; - protected IAppManager|MockObject $appManager; - protected ITranslationManager|MockObject $translationManager; - protected ICacheFactory|MockObject $cacheFactory; - protected ICache|MockObject $talkCache; + protected IConfig&MockObject $serverConfig; + protected Config&MockObject $talkConfig; + protected IAppConfig&MockObject $appConfig; + protected CommentsManager&MockObject $commentsManager; + protected IUserSession&MockObject $userSession; + protected IAppManager&MockObject $appManager; + protected ITranslationManager&MockObject $translationManager; + protected ICacheFactory&MockObject $cacheFactory; + protected ICache&MockObject $talkCache; protected ?array $baseFeatures = null; public function setUp(): void { @@ -256,11 +256,6 @@ public static function dataGetCapabilitiesUserAllowed(): array { /** * @dataProvider dataGetCapabilitiesUserAllowed - * @param bool $isNotAllowed - * @param bool $canCreate - * @param string $quota - * @param bool $canUpload - * @param int $readPrivacy */ public function testGetCapabilitiesUserAllowed(bool $isNotAllowed, bool $canCreate, string $quota, bool $canUpload, int $readPrivacy): void { $capabilities = new Capabilities( @@ -442,6 +437,13 @@ public function testCapabilitiesHelloV2Key(): void { $this->assertEquals('this-is-the-key', $data['spreed']['config']['signaling']['hello-v2-token-key']); } + public static function dataTestConfigRecording(): array { + return [ + [true], + [false], + ]; + } + /** * @dataProvider dataTestConfigRecording */ @@ -465,13 +467,6 @@ public function testConfigRecording(bool $enabled): void { $this->assertEquals($data['spreed']['config']['call']['recording'], $enabled); } - public static function dataTestConfigRecording(): array { - return [ - [true], - [false], - ]; - } - public function testCapabilitiesTranslations(): void { $capabilities = new Capabilities( $this->serverConfig, diff --git a/tests/php/Chat/AutoComplete/SearchPluginTest.php b/tests/php/Chat/AutoComplete/SearchPluginTest.php index b6e4029da4b..e7e7d3ce4c7 100644 --- a/tests/php/Chat/AutoComplete/SearchPluginTest.php +++ b/tests/php/Chat/AutoComplete/SearchPluginTest.php @@ -42,19 +42,13 @@ use Test\TestCase; class SearchPluginTest extends TestCase { - /** @var IUserManager|MockObject */ - protected $userManager; - /** @var GuestManager|MockObject */ - protected $guestManager; - /** @var TalkSession|MockObject */ - protected $talkSession; - /** @var ParticipantService|MockObject */ - protected $participantService; - /** @var Util|MockObject */ - protected $util; - protected Authenticator|MockObject $federationAuthenticator; - /** @var IL10N|MockObject */ - protected $l; + protected IUserManager&MockObject $userManager; + protected GuestManager&MockObject $guestManager; + protected TalkSession&MockObject $talkSession; + protected ParticipantService&MockObject $participantService; + protected Util&MockObject $util; + protected Authenticator&MockObject $federationAuthenticator; + protected IL10N&MockObject $l; protected ?string $userId = null; protected SearchPlugin $plugin; @@ -110,7 +104,7 @@ protected function getPlugin(array $methods = []) { } protected function createParticipantMock(string $uid, string $displayName, string $session = ''): Participant { - /** @var Participant|MockObject $p */ + /** @var Participant&MockObject $p */ $p = $this->createMock(Participant::class); $a = Attendee::fromRow([ 'actor_type' => $uid ? 'users' : 'guests', @@ -134,7 +128,7 @@ protected function createParticipantMock(string $uid, string $displayName, strin return $p; } - public function testSearch() { + public function testSearch(): void { $result = $this->createMock(ISearchResult::class); $room = $this->createMock(Room::class); @@ -221,13 +215,8 @@ public static function dataSearchGuests(): array { /** * @dataProvider dataSearchGuests - * @param string $search - * @param string[] $sessionHashes - * @param array $displayNames - * @param array $expected - * @param array $expectedExact */ - public function testSearchGuests($search, array $guests, array $expected, array $expectedExact): void { + public function testSearchGuests(string $search, array $guests, array $expected, array $expectedExact): void { $result = $this->createMock(ISearchResult::class); $result->expects($this->once()) ->method('addResultSet') @@ -262,7 +251,7 @@ protected function createUserMock(array $userData) { return $user; } - public static function dataCreateResult() { + public static function dataCreateResult(): array { return [ ['user', 'foo', 'bar', '', ['label' => 'bar', 'value' => ['shareType' => 'user', 'shareWith' => 'foo']]], ['user', 'test', 'Test', '', ['label' => 'Test', 'value' => ['shareType' => 'user', 'shareWith' => 'test']]], @@ -273,13 +262,8 @@ public static function dataCreateResult() { /** * @dataProvider dataCreateResult - * @param string $type - * @param string $uid - * @param string $name - * @param string $managerName - * @param array $expected */ - public function testCreateResult($type, $uid, $name, $managerName, array $expected) { + public function testCreateResult(string $type, string $uid, string $name, ?string $managerName, array $expected): void { if ($managerName !== null) { $this->userManager->expects($this->any()) ->method('getDisplayName') @@ -306,9 +290,6 @@ public static function dataCreateGuestResult(): array { /** * @dataProvider dataCreateGuestResult - * @param string $actorId - * @param string $name - * @param array $expected */ public function testCreateGuestResult(string $actorId, string $name, array $expected): void { $plugin = $this->getPlugin(); diff --git a/tests/php/Chat/AutoComplete/SorterTest.php b/tests/php/Chat/AutoComplete/SorterTest.php index 3946bb19920..3243b926578 100644 --- a/tests/php/Chat/AutoComplete/SorterTest.php +++ b/tests/php/Chat/AutoComplete/SorterTest.php @@ -29,8 +29,7 @@ use Test\TestCase; class SorterTest extends TestCase { - /** @var CommentsManager|MockObject */ - protected $commentsManager; + protected CommentsManager&MockObject $commentsManager; protected string $userId; @@ -67,7 +66,7 @@ public function setUp(): void { $this->sorter = new Sorter($this->commentsManager); } - public function testGetId() { + public function testGetId(): void { $this->assertSame('talk_chat_participants', $this->sorter->getId()); } @@ -85,13 +84,8 @@ public static function dataSort(): array { /** * @dataProvider dataSort - * - * @param string $search - * @param array $toSort - * @param array $comments - * @param array $expected */ - public function testSort(string $search, array $toSort, array $comments, array $expected) { + public function testSort(string $search, array $toSort, array $comments, array $expected): void { $this->commentsManager->expects(isset($toSort['users']) ? $this->once() : $this->never()) ->method('getLastCommentDateByActor') ->with('chat', '23', 'comment', 'users', $this->anything()) diff --git a/tests/php/Chat/ChatManagerTest.php b/tests/php/Chat/ChatManagerTest.php index 92246fd25a9..8c618da37c5 100644 --- a/tests/php/Chat/ChatManagerTest.php +++ b/tests/php/Chat/ChatManagerTest.php @@ -43,6 +43,7 @@ use OCP\Comments\ICommentsManager; use OCP\EventDispatcher\IEventDispatcher; use OCP\ICacheFactory; +use OCP\IDBConnection; use OCP\IRequest; use OCP\IUser; use OCP\Notification\IManager as INotificationManager; @@ -58,35 +59,21 @@ * @group DB */ class ChatManagerTest extends TestCase { - /** @var CommentsManager|ICommentsManager|MockObject */ - protected $commentsManager; - /** @var IEventDispatcher|MockObject */ - protected $dispatcher; - /** @var INotificationManager|MockObject */ - protected $notificationManager; - /** @var IManager|MockObject */ - protected $shareManager; - /** @var RoomShareProvider|MockObject */ - protected $shareProvider; - /** @var ParticipantService|MockObject */ - protected $participantService; - /** @var RoomService|MockObject */ - protected $roomService; - /** @var PollService|MockObject */ - protected $pollService; - /** @var Notifier|MockObject */ - protected $notifier; - /** @var ITimeFactory|MockObject */ - protected $timeFactory; - /** @var AttachmentService|MockObject */ - protected $attachmentService; - /** @var IReferenceManager|MockObject */ - protected $referenceManager; - /** @var ILimiter|MockObject */ - protected $rateLimiter; - /** @var IRequest|MockObject */ - protected $request; - protected LoggerInterface|MockObject $logger; + protected CommentsManager|ICommentsManager|MockObject $commentsManager; + protected IEventDispatcher&MockObject $dispatcher; + protected INotificationManager&MockObject $notificationManager; + protected IManager&MockObject $shareManager; + protected RoomShareProvider&MockObject $shareProvider; + protected ParticipantService&MockObject $participantService; + protected RoomService&MockObject $roomService; + protected PollService&MockObject $pollService; + protected Notifier&MockObject $notifier; + protected ITimeFactory&MockObject $timeFactory; + protected AttachmentService&MockObject $attachmentService; + protected IReferenceManager&MockObject $referenceManager; + protected ILimiter&MockObject $rateLimiter; + protected IRequest&MockObject $request; + protected LoggerInterface&MockObject $logger; protected ?ChatManager $chatManager = null; public function setUp(): void { @@ -123,7 +110,7 @@ protected function getManager(array $methods = []): ChatManager { ->setConstructorArgs([ $this->commentsManager, $this->dispatcher, - \OC::$server->getDatabaseConnection(), + \OCP\Server::get(IDBConnection::class), $this->notificationManager, $this->shareManager, $this->shareProvider, @@ -146,7 +133,7 @@ protected function getManager(array $methods = []): ChatManager { return new ChatManager( $this->commentsManager, $this->dispatcher, - \OC::$server->getDatabaseConnection(), + \OCP\Server::get(IDBConnection::class), $this->notificationManager, $this->shareManager, $this->shareProvider, @@ -223,10 +210,6 @@ public static function dataSendMessage(): array { /** * @dataProvider dataSendMessage - * @param string $userId - * @param string $message - * @param string $referenceId - * @param string $parentId */ public function testSendMessage(string $userId, string $message, string $referenceId, string $parentId): void { $creationDateTime = new \DateTime(); @@ -343,7 +326,7 @@ public function testWaitForNewMessages(): void { ->method('markMentionNotificationsRead') ->with($chat, 'userId'); - /** @var IUser|MockObject $user */ + /** @var IUser&MockObject $user */ $user = $this->createMock(IUser::class); $user->expects($this->any()) ->method('getUID') @@ -381,7 +364,7 @@ public function testWaitForNewMessagesWithWaiting(): void { ->method('markMentionNotificationsRead') ->with($chat, 'userId'); - /** @var IUser|MockObject $user */ + /** @var IUser&MockObject $user */ $user = $this->createMock(IUser::class); $user->expects($this->any()) ->method('getUID') @@ -393,7 +376,7 @@ public function testWaitForNewMessagesWithWaiting(): void { } public function testGetUnreadCount(): void { - /** @var Room|MockObject $chat */ + /** @var Room&MockObject $chat */ $chat = $this->createMock(Room::class); $chat->expects($this->atLeastOnce()) ->method('getId') @@ -424,7 +407,7 @@ public function testDeleteMessages(): void { } public function testDeleteMessage(): void { - $mapper = new AttendeeMapper(\OC::$server->getDatabaseConnection()); + $mapper = new AttendeeMapper(\OCP\Server::get(IDBConnection::class)); $attendee = $mapper->createAttendeeFromRow([ 'a_id' => 1, 'room_id' => 123, @@ -485,7 +468,7 @@ public function testDeleteMessage(): void { } public function testDeleteMessageFileShare(): void { - $mapper = new AttendeeMapper(\OC::$server->getDatabaseConnection()); + $mapper = new AttendeeMapper(\OCP\Server::get(IDBConnection::class)); $attendee = $mapper->createAttendeeFromRow([ 'a_id' => 1, 'room_id' => 123, @@ -568,7 +551,7 @@ public function testDeleteMessageFileShare(): void { } public function testDeleteMessageFileShareNotFound(): void { - $mapper = new AttendeeMapper(\OC::$server->getDatabaseConnection()); + $mapper = new AttendeeMapper(\OCP\Server::get(IDBConnection::class)); $attendee = $mapper->createAttendeeFromRow([ 'a_id' => 1, 'room_id' => 123, @@ -755,7 +738,7 @@ public static function dataAddConversationNotify(): array { /** * @dataProvider dataAddConversationNotify */ - public function testAddConversationNotify($search, $roomMocks, $participantMocks, $expected) { + public function testAddConversationNotify(string $search, array$roomMocks, array $participantMocks, array $expected): void { $room = $this->createMock(Room::class); foreach ($roomMocks as $method => $return) { $room->expects($this->once()) diff --git a/tests/php/Chat/Command/ExecutorTest.php b/tests/php/Chat/Command/ExecutorTest.php index 12027c7c708..8ec95901599 100644 --- a/tests/php/Chat/Command/ExecutorTest.php +++ b/tests/php/Chat/Command/ExecutorTest.php @@ -1,5 +1,6 @@ createMock(IComment::class); @@ -125,14 +114,9 @@ public static function dataExecShell(): array { /** * @dataProvider dataExecShell - * @param string|null $actorId - * @param string $roomToken - * @param string $script - * @param string $arguments - * @param string $output */ public function testExecShell(?string $actorId, string $roomToken, string $script, string $arguments, string $output): void { - /** @var IComment|MockObject $message */ + /** @var IComment&MockObject $message */ $message = $this->createMock(IComment::class); if ($actorId === null) { $message->expects($this->once()) @@ -149,7 +133,7 @@ public function testExecShell(?string $actorId, string $roomToken, string $scrip ->willReturn($actorId); } - /** @var Room|MockObject $room */ + /** @var Room&MockObject $room */ $room = $this->createMock(Room::class); $room->expects($this->once()) ->method('getToken') diff --git a/tests/php/Chat/Command/ShellExecutorTest.php b/tests/php/Chat/Command/ShellExecutorTest.php index 4d26bb3c9f7..071e2bc9e75 100644 --- a/tests/php/Chat/Command/ShellExecutorTest.php +++ b/tests/php/Chat/Command/ShellExecutorTest.php @@ -1,5 +1,6 @@ getMockBuilder(ShellExecutor::class) diff --git a/tests/php/Chat/NotifierTest.php b/tests/php/Chat/NotifierTest.php index c9554e11a7d..a63bf26215c 100644 --- a/tests/php/Chat/NotifierTest.php +++ b/tests/php/Chat/NotifierTest.php @@ -1,5 +1,6 @@ notificationManager->expects($this->exactly(count($notify))) - ->method('notify'); - } - - $room = $this->getRoom(); - $comment = $this->newComment('108', 'users', 'testUser', new \DateTime('@' . 1000000016), $message); - $notifier = $this->getNotifier([]); - $actual = $notifier->notifyMentionedUsers($room, $comment, $alreadyNotifiedUsers, false); - - $this->assertEqualsCanonicalizing($expectedReturn, $actual); - } - public static function dataNotifyMentionedUsers(): array { return [ 'no notifications' => [ @@ -203,6 +180,23 @@ public static function dataNotifyMentionedUsers(): array { ]; } + /** + * @dataProvider dataNotifyMentionedUsers + */ + public function testNotifyMentionedUsers(string $message, array $alreadyNotifiedUsers, array $notify, array $expectedReturn): void { + if (count($notify)) { + $this->notificationManager->expects($this->exactly(count($notify))) + ->method('notify'); + } + + $room = $this->getRoom(); + $comment = $this->newComment('108', 'users', 'testUser', new \DateTime('@' . 1000000016), $message); + $notifier = $this->getNotifier([]); + $actual = $notifier->notifyMentionedUsers($room, $comment, $alreadyNotifiedUsers, false); + + $this->assertEqualsCanonicalizing($expectedReturn, $actual); + } + public static function dataShouldParticipantBeNotified(): array { return [ [Attendee::ACTOR_GROUPS, 'test1', null, Attendee::ACTOR_USERS, 'test1', [], false], @@ -217,13 +211,6 @@ public static function dataShouldParticipantBeNotified(): array { /** * @dataProvider dataShouldParticipantBeNotified - * @param string $actorType - * @param string $actorId - * @param int|null $sessionAge - * @param string $commentActorType - * @param string $commentActorId - * @param array $alreadyNotifiedUsers - * @param bool $expected */ public function testShouldParticipantBeNotified(string $actorType, string $actorId, ?int $sessionAge, string $commentActorType, string $commentActorId, array $alreadyNotifiedUsers, bool $expected): void { $comment = $this->createMock(IComment::class); @@ -310,27 +297,6 @@ public function testRemovePendingNotificationsForChatOnly(): void { $this->getNotifier()->removePendingNotificationsForRoom($room, true); } - /** - * @dataProvider dataAddMentionAllToList - */ - public function testAddMentionAllToList(array $usersToNotify, array $participants, array $return): void { - $room = $this->createMock(Room::class); - $this->participantService - ->method('getActorsByType') - ->willReturn($participants); - - $actual = self::invokePrivate($this->getNotifier(), 'addMentionAllToList', [$room, $usersToNotify]); - $this->assertCount(count($return), $actual); - foreach ($actual as $key => $value) { - $this->assertIsArray($value); - if (array_key_exists('attendee', $value)) { - $this->assertInstanceOf(Attendee::class, $value['attendee']); - unset($value['attendee']); - } - $this->assertEqualsCanonicalizing($return[$key], $value); - } - } - public static function dataAddMentionAllToList(): array { return [ 'not notify' => [ @@ -365,26 +331,24 @@ public static function dataAddMentionAllToList(): array { } /** - * @dataProvider dataNotifyReacted + * @dataProvider dataAddMentionAllToList */ - public function testNotifyReacted(int $notify, int $notifyType, int $roomType, string $authorId): void { - $this->notificationManager->expects($this->exactly($notify)) - ->method('notify'); - - $room = $this->getRoom([ - 'attendee' => [ - 'testUser' => [ - 'notificationLevel' => $notifyType, - ] - ] - ]); - $room->method('getType') - ->willReturn($roomType); - $comment = $this->newComment('108', 'users', 'testUser', new \DateTime('@' . 1000000016), 'message'); - $reaction = $this->newComment('108', 'users', $authorId, new \DateTime('@' . 1000000016), 'message'); + public function testAddMentionAllToList(array $usersToNotify, array $participants, array $return): void { + $room = $this->createMock(Room::class); + $this->participantService + ->method('getActorsByType') + ->willReturn($participants); - $notifier = $this->getNotifier([]); - $notifier->notifyReacted($room, $comment, $reaction); + $actual = self::invokePrivate($this->getNotifier(), 'addMentionAllToList', [$room, $usersToNotify]); + $this->assertCount(count($return), $actual); + foreach ($actual as $key => $value) { + $this->assertIsArray($value); + if (array_key_exists('attendee', $value)) { + $this->assertInstanceOf(Attendee::class, $value['attendee']); + unset($value['attendee']); + } + $this->assertEqualsCanonicalizing($return[$key], $value); + } } public static function dataNotifyReacted(): array { @@ -403,12 +367,26 @@ public static function dataNotifyReacted(): array { } /** - * @dataProvider dataGetMentionedUsers + * @dataProvider dataNotifyReacted */ - public function testGetMentionedUsers(string $message, array $expectedReturn): void { - $comment = $this->newComment('108', 'users', 'testUser', new \DateTime('@' . 1000000016), $message); - $actual = self::invokePrivate($this->getNotifier(), 'getMentionedUsers', [$comment]); - $this->assertEqualsCanonicalizing($expectedReturn, $actual); + public function testNotifyReacted(int $notify, int $notifyType, int $roomType, string $authorId): void { + $this->notificationManager->expects($this->exactly($notify)) + ->method('notify'); + + $room = $this->getRoom([ + 'attendee' => [ + 'testUser' => [ + 'notificationLevel' => $notifyType, + ] + ] + ]); + $room->method('getType') + ->willReturn($roomType); + $comment = $this->newComment('108', 'users', 'testUser', new \DateTime('@' . 1000000016), 'message'); + $reaction = $this->newComment('108', 'users', $authorId, new \DateTime('@' . 1000000016), 'message'); + + $notifier = $this->getNotifier([]); + $notifier->notifyReacted($room, $comment, $reaction); } public static function dataGetMentionedUsers(): array { @@ -443,11 +421,11 @@ public static function dataGetMentionedUsers(): array { } /** - * @dataProvider dataGetMentionedUserIds + * @dataProvider dataGetMentionedUsers */ - public function testGetMentionedUserIds(string $message, array $expectedReturn): void { + public function testGetMentionedUsers(string $message, array $expectedReturn): void { $comment = $this->newComment('108', 'users', 'testUser', new \DateTime('@' . 1000000016), $message); - $actual = self::invokePrivate($this->getNotifier(), 'getMentionedUserIds', [$comment]); + $actual = self::invokePrivate($this->getNotifier(), 'getMentionedUsers', [$comment]); $this->assertEqualsCanonicalizing($expectedReturn, $actual); } @@ -461,4 +439,13 @@ public static function dataGetMentionedUserIds(): array { }); return $return; } + + /** + * @dataProvider dataGetMentionedUserIds + */ + public function testGetMentionedUserIds(string $message, array $expectedReturn): void { + $comment = $this->newComment('108', 'users', 'testUser', new \DateTime('@' . 1000000016), $message); + $actual = self::invokePrivate($this->getNotifier(), 'getMentionedUserIds', [$comment]); + $this->assertEqualsCanonicalizing($expectedReturn, $actual); + } } diff --git a/tests/php/Chat/Parser/SystemMessageTest.php b/tests/php/Chat/Parser/SystemMessageTest.php index 269643705c9..d7a4ece76e8 100644 --- a/tests/php/Chat/Parser/SystemMessageTest.php +++ b/tests/php/Chat/Parser/SystemMessageTest.php @@ -1,4 +1,6 @@ * @@ -57,31 +59,19 @@ * @group DB */ class SystemMessageTest extends TestCase { - /** @var IUserManager|MockObject */ - protected $userManager; - /** @var IGroupManager|MockObject */ - protected $groupManager; - /** @var GuestManager|MockObject */ - protected $guestManager; - /** @var ParticipantService|MockObject */ - protected $participantService; - /** @var IPreviewManager|MockObject */ - protected $previewManager; - /** @var RoomShareProvider|MockObject */ - protected $shareProvider; - /** @var PhotoCache|MockObject */ - protected $photoCache; - /** @var IRootFolder|MockObject */ - protected $rootFolder; - /** @var IURLGenerator|MockObject */ - protected $url; - /** @var ICloudIdManager|MockObject */ - protected $cloudIdManager; - /** @var FilesMetadataCache|MockObject */ - protected $filesMetadataCache; - protected Authenticator|MockObject $federationAuthenticator; - /** @var IL10N|MockObject */ - protected $l; + protected IUserManager&MockObject $userManager; + protected IGroupManager&MockObject $groupManager; + protected GuestManager&MockObject $guestManager; + protected ParticipantService&MockObject $participantService; + protected IPreviewManager&MockObject $previewManager; + protected RoomShareProvider&MockObject $shareProvider; + protected PhotoCache&MockObject $photoCache; + protected IRootFolder&MockObject $rootFolder; + protected IURLGenerator&MockObject $url; + protected ICloudIdManager&MockObject $cloudIdManager; + protected FilesMetadataCache&MockObject $filesMetadataCache; + protected Authenticator&MockObject $federationAuthenticator; + protected IL10N&MockObject $l; public function setUp(): void { parent::setUp(); @@ -104,9 +94,9 @@ public function setUp(): void { return vsprintf($text, $parameters); }); $this->l->method('n') - ->willReturnCallback(function ($singular, $plural, $count, $parameters = []) { + ->willReturnCallback(function (string $singular, string $plural, int $count, array $parameters = []) { $text = $count === 1 ? $singular : $plural; - return vsprintf(str_replace('%n', $count, $text), $parameters); + return vsprintf(str_replace('%n', (string) $count, $text), $parameters); }); } @@ -461,14 +451,9 @@ public static function dataParseMessage(): array { /** * @dataProvider dataParseMessage - * @param string $message - * @param array $parameters - * @param string|null $recipientId - * @param string $expectedMessage - * @param array $expectedParameters */ - public function testParseMessage(string $message, array $parameters, ?string $recipientId, string $expectedMessage, array $expectedParameters) { - /** @var Participant|MockObject $participant */ + public function testParseMessage(string $message, array $parameters, ?string $recipientId, string $expectedMessage, array $expectedParameters): void { + /** @var Participant&MockObject $participant */ $participant = $this->createMock(Participant::class); if ($recipientId === null) { $participant = null; @@ -506,7 +491,7 @@ public function testParseMessage(string $message, array $parameters, ?string $re ->willReturn($session); } - /** @var IComment|MockObject $comment */ + /** @var IComment&MockObject $comment */ $comment = $this->createMock(IComment::class); if ($recipientId && strpos($recipientId, 'guest::') !== false) { $comment->method('getActorType') @@ -520,7 +505,7 @@ public function testParseMessage(string $message, array $parameters, ?string $re ->willReturn($recipientId); } - /** @var Room|MockObject $room */ + /** @var Room&MockObject $room */ $room = $this->createMock(Room::class); $parser = $this->getParser(['getActorFromComment', 'getUser', 'getGroup', 'getGuest', 'parseCall', 'getFileFromShare']); @@ -594,13 +579,12 @@ public static function dataParseMessageThrows(): array { /** * @dataProvider dataParseMessageThrows - * @param string|null $return */ - public function testParseMessageThrows($return) { - /** @var IComment|MockObject $comment */ + public function testParseMessageThrows(?string $return): void { + /** @var IComment&MockObject $comment */ $comment = $this->createMock(IComment::class); - /** @var Room|MockObject $room */ + /** @var Room&MockObject $room */ $room = $this->createMock(Room::class); $parser = $this->getParser(['getActorFromComment']); @@ -609,7 +593,7 @@ public function testParseMessageThrows($return) { ->with($room, $comment) ->willReturn(['id' => 'actor', 'type' => 'user']); - /** @var Participant|MockObject $participant */ + /** @var Participant&MockObject $participant */ $participant = $this->createMock(Participant::class); $chatMessage = new Message($room, $participant, $comment, $this->l); $chatMessage->setMessage($return, []); @@ -618,7 +602,7 @@ public function testParseMessageThrows($return) { self::invokePrivate($parser, 'parseMessage', [$chatMessage]); } - public function testGetFileFromShareForGuest() { + public function testGetFileFromShareForGuest(): void { $node = $this->createMock(Node::class); $node->expects($this->once()) ->method('getId') @@ -691,7 +675,7 @@ public function testGetFileFromShareForGuest() { ], self::invokePrivate($parser, 'getFileFromShare', [$participant, '23'])); } - public function testGetFileFromShareForOwner() { + public function testGetFileFromShareForOwner(): void { $node = $this->createMock(Node::class); $node->expects($this->exactly(2)) ->method('getId') @@ -770,7 +754,7 @@ public function testGetFileFromShareForOwner() { ], self::invokePrivate($parser, 'getFileFromShare', [$participant, '23'])); } - public function testGetFileFromShareForRecipient() { + public function testGetFileFromShareForRecipient(): void { $share = $this->createMock(IShare::class); $share->expects($this->any()) ->method('getNodeId') @@ -857,7 +841,7 @@ public function testGetFileFromShareForRecipient() { ], self::invokePrivate($parser, 'getFileFromShare', [$participant, '23'])); } - public function testGetFileFromShareForRecipientThrows() { + public function testGetFileFromShareForRecipientThrows(): void { $share = $this->createMock(IShare::class); $share->expects($this->any()) ->method('getNodeId') @@ -899,7 +883,7 @@ public function testGetFileFromShareForRecipientThrows() { self::invokePrivate($parser, 'getFileFromShare', [$participant, '23']); } - public function testGetFileFromShareThrows() { + public function testGetFileFromShareThrows(): void { $this->shareProvider->expects($this->once()) ->method('getShareById') ->with('23') @@ -920,13 +904,9 @@ public static function dataGetActor(): array { /** * @dataProvider dataGetActor - * @param string $actorType - * @param array $guestData - * @param array $userData - * @param array $expected */ - public function testGetActor(string $actorType, array $guestData, array $userData, array $expected) { - /** @var Room|MockObject $room */ + public function testGetActor(string $actorType, array $guestData, array $userData, array $expected): void { + /** @var Room&MockObject $room */ $room = $this->createMock(Room::class); $chatMessage = $this->createMock(IComment::class); @@ -971,12 +951,8 @@ public static function dataGetUser(): array { /** * @dataProvider dataGetUser - * @param string $uid - * @param array $cache - * @param bool $cacheHit - * @param string $name */ - public function testGetUser(string $uid, array $cache, bool $cacheHit, string $name) { + public function testGetUser(string $uid, array $cache, bool $cacheHit, string $name): void { $parser = $this->getParser(['getDisplayName']); self::invokePrivate($parser, 'displayNames', [$cache]); @@ -1006,11 +982,8 @@ public static function dataGetDisplayName(): array { /** * @dataProvider dataGetDisplayName - * @param string $uid - * @param bool $validUser - * @param string $name */ - public function testGetDisplayName(string $uid, bool $validUser, string $name) { + public function testGetDisplayName(string $uid, bool $validUser, string $name): void { $parser = $this->getParser(); if ($validUser) { @@ -1039,10 +1012,6 @@ public static function dataGetGroup(): array { /** * @dataProvider dataGetGroup - * @param string $gid - * @param array $cache - * @param bool $cacheHit - * @param string $name */ public function testGetGroup(string $gid, array $cache, bool $cacheHit, string $name): void { $parser = $this->getParser(['getDisplayNameGroup']); @@ -1074,9 +1043,6 @@ public static function dataGetDisplayNameGroup(): array { /** * @dataProvider dataGetDisplayNameGroup - * @param string $gid - * @param bool $validGroup - * @param string $name */ public function testGetDisplayNameGroup(string $gid, bool $validGroup, string $name): void { $parser = $this->getParser(); @@ -1109,11 +1075,9 @@ public static function dataGetGuest(): array { /** * @dataProvider dataGetGuest - * @param string $attendeeType - * @param string $actorId */ public function testGetGuest(string $attendeeType, string $actorId): void { - /** @var Room|MockObject $room */ + /** @var Room&MockObject $room */ $room = $this->createMock(Room::class); $parser = $this->getParser(['getGuestName']); @@ -1147,20 +1111,16 @@ public static function dataGetGuestName(): array { /** * @dataProvider dataGetGuestName - * @param string $actorType - * @param string $actorId - * @param string $attendeeName - * @param string $expected */ public function testGetGuestName(string $actorType, string $actorId, string $attendeeName, string $expected): void { - /** @var Room|MockObject $room */ + /** @var Room&MockObject $room */ $room = $this->createMock(Room::class); $attendee = Attendee::fromParams([ 'displayName' => $attendeeName, ]); - /** @var Participant|MockObject $room */ + /** @var Participant&MockObject $room */ $participant = $this->createMock(Participant::class); $participant->method('getAttendee') ->willReturn($attendee); @@ -1174,10 +1134,10 @@ public function testGetGuestName(string $actorType, string $actorId, string $att $this->assertSame($expected, self::invokePrivate($parser, 'getGuestName', [$room, $actorType, $actorId])); } - public function testGetGuestNameThrows() { + public function testGetGuestNameThrows(): void { $actorId = sha1('name'); - /** @var Room|MockObject $room */ + /** @var Room&MockObject $room */ $room = $this->createMock(Room::class); $this->participantService->method('getParticipantByActor') @@ -1423,10 +1383,8 @@ public static function dataParseCall(): array { /** * @dataProvider dataParseCall - * @param array $parameters - * @param array $expected */ - public function testParseCall(string $message, array $parameters, array $actor, array $expected) { + public function testParseCall(string $message, array $parameters, array $actor, array $expected): void { $parser = $this->getParser(['getDuration', 'getUser']); $parser->expects($this->once()) ->method('getDuration') @@ -1456,10 +1414,8 @@ public static function dataGetDuration(): array { /** * @dataProvider dataGetDuration - * @param int $seconds - * @param string $expected */ - public function testGetDuration(int $seconds, string $expected) { + public function testGetDuration(int $seconds, string $expected): void { $parser = $this->getParser(); $this->assertSame($expected, self::invokePrivate($parser, 'getDuration', [$seconds])); } diff --git a/tests/php/Chat/Parser/UserMentionTest.php b/tests/php/Chat/Parser/UserMentionTest.php index 2cb4fd44302..653a5f238d8 100644 --- a/tests/php/Chat/Parser/UserMentionTest.php +++ b/tests/php/Chat/Parser/UserMentionTest.php @@ -44,21 +44,14 @@ use Test\TestCase; class UserMentionTest extends TestCase { - /** @var ICommentsManager|MockObject */ - protected $commentsManager; - /** @var IUserManager|MockObject */ - protected $userManager; - /** @var IGroupManager */ - protected $groupManager; - /** @var GuestManager|MockObject */ - protected $guestManager; - /** @var AvatarService|MockObject */ - protected $avatarService; - protected ICloudIdManager|MockObject $cloudIdManager; - /** @var ParticipantService|MockObject */ - protected $participantService; - /** @var IL10N|MockObject */ - protected $l; + protected ICommentsManager&MockObject $commentsManager; + protected IUserManager&MockObject $userManager; + protected IGroupManager&MockObject $groupManager; + protected GuestManager&MockObject $guestManager; + protected AvatarService&MockObject $avatarService; + protected ICloudIdManager&MockObject $cloudIdManager; + protected ParticipantService&MockObject $participantService; + protected IL10N&MockObject $l; protected ?UserMention $parser = null; @@ -98,14 +91,14 @@ private function newComment(array $mentions): IComment { return $comment; } - public function testGetRichMessageWithoutEnrichableReferences() { + public function testGetRichMessageWithoutEnrichableReferences(): void { $comment = $this->newComment([]); - /** @var Room|MockObject $room */ + /** @var Room&MockObject $room */ $room = $this->createMock(Room::class); - /** @var Participant|MockObject $participant */ + /** @var Participant&MockObject $participant */ $participant = $this->createMock(Participant::class); - /** @var IL10N|MockObject $l */ + /** @var IL10N&MockObject $l */ $l = $this->createMock(IL10N::class); $chatMessage = new Message($room, $participant, $comment, $l); $chatMessage->setMessage('Message without enrichable references', []); @@ -132,11 +125,11 @@ public function testGetRichMessageWithSingleMention(): void { ->with('testUser') ->willReturn('testUser display name'); - /** @var Room|MockObject $room */ + /** @var Room&MockObject $room */ $room = $this->createMock(Room::class); - /** @var Participant|MockObject $participant */ + /** @var Participant&MockObject $participant */ $participant = $this->createMock(Participant::class); - /** @var IL10N|MockObject $l */ + /** @var IL10N&MockObject $l */ $l = $this->createMock(IL10N::class); $chatMessage = new Message($room, $participant, $comment, $l); $chatMessage->setMessage('Mention to @testUser', []); @@ -155,7 +148,7 @@ public function testGetRichMessageWithSingleMention(): void { $this->assertEquals($expectedMessageParameters, $chatMessage->getMessageParameters()); } - public function testGetRichMessageWithDuplicatedMention() { + public function testGetRichMessageWithDuplicatedMention(): void { $mentions = [ ['type' => 'user', 'id' => 'testUser'], ]; @@ -171,11 +164,11 @@ public function testGetRichMessageWithDuplicatedMention() { ->with('testUser') ->willReturn('testUser display name'); - /** @var Room|MockObject $room */ + /** @var Room&MockObject $room */ $room = $this->createMock(Room::class); - /** @var Participant|MockObject $participant */ + /** @var Participant&MockObject $participant */ $participant = $this->createMock(Participant::class); - /** @var IL10N|MockObject $l */ + /** @var IL10N&MockObject $l */ $l = $this->createMock(IL10N::class); $chatMessage = new Message($room, $participant, $comment, $l); $chatMessage->setMessage('Mention to @testUser and @testUser again', []); @@ -194,7 +187,7 @@ public function testGetRichMessageWithDuplicatedMention() { $this->assertEquals($expectedMessageParameters, $chatMessage->getMessageParameters()); } - public static function dataGetRichMessageWithMentionsFullyIncludedInOtherMentions() { + public static function dataGetRichMessageWithMentionsFullyIncludedInOtherMentions(): array { // Based on valid characters from server/lib/private/User/Manager.php return [ ['testUser', 'testUser1', false], @@ -215,7 +208,7 @@ public static function dataGetRichMessageWithMentionsFullyIncludedInOtherMention /** * @dataProvider dataGetRichMessageWithMentionsFullyIncludedInOtherMentions */ - public function testGetRichMessageWithMentionsFullyIncludedInOtherMentions(string $baseId, string $longerId, bool $quoted) { + public function testGetRichMessageWithMentionsFullyIncludedInOtherMentions(string $baseId, string $longerId, bool $quoted): void { $mentions = [ ['type' => 'user', 'id' => $baseId], ['type' => 'user', 'id' => $longerId], @@ -235,11 +228,11 @@ public function testGetRichMessageWithMentionsFullyIncludedInOtherMentions(strin [$baseId, $baseId . ' display name'] ]); - /** @var Room|MockObject $room */ + /** @var Room&MockObject $room */ $room = $this->createMock(Room::class); - /** @var Participant|MockObject $participant */ + /** @var Participant&MockObject $participant */ $participant = $this->createMock(Participant::class); - /** @var IL10N|MockObject $l */ + /** @var IL10N&MockObject $l */ $l = $this->createMock(IL10N::class); $chatMessage = new Message($room, $participant, $comment, $l); if ($quoted) { @@ -267,7 +260,7 @@ public function testGetRichMessageWithMentionsFullyIncludedInOtherMentions(strin $this->assertEquals($expectedMessageParameters, $chatMessage->getMessageParameters()); } - public function testGetRichMessageWithSeveralMentions() { + public function testGetRichMessageWithSeveralMentions(): void { $mentions = [ ['type' => 'user', 'id' => 'testUser1'], ['type' => 'user', 'id' => 'testUser2'], @@ -291,11 +284,11 @@ public function testGetRichMessageWithSeveralMentions() { ['testUser3', 'testUser3 display name'], ]); - /** @var Room|MockObject $room */ + /** @var Room&MockObject $room */ $room = $this->createMock(Room::class); - /** @var Participant|MockObject $participant */ + /** @var Participant&MockObject $participant */ $participant = $this->createMock(Participant::class); - /** @var IL10N|MockObject $l */ + /** @var IL10N&MockObject $l */ $l = $this->createMock(IL10N::class); $chatMessage = new Message($room, $participant, $comment, $l); $chatMessage->setMessage('Mention to @testUser1, @testUser2, @testUser1 again and @testUser3', []); @@ -324,7 +317,7 @@ public function testGetRichMessageWithSeveralMentions() { $this->assertEquals($expectedMessageParameters, $chatMessage->getMessageParameters()); } - public function testGetRichMessageWithNonExistingUserMention() { + public function testGetRichMessageWithNonExistingUserMention(): void { $mentions = [ ['type' => 'user', 'id' => 'me'], ['type' => 'user', 'id' => 'testUser'], @@ -343,11 +336,11 @@ public function testGetRichMessageWithNonExistingUserMention() { ['testUser', 'testUser display name'], ]); - /** @var Room|MockObject $room */ + /** @var Room&MockObject $room */ $room = $this->createMock(Room::class); - /** @var Participant|MockObject $participant */ + /** @var Participant&MockObject $participant */ $participant = $this->createMock(Participant::class); - /** @var IL10N|MockObject $l */ + /** @var IL10N&MockObject $l */ $l = $this->createMock(IL10N::class); $chatMessage = new Message($room, $participant, $comment, $l); $chatMessage->setMessage('Mention @me to @testUser', []); @@ -366,7 +359,7 @@ public function testGetRichMessageWithNonExistingUserMention() { $this->assertEquals($expectedMessageParameters, $chatMessage->getMessageParameters()); } - public function testGetRichMessageWhenDisplayNameCanNotBeResolved() { + public function testGetRichMessageWhenDisplayNameCanNotBeResolved(): void { $mentions = [ ['type' => 'user', 'id' => 'testUser'], ]; @@ -381,11 +374,11 @@ public function testGetRichMessageWhenDisplayNameCanNotBeResolved() { ->with('testUser') ->willReturn('existing user but does not resolve later'); - /** @var Room|MockObject $room */ + /** @var Room&MockObject $room */ $room = $this->createMock(Room::class); - /** @var Participant|MockObject $participant */ + /** @var Participant&MockObject $participant */ $participant = $this->createMock(Participant::class); - /** @var IL10N|MockObject $l */ + /** @var IL10N&MockObject $l */ $l = $this->createMock(IL10N::class); $chatMessage = new Message($room, $participant, $comment, $l); $chatMessage->setMessage('Mention to @testUser', []); @@ -410,7 +403,7 @@ public function testGetRichMessageWithAtAll(): void { ]; $comment = $this->newComment($mentions); - /** @var Room|MockObject $room */ + /** @var Room&MockObject $room */ $room = $this->createMock(Room::class); $room->expects($this->once()) ->method('getType') @@ -421,9 +414,9 @@ public function testGetRichMessageWithAtAll(): void { $room->expects($this->once()) ->method('getDisplayName') ->willReturn('name'); - /** @var Participant|MockObject $participant */ + /** @var Participant&MockObject $participant */ $participant = $this->createMock(Participant::class); - /** @var IL10N|MockObject $l */ + /** @var IL10N&MockObject $l */ $l = $this->createMock(IL10N::class); $chatMessage = new Message($room, $participant, $comment, $l); $chatMessage->setMessage('Mention to @all', []); @@ -454,11 +447,11 @@ public function testGetRichMessageWithFederatedUserMention(): void { ]; $comment = $this->newComment($mentions); - /** @var Room|MockObject $room */ + /** @var Room&MockObject $room */ $room = $this->createMock(Room::class); - /** @var Participant|MockObject $participant */ + /** @var Participant&MockObject $participant */ $participant = $this->createMock(Participant::class); - /** @var IL10N|MockObject $l */ + /** @var IL10N&MockObject $l */ $l = $this->createMock(IL10N::class); $chatMessage = new Message($room, $participant, $comment, $l); $chatMessage->setMessage('Mention to @"federated_user/testUser@example.tld"', []); @@ -495,11 +488,11 @@ public function testGetRichMessageWhenAGuestWithoutNameIsMentioned(): void { ]; $comment = $this->newComment($mentions); - /** @var Room|MockObject $room */ + /** @var Room&MockObject $room */ $room = $this->createMock(Room::class); - /** @var Participant|MockObject $participant */ + /** @var Participant&MockObject $participant */ $participant = $this->createMock(Participant::class); - /** @var IL10N|MockObject $l */ + /** @var IL10N&MockObject $l */ $l = $this->createMock(IL10N::class); $this->participantService->method('getParticipantByActor') @@ -534,11 +527,11 @@ public function testGetRichMessageWhenAGuestWithoutNameIsMentionedMultipleTimes( ]; $comment = $this->newComment($mentions); - /** @var Room|MockObject $room */ + /** @var Room&MockObject $room */ $room = $this->createMock(Room::class); - /** @var Participant|MockObject $participant */ + /** @var Participant&MockObject $participant */ $participant = $this->createMock(Participant::class); - /** @var IL10N|MockObject $l */ + /** @var IL10N&MockObject $l */ $l = $this->createMock(IL10N::class); $this->participantService->method('getParticipantByActor') @@ -573,11 +566,11 @@ public function testGetRichMessageWhenAGuestWithANameIsMentionedMultipleTimes(): ]; $comment = $this->newComment($mentions); - /** @var Room|MockObject $room */ + /** @var Room&MockObject $room */ $room = $this->createMock(Room::class); - /** @var Participant|MockObject $participant */ + /** @var Participant&MockObject $participant */ $participant = $this->createMock(Participant::class); - /** @var IL10N|MockObject $l */ + /** @var IL10N&MockObject $l */ $l = $this->createMock(IL10N::class); $attendee = Attendee::fromRow([ diff --git a/tests/php/Chat/SystemMessage/ListenerTest.php b/tests/php/Chat/SystemMessage/ListenerTest.php index 820ea4c5b6a..ab5a8d6c577 100644 --- a/tests/php/Chat/SystemMessage/ListenerTest.php +++ b/tests/php/Chat/SystemMessage/ListenerTest.php @@ -54,31 +54,20 @@ class ListenerTest extends TestCase { public const DUMMY_REFERENCE_ID = 'DUMMY_REFERENCE_ID'; - protected ?Listener $listener = null; - - /** @var IRequest|MockObject */ - protected $request; - /** @var ChatManager|MockObject */ - protected $chatManager; - /** @var IUserSession|MockObject */ - protected $userSession; - /** @var ISession|MockObject */ - protected $session; - /** @var TalkSession|MockObject */ - protected $talkSession; - /** @var ITimeFactory|MockObject */ - protected $timeFactory; - /** @var IEventDispatcher|MockObject */ - protected $eventDispatcher; - /** @var Manager|MockObject */ - protected $manager; - /** @var ParticipantService|MockObject */ - protected $participantService; - /** @var MessageParser|MockObject */ - protected $messageParser; - protected LoggerInterface|MockObject $logger; + protected IRequest&MockObject $request; + protected ChatManager&MockObject $chatManager; + protected IUserSession&MockObject $userSession; + protected ISession&MockObject $session; + protected TalkSession&MockObject $talkSession; + protected ITimeFactory&MockObject $timeFactory; + protected IEventDispatcher&MockObject $eventDispatcher; + protected Manager&MockObject $manager; + protected ParticipantService&MockObject $participantService; + protected MessageParser&MockObject $messageParser; + protected LoggerInterface&MockObject $logger; protected ?array $handlers = null; protected ?\DateTime $dummyTime = null; + protected ?Listener $listener = null; protected function setUp(): void { parent::setUp(); diff --git a/tests/php/Collaboration/Collaborators/RoomPluginTest.php b/tests/php/Collaboration/Collaborators/RoomPluginTest.php index 7077ad1294b..60037bb0be4 100644 --- a/tests/php/Collaboration/Collaborators/RoomPluginTest.php +++ b/tests/php/Collaboration/Collaborators/RoomPluginTest.php @@ -36,19 +36,15 @@ use OCP\IUser; use OCP\IUserSession; use OCP\Share\IShare; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class RoomPluginTest extends TestCase { + protected ParticipantService&MockObject $participantService; protected ?Manager $manager = null; - /** @var ParticipantService|MockObject */ - protected $participantService; - protected ?IUserSession $userSession = null; - protected ?IUser $user = null; - protected ?ISearchResult $searchResult = null; - protected ?RoomPlugin $plugin = null; public function setUp(): void { @@ -234,14 +230,6 @@ public static function dataSearch(): array { /** * @dataProvider dataSearch - * - * @param string $searchTerm - * @param int $limit - * @param int $offset - * @param array $roomsForParticipant - * @param array $expectedMatchesExact - * @param array $expectedMatches - * @param bool $expectedHasMoreResults */ public function testSearch( string $searchTerm, diff --git a/tests/php/Collaboration/Reference/TalkReferenceProviderTest.php b/tests/php/Collaboration/Reference/TalkReferenceProviderTest.php index 61b6080652b..a54c0ce0cdb 100644 --- a/tests/php/Collaboration/Reference/TalkReferenceProviderTest.php +++ b/tests/php/Collaboration/Reference/TalkReferenceProviderTest.php @@ -1,6 +1,5 @@ @@ -36,20 +35,13 @@ use Test\TestCase; class TalkReferenceProviderTest extends TestCase { - /** @var IURLGenerator|MockObject */ - protected $urlGenerator; - /** @var Manager|MockObject */ - protected $roomManager; - /** @var ParticipantService|MockObject */ - protected $participantService; - /** @var ChatManager|MockObject */ - protected $chatManager; - /** @var AvatarService|MockObject */ - protected $avatarService; - /** @var MessageParser|MockObject */ - protected $messageParser; - /** @var IL10N|MockObject */ - protected $l; + protected IURLGenerator&MockObject $urlGenerator; + protected Manager&MockObject $roomManager; + protected ParticipantService&MockObject $participantService; + protected ChatManager&MockObject $chatManager; + protected AvatarService&MockObject $avatarService; + protected MessageParser&MockObject $messageParser; + protected IL10N&MockObject $l; protected ?TalkReferenceProvider $provider = null; public function setUp(): void { @@ -90,9 +82,6 @@ public static function dataGetTalkAppLinkToken(): array { /** * @dataProvider dataGetTalkAppLinkToken - * @param string $reference - * @param array|null $expected - * @return void */ public function testGetTalkAppLinkToken(string $reference, ?array $expected): void { $this->urlGenerator->expects($this->any()) diff --git a/tests/php/Collaboration/Resources/ConversationProviderTest.php b/tests/php/Collaboration/Resources/ConversationProviderTest.php index ac91faab8ef..39bbd8be6d5 100644 --- a/tests/php/Collaboration/Resources/ConversationProviderTest.php +++ b/tests/php/Collaboration/Resources/ConversationProviderTest.php @@ -41,16 +41,11 @@ use Test\TestCase; class ConversationProviderTest extends TestCase { - /** @var Manager|MockObject */ - protected $manager; - /** @var AvatarService|MockObject */ - protected $avatarService; - /** @var ParticipantService|MockObject */ - protected $participantService; - /** @var IUserSession|MockObject */ - protected $userSession; - /** @var IURLGenerator|MockObject */ - protected $urlGenerator; + protected Manager&MockObject $manager; + protected AvatarService&MockObject $avatarService; + protected ParticipantService&MockObject $participantService; + protected IUserSession&MockObject $userSession; + protected IURLGenerator&MockObject $urlGenerator; protected ?ConversationProvider $provider = null; public function setUp(): void { @@ -165,7 +160,6 @@ public static function dataCanAccessResourceYes(): array { /** * @dataProvider dataCanAccessResourceYes - * @param int $participantType */ public function testCanAccessResourceYes(int $participantType): void { $user = $this->createMock(IUser::class); diff --git a/tests/php/Command/Signaling/AddTest.php b/tests/php/Command/Signaling/AddTest.php index 2434c9f3e4d..b379294f88f 100644 --- a/tests/php/Command/Signaling/AddTest.php +++ b/tests/php/Command/Signaling/AddTest.php @@ -1,4 +1,6 @@ * @@ -24,22 +26,16 @@ use OCA\Talk\Command\Signaling\Add; use OCP\IConfig; +use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Test\TestCase; class AddTest extends TestCase { - /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ - private $config; - - /** @var Add|\PHPUnit_Framework_MockObject_MockObject */ - private $command; - - /** @var InputInterface|\PHPUnit_Framework_MockObject_MockObject */ - private $input; - - /** @var OutputInterface|\PHPUnit_Framework_MockObject_MockObject */ - private $output; + protected IConfig&MockObject $config; + protected InputInterface&MockObject $input; + protected OutputInterface&MockObject $output; + protected Add $command; public function setUp(): void { parent::setUp(); @@ -52,7 +48,7 @@ public function setUp(): void { $this->output = $this->createMock(OutputInterface::class); } - public function testServerEmptyString() { + public function testServerEmptyString(): void { $this->input->method('getArgument') ->willReturnCallback(function ($arg) { if ($arg === 'server') { @@ -71,10 +67,10 @@ public function testServerEmptyString() { $this->config->expects($this->never()) ->method('setAppValue'); - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } - public function testSecretEmptyString() { + public function testSecretEmptyString(): void { $this->input->method('getArgument') ->willReturnCallback(function ($arg) { if ($arg === 'server') { @@ -93,10 +89,10 @@ public function testSecretEmptyString() { $this->config->expects($this->never()) ->method('setAppValue'); - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } - public function testAddServerToEmptyList() { + public function testAddServerToEmptyList(): void { $this->input->method('getArgument') ->willReturnCallback(function ($arg) { if ($arg === 'server') { @@ -132,10 +128,10 @@ public function testAddServerToEmptyList() { ->method('writeln') ->with($this->equalTo('Added signaling server wss://signaling.test.com.')); - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } - public function testAddServerToNonEmptyList() { + public function testAddServerToNonEmptyList(): void { $this->input->method('getArgument') ->willReturnCallback(function ($arg) { if ($arg === 'server') { @@ -183,6 +179,6 @@ public function testAddServerToNonEmptyList() { ->method('writeln') ->with($this->equalTo('Added signaling server wss://signaling2.test.com.')); - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } } diff --git a/tests/php/Command/Signaling/DeleteTest.php b/tests/php/Command/Signaling/DeleteTest.php index 492fc0aa618..63aa86a3dcb 100644 --- a/tests/php/Command/Signaling/DeleteTest.php +++ b/tests/php/Command/Signaling/DeleteTest.php @@ -1,4 +1,6 @@ * @@ -24,22 +26,16 @@ use OCA\Talk\Command\Signaling\Delete; use OCP\IConfig; +use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Test\TestCase; class DeleteTest extends TestCase { - /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ - private $config; - - /** @var Delete|\PHPUnit_Framework_MockObject_MockObject */ - private $command; - - /** @var InputInterface|\PHPUnit_Framework_MockObject_MockObject */ - private $input; - - /** @var OutputInterface|\PHPUnit_Framework_MockObject_MockObject */ - private $output; + protected IConfig&MockObject $config; + protected InputInterface&MockObject $input; + protected OutputInterface&MockObject $output; + protected Delete $command; public function setUp(): void { parent::setUp(); @@ -52,7 +48,7 @@ public function setUp(): void { $this->output = $this->createMock(OutputInterface::class); } - public function testDeleteIfEmpty() { + public function testDeleteIfEmpty(): void { $this->input->method('getArgument') ->with('server') ->willReturn('wss://signaling.example.com'); @@ -74,10 +70,10 @@ public function testDeleteIfEmpty() { ->method('writeln') ->with($this->equalTo('There is nothing to delete.')); - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } - public function testDelete() { + public function testDelete(): void { $this->input->method('getArgument') ->with('server') ->willReturn('wss://signaling2.test.com'); @@ -124,10 +120,10 @@ public function testDelete() { ->method('writeln') ->with($this->equalTo('Deleted wss://signaling2.test.com.')); - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } - public function testNothingToDelete() { + public function testNothingToDelete(): void { $this->input->method('getArgument') ->with('server') ->willReturn('wss://signaling4.test.com'); @@ -162,6 +158,6 @@ public function testNothingToDelete() { ->method('writeln') ->with($this->equalTo('There is nothing to delete.')); - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } } diff --git a/tests/php/Command/Signaling/ListCommandTest.php b/tests/php/Command/Signaling/ListCommandTest.php index 1d7ed33a2e6..fb77e2b48a3 100644 --- a/tests/php/Command/Signaling/ListCommandTest.php +++ b/tests/php/Command/Signaling/ListCommandTest.php @@ -1,4 +1,6 @@ * @@ -24,22 +26,16 @@ use OCA\Talk\Command\Signaling\ListCommand; use OCP\IConfig; +use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Test\TestCase; class ListCommandTest extends TestCase { - /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ - private $config; - - /** @var ListCommand|\PHPUnit_Framework_MockObject_MockObject */ - private $command; - - /** @var InputInterface|\PHPUnit_Framework_MockObject_MockObject */ - private $input; - - /** @var OutputInterface|\PHPUnit_Framework_MockObject_MockObject */ - private $output; + protected IConfig&MockObject $config; + protected InputInterface&MockObject $input; + protected OutputInterface&MockObject $output; + protected ListCommand&MockObject $command; public function setUp(): void { parent::setUp(); @@ -55,7 +51,7 @@ public function setUp(): void { $this->output = $this->createMock(OutputInterface::class); } - public function testEmptyAppConfig() { + public function testEmptyAppConfig(): void { $this->config->expects($this->once()) ->method('getAppValue') ->with('spreed', 'signaling_servers') @@ -69,10 +65,10 @@ public function testEmptyAppConfig() { $this->equalTo([]) ); - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } - public function testAppConfigDataChanges() { + public function testAppConfigDataChanges(): void { $this->config->expects($this->once()) ->method('getAppValue') ->with('spreed', 'signaling_servers') @@ -102,6 +98,6 @@ public function testAppConfigDataChanges() { ]) ); - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } } diff --git a/tests/php/Command/Stun/AddTest.php b/tests/php/Command/Stun/AddTest.php index 5ac4c87525d..f8d49fac504 100644 --- a/tests/php/Command/Stun/AddTest.php +++ b/tests/php/Command/Stun/AddTest.php @@ -1,4 +1,6 @@ * @@ -24,22 +26,16 @@ use OCA\Talk\Command\Stun\Add; use OCP\IConfig; +use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Test\TestCase; class AddTest extends TestCase { - /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ - private $config; - - /** @var Add|\PHPUnit_Framework_MockObject_MockObject */ - private $command; - - /** @var InputInterface|\PHPUnit_Framework_MockObject_MockObject */ - private $input; - - /** @var OutputInterface|\PHPUnit_Framework_MockObject_MockObject */ - private $output; + protected IConfig&MockObject $config; + protected InputInterface&MockObject $input; + protected OutputInterface&MockObject $output; + protected Add $command; public function setUp(): void { parent::setUp(); @@ -52,7 +48,7 @@ public function setUp(): void { $this->output = $this->createMock(OutputInterface::class); } - public function testMalformedServerString() { + public function testMalformedServerString(): void { $this->input->method('getArgument') ->with('server') ->willReturn('stun.test.com'); @@ -62,10 +58,10 @@ public function testMalformedServerString() { $this->config->expects($this->never()) ->method('setAppValue'); - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } - public function testAddServerToEmptyList() { + public function testAddServerToEmptyList(): void { $this->input->method('getArgument') ->with('server') ->willReturn('stun.test.com:443'); @@ -83,10 +79,10 @@ public function testAddServerToEmptyList() { ->method('writeln') ->with($this->equalTo('Added stun.test.com:443.')); - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } - public function testAddServerToNonEmptyList() { + public function testAddServerToNonEmptyList(): void { $this->input->method('getArgument') ->with('server') ->willReturn('stun2.test.com:443'); @@ -104,6 +100,6 @@ public function testAddServerToNonEmptyList() { ->method('writeln') ->with($this->equalTo('Added stun2.test.com:443.')); - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } } diff --git a/tests/php/Command/Stun/DeleteTest.php b/tests/php/Command/Stun/DeleteTest.php index be2539fc773..02d0500b54a 100644 --- a/tests/php/Command/Stun/DeleteTest.php +++ b/tests/php/Command/Stun/DeleteTest.php @@ -1,4 +1,6 @@ * @@ -24,22 +26,16 @@ use OCA\Talk\Command\Stun\Delete; use OCP\IConfig; +use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Test\TestCase; class DeleteTest extends TestCase { - /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ - private $config; - - /** @var Delete|\PHPUnit_Framework_MockObject_MockObject */ - private $command; - - /** @var InputInterface|\PHPUnit_Framework_MockObject_MockObject */ - private $input; - - /** @var OutputInterface|\PHPUnit_Framework_MockObject_MockObject */ - private $output; + protected IConfig&MockObject $config; + protected InputInterface&MockObject $input; + protected OutputInterface&MockObject $output; + protected Delete $command; public function setUp(): void { parent::setUp(); @@ -52,7 +48,7 @@ public function setUp(): void { $this->output = $this->createMock(OutputInterface::class); } - public function testAddDefaultServerIfEmpty() { + public function testAddDefaultServerIfEmpty(): void { $this->input->method('getArgument') ->with('server') ->willReturn('stun1.test.com:443'); @@ -71,10 +67,10 @@ public function testAddDefaultServerIfEmpty() { ->method('writeln') ->with($this->equalTo('You deleted all STUN servers. A default STUN server was added.')); - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } - public function testDelete() { + public function testDelete(): void { $this->input->method('getArgument') ->with('server') ->willReturn('stun1.test.com:443'); @@ -93,10 +89,10 @@ public function testDelete() { ->method('writeln') ->with($this->equalTo('Deleted stun1.test.com:443.')); - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } - public function testNothingToDelete() { + public function testNothingToDelete(): void { $this->input->method('getArgument') ->with('server') ->willReturn('stun3.test.com:443'); @@ -115,6 +111,6 @@ public function testNothingToDelete() { ->method('writeln') ->with($this->equalTo('There is nothing to delete.')); - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } } diff --git a/tests/php/Command/Stun/ListCommandTest.php b/tests/php/Command/Stun/ListCommandTest.php index 53c7d67390a..1017593571b 100644 --- a/tests/php/Command/Stun/ListCommandTest.php +++ b/tests/php/Command/Stun/ListCommandTest.php @@ -1,4 +1,6 @@ * @@ -24,22 +26,16 @@ use OCA\Talk\Command\Stun\ListCommand; use OCP\IConfig; +use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Test\TestCase; class ListCommandTest extends TestCase { - /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ - private $config; - - /** @var ListCommand|\PHPUnit_Framework_MockObject_MockObject */ - private $command; - - /** @var InputInterface|\PHPUnit_Framework_MockObject_MockObject */ - private $input; - - /** @var OutputInterface|\PHPUnit_Framework_MockObject_MockObject */ - private $output; + protected IConfig&MockObject $config; + protected InputInterface&MockObject $input; + protected OutputInterface&MockObject $output; + protected ListCommand&MockObject $command; public function setUp(): void { parent::setUp(); @@ -55,7 +51,7 @@ public function setUp(): void { $this->output = $this->createMock(OutputInterface::class); } - public function testEmptyAppConfig() { + public function testEmptyAppConfig(): void { $this->config->expects($this->once()) ->method('getAppValue') ->with('spreed', 'stun_servers') @@ -69,10 +65,10 @@ public function testEmptyAppConfig() { $this->equalTo([]) ); - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } - public function testAppConfigDataChanges() { + public function testAppConfigDataChanges(): void { $this->config->expects($this->once()) ->method('getAppValue') ->with('spreed', 'stun_servers') @@ -92,6 +88,6 @@ public function testAppConfigDataChanges() { ]) ); - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } } diff --git a/tests/php/Command/Turn/AddTest.php b/tests/php/Command/Turn/AddTest.php index 442c6d239c4..9ab25c666ae 100644 --- a/tests/php/Command/Turn/AddTest.php +++ b/tests/php/Command/Turn/AddTest.php @@ -1,4 +1,6 @@ * @@ -24,22 +26,16 @@ use OCA\Talk\Command\Turn\Add; use OCP\IConfig; +use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Test\TestCase; class AddTest extends TestCase { - /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ - private $config; - - /** @var Add|\PHPUnit_Framework_MockObject_MockObject */ - private $command; - - /** @var InputInterface|\PHPUnit_Framework_MockObject_MockObject */ - private $input; - - /** @var OutputInterface|\PHPUnit_Framework_MockObject_MockObject */ - private $output; + protected IConfig&MockObject $config; + protected InputInterface&MockObject $input; + protected OutputInterface&MockObject $output; + protected Add $command; public function setUp(): void { parent::setUp(); @@ -52,7 +48,7 @@ public function setUp(): void { $this->output = $this->createMock(OutputInterface::class); } - public function testServerEmptyString() { + public function testServerEmptyString(): void { $this->input->method('getArgument') ->willReturnCallback(function ($arg) { if ($arg === 'schemes') { @@ -79,10 +75,10 @@ public function testServerEmptyString() { $this->config->expects($this->never()) ->method('setAppValue'); - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } - public function testSecretEmpty() { + public function testSecretEmpty(): void { $this->input->method('getArgument') ->willReturnCallback(function ($arg) { if ($arg === 'schemes') { @@ -109,10 +105,10 @@ public function testSecretEmpty() { $this->config->expects($this->never()) ->method('setAppValue'); - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } - public function testGenerateSecret() { + public function testGenerateSecret(): void { $this->input->method('getArgument') ->willReturnCallback(function ($arg) { if ($arg === 'schemes') { @@ -162,10 +158,10 @@ public function testGenerateSecret() { ->method('writeln') ->with($this->equalTo('Added turn.test.com.')); - $this->invokePrivate($command, 'execute', [$this->input, $this->output]); + self::invokePrivate($command, 'execute', [$this->input, $this->output]); } - public function testSecretAndGenerateSecretOptions() { + public function testSecretAndGenerateSecretOptions(): void { $this->input->method('getArgument') ->willReturnCallback(function ($arg) { if ($arg === 'schemes') { @@ -192,10 +188,10 @@ public function testSecretAndGenerateSecretOptions() { $this->config->expects($this->never()) ->method('setAppValue'); - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } - public function testInvalidSchemesString() { + public function testInvalidSchemesString(): void { $this->input->method('getArgument') ->willReturnCallback(function ($arg) { if ($arg === 'schemes') { @@ -222,10 +218,10 @@ public function testInvalidSchemesString() { $this->config->expects($this->never()) ->method('setAppValue'); - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } - public function testInvalidProtocolsString() { + public function testInvalidProtocolsString(): void { $this->input->method('getArgument') ->willReturnCallback(function ($arg) { if ($arg === 'schemes') { @@ -252,10 +248,10 @@ public function testInvalidProtocolsString() { $this->config->expects($this->never()) ->method('setAppValue'); - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } - public function testAddServerToEmptyList() { + public function testAddServerToEmptyList(): void { $this->input->method('getArgument') ->willReturnCallback(function ($arg) { if ($arg === 'schemes') { @@ -297,10 +293,10 @@ public function testAddServerToEmptyList() { ->method('writeln') ->with($this->equalTo('Added turn.test.com.')); - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } - public function testAddServerToNonEmptyList() { + public function testAddServerToNonEmptyList(): void { $this->input->method('getArgument') ->willReturnCallback(function ($arg) { if ($arg === 'schemes') { @@ -353,10 +349,10 @@ public function testAddServerToNonEmptyList() { ->method('writeln') ->with($this->equalTo('Added turn2.test.com.')); - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } - public function testServerSanitization() { + public function testServerSanitization(): void { $this->input->method('getArgument') ->willReturnCallback(function ($arg) { if ($arg === 'schemes') { @@ -395,6 +391,6 @@ public function testServerSanitization() { ])) ); - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } } diff --git a/tests/php/Command/Turn/DeleteTest.php b/tests/php/Command/Turn/DeleteTest.php index 97065308c29..ac2910d761e 100644 --- a/tests/php/Command/Turn/DeleteTest.php +++ b/tests/php/Command/Turn/DeleteTest.php @@ -1,4 +1,6 @@ * @@ -24,22 +26,16 @@ use OCA\Talk\Command\Turn\Delete; use OCP\IConfig; +use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Test\TestCase; class DeleteTest extends TestCase { - /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ - private $config; - - /** @var Delete|\PHPUnit_Framework_MockObject_MockObject */ - private $command; - - /** @var InputInterface|\PHPUnit_Framework_MockObject_MockObject */ - private $input; - - /** @var OutputInterface|\PHPUnit_Framework_MockObject_MockObject */ - private $output; + protected IConfig&MockObject $config; + protected InputInterface&MockObject $input; + protected OutputInterface&MockObject $output; + protected Delete $command; public function setUp(): void { parent::setUp(); @@ -52,7 +48,7 @@ public function setUp(): void { $this->output = $this->createMock(OutputInterface::class); } - public function testDeleteIfEmpty() { + public function testDeleteIfEmpty(): void { $this->input->method('getArgument') ->willReturnCallback(function ($arg) { if ($arg === 'schemes') { @@ -79,10 +75,10 @@ public function testDeleteIfEmpty() { ->method('writeln') ->with($this->equalTo('There is nothing to delete.')); - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } - public function testDelete() { + public function testDelete(): void { $this->input->method('getArgument') ->willReturnCallback(function ($arg) { if ($arg === 'schemes') { @@ -123,10 +119,10 @@ public function testDelete() { ->method('writeln') ->with($this->equalTo('There is nothing to delete.')); - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } - public function testNothingToDelete() { + public function testNothingToDelete(): void { $this->input->method('getArgument') ->willReturnCallback(function ($arg) { if ($arg === 'schemes') { @@ -191,10 +187,10 @@ public function testNothingToDelete() { ->method('writeln') ->with($this->equalTo('There is nothing to delete.')); - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } - public function testDeleteMatchingSchemes() { + public function testDeleteMatchingSchemes(): void { $this->input->method('getArgument') ->willReturnCallback(function ($arg) { if ($arg === 'schemes') { @@ -241,6 +237,6 @@ public function testDeleteMatchingSchemes() { ->method('writeln') ->with($this->equalTo('Deleted turn.example.com.')); - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } } diff --git a/tests/php/Command/Turn/ListCommandTest.php b/tests/php/Command/Turn/ListCommandTest.php index 81150c7931e..2c265422aac 100644 --- a/tests/php/Command/Turn/ListCommandTest.php +++ b/tests/php/Command/Turn/ListCommandTest.php @@ -1,4 +1,6 @@ * @@ -24,22 +26,16 @@ use OCA\Talk\Command\Turn\ListCommand; use OCP\IConfig; +use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Test\TestCase; class ListCommandTest extends TestCase { - /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ - private $config; - - /** @var ListCommand|\PHPUnit_Framework_MockObject_MockObject */ - private $command; - - /** @var InputInterface|\PHPUnit_Framework_MockObject_MockObject */ - private $input; - - /** @var OutputInterface|\PHPUnit_Framework_MockObject_MockObject */ - private $output; + protected IConfig&MockObject $config; + protected InputInterface&MockObject $input; + protected OutputInterface&MockObject $output; + protected ListCommand&MockObject $command; public function setUp(): void { parent::setUp(); @@ -55,7 +51,7 @@ public function setUp(): void { $this->output = $this->createMock(OutputInterface::class); } - public function testEmptyAppConfig() { + public function testEmptyAppConfig(): void { $this->config->expects($this->once()) ->method('getAppValue') ->with('spreed', 'turn_servers') @@ -69,10 +65,10 @@ public function testEmptyAppConfig() { $this->equalTo([]) ); - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } - public function testAppConfigDataChanges() { + public function testAppConfigDataChanges(): void { $this->config->expects($this->once()) ->method('getAppValue') ->with('spreed', 'turn_servers') @@ -108,6 +104,6 @@ public function testAppConfigDataChanges() { ]) ); - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + self::invokePrivate($this->command, 'execute', [$this->input, $this->output]); } } diff --git a/tests/php/ConfigTest.php b/tests/php/ConfigTest.php index 092fbd6b606..7d189b34910 100644 --- a/tests/php/ConfigTest.php +++ b/tests/php/ConfigTest.php @@ -1,4 +1,6 @@ * @@ -58,7 +60,7 @@ private function createConfig(IConfig $config) { return $helper; } - public function testGetStunServers() { + public function testGetStunServers(): void { $servers = [ 'stun1.example.com:443', 'stun2.example.com:129', @@ -81,7 +83,7 @@ public function testGetStunServers() { $this->assertSame($helper->getStunServers(), $servers); } - public function testGetDefaultStunServer() { + public function testGetDefaultStunServer(): void { /** @var MockObject|IConfig $config */ $config = $this->createMock(IConfig::class); $config @@ -99,7 +101,7 @@ public function testGetDefaultStunServer() { $this->assertSame(['stun.nextcloud.com:443'], $helper->getStunServers()); } - public function testGetDefaultStunServerNoInternet() { + public function testGetDefaultStunServerNoInternet(): void { /** @var MockObject|IConfig $config */ $config = $this->createMock(IConfig::class); $config @@ -117,7 +119,7 @@ public function testGetDefaultStunServerNoInternet() { $this->assertSame([], $helper->getStunServers()); } - public function testGenerateTurnSettings() { + public function testGenerateTurnSettings(): void { /** @var MockObject|IConfig $config */ $config = $this->createMock(IConfig::class); $config @@ -198,7 +200,7 @@ public function testGenerateTurnSettings() { ], $settings[2]); } - public function testGenerateTurnSettingsEmpty() { + public function testGenerateTurnSettingsEmpty(): void { /** @var MockObject|IConfig $config */ $config = $this->createMock(IConfig::class); $config @@ -213,7 +215,7 @@ public function testGenerateTurnSettingsEmpty() { $this->assertEquals(0, count($settings)); } - public function testGenerateTurnSettingsEvent() { + public function testGenerateTurnSettingsEvent(): void { /** @var MockObject|IConfig $config */ $config = $this->createMock(IConfig::class); $config @@ -241,7 +243,7 @@ public function testGenerateTurnSettingsEvent() { $secureRandom = $this->createMock(ISecureRandom::class); /** @var IEventDispatcher $dispatcher */ - $dispatcher = \OC::$server->get(IEventDispatcher::class); + $dispatcher = \OCP\Server::get(IEventDispatcher::class); $servers = [ [ @@ -268,7 +270,7 @@ public function testGenerateTurnSettingsEvent() { $this->assertSame($servers, $settings); } - public static function dataGetWebSocketDomainForSignalingServer() { + public static function dataGetWebSocketDomainForSignalingServer(): array { return [ ['http://blabla.nextcloud.com', 'ws://blabla.nextcloud.com'], ['http://blabla.nextcloud.com/', 'ws://blabla.nextcloud.com'], @@ -329,7 +331,7 @@ public static function dataGetWebSocketDomainForSignalingServer() { * @param string $url * @param string $expectedWebSocketDomain */ - public function testGetWebSocketDomainForSignalingServer($url, $expectedWebSocketDomain) { + public function testGetWebSocketDomainForSignalingServer($url, $expectedWebSocketDomain): void { /** @var MockObject|IConfig $config */ $config = $this->createMock(IConfig::class); @@ -341,7 +343,7 @@ public function testGetWebSocketDomainForSignalingServer($url, $expectedWebSocke ); } - public static function dataTicketV2Algorithm() { + public static function dataTicketV2Algorithm(): array { return [ ['ES384'], ['ES256'], @@ -354,11 +356,9 @@ public static function dataTicketV2Algorithm() { /** * @dataProvider dataTicketV2Algorithm - * @param string $algo */ public function testSignalingTicketV2User(string $algo): void { - /** @var IConfig $config */ - $config = \OC::$server->getConfig(); + $config = \OCP\Server::get(IConfig::class); /** @var MockObject|IAppConfig $appConfig */ $appConfig = $this->createMock(IAppConfig::class); /** @var MockObject|ITimeFactory $timeFactory */ @@ -420,11 +420,10 @@ public function testSignalingTicketV2User(string $algo): void { /** * @dataProvider dataTicketV2Algorithm - * @param string $algo */ public function testSignalingTicketV2Anonymous(string $algo): void { /** @var IConfig $config */ - $config = \OC::$server->getConfig(); + $config = \OCP\Server::get(IConfig::class); /** @var MockObject|IAppConfig $appConfig */ $appConfig = $this->createMock(IAppConfig::class); /** @var MockObject|ITimeFactory $timeFactory */ diff --git a/tests/php/Controller/ChatControllerTest.php b/tests/php/Controller/ChatControllerTest.php index feb8588098a..5741f92a6fb 100644 --- a/tests/php/Controller/ChatControllerTest.php +++ b/tests/php/Controller/ChatControllerTest.php @@ -1,5 +1,6 @@ createMock(Participant::class); $date = new \DateTime(); $this->timeFactory->expects($this->once()) ->method('getDateTime') ->willReturn($date); - /** @var IComment|MockObject $comment */ + /** @var IComment&MockObject $comment */ $comment = $this->newComment(42, 'user', $this->userId, $date, 'testMessage'); $this->chatManager->expects($this->once()) ->method('sendMessage') @@ -293,14 +270,14 @@ public function testSendMessageByUser() { $this->assertEquals($expected, $response); } - public function testSendMessageByUserWithReferenceId() { + public function testSendMessageByUserWithReferenceId(): void { $participant = $this->createMock(Participant::class); $date = new \DateTime(); $this->timeFactory->expects($this->once()) ->method('getDateTime') ->willReturn($date); - /** @var IComment|MockObject $comment */ + /** @var IComment&MockObject $comment */ $comment = $this->newComment(42, 'user', $this->userId, $date, 'testMessage'); $this->chatManager->expects($this->once()) ->method('sendMessage') @@ -364,7 +341,7 @@ public function testSendMessageByUserWithReferenceId() { $this->assertEquals($expected, $response); } - public function testSendReplyByUser() { + public function testSendReplyByUser(): void { $participant = $this->createMock(Participant::class); $date = new \DateTime(); @@ -372,10 +349,10 @@ public function testSendReplyByUser() { ->method('getDateTime') ->willReturn($date); - /** @var IComment|MockObject $comment */ + /** @var IComment&MockObject $comment */ $parent = $this->newComment(23, 'users', $this->userId . '2', $date, 'testMessage original'); - /** @var IComment|MockObject $comment */ + /** @var IComment&MockObject $comment */ $comment = $this->newComment(42, 'users', $this->userId, $date, 'testMessage'); $this->chatManager->expects($this->once()) ->method('sendMessage') @@ -490,11 +467,11 @@ public function testSendReplyByUser() { $this->assertEquals($expected, $response); } - public function testSendReplyByUserToNotReplyable() { + public function testSendReplyByUserToNotReplyable(): void { $participant = $this->createMock(Participant::class); $date = new \DateTime(); - /** @var IComment|MockObject $comment */ + /** @var IComment&MockObject $comment */ $parent = $this->newComment(23, 'user', $this->userId . '2', $date, 'testMessage original'); $this->chatManager->expects($this->never()) @@ -526,14 +503,14 @@ public function testSendReplyByUserToNotReplyable() { $this->assertEquals($expected, $response); } - public function testSendMessageByUserNotJoinedButInRoom() { + public function testSendMessageByUserNotJoinedButInRoom(): void { $participant = $this->createMock(Participant::class); $date = new \DateTime(); $this->timeFactory->expects($this->once()) ->method('getDateTime') ->willReturn($date); - /** @var IComment|MockObject $comment */ + /** @var IComment&MockObject $comment */ $comment = $this->newComment(23, 'user', $this->userId, $date, 'testMessage'); $this->chatManager->expects($this->once()) ->method('sendMessage') @@ -595,7 +572,7 @@ public function testSendMessageByUserNotJoinedButInRoom() { $this->assertEquals($expected, $response); } - public function testSendMessageByGuest() { + public function testSendMessageByGuest(): void { $this->userId = null; $this->recreateChatController(); @@ -612,7 +589,7 @@ public function testSendMessageByGuest() { $this->timeFactory->expects($this->once()) ->method('getDateTime') ->willReturn($date); - /** @var IComment|MockObject $comment */ + /** @var IComment&MockObject $comment */ $comment = $this->newComment(64, 'guest', sha1('testSpreedSession'), $date, 'testMessage'); $this->chatManager->expects($this->once()) ->method('sendMessage') @@ -674,7 +651,7 @@ public function testSendMessageByGuest() { $this->assertEquals($expected, $response); } - public function testShareObjectToChatByUser() { + public function testShareObjectToChatByUser(): void { $participant = $this->createMock(Participant::class); $this->avatarService->method('getAvatarUrl') @@ -692,7 +669,7 @@ public function testShareObjectToChatByUser() { $this->timeFactory->expects($this->once()) ->method('getDateTime') ->willReturn($date); - /** @var IComment|MockObject $comment */ + /** @var IComment&MockObject $comment */ $comment = $this->newComment(42, 'user', $this->userId, $date, 'testMessage'); $this->chatManager->expects($this->once()) ->method('addSystemMessage') @@ -768,7 +745,7 @@ public function testShareObjectToChatByUser() { $this->assertEquals($expected->getData(), $response->getData()); } - public function testReceiveHistoryByUser() { + public function testReceiveHistoryByUser(): void { $offset = 23; $limit = 4; $this->chatManager->expects($this->once()) @@ -837,7 +814,7 @@ public function testReceiveHistoryByUser() { $this->assertEquals($expected, $response); } - public function testReceiveMessagesByUserNotJoinedButInRoom() { + public function testReceiveMessagesByUserNotJoinedButInRoom(): void { $participant = $this->createMock(Participant::class); $offset = 23; @@ -906,7 +883,7 @@ public function testReceiveMessagesByUserNotJoinedButInRoom() { $this->assertEquals($expected, $response); } - public function testReceiveMessagesByGuest() { + public function testReceiveMessagesByGuest(): void { $this->userId = null; $this->recreateChatController(); @@ -978,7 +955,7 @@ public function testReceiveMessagesByGuest() { $this->assertEquals($expected, $response); } - public function testWaitForNewMessagesByUser() { + public function testWaitForNewMessagesByUser(): void { $testUser = $this->createMock(IUser::class); $testUser->expects($this->any()) ->method('getUID') @@ -1058,7 +1035,7 @@ public function testWaitForNewMessagesByUser() { $this->assertEquals($expected, $response); } - public function testWaitForNewMessagesTimeoutExpired() { + public function testWaitForNewMessagesTimeoutExpired(): void { $participant = $this->createMock(Participant::class); $testUser = $this->createMock(IUser::class); $testUser->expects($this->any()) @@ -1086,7 +1063,7 @@ public function testWaitForNewMessagesTimeoutExpired() { $this->assertEquals($expected, $response); } - public function testWaitForNewMessagesTimeoutTooLarge() { + public function testWaitForNewMessagesTimeoutTooLarge(): void { $participant = $this->createMock(Participant::class); $testUser = $this->createMock(IUser::class); $testUser->expects($this->any()) @@ -1115,7 +1092,7 @@ public function testWaitForNewMessagesTimeoutTooLarge() { $this->assertEquals($expected, $response); } - public static function dataMentions() { + public static function dataMentions(): array { return [ ['tes', 10, ['exact' => []], []], [ @@ -1146,7 +1123,7 @@ public static function dataMentions() { /** * @dataProvider dataMentions */ - public function testMentions($search, $limit, $result, $expected) { + public function testMentions(string $search, int $limit, array $result, array $expected): void { $participant = $this->createMock(Participant::class); $this->room->expects($this->any()) ->method('getId') diff --git a/tests/php/Controller/SignalingControllerTest.php b/tests/php/Controller/SignalingControllerTest.php index 458a9bfa13e..cce5d4a188e 100644 --- a/tests/php/Controller/SignalingControllerTest.php +++ b/tests/php/Controller/SignalingControllerTest.php @@ -77,37 +77,24 @@ protected function getInputStream(): string { * @group DB */ class SignalingControllerTest extends TestCase { - private IConfig $serverConfig; - private ?Config $config = null; - /** @var TalkSession|MockObject */ - private $session; - /** @var \OCA\Talk\Signaling\Manager|MockObject */ - private $signalingManager; - /** @var Manager|MockObject */ - protected $manager; - /** @var CertificateService|MockObject */ - protected $certificateService; - /** @var ParticipantService|MockObject */ - protected $participantService; - /** @var SessionService|MockObject */ - protected $sessionService; - /** @var IDBConnection|MockObject */ - protected $dbConnection; - /** @var Messages|MockObject */ - protected $messages; - /** @var IUserManager|MockObject */ - protected $userManager; - /** @var ITimeFactory|MockObject */ - protected $timeFactory; - /** @var IClientService|MockObject */ - protected $clientService; - private ?string $userId = null; - private ?ISecureRandom $secureRandom = null; - private ?IEventDispatcher $dispatcher = null; - /** @var IThrottler|MockObject */ - private $throttler; - /** @var LoggerInterface|MockObject */ - private $logger; + protected TalkSession&MockObject $session; + protected \OCA\Talk\Signaling\Manager&MockObject $signalingManager; + protected Manager|MockObject $manager; + protected CertificateService&MockObject $certificateService; + protected ParticipantService&MockObject $participantService; + protected SessionService&MockObject $sessionService; + protected Messages&MockObject $messages; + protected IUserManager&MockObject $userManager; + protected ITimeFactory&MockObject $timeFactory; + protected IClientService&MockObject $clientService; + protected IThrottler&MockObject $throttler; + protected LoggerInterface&MockObject $logger; + protected IDBConnection $dbConnection; + protected IConfig $serverConfig; + protected ?Config $config = null; + protected ?string $userId = null; + protected ?ISecureRandom $secureRandom = null; + protected ?IEventDispatcher $dispatcher = null; private ?CustomInputSignalingController $controller = null; @@ -115,23 +102,23 @@ public function setUp(): void { parent::setUp(); $this->userId = 'testUser'; - $this->secureRandom = \OC::$server->getSecureRandom(); + $this->secureRandom = \OCP\Server::get(ISecureRandom::class); /** @var MockObject|IAppConfig $appConfig */ $appConfig = $this->createMock(IAppConfig::class); $timeFactory = $this->createMock(ITimeFactory::class); $groupManager = $this->createMock(IGroupManager::class); - $this->serverConfig = \OC::$server->getConfig(); + $this->serverConfig = \OCP\Server::get(IConfig::class); $this->serverConfig->setAppValue('spreed', 'signaling_servers', json_encode([ 'secret' => 'MySecretValue', ])); $this->serverConfig->setAppValue('spreed', 'signaling_ticket_secret', 'the-app-ticket-secret'); $this->serverConfig->setUserValue($this->userId, 'spreed', 'signaling_ticket_secret', 'the-user-ticket-secret'); $this->userManager = $this->createMock(IUserManager::class); - $this->dispatcher = \OC::$server->get(IEventDispatcher::class); + $this->dispatcher = \OCP\Server::get(IEventDispatcher::class); $urlGenerator = $this->createMock(IURLGenerator::class); $this->config = new Config($this->serverConfig, $appConfig, $this->secureRandom, $groupManager, $this->userManager, $urlGenerator, $timeFactory, $this->dispatcher); $this->session = $this->createMock(TalkSession::class); - $this->dbConnection = \OC::$server->getDatabaseConnection(); + $this->dbConnection = \OCP\Server::get(IDBConnection::class); $this->signalingManager = $this->createMock(\OCA\Talk\Signaling\Manager::class); $this->manager = $this->createMock(Manager::class); $this->certificateService = $this->createMock(CertificateService::class); @@ -185,7 +172,7 @@ private function calculateBackendChecksum($data, $random) { return $hash; } - public function testBackendChecksums() { + public function testBackendChecksums(): void { // Test checksum generation / validation with the example from the API documentation. $data = '{"type":"auth","auth":{"version":"1.0","params":{"hello":"world"}}}'; $random = 'afb6b872ab03e3376b31bf0af601067222ff7990335ca02d327071b73c0119c6'; @@ -206,7 +193,7 @@ private function performBackendRequest($data) { return $this->controller->backend(); } - public function testBackendChecksumValidation() { + public function testBackendChecksumValidation(): void { $data = '{}'; // Random and checksum missing. @@ -251,7 +238,7 @@ public function testBackendChecksumValidation() { ], $result->getData()); } - public function testBackendUnsupportedType() { + public function testBackendUnsupportedType(): void { $result = $this->performBackendRequest([ 'type' => 'unsupported-type', ]); @@ -264,7 +251,7 @@ public function testBackendUnsupportedType() { ], $result->getData()); } - public function testBackendAuth() { + public function testBackendAuth(): void { // Check validating of tickets. $result = $this->performBackendRequest([ 'type' => 'auth', @@ -369,7 +356,7 @@ public function testBackendAuth() { ], $result->getData()); } - public function testBackendRoomUnknown() { + public function testBackendRoomUnknown(): void { $roomToken = 'the-room'; $room = $this->createMock(Room::class); $this->manager->expects($this->once()) @@ -394,7 +381,7 @@ public function testBackendRoomUnknown() { ], $result->getData()); } - public function testBackendRoomInvited() { + public function testBackendRoomInvited(): void { $roomToken = 'the-room'; $roomName = 'the-room-name'; $room = $this->createMock(Room::class); @@ -455,7 +442,7 @@ public function testBackendRoomInvited() { ], $result->getData()); } - public function testBackendRoomUserPublic() { + public function testBackendRoomUserPublic(): void { $roomToken = 'the-room'; $roomName = 'the-room-name'; $room = $this->createMock(Room::class); @@ -516,7 +503,7 @@ public function testBackendRoomUserPublic() { ], $result->getData()); } - public function testBackendRoomModeratorPublic() { + public function testBackendRoomModeratorPublic(): void { $roomToken = 'the-room'; $roomName = 'the-room-name'; $room = $this->createMock(Room::class); @@ -582,7 +569,7 @@ public function testBackendRoomModeratorPublic() { ], $result->getData()); } - public function testBackendRoomAnonymousPublic() { + public function testBackendRoomAnonymousPublic(): void { $roomToken = 'the-room'; $roomName = 'the-room-name'; $sessionId = 'the-session'; @@ -644,7 +631,7 @@ public function testBackendRoomAnonymousPublic() { ], $result->getData()); } - public function testBackendRoomInvitedPublic() { + public function testBackendRoomInvitedPublic(): void { $roomToken = 'the-room'; $roomName = 'the-room-name'; $sessionId = 'the-session'; @@ -721,11 +708,8 @@ public static function dataBackendRoomUserPublicPermissions(): array { /** * @dataProvider dataBackendRoomUserPublicPermissions - * - * @param int $permissions - * @param array $expectedBackendPermissions */ - public function testBackendRoomUserPublicPermissions(int $permissions, array $expectedBackendPermissions) { + public function testBackendRoomUserPublicPermissions(int $permissions, array $expectedBackendPermissions): void { $roomToken = 'the-room'; $roomName = 'the-room-name'; $room = $this->createMock(Room::class); @@ -782,7 +766,7 @@ public function testBackendRoomUserPublicPermissions(int $permissions, array $ex ], $result->getData()); } - public function testBackendRoomAnonymousOneToOne() { + public function testBackendRoomAnonymousOneToOne(): void { $roomToken = 'the-room'; $sessionId = 'the-session'; $room = $this->createMock(Room::class); @@ -812,7 +796,7 @@ public function testBackendRoomAnonymousOneToOne() { ], $result->getData()); } - public function testBackendRoomSessionFromEvent() { + public function testBackendRoomSessionFromEvent(): void { $this->dispatcher->addListener(BeforeSignalingResponseSentEvent::class, static function (BeforeSignalingResponseSentEvent $event) { $room = $event->getRoom(); $event->setSession([ @@ -885,7 +869,7 @@ public function testBackendRoomSessionFromEvent() { ], $result->getData()); } - public function testBackendPingUser() { + public function testBackendPingUser(): void { $sessionId = 'the-session'; $this->timeFactory->method('getTime') @@ -913,7 +897,7 @@ public function testBackendPingUser() { ], $result->getData()); } - public function testBackendPingAnonymous() { + public function testBackendPingAnonymous(): void { $sessionId = 'the-session'; $this->timeFactory->method('getTime') @@ -941,7 +925,7 @@ public function testBackendPingAnonymous() { ], $result->getData()); } - public function testBackendPingMixedAndInactive() { + public function testBackendPingMixedAndInactive(): void { $sessionId = 'the-session'; $this->timeFactory->method('getTime') @@ -978,21 +962,21 @@ public function testBackendPingMixedAndInactive() { } - public function testLeaveRoomWithOldSession() { + public function testLeaveRoomWithOldSession(): void { // Make sure that leaving a user with an old session id doesn't remove // the current user from the room if he re-joined in the meantime. - $dbConnection = \OC::$server->getDatabaseConnection(); - $dispatcher = \OC::$server->get(IEventDispatcher::class); + $dbConnection = \OCP\Server::get(IDBConnection::class); + $dispatcher = \OCP\Server::get(IEventDispatcher::class); /** @var ParticipantService $participantService */ - $participantService = \OC::$server->get(ParticipantService::class); + $participantService = \OCP\Server::get(ParticipantService::class); $this->manager = new Manager( $dbConnection, - \OC::$server->getConfig(), + \OCP\Server::get(IConfig::class), $this->createMock(Config::class), - \OC::$server->get(IAppManager::class), - \OC::$server->get(AttendeeMapper::class), - \OC::$server->get(SessionMapper::class), + \OCP\Server::get(IAppManager::class), + \OCP\Server::get(AttendeeMapper::class), + \OCP\Server::get(SessionMapper::class), $participantService, $this->secureRandom, $this->createMock(IUserManager::class), diff --git a/tests/php/EventDocumentationTest.php b/tests/php/EventDocumentationTest.php index 9ec4e42ed3e..0142ff2dc6c 100644 --- a/tests/php/EventDocumentationTest.php +++ b/tests/php/EventDocumentationTest.php @@ -43,7 +43,6 @@ public static function dataEventDocumentation(): array { /** * @dataProvider dataEventDocumentation - * @param string $eventClass */ public function testEventDocumentation(string $eventClass): void { $reflectionClass = new \ReflectionClass($eventClass); diff --git a/tests/php/Federation/FederationTest.php b/tests/php/Federation/FederationTest.php index e0d83b6817c..16c9fd4774c 100644 --- a/tests/php/Federation/FederationTest.php +++ b/tests/php/Federation/FederationTest.php @@ -66,49 +66,29 @@ use Test\TestCase; class FederationTest extends TestCase { - protected ?FederationManager $federationManager = null; - - protected ?BackendNotifier $backendNotifier = null; - - protected ICloudIdManager|MockObject $cloudIdManager; - /** @var ICloudFederationProviderManager|MockObject */ - protected $cloudFederationProviderManager; - - /** @var ICloudFederationFactory|MockObject */ - protected $cloudFederationFactory; - - /** @var Config|MockObject */ - protected $config; - protected IAppConfig|MockObject $appConfig; - /** @var LoggerInterface|MockObject */ - protected $logger; - - /** @var AddressHandler|MockObject */ - protected $addressHandler; - + protected FederationManager&MockObject $federationManager; + protected ICloudIdManager&MockObject $cloudIdManager; + protected ICloudFederationProviderManager&MockObject $cloudFederationProviderManager; + protected ICloudFederationFactory&MockObject $cloudFederationFactory; + protected Config&MockObject $config; + protected IAppConfig&MockObject $appConfig; + protected LoggerInterface&MockObject $logger; + protected AddressHandler&MockObject $addressHandler; + protected IUserManager&MockObject $userManager; + protected IAppManager&MockObject $appManager; + protected IURLGenerator&MockObject $url; + protected INotificationManager&MockObject $notificationManager; + protected AttendeeMapper&MockObject $attendeeMapper; + protected ProxyCacheMessageMapper&MockObject $proxyCacheMessageMapper; + protected ProxyCacheMessageService&MockObject $proxyCacheMessageService; + protected FederationChatNotifier&MockObject $federationChatNotifier; + protected UserConverter&MockObject $userConverter; + protected ICacheFactory&MockObject $cacheFactory; + protected RetryNotificationMapper&MockObject $retryNotificationMapper; + protected ITimeFactory&MockObject $timeFactory; + protected RestrictionValidator&MockObject $restrictionValidator; protected ?CloudFederationProviderTalk $cloudFederationProvider = null; - - /** @var IUserManager|MockObject */ - protected $userManager; - protected IAppManager|MockObject $appManager; - - /** @var IURLGenerator|MockObject */ - protected $url; - - /** @var INotificationManager|MockObject */ - protected $notificationManager; - - /** @var AttendeeMapper|MockObject */ - protected $attendeeMapper; - - protected ProxyCacheMessageMapper|MockObject $proxyCacheMessageMapper; - protected ProxyCacheMessageService|MockObject $proxyCacheMessageService; - protected FederationChatNotifier|MockObject $federationChatNotifier; - protected UserConverter|MockObject $userConverter; - protected ICacheFactory|MockObject $cacheFactory; - protected RetryNotificationMapper|MockObject $retryNotificationMapper; - protected ITimeFactory|MockObject $timeFactory; - protected RestrictionValidator|MockObject $restrictionValidator; + protected ?BackendNotifier $backendNotifier = null; public function setUp(): void { parent::setUp(); @@ -173,7 +153,7 @@ public function setUp(): void { ); } - public function testSendRemoteShareWithOwner() { + public function testSendRemoteShareWithOwner(): void { $cloudShare = $this->createMock(ICloudFederationShare::class); $providerId = '3'; @@ -276,7 +256,7 @@ public function testSendRemoteShareWithOwner() { $this->backendNotifier->sendRemoteShare($providerId, $token, $shareWith, $sharedBy, $shareType, $room, $attendee); } - public function testReceiveRemoteShare() { + public function testReceiveRemoteShare(): void { $providerId = '3'; $token = 'abcdefghijklmno'; $shareWith = 'test@remote.test.local'; @@ -400,7 +380,7 @@ public function testReceiveRemoteShare() { ); } - public function testSendAcceptNotification() { + public function testSendAcceptNotification(): void { $remote = 'https://remote.test.local'; $id = 50; $token = 'abcdefghijklmno'; @@ -447,7 +427,7 @@ public function testSendAcceptNotification() { $this->assertTrue($success); } - public function testSendRejectNotification() { + public function testSendRejectNotification(): void { $remote = 'https://remote.test.local'; $id = 50; $token = 'abcdefghijklmno'; diff --git a/tests/php/Listener/RestrictStartingCallsTest.php b/tests/php/Listener/RestrictStartingCallsTest.php index 1d5238d9a4e..4f82b7bdd82 100644 --- a/tests/php/Listener/RestrictStartingCallsTest.php +++ b/tests/php/Listener/RestrictStartingCallsTest.php @@ -36,10 +36,8 @@ use Test\TestCase; class RestrictStartingCallsTest extends TestCase { - /** @var IConfig|MockObject */ - protected $serverConfig; - /** @var ParticipantService|MockObject */ - protected $participantService; + protected IConfig&MockObject $serverConfig; + protected ParticipantService&MockObject $participantService; protected ?RestrictStartingCalls $listener = null; public function setUp(): void { @@ -63,12 +61,6 @@ public static function dataCheckStartCallPermissions(): array { /** * @dataProvider dataCheckStartCallPermissions - * @param int $roomType - * @param string $roomObjectType - * @param bool $canStart - * @param bool $hasParticipants - * @param bool $throws - * @throws ForbiddenException */ public function testCheckStartCallPermissions(int $roomType, string $roomObjectType, bool $canStart, bool $hasParticipants, bool $throws): void { $room = $this->createMock(Room::class); diff --git a/tests/php/Model/AttendeeMapperTest.php b/tests/php/Model/AttendeeMapperTest.php index e0fea0ea9df..9b2e140dec8 100644 --- a/tests/php/Model/AttendeeMapperTest.php +++ b/tests/php/Model/AttendeeMapperTest.php @@ -27,6 +27,7 @@ use OCA\Talk\Model\AttendeeMapper; use OCA\Talk\Participant; use OCP\AppFramework\Db\DoesNotExistException; +use OCP\IDBConnection; use Test\TestCase; /** @@ -40,7 +41,7 @@ public function setUp(): void { parent::setUp(); $this->attendeeMapper = new AttendeeMapper( - \OC::$server->getDatabaseConnection() + \OCP\Server::get(IDBConnection::class) ); } @@ -355,10 +356,6 @@ public static function dataModifyPermissions(): array { /** * @dataProvider dataModifyPermissions - * @param array $attendees - * @param string $mode - * @param int $permission - * @param array $expected */ public function testModifyPermissions(array $attendees, string $mode, int $permission, array $expected): void { $roomId = 12345678; diff --git a/tests/php/Notification/NotifierTest.php b/tests/php/Notification/NotifierTest.php index 0f9de3c1e00..98846389add 100644 --- a/tests/php/Notification/NotifierTest.php +++ b/tests/php/Notification/NotifierTest.php @@ -1,4 +1,6 @@ * @@ -59,47 +61,28 @@ use Test\TestCase; class NotifierTest extends TestCase { - /** @var IFactory|MockObject */ - protected $lFactory; - /** @var IURLGenerator|MockObject */ - protected $url; - /** @var Config|MockObject */ - protected $config; - /** @var IUserManager|MockObject */ - protected $userManager; - /** @var IGroupManager|MockObject */ - protected $groupManager; - /** @var GuestManager|MockObject */ - protected $guestManager; - /** @var IShareManager|MockObject */ - protected $shareManager; - /** @var Manager|MockObject */ - protected $manager; - /** @var ParticipantService|MockObject */ - protected $participantService; - /** @var AvatarService|MockObject */ - protected $avatarService; - /** @var INotificationManager|MockObject */ - protected $notificationManager; - /** @var CommentsManager|MockObject */ - protected $commentsManager; - protected ProxyCacheMessageMapper|MockObject $proxyCacheMessageMapper; - /** @var MessageParser|MockObject */ - protected $messageParser; - /** @var IRootFolder|MockObject */ - protected $rootFolder; - /** @var ITimeFactory|MockObject */ - protected $timeFactory; - /** @var Definitions|MockObject */ - protected $definitions; + protected IFactory&MockObject $lFactory; + protected IURLGenerator&MockObject $url; + protected Config&MockObject $config; + protected IUserManager&MockObject $userManager; + protected IGroupManager&MockObject $groupManager; + protected GuestManager&MockObject $guestManager; + protected IShareManager&MockObject $shareManager; + protected Manager&MockObject $manager; + protected ParticipantService&MockObject $participantService; + protected AvatarService&MockObject $avatarService; + protected INotificationManager&MockObject $notificationManager; + protected CommentsManager&MockObject $commentsManager; + protected ProxyCacheMessageMapper&MockObject $proxyCacheMessageMapper; + protected MessageParser&MockObject $messageParser; + protected IRootFolder&MockObject $rootFolder; + protected ITimeFactory&MockObject $timeFactory; + protected Definitions&MockObject $definitions; + protected AddressHandler&MockObject $addressHandler; + protected BotServerMapper&MockObject $botServerMapper; + protected FederationManager&MockObject $federationManager; + protected ICloudIdManager&MockObject $cloudIdManager; protected ?Notifier $notifier = null; - /** @var AddressHandler|MockObject */ - protected $addressHandler; - /** @var BotServerMapper|MockObject */ - protected $botServerMapper; - /** @var FederationManager|MockObject */ - protected $federationManager; - protected ICloudIdManager|MockObject $cloudIdManager; public function setUp(): void { parent::setUp(); @@ -160,12 +143,9 @@ public static function dataPrepareOne2One(): array { /** * @dataProvider dataPrepareOne2One - * @param string $uid - * @param string $displayName - * @param string $parsedSubject */ public function testPrepareOne2One(string $uid, string $displayName, string $parsedSubject): void { - /** @var INotification|MockObject $n */ + /** @var INotification&MockObject $n */ $n = $this->createMock(INotification::class); $l = $this->createMock(IL10N::class); $l->expects($this->any()) @@ -260,7 +240,7 @@ public function testPrepareOne2One(string $uid, string $displayName, string $par * @param string $displayName * @param string $parsedSubject */ - public function testPreparingMultipleTimesOnlyGetsTheRoomOnce($uid, $displayName, $parsedSubject) { + public function testPreparingMultipleTimesOnlyGetsTheRoomOnce($uid, $displayName, $parsedSubject): void { $numNotifications = 4; $l = $this->createMock(IL10N::class); @@ -319,7 +299,7 @@ public function testPreparingMultipleTimesOnlyGetsTheRoomOnce($uid, $displayName } public function getNotificationMock(string $parsedSubject, string $uid, string $displayName) { - /** @var INotification|MockObject $n */ + /** @var INotification&MockObject $n */ $n = $this->createMock(INotification::class); $n->expects($this->once()) ->method('setIcon') @@ -369,7 +349,7 @@ public function getNotificationMock(string $parsedSubject, string $uid, string $ return $n; } - public static function dataPrepareGroup() { + public static function dataPrepareGroup(): array { return [ [Room::TYPE_GROUP, 'admin', 'Admin', 'Group', 'Admin invited you to a group conversation: Group'], [Room::TYPE_PUBLIC, 'test', 'Test user', 'Public', 'Test user invited you to a group conversation: Public'], @@ -378,15 +358,10 @@ public static function dataPrepareGroup() { /** * @dataProvider dataPrepareGroup - * @param int $type - * @param string $uid - * @param string $displayName - * @param string $name - * @param string $parsedSubject */ - public function testPrepareGroup($type, $uid, $displayName, $name, $parsedSubject) { + public function testPrepareGroup(int $type, string $uid, string $displayName, string $name, string $parsedSubject): void { $roomId = $type; - /** @var INotification|MockObject $n */ + /** @var INotification&MockObject $n */ $n = $this->createMock(INotification::class); $l = $this->createMock(IL10N::class); $l->expects($this->any()) @@ -879,18 +854,9 @@ public static function dataPrepareChatMessage(): array { /** * @dataProvider dataPrepareChatMessage - * @param string $subject - * @param int $roomType - * @param array $subjectParameters - * @param string $displayName - * @param string $roomName - * @param string $parsedSubject - * @param array $richSubject - * @param bool $deletedUser - * @param null|string $guestName */ - public function testPrepareChatMessage(string $subject, int $roomType, array $subjectParameters, $displayName, string $roomName, string $parsedSubject, array $richSubject, bool $deletedUser = false, ?string $guestName = null, bool $isPushNotification = false) { - /** @var INotification|MockObject $notification */ + public function testPrepareChatMessage(string $subject, int $roomType, array $subjectParameters, ?string $displayName, string $roomName, string $parsedSubject, array $richSubject, bool $deletedUser = false, ?string $guestName = null, bool $isPushNotification = false): void { + /** @var INotification&MockObject $notification */ $notification = $this->createMock(INotification::class); $l = $this->createMock(IL10N::class); $l->expects($this->any()) @@ -1073,7 +1039,7 @@ public function testPrepareChatMessage(string $subject, int $roomType, array $su $this->assertEquals($notification, $this->notifier->prepare($notification, 'de')); } - public static function dataPrepareThrows() { + public static function dataPrepareThrows(): array { return [ ['Incorrect app', 'invalid-app', null, null, null, null, null], 'User can not use Talk' => [AlreadyProcessedException::class, 'spreed', true, null, null, null, null], @@ -1088,18 +1054,9 @@ public static function dataPrepareThrows() { /** * @dataProvider dataPrepareThrows - * - * @param string $message - * @param string $app - * @param bool|null $isDisabledForUser - * @param bool|null $validRoom - * @param string|null $subject - * @param array|null $params - * @param string|null $objectType - * @param string $token */ - public function testPrepareThrows($message, $app, $isDisabledForUser, $validRoom, $subject, $params, $objectType, $token = 'roomToken') { - /** @var INotification|MockObject $n */ + public function testPrepareThrows(string $message, string $app, ?bool $isDisabledForUser, ?bool $validRoom, ?string $subject, ?array $params, ?string $objectType, string $token = 'roomToken'): void { + /** @var INotification&MockObject $n */ $n = $this->createMock(INotification::class); $l = $this->createMock(IL10N::class); diff --git a/tests/php/Recording/BackendNotifierTest.php b/tests/php/Recording/BackendNotifierTest.php index 50ec1a2324b..6ed1c8c103d 100644 --- a/tests/php/Recording/BackendNotifierTest.php +++ b/tests/php/Recording/BackendNotifierTest.php @@ -1,4 +1,6 @@ @@ -75,18 +77,14 @@ protected function doRequest(string $url, array $params, int $retries = 3): void * @group DB */ class BackendNotifierTest extends TestCase { - private ?Config $config = null; - private ?ISecureRandom $secureRandom = null; - /** @var IURLGenerator|MockObject */ - private $urlGenerator; - private ?CustomBackendNotifier $backendNotifier = null; - - /** @var ParticipantService|MockObject */ - private $participantService; - private ?Manager $manager = null; - - private ?string $recordingSecret = null; - private ?string $baseUrl = null; + protected IURLGenerator&MockObject $urlGenerator; + protected ParticipantService $participantService; + protected ?CustomBackendNotifier $backendNotifier = null; + protected ?Config $config = null; + protected ?ISecureRandom $secureRandom = null; + protected ?Manager $manager = null; + protected ?string $recordingSecret = null; + protected ?string $baseUrl = null; public function setUp(): void { parent::setUp(); @@ -193,10 +191,10 @@ private function assertMessageWasSent(Room $room, array $message): void { $this->assertContainsEquals($message, $bodies, json_encode($bodies, JSON_PRETTY_PRINT)); } - public function testStart() { + public function testStart(): void { $userId = 'testUser'; - /** @var IUser|MockObject $testUser */ + /** @var IUser&MockObject $testUser */ $testUser = $this->createMock(IUser::class); $testUser->expects($this->any()) ->method('getUID') @@ -228,10 +226,10 @@ public function testStart() { ]); } - public function testStop() { + public function testStop(): void { $userId = 'testUser'; - /** @var IUser|MockObject $testUser */ + /** @var IUser&MockObject $testUser */ $testUser = $this->createMock(IUser::class); $testUser->expects($this->any()) ->method('getUID') diff --git a/tests/php/Service/AvatarServiceTest.php b/tests/php/Service/AvatarServiceTest.php index 74923de22bc..819f9f16c97 100644 --- a/tests/php/Service/AvatarServiceTest.php +++ b/tests/php/Service/AvatarServiceTest.php @@ -1,7 +1,6 @@ * @@ -43,21 +42,14 @@ * @group DB */ class AvatarServiceTest extends TestCase { - private AvatarService $service; - /** @var IAppData|MockObject */ - private $appData; - /** @var IL10N|MockObject */ - private $l; - /** @var IURLGenerator|MockObject */ - private $url; - /** @var ISecureRandom|MockObject */ - private $random; - /** @var RoomService|MockObject */ - private $roomService; - /** @var IAvatarManager|MockObject */ - private $avatarManager; - /** @var EmojiHelper|MockObject */ - private $emojiHelper; + protected IAppData&MockObject $appData; + protected IL10N&MockObject $l; + protected IURLGenerator&MockObject $url; + protected ISecureRandom&MockObject $random; + protected RoomService&MockObject $roomService; + protected IAvatarManager&MockObject $avatarManager; + protected EmojiHelper $emojiHelper; + protected ?AvatarService $service = null; public function setUp(): void { parent::setUp(); @@ -80,11 +72,19 @@ public function setUp(): void { ); } + public static function dataGetAvatarVersion(): array { + return [ + ['', 'STRING WITH 8 CHARS'], + ['1', '1'], + ['1.png', '1'], + ]; + } + /** * @dataProvider dataGetAvatarVersion */ public function testGetAvatarVersion(string $avatar, string $expected): void { - /** @var Room|MockObject $room */ + /** @var Room&MockObject $room */ $room = $this->createMock(Room::class); $room->method('getAvatar') ->willReturn($avatar); @@ -96,14 +96,6 @@ public function testGetAvatarVersion(string $avatar, string $expected): void { } } - public static function dataGetAvatarVersion(): array { - return [ - ['', 'STRING WITH 8 CHARS'], - ['1', '1'], - ['1.png', '1'], - ]; - } - public static function dataGetFirstCombinedEmoji(): array { return [ ['👋 Hello', '👋'], diff --git a/tests/php/Service/BreakoutRoomServiceTest.php b/tests/php/Service/BreakoutRoomServiceTest.php index e9141575473..bb2b552eb22 100644 --- a/tests/php/Service/BreakoutRoomServiceTest.php +++ b/tests/php/Service/BreakoutRoomServiceTest.php @@ -1,7 +1,6 @@ * @@ -40,26 +39,16 @@ use Test\TestCase; class BreakoutRoomServiceTest extends TestCase { - private BreakoutRoomService $service; - - /** @var Config|MockObject */ - private $config; - /** @var Manager|MockObject */ - private $manager; - /** @var RoomService|MockObject */ - private $roomService; - /** @var ParticipantService|MockObject */ - private $participantService; - /** @var ChatManager|MockObject */ - private $chatManager; - /** @var INotificationManager|MockObject */ - private $notificationManager; - /** @var ITimeFactory|MockObject */ - protected $timeFactory; - /** @var IEventDispatcher|MockObject */ - private $dispatcher; - /** @var IL10N|MockObject */ - private $l; + protected Config&MockObject $config; + protected Manager&MockObject $manager; + protected RoomService&MockObject $roomService; + protected ParticipantService&MockObject $participantService; + protected ChatManager&MockObject $chatManager; + protected INotificationManager&MockObject $notificationManager; + protected ITimeFactory&MockObject $timeFactory; + protected IEventDispatcher&MockObject $dispatcher; + protected IL10N&MockObject $l; + protected BreakoutRoomService $service; public function setUp(): void { parent::setUp(); diff --git a/tests/php/Service/CertificateServiceTest.php b/tests/php/Service/CertificateServiceTest.php index bffc1a0e78a..94f871cbf85 100644 --- a/tests/php/Service/CertificateServiceTest.php +++ b/tests/php/Service/CertificateServiceTest.php @@ -39,7 +39,7 @@ public function setUp(): void { $this->service = new CertificateService($logger); } - public function testGetParsedTlsHost() { + public function testGetParsedTlsHost(): void { $actual = $this->service->getParsedTlsHost("domain.com"); $this->assertEquals($actual, "domain.com"); diff --git a/tests/php/Service/ParticipantServiceTest.php b/tests/php/Service/ParticipantServiceTest.php index aa99a35d607..1c546aac461 100644 --- a/tests/php/Service/ParticipantServiceTest.php +++ b/tests/php/Service/ParticipantServiceTest.php @@ -40,6 +40,7 @@ use OCP\Federation\ICloudIdManager; use OCP\ICacheFactory; use OCP\IConfig; +use OCP\IDBConnection; use OCP\IGroupManager; use OCP\IUserManager; use OCP\Security\ISecureRandom; @@ -50,31 +51,20 @@ * @group DB */ class ParticipantServiceTest extends TestCase { - /** @var IConfig|MockObject */ - protected $serverConfig; - /** @var Config|MockObject */ - protected $talkConfig; + protected IConfig&MockObject $serverConfig; + protected Config&MockObject $talkConfig; protected ?AttendeeMapper $attendeeMapper = null; protected ?SessionMapper $sessionMapper = null; - /** @var SessionService|MockObject */ - protected $sessionService; - /** @var ISecureRandom|MockObject */ - protected $secureRandom; - /** @var IEventDispatcher|MockObject */ - protected $dispatcher; - /** @var IUserManager|MockObject */ - protected $userManager; - protected ICloudIdManager|MockObject $cloudIdManager; - /** @var IGroupManager|MockObject */ - protected $groupManager; - /** @var MembershipService|MockObject */ - protected $membershipService; - /** @var BackendNotifier|MockObject */ - protected $federationBackendNotifier; - /** @var ITimeFactory|MockObject */ - protected $time; - /** @var ICacheFactory|MockObject */ - protected $cacheFactory; + protected SessionService&MockObject $sessionService; + protected ISecureRandom&MockObject $secureRandom; + protected IEventDispatcher&MockObject $dispatcher; + protected IUserManager&MockObject $userManager; + protected ICloudIdManager&MockObject $cloudIdManager; + protected IGroupManager&MockObject $groupManager; + protected MembershipService&MockObject $membershipService; + protected BackendNotifier&MockObject $federationBackendNotifier; + protected ITimeFactory&MockObject $time; + protected ICacheFactory&MockObject $cacheFactory; private ?ParticipantService $service = null; @@ -83,8 +73,8 @@ public function setUp(): void { $this->serverConfig = $this->createMock(IConfig::class); $this->talkConfig = $this->createMock(Config::class); - $this->attendeeMapper = new AttendeeMapper(\OC::$server->getDatabaseConnection()); - $this->sessionMapper = new SessionMapper(\OC::$server->getDatabaseConnection()); + $this->attendeeMapper = new AttendeeMapper(\OCP\Server::get(IDBConnection::class)); + $this->sessionMapper = new SessionMapper(\OCP\Server::get(IDBConnection::class)); $this->sessionService = $this->createMock(SessionService::class); $this->secureRandom = $this->createMock(ISecureRandom::class); $this->dispatcher = $this->createMock(IEventDispatcher::class); @@ -102,7 +92,7 @@ public function setUp(): void { $this->sessionMapper, $this->sessionService, $this->secureRandom, - \OC::$server->getDatabaseConnection(), + \OCP\Server::get(IDBConnection::class), $this->dispatcher, $this->userManager, $this->cloudIdManager, diff --git a/tests/php/Service/ProxyCacheMessageServiceTest.php b/tests/php/Service/ProxyCacheMessageServiceTest.php index 7bd3b367d65..5bb48bdc6e3 100644 --- a/tests/php/Service/ProxyCacheMessageServiceTest.php +++ b/tests/php/Service/ProxyCacheMessageServiceTest.php @@ -39,9 +39,9 @@ * @group DB */ class ProxyCacheMessageServiceTest extends TestCase { + protected LoggerInterface&MockObject $logger; + protected ITimeFactory&MockObject $timeFactory; protected ?ProxyCacheMessageMapper $mapper = null; - protected LoggerInterface|MockObject $logger; - protected ITimeFactory|MockObject $timeFactory; protected ?ProxyCacheMessageService $service = null; diff --git a/tests/php/Service/RecordingServiceTest.php b/tests/php/Service/RecordingServiceTest.php index 42d4383b5ef..4ad5132d9d7 100644 --- a/tests/php/Service/RecordingServiceTest.php +++ b/tests/php/Service/RecordingServiceTest.php @@ -58,40 +58,26 @@ function is_uploaded_file($filename) { use Test\TestCase; class RecordingServiceTest extends TestCase { - /** @var IMimeTypeDetector */ - private $mimeTypeDetector; - /** @var ParticipantService|MockObject */ - private $participantService; - /** @var IRootFolder|MockObject */ - private $rootFolder; - /** @var Config|MockObject */ - private $config; - /** @var IConfig|MockObject */ - private $serverConfig; - /** @var IManager|MockObject */ - private $notificationManager; - /** @var Manager|MockObject */ - private $roomManager; - /** @var ITimeFactory|MockObject */ - private $timeFactory; - /** @var RoomService|MockObject */ - private $roomService; - /** @var ShareManager|MockObject */ - private $shareManager; - /** @var ChatManager|MockObject */ - private $chatManager; - /** @var LoggerInterface|MockObject */ - private $logger; - /** @var BackendNotifier|MockObject */ - private $backendNotifier; - private ISpeechToTextManager|MockObject $speechToTextManager; - /** @var RecordingService */ - protected $recordingService; + private IMimeTypeDetector $mimeTypeDetector; + protected ParticipantService&MockObject $participantService; + protected IRootFolder&MockObject $rootFolder; + protected Config&MockObject $config; + protected IConfig&MockObject $serverConfig; + protected IManager&MockObject $notificationManager; + protected Manager&MockObject $roomManager; + protected ITimeFactory&MockObject $timeFactory; + protected RoomService&MockObject $roomService; + protected ShareManager&MockObject $shareManager; + protected ChatManager&MockObject $chatManager; + protected LoggerInterface&MockObject $logger; + protected BackendNotifier&MockObject $backendNotifier; + protected ISpeechToTextManager&MockObject $speechToTextManager; + protected RecordingService $recordingService; public function setUp(): void { parent::setUp(); - $this->mimeTypeDetector = \OC::$server->get(IMimeTypeDetector::class); + $this->mimeTypeDetector = \OCP\Server::get(IMimeTypeDetector::class); $this->participantService = $this->createMock(ParticipantService::class); $this->rootFolder = $this->createMock(IRootFolder::class); $this->notificationManager = $this->createMock(IManager::class); @@ -124,16 +110,6 @@ public function setUp(): void { ); } - /** @dataProvider dataValidateFileFormat */ - public function testValidateFileFormat(string $fileName, string $fileRealPath, string $exceptionMessage): void { - if ($exceptionMessage) { - $this->expectExceptionMessage($exceptionMessage); - } else { - $this->expectNotToPerformAssertions(); - } - $this->recordingService->validateFileFormat($fileName, $fileRealPath); - } - public static function dataValidateFileFormat(): array { return [ # file_invalid_path @@ -151,22 +127,15 @@ public static function dataValidateFileFormat(): array { } /** - * @dataProvider dataGetResourceFromFileArray + * @dataProvider dataValidateFileFormat */ - public function testGetResourceFromFileArray(array $file, $expected, string $exceptionMessage): void { + public function testValidateFileFormat(string $fileName, string $fileRealPath, string $exceptionMessage): void { if ($exceptionMessage) { $this->expectExceptionMessage($exceptionMessage); + } else { + $this->expectNotToPerformAssertions(); } - - $room = $this->createMock(Room::class); - $attendee = Attendee::fromRow([ - 'actor_type' => Attendee::ACTOR_USERS, - 'actor_id' => 'participant1', - ]); - $participant = new Participant($room, $attendee, null); - - $actual = stream_get_contents($this->recordingService->getResourceFromFileArray($file, $room, $participant)); - $this->assertEquals($expected, $actual); + $this->recordingService->validateFileFormat($fileName, $fileRealPath); } public static function dataGetResourceFromFileArray(): array { @@ -181,4 +150,23 @@ public static function dataGetResourceFromFileArray(): array { [['error' => 0, 'tmp_name' => $fileWithContent], 'bla', ''], ]; } + + /** + * @dataProvider dataGetResourceFromFileArray + */ + public function testGetResourceFromFileArray(array $file, string $expected, string $exceptionMessage): void { + if ($exceptionMessage) { + $this->expectExceptionMessage($exceptionMessage); + } + + $room = $this->createMock(Room::class); + $attendee = Attendee::fromRow([ + 'actor_type' => Attendee::ACTOR_USERS, + 'actor_id' => 'participant1', + ]); + $participant = new Participant($room, $attendee, null); + + $actual = stream_get_contents($this->recordingService->getResourceFromFileArray($file, $room, $participant)); + $this->assertEquals($expected, $actual); + } } diff --git a/tests/php/Service/RoomServiceTest.php b/tests/php/Service/RoomServiceTest.php index e944ff03cf3..62f75dc90a4 100644 --- a/tests/php/Service/RoomServiceTest.php +++ b/tests/php/Service/RoomServiceTest.php @@ -52,23 +52,15 @@ * @group DB */ class RoomServiceTest extends TestCase { - /** @var Manager|MockObject */ - protected $manager; - /** @var ParticipantService|MockObject */ - protected $participantService; - /** @var ITimeFactory|MockObject */ - protected $timeFactory; - /** @var IShareManager|MockObject */ - protected $shareManager; - /** @var Config|MockObject */ - protected $config; - /** @var IHasher|MockObject */ - protected $hasher; - /** @var IEventDispatcher|MockObject */ - protected $dispatcher; - private ?RoomService $service = null; - /** @var IJobList|MockObject */ - private IJobList $jobList; + protected Manager&MockObject $manager; + protected ParticipantService&MockObject $participantService; + protected ITimeFactory&MockObject $timeFactory; + protected IShareManager&MockObject $shareManager; + protected Config&MockObject $config; + protected IHasher&MockObject $hasher; + protected IEventDispatcher&MockObject $dispatcher; + protected IJobList&MockObject $jobList; + protected ?RoomService $service = null; public function setUp(): void { parent::setUp(); @@ -84,7 +76,7 @@ public function setUp(): void { $this->service = new RoomService( $this->manager, $this->participantService, - \OC::$server->get(IDBConnection::class), + \OCP\Server::get(IDBConnection::class), $this->timeFactory, $this->shareManager, $this->config, @@ -208,7 +200,6 @@ public static function dataCreateConversationInvalidNames(): array { /** * @dataProvider dataCreateConversationInvalidNames - * @param string $name */ public function testCreateConversationInvalidNames(string $name): void { $this->manager->expects($this->never()) @@ -230,7 +221,6 @@ public static function dataCreateConversationInvalidTypes(): array { /** * @dataProvider dataCreateConversationInvalidTypes - * @param int $type */ public function testCreateConversationInvalidTypes(int $type): void { $this->manager->expects($this->never()) @@ -252,9 +242,6 @@ public static function dataCreateConversationInvalidObjects(): array { /** * @dataProvider dataCreateConversationInvalidObjects - * @param string $type - * @param string $id - * @param string $exception */ public function testCreateConversationInvalidObjects(string $type, string $id, string $exception): void { $this->manager->expects($this->never()) @@ -275,11 +262,6 @@ public static function dataCreateConversation(): array { /** * @dataProvider dataCreateConversation - * @param int $type - * @param string $name - * @param string $ownerId - * @param string $objectType - * @param string $objectId */ public function testCreateConversation(int $type, string $name, string $ownerId, string $objectType, string $objectId): void { $room = $this->createMock(Room::class); @@ -328,8 +310,6 @@ public static function dataPrepareConversationName(): array { /** * @dataProvider dataPrepareConversationName - * @param string $input - * @param string $expected */ public function testPrepareConversationName(string $input, string $expected): void { $this->assertSame($expected, $this->service->prepareConversationName($input)); @@ -356,7 +336,7 @@ public function testVerifyPassword(): void { $service = new RoomService( $this->manager, $this->participantService, - \OC::$server->get(IDBConnection::class), + \OCP\Server::get(IDBConnection::class), $this->timeFactory, $this->shareManager, $this->config, diff --git a/tests/php/Service/SIPDialOutServiceTest.php b/tests/php/Service/SIPDialOutServiceTest.php index 5f0f709bd60..08aaf79b2de 100644 --- a/tests/php/Service/SIPDialOutServiceTest.php +++ b/tests/php/Service/SIPDialOutServiceTest.php @@ -33,9 +33,9 @@ use Test\TestCase; class SIPDialOutServiceTest extends TestCase { - protected BackendNotifier|MockObject $backendNotifier; - protected LoggerInterface|MockObject $logger; - private ?SIPDialOutService $service = null; + protected BackendNotifier&MockObject $backendNotifier; + protected LoggerInterface&MockObject $logger; + protected ?SIPDialOutService $service = null; public function setUp(): void { parent::setUp(); diff --git a/tests/php/Settings/Admin/AdminSettingsTest.php b/tests/php/Settings/Admin/AdminSettingsTest.php index 023ea331d45..91e9e6eda62 100644 --- a/tests/php/Settings/Admin/AdminSettingsTest.php +++ b/tests/php/Settings/Admin/AdminSettingsTest.php @@ -40,27 +40,17 @@ use Test\TestCase; class AdminSettingsTest extends TestCase { - /** @var Config|MockObject */ - protected $talkConfig; - /** @var IConfig|MockObject */ - protected $serverConfig; - protected IAppConfig|MockObject $appConfig; - /** @var CommandService|MockObject */ - protected $commandService; - /** @var IInitialState|MockObject */ - protected $initialState; - /** @var ICacheFactory|MockObject */ - protected $cacheFactory; - /** @var IGroupManager|MockObject */ - protected $groupManager; - /** @var MatterbridgeManager|MockObject */ - protected $matterbridgeManager; - /** @var IUserSession|MockObject */ - protected $userSession; - /** @var IL10N|MockObject */ - protected $l10n; - /** @var IFactory|MockObject */ - protected $l10nFactory; + protected Config&MockObject $talkConfig; + protected IConfig&MockObject $serverConfig; + protected IAppConfig&MockObject $appConfig; + protected CommandService&MockObject $commandService; + protected IInitialState&MockObject $initialState; + protected ICacheFactory&MockObject $cacheFactory; + protected IGroupManager&MockObject $groupManager; + protected MatterbridgeManager&MockObject $matterbridgeManager; + protected IUserSession&MockObject $userSession; + protected IL10N&MockObject $l10n; + protected IFactory&MockObject $l10nFactory; protected ?AdminSettings $admin = null; public function setUp(): void { diff --git a/tests/php/Settings/Admin/SectionTest.php b/tests/php/Settings/Admin/SectionTest.php index 76d7165a07e..aceaf81dabb 100644 --- a/tests/php/Settings/Admin/SectionTest.php +++ b/tests/php/Settings/Admin/SectionTest.php @@ -30,10 +30,8 @@ use Test\TestCase; class SectionTest extends TestCase { - /** @var IURLGenerator|MockObject */ - protected $url; - /** @var IL10N|MockObject */ - protected $l; + protected IURLGenerator&MockObject $url; + protected IL10N&MockObject $l; protected ?Section $admin = null; public function setUp(): void { diff --git a/tests/php/Signaling/ListenerTest.php b/tests/php/Signaling/ListenerTest.php index eb460aa775f..374b7fdc131 100644 --- a/tests/php/Signaling/ListenerTest.php +++ b/tests/php/Signaling/ListenerTest.php @@ -1,4 +1,6 @@ createMock(Room::class); @@ -197,7 +196,7 @@ public function testRoomLobbyModified(int $newValue, int $oldValue, ?\DateTime $ $this->listener->handle($event); } - public function testRoomLobbyRemoved() { + public function testRoomLobbyRemoved(): void { $room = $this->createMock(Room::class); $event = new LobbyModifiedEvent( diff --git a/tests/php/TalkSessionTest.php b/tests/php/TalkSessionTest.php index 34948b3e6d1..525e76ab984 100644 --- a/tests/php/TalkSessionTest.php +++ b/tests/php/TalkSessionTest.php @@ -31,9 +31,7 @@ use Test\TestCase; class TalkSessionTest extends TestCase { - /** @var ISession|MockObject */ - protected $session; - + protected ISession&MockObject $session; protected ?TalkSession $talkSession = null; public function setUp(): void { @@ -54,11 +52,8 @@ public static function dataGet(): array { /** * @dataProvider dataGet - * - * @param null|string $sessionData - * @param null|string $expected */ - public function testGetSessionForRoom($sessionData, $expected) { + public function testGetSessionForRoom(?string $sessionData, ?string $expected): void { $this->session->expects($this->once()) ->method('get') ->with('spreed-session') @@ -68,11 +63,8 @@ public function testGetSessionForRoom($sessionData, $expected) { /** * @dataProvider dataGet - * - * @param null|string $sessionData - * @param null|string $expected */ - public function testGetPasswordForRoom($sessionData, $expected) { + public function testGetPasswordForRoom(?string $sessionData, ?string $expected): void { $this->session->expects($this->once()) ->method('get') ->with('spreed-password') @@ -91,11 +83,8 @@ public static function dataSet(): array { /** * @dataProvider dataSet - * - * @param null|string $sessionData - * @param null|string $expected */ - public function testSetSessionForRoom($sessionData, $expected) { + public function testSetSessionForRoom(?string $sessionData, ?string $expected): void { $this->session->expects($this->once()) ->method('get') ->with('spreed-session') @@ -108,11 +97,8 @@ public function testSetSessionForRoom($sessionData, $expected) { /** * @dataProvider dataSet - * - * @param null|string $sessionData - * @param null|string $expected */ - public function testSetPasswordForRoom($sessionData, $expected) { + public function testSetPasswordForRoom(?string $sessionData, ?string $expected): void { $this->session->expects($this->once()) ->method('get') ->with('spreed-password') @@ -134,11 +120,8 @@ public static function dataRemove(): array { /** * @dataProvider dataRemove - * - * @param null|string $sessionData - * @param null|string $expected */ - public function testRemoveSessionForRoom($sessionData, $expected) { + public function testRemoveSessionForRoom(?string $sessionData, ?string $expected): void { $this->session->expects($this->once()) ->method('get') ->with('spreed-session') @@ -151,11 +134,8 @@ public function testRemoveSessionForRoom($sessionData, $expected) { /** * @dataProvider dataRemove - * - * @param null|string $sessionData - * @param null|string $expected */ - public function testRemovePasswordForRoom($sessionData, $expected) { + public function testRemovePasswordForRoom(?string $sessionData, ?string $expected): void { $this->session->expects($this->once()) ->method('get') ->with('spreed-password')