diff options
Diffstat (limited to 'apps/user_status/tests/Unit/Controller')
3 files changed, 30 insertions, 71 deletions
diff --git a/apps/user_status/tests/Unit/Controller/PredefinedStatusControllerTest.php b/apps/user_status/tests/Unit/Controller/PredefinedStatusControllerTest.php index 5709cdc89cf..0f96f41a524 100644 --- a/apps/user_status/tests/Unit/Controller/PredefinedStatusControllerTest.php +++ b/apps/user_status/tests/Unit/Controller/PredefinedStatusControllerTest.php @@ -11,15 +11,12 @@ namespace OCA\UserStatus\Tests\Controller; use OCA\UserStatus\Controller\PredefinedStatusController; use OCA\UserStatus\Service\PredefinedStatusService; use OCP\IRequest; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class PredefinedStatusControllerTest extends TestCase { - - /** @var PredefinedStatusService|\PHPUnit\Framework\MockObject\MockObject */ - private $service; - - /** @var PredefinedStatusController */ - private $controller; + private PredefinedStatusService&MockObject $service; + private PredefinedStatusController $controller; protected function setUp(): void { parent::setUp(); @@ -27,8 +24,7 @@ class PredefinedStatusControllerTest extends TestCase { $request = $this->createMock(IRequest::class); $this->service = $this->createMock(PredefinedStatusService::class); - $this->controller = new PredefinedStatusController('user_status', $request, - $this->service); + $this->controller = new PredefinedStatusController('user_status', $request, $this->service); } public function testFindAll(): void { diff --git a/apps/user_status/tests/Unit/Controller/StatusesControllerTest.php b/apps/user_status/tests/Unit/Controller/StatusesControllerTest.php index fe3e1c56a7e..76d337879c3 100644 --- a/apps/user_status/tests/Unit/Controller/StatusesControllerTest.php +++ b/apps/user_status/tests/Unit/Controller/StatusesControllerTest.php @@ -14,15 +14,12 @@ use OCA\UserStatus\Service\StatusService; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\OCS\OCSNotFoundException; use OCP\IRequest; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class StatusesControllerTest extends TestCase { - - /** @var StatusService|\PHPUnit\Framework\MockObject\MockObject */ - private $service; - - /** @var StatusesController */ - private $controller; + private StatusService&MockObject $service; + private StatusesController $controller; protected function setUp(): void { parent::setUp(); diff --git a/apps/user_status/tests/Unit/Controller/UserStatusControllerTest.php b/apps/user_status/tests/Unit/Controller/UserStatusControllerTest.php index 26b29bcc74c..e99290319ed 100644 --- a/apps/user_status/tests/Unit/Controller/UserStatusControllerTest.php +++ b/apps/user_status/tests/Unit/Controller/UserStatusControllerTest.php @@ -21,22 +21,16 @@ use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\OCS\OCSBadRequestException; use OCP\AppFramework\OCS\OCSNotFoundException; use OCP\IRequest; +use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; use Test\TestCase; use Throwable; class UserStatusControllerTest extends TestCase { - /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */ - private $logger; - - /** @var StatusService|\PHPUnit\Framework\MockObject\MockObject */ - private $statusService; - - /** @var CalendarStatusService|\PHPUnit\Framework\MockObject\MockObject $calendarStatusService */ - private $calendarStatusService; - - /** @var UserStatusController */ - private $controller; + private LoggerInterface&MockObject $logger; + private StatusService&MockObject $statusService; + private CalendarStatusService&MockObject $calendarStatusService; + private UserStatusController $controller; protected function setUp(): void { parent::setUp(); @@ -93,20 +87,9 @@ class UserStatusControllerTest extends TestCase { $this->controller->getStatus(); } - /** - * @param string $statusType - * @param string|null $statusIcon - * @param string|null $message - * @param int|null $clearAt - * @param bool $expectSuccess - * @param bool $expectException - * @param Throwable|null $exception - * @param bool $expectLogger - * @param string|null $expectedLogMessage - * - * @dataProvider setStatusDataProvider - */ - public function testSetStatus(string $statusType, + #[\PHPUnit\Framework\Attributes\DataProvider('setStatusDataProvider')] + public function testSetStatus( + string $statusType, ?string $statusIcon, ?string $message, ?int $clearAt, @@ -114,7 +97,8 @@ class UserStatusControllerTest extends TestCase { bool $expectException, ?Throwable $exception, bool $expectLogger, - ?string $expectedLogMessage): void { + ?string $expectedLogMessage, + ): void { $userStatus = $this->getUserStatus(); if ($expectException) { @@ -155,7 +139,7 @@ class UserStatusControllerTest extends TestCase { } } - public function setStatusDataProvider(): array { + public static function setStatusDataProvider(): array { return [ ['busy', '👨🏽💻', 'Busy developing the status feature', 500, true, false, null, false, null], ['busy', '👨🏽💻', 'Busy developing the status feature', 500, false, true, new InvalidStatusTypeException('Original exception message'), true, @@ -163,24 +147,16 @@ class UserStatusControllerTest extends TestCase { ]; } - /** - * @param string $messageId - * @param int|null $clearAt - * @param bool $expectSuccess - * @param bool $expectException - * @param Throwable|null $exception - * @param bool $expectLogger - * @param string|null $expectedLogMessage - * - * @dataProvider setPredefinedMessageDataProvider - */ - public function testSetPredefinedMessage(string $messageId, + #[\PHPUnit\Framework\Attributes\DataProvider('setPredefinedMessageDataProvider')] + public function testSetPredefinedMessage( + string $messageId, ?int $clearAt, bool $expectSuccess, bool $expectException, ?Throwable $exception, bool $expectLogger, - ?string $expectedLogMessage): void { + ?string $expectedLogMessage, + ): void { $userStatus = $this->getUserStatus(); if ($expectException) { @@ -221,7 +197,7 @@ class UserStatusControllerTest extends TestCase { } } - public function setPredefinedMessageDataProvider(): array { + public static function setPredefinedMessageDataProvider(): array { return [ ['messageId-42', 500, true, false, null, false, null], ['messageId-42', 500, false, true, new InvalidClearAtException('Original exception message'), true, @@ -231,20 +207,9 @@ class UserStatusControllerTest extends TestCase { ]; } - /** - * @param string|null $statusIcon - * @param string $message - * @param int|null $clearAt - * @param bool $expectSuccess - * @param bool $expectException - * @param Throwable|null $exception - * @param bool $expectLogger - * @param string|null $expectedLogMessage - * @param bool $expectSuccessAsReset - * - * @dataProvider setCustomMessageDataProvider - */ - public function testSetCustomMessage(?string $statusIcon, + #[\PHPUnit\Framework\Attributes\DataProvider('setCustomMessageDataProvider')] + public function testSetCustomMessage( + ?string $statusIcon, string $message, ?int $clearAt, bool $expectSuccess, @@ -252,7 +217,8 @@ class UserStatusControllerTest extends TestCase { ?Throwable $exception, bool $expectLogger, ?string $expectedLogMessage, - bool $expectSuccessAsReset = false): void { + bool $expectSuccessAsReset = false, + ): void { $userStatus = $this->getUserStatus(); if ($expectException) { @@ -308,7 +274,7 @@ class UserStatusControllerTest extends TestCase { } } - public function setCustomMessageDataProvider(): array { + public static function setCustomMessageDataProvider(): array { return [ ['👨🏽💻', 'Busy developing the status feature', 500, true, false, null, false, null], ['👨🏽💻', '', 500, true, false, null, false, null, false], |