diff options
author | Joas Schilling <coding@schilljs.com> | 2024-04-12 12:46:48 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2024-04-12 12:46:48 +0200 |
commit | f28f7e6354cce3ea56047b2830957eea232e02a2 (patch) | |
tree | cb64e56faefbe4eed2da3268197265a2a85d927d | |
parent | 19937f6068274e311c13b1e4ff7e34ce5af1afca (diff) |
fix(tests): Clean up unit test code
- static data providers
- typed methods that consume data providers
- type intersection with MockObject
- move away from deprecated methods
Signed-off-by: Joas Schilling <coding@schilljs.com>
48 files changed, 789 insertions, 1261 deletions
diff --git a/tests/php/Activity/Provider/BaseTest.php b/tests/php/Activity/Provider/BaseTest.php index b80824bcb..71b9ccd70 100644 --- a/tests/php/Activity/Provider/BaseTest.php +++ b/tests/php/Activity/Provider/BaseTest.php @@ -1,4 +1,6 @@ <?php + +declare(strict_types=1); /** * @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com> * @@ -41,20 +43,13 @@ use Test\TestCase; * @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 @@ class BaseTest extends TestCase { 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 @@ class BaseTest extends TestCase { 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 @@ class BaseTest extends TestCase { 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 @@ class BaseTest extends TestCase { /** * @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 @@ class BaseTest extends TestCase { 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 @@ class BaseTest extends TestCase { /** * @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 @@ class BaseTest extends TestCase { /** * @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 f6edb1c18..2d9a44e5a 100644 --- a/tests/php/Activity/Provider/InvitationTest.php +++ b/tests/php/Activity/Provider/InvitationTest.php @@ -1,4 +1,6 @@ <?php + +declare(strict_types=1); /** * @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com> * @@ -43,20 +45,13 @@ use Test\TestCase; * @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 @@ class InvitationTest extends TestCase { ); } - 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 @@ class InvitationTest extends TestCase { $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 @@ class InvitationTest extends TestCase { /** * @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 { |