providerManager = $this->createMock(ProviderManager::class); $this->userManager = $this->createMock(IUserManager::class); $cmd = new Enable($this->providerManager, $this->userManager); $this->command = new CommandTester($cmd); } public function testInvalidUID(): void { $this->userManager->expects($this->once()) ->method('get') ->with('nope') ->willReturn(null); $rc = $this->command->execute([ 'uid' => 'nope', 'provider_id' => 'nope', ]); $this->assertEquals(1, $rc); $this->assertStringContainsString('Invalid UID', $this->command->getDisplay()); } public function testEnableNotSupported(): void { $user = $this->createMock(IUser::class); $this->userManager->expects($this->once()) ->method('get') ->with('belle') ->willReturn($user); $this->providerManager->expects($this->once()) ->method('tryEnableProviderFor') ->with('totp', $user) ->willReturn(false); $rc = $this->command->execute([ 'uid' => 'belle', 'provider_id' => 'totp', ]); $this->assertEquals(2, $rc); $this->assertStringContainsString('The provider does not support this operation', $this->command->getDisplay()); } public function testEnabled(): void { $user = $this->createMock(IUser::class); $this->userManager->expects($this->once()) ->method('get') ->with('belle') ->willReturn($user); $this->providerManager->expects($this->once()) ->method('tryEnableProviderFor') ->with('totp', $user) ->willReturn(true); $rc = $this->command->execute([ 'uid' => 'belle', 'provider_id' => 'totp', ]); $this->assertEquals(0, $rc); $this->assertStringContainsString('Two-factor provider totp enabled for user belle', $this->command->getDisplay()); } }