diff options
Diffstat (limited to 'tests/lib/Authentication/Token/ManagerTest.php')
-rw-r--r-- | tests/lib/Authentication/Token/ManagerTest.php | 99 |
1 files changed, 56 insertions, 43 deletions
diff --git a/tests/lib/Authentication/Token/ManagerTest.php b/tests/lib/Authentication/Token/ManagerTest.php index 98baffed14b..58bbe236248 100644 --- a/tests/lib/Authentication/Token/ManagerTest.php +++ b/tests/lib/Authentication/Token/ManagerTest.php @@ -33,7 +33,7 @@ class ManagerTest extends TestCase { ); } - public function testGenerateToken() { + public function testGenerateToken(): void { $token = new PublicKeyToken(); $this->publicKeyTokenProvider->expects($this->once()) @@ -61,7 +61,7 @@ class ManagerTest extends TestCase { $this->assertSame($token, $actual); } - public function testGenerateConflictingToken() { + public function testGenerateConflictingToken(): void { /** @var MockObject|UniqueConstraintViolationException $exception */ $exception = $this->createMock(UniqueConstraintViolationException::class); @@ -97,7 +97,7 @@ class ManagerTest extends TestCase { $this->assertSame($token, $actual); } - public function testGenerateTokenTooLongName() { + public function testGenerateTokenTooLongName(): void { $token = $this->createMock(IToken::class); $token->method('getName') ->willReturn(str_repeat('a', 120) . '…'); @@ -128,10 +128,10 @@ class ManagerTest extends TestCase { $this->assertSame(121, mb_strlen($actual->getName())); } - public function tokenData(): array { + public static function tokenData(): array { return [ [new PublicKeyToken()], - [$this->createMock(IToken::class)], + [IToken::class], ]; } @@ -157,10 +157,12 @@ class ManagerTest extends TestCase { } } - /** - * @dataProvider tokenData - */ - public function testUpdateToken(IToken $token) { + #[\PHPUnit\Framework\Attributes\DataProvider('tokenData')] + public function testUpdateToken(IToken|string $token): void { + if (is_string($token)) { + $token = $this->createMock($token); + } + $this->setNoCall($token); $this->setCall($token, 'updateToken'); $this->setException($token); @@ -168,10 +170,12 @@ class ManagerTest extends TestCase { $this->manager->updateToken($token); } - /** - * @dataProvider tokenData - */ - public function testUpdateTokenActivity(IToken $token) { + #[\PHPUnit\Framework\Attributes\DataProvider('tokenData')] + public function testUpdateTokenActivity(IToken|string $token): void { + if (is_string($token)) { + $token = $this->createMock($token); + } + $this->setNoCall($token); $this->setCall($token, 'updateTokenActivity'); $this->setException($token); @@ -179,10 +183,12 @@ class ManagerTest extends TestCase { $this->manager->updateTokenActivity($token); } - /** - * @dataProvider tokenData - */ - public function testGetPassword(IToken $token) { + #[\PHPUnit\Framework\Attributes\DataProvider('tokenData')] + public function testGetPassword(IToken|string $token): void { + if (is_string($token)) { + $token = $this->createMock($token); + } + $this->setNoCall($token); $this->setCall($token, 'getPassword', 'password'); $this->setException($token); @@ -192,10 +198,12 @@ class ManagerTest extends TestCase { $this->assertSame('password', $result); } - /** - * @dataProvider tokenData - */ - public function testSetPassword(IToken $token) { + #[\PHPUnit\Framework\Attributes\DataProvider('tokenData')] + public function testSetPassword(IToken|string $token): void { + if (is_string($token)) { + $token = $this->createMock($token); + } + $this->setNoCall($token); $this->setCall($token, 'setPassword'); $this->setException($token); @@ -203,7 +211,7 @@ class ManagerTest extends TestCase { $this->manager->setPassword($token, 'tokenId', 'password'); } - public function testInvalidateTokens() { + public function testInvalidateTokens(): void { $this->publicKeyTokenProvider->expects($this->once()) ->method('invalidateToken') ->with('token'); @@ -211,7 +219,7 @@ class ManagerTest extends TestCase { $this->manager->invalidateToken('token'); } - public function testInvalidateTokenById() { + public function testInvalidateTokenById(): void { $this->publicKeyTokenProvider->expects($this->once()) ->method('invalidateTokenById') ->with('uid', 42); @@ -219,14 +227,14 @@ class ManagerTest extends TestCase { $this->manager->invalidateTokenById('uid', 42); } - public function testInvalidateOldTokens() { + public function testInvalidateOldTokens(): void { $this->publicKeyTokenProvider->expects($this->once()) ->method('invalidateOldTokens'); $this->manager->invalidateOldTokens(); } - public function testInvalidateLastUsedBefore() { + public function testInvalidateLastUsedBefore(): void { $this->publicKeyTokenProvider->expects($this->once()) ->method('invalidateLastUsedBefore') ->with('user', 946684800); @@ -234,7 +242,7 @@ class ManagerTest extends TestCase { $this->manager->invalidateLastUsedBefore('user', 946684800); } - public function testGetTokenByUser() { + public function testGetTokenByUser(): void { $t1 = new PublicKeyToken(); $t2 = new PublicKeyToken(); @@ -247,7 +255,7 @@ class ManagerTest extends TestCase { $this->assertEquals([$t1, $t2], $result); } - public function testRenewSessionTokenPublicKey() { + public function testRenewSessionTokenPublicKey(): void { $this->publicKeyTokenProvider->expects($this->once()) ->method('renewSessionToken') ->with('oldId', 'newId'); @@ -255,7 +263,7 @@ class ManagerTest extends TestCase { $this->manager->renewSessionToken('oldId', 'newId'); } - public function testRenewSessionInvalid() { + public function testRenewSessionInvalid(): void { $this->publicKeyTokenProvider->expects($this->once()) ->method('renewSessionToken') ->with('oldId', 'newId') @@ -265,7 +273,7 @@ class ManagerTest extends TestCase { $this->manager->renewSessionToken('oldId', 'newId'); } - public function testGetTokenByIdPublicKey() { + public function testGetTokenByIdPublicKey(): void { $token = $this->createMock(IToken::class); $this->publicKeyTokenProvider->expects($this->once()) @@ -276,7 +284,7 @@ class ManagerTest extends TestCase { $this->assertSame($token, $this->manager->getTokenById(42)); } - public function testGetTokenByIdInvalid() { + public function testGetTokenByIdInvalid(): void { $this->publicKeyTokenProvider->expects($this->once()) ->method('getTokenById') ->with(42) @@ -286,7 +294,7 @@ class ManagerTest extends TestCase { $this->manager->getTokenById(42); } - public function testGetTokenPublicKey() { + public function testGetTokenPublicKey(): void { $token = new PublicKeyToken(); $this->publicKeyTokenProvider @@ -297,7 +305,7 @@ class ManagerTest extends TestCase { $this->assertSame($token, $this->manager->getToken('tokenId')); } - public function testGetTokenInvalid() { + public function testGetTokenInvalid(): void { $this->publicKeyTokenProvider ->method('getToken') ->with('tokenId') @@ -307,12 +315,12 @@ class ManagerTest extends TestCase { $this->manager->getToken('tokenId'); } - public function testRotateInvalid() { + public function testRotateInvalid(): void { $this->expectException(InvalidTokenException::class); $this->manager->rotate($this->createMock(IToken::class), 'oldId', 'newId'); } - public function testRotatePublicKey() { + public function testRotatePublicKey(): void { $token = new PublicKeyToken(); $this->publicKeyTokenProvider @@ -323,7 +331,7 @@ class ManagerTest extends TestCase { $this->assertSame($token, $this->manager->rotate($token, 'oldId', 'newId')); } - public function testMarkPasswordInvalidPublicKey() { + public function testMarkPasswordInvalidPublicKey(): void { $token = $this->createMock(PublicKeyToken::class); $this->publicKeyTokenProvider->expects($this->once()) @@ -333,13 +341,13 @@ class ManagerTest extends TestCase { $this->manager->markPasswordInvalid($token, 'tokenId'); } - public function testMarkPasswordInvalidInvalidToken() { + public function testMarkPasswordInvalidInvalidToken(): void { $this->expectException(InvalidTokenException::class); $this->manager->markPasswordInvalid($this->createMock(IToken::class), 'tokenId'); } - public function testUpdatePasswords() { + public function testUpdatePasswords(): void { $this->publicKeyTokenProvider->expects($this->once()) ->method('updatePasswords') ->with('uid', 'pass'); @@ -347,7 +355,7 @@ class ManagerTest extends TestCase { $this->manager->updatePasswords('uid', 'pass'); } - public function testInvalidateTokensOfUserNoClientName() { + public function testInvalidateTokensOfUserNoClientName(): void { $t1 = new PublicKeyToken(); $t2 = new PublicKeyToken(); $t1->setId(123); @@ -358,17 +366,22 @@ class ManagerTest extends TestCase { ->method('getTokenByUser') ->with('theUser') ->willReturn([$t1, $t2]); + + $calls = [ + ['theUser', 123], + ['theUser', 456], + ]; $this->publicKeyTokenProvider ->expects($this->exactly(2)) ->method('invalidateTokenById') - ->withConsecutive( - ['theUser', 123], - ['theUser', 456], - ); + ->willReturnCallback(function () use (&$calls): void { + $expected = array_shift($calls); + $this->assertEquals($expected, func_get_args()); + }); $this->manager->invalidateTokensOfUser('theUser', null); } - public function testInvalidateTokensOfUserClientNameGiven() { + public function testInvalidateTokensOfUserClientNameGiven(): void { $t1 = new PublicKeyToken(); $t2 = new PublicKeyToken(); $t3 = new PublicKeyToken(); |