@@ -18,77 +18,77 @@ |
||
18 | 18 | use Test\TestCase; |
19 | 19 | |
20 | 20 | class StateTest extends TestCase { |
21 | - /** @var IRegistry|MockObject */ |
|
22 | - private $registry; |
|
23 | - |
|
24 | - /** @var IUserManager|MockObject */ |
|
25 | - private $userManager; |
|
26 | - |
|
27 | - /** @var CommandTester|MockObject */ |
|
28 | - private $cmd; |
|
29 | - |
|
30 | - protected function setUp(): void { |
|
31 | - parent::setUp(); |
|
32 | - |
|
33 | - $this->registry = $this->createMock(IRegistry::class); |
|
34 | - $this->userManager = $this->createMock(IUserManager::class); |
|
35 | - |
|
36 | - $cmd = new State($this->registry, $this->userManager); |
|
37 | - $this->cmd = new CommandTester($cmd); |
|
38 | - } |
|
39 | - |
|
40 | - public function testWrongUID(): void { |
|
41 | - $this->cmd->execute([ |
|
42 | - 'uid' => 'nope', |
|
43 | - ]); |
|
44 | - |
|
45 | - $output = $this->cmd->getDisplay(); |
|
46 | - $this->assertStringContainsString('Invalid UID', $output); |
|
47 | - } |
|
48 | - |
|
49 | - public function testStateNoProvidersActive(): void { |
|
50 | - $user = $this->createMock(IUser::class); |
|
51 | - $this->userManager->expects($this->once()) |
|
52 | - ->method('get') |
|
53 | - ->with('eldora') |
|
54 | - ->willReturn($user); |
|
55 | - $states = [ |
|
56 | - 'u2f' => false, |
|
57 | - 'totp' => false, |
|
58 | - ]; |
|
59 | - $this->registry->expects($this->once()) |
|
60 | - ->method('getProviderStates') |
|
61 | - ->with($user) |
|
62 | - ->willReturn($states); |
|
63 | - |
|
64 | - $this->cmd->execute([ |
|
65 | - 'uid' => 'eldora', |
|
66 | - ]); |
|
67 | - |
|
68 | - $output = $this->cmd->getDisplay(); |
|
69 | - $this->assertStringContainsString('Two-factor authentication is not enabled for user eldora', $output); |
|
70 | - } |
|
71 | - |
|
72 | - public function testStateOneProviderActive(): void { |
|
73 | - $user = $this->createMock(IUser::class); |
|
74 | - $this->userManager->expects($this->once()) |
|
75 | - ->method('get') |
|
76 | - ->with('mohamed') |
|
77 | - ->willReturn($user); |
|
78 | - $states = [ |
|
79 | - 'u2f' => true, |
|
80 | - 'totp' => false, |
|
81 | - ]; |
|
82 | - $this->registry->expects($this->once()) |
|
83 | - ->method('getProviderStates') |
|
84 | - ->with($user) |
|
85 | - ->willReturn($states); |
|
86 | - |
|
87 | - $this->cmd->execute([ |
|
88 | - 'uid' => 'mohamed', |
|
89 | - ]); |
|
90 | - |
|
91 | - $output = $this->cmd->getDisplay(); |
|
92 | - $this->assertStringContainsString('Two-factor authentication is enabled for user mohamed', $output); |
|
93 | - } |
|
21 | + /** @var IRegistry|MockObject */ |
|
22 | + private $registry; |
|
23 | + |
|
24 | + /** @var IUserManager|MockObject */ |
|
25 | + private $userManager; |
|
26 | + |
|
27 | + /** @var CommandTester|MockObject */ |
|
28 | + private $cmd; |
|
29 | + |
|
30 | + protected function setUp(): void { |
|
31 | + parent::setUp(); |
|
32 | + |
|
33 | + $this->registry = $this->createMock(IRegistry::class); |
|
34 | + $this->userManager = $this->createMock(IUserManager::class); |
|
35 | + |
|
36 | + $cmd = new State($this->registry, $this->userManager); |
|
37 | + $this->cmd = new CommandTester($cmd); |
|
38 | + } |
|
39 | + |
|
40 | + public function testWrongUID(): void { |
|
41 | + $this->cmd->execute([ |
|
42 | + 'uid' => 'nope', |
|
43 | + ]); |
|
44 | + |
|
45 | + $output = $this->cmd->getDisplay(); |
|
46 | + $this->assertStringContainsString('Invalid UID', $output); |
|
47 | + } |
|
48 | + |
|
49 | + public function testStateNoProvidersActive(): void { |
|
50 | + $user = $this->createMock(IUser::class); |
|
51 | + $this->userManager->expects($this->once()) |
|
52 | + ->method('get') |
|
53 | + ->with('eldora') |
|
54 | + ->willReturn($user); |
|
55 | + $states = [ |
|
56 | + 'u2f' => false, |
|
57 | + 'totp' => false, |
|
58 | + ]; |
|
59 | + $this->registry->expects($this->once()) |
|
60 | + ->method('getProviderStates') |
|
61 | + ->with($user) |
|
62 | + ->willReturn($states); |
|
63 | + |
|
64 | + $this->cmd->execute([ |
|
65 | + 'uid' => 'eldora', |
|
66 | + ]); |
|
67 | + |
|
68 | + $output = $this->cmd->getDisplay(); |
|
69 | + $this->assertStringContainsString('Two-factor authentication is not enabled for user eldora', $output); |
|
70 | + } |
|
71 | + |
|
72 | + public function testStateOneProviderActive(): void { |
|
73 | + $user = $this->createMock(IUser::class); |
|
74 | + $this->userManager->expects($this->once()) |
|
75 | + ->method('get') |
|
76 | + ->with('mohamed') |
|
77 | + ->willReturn($user); |
|
78 | + $states = [ |
|
79 | + 'u2f' => true, |
|
80 | + 'totp' => false, |
|
81 | + ]; |
|
82 | + $this->registry->expects($this->once()) |
|
83 | + ->method('getProviderStates') |
|
84 | + ->with($user) |
|
85 | + ->willReturn($states); |
|
86 | + |
|
87 | + $this->cmd->execute([ |
|
88 | + 'uid' => 'mohamed', |
|
89 | + ]); |
|
90 | + |
|
91 | + $output = $this->cmd->getDisplay(); |
|
92 | + $this->assertStringContainsString('Two-factor authentication is enabled for user mohamed', $output); |
|
93 | + } |
|
94 | 94 | } |
@@ -17,36 +17,36 @@ |
||
17 | 17 | use Test\TestCase; |
18 | 18 | |
19 | 19 | class CleanupTest extends TestCase { |
20 | - /** @var IRegistry|MockObject */ |
|
21 | - private $registry; |
|
20 | + /** @var IRegistry|MockObject */ |
|
21 | + private $registry; |
|
22 | 22 | |
23 | - /** @var IUserManager|MockObject */ |
|
24 | - private $userManager; |
|
23 | + /** @var IUserManager|MockObject */ |
|
24 | + private $userManager; |
|
25 | 25 | |
26 | - /** @var CommandTester */ |
|
27 | - private $cmd; |
|
26 | + /** @var CommandTester */ |
|
27 | + private $cmd; |
|
28 | 28 | |
29 | - protected function setUp(): void { |
|
30 | - parent::setUp(); |
|
29 | + protected function setUp(): void { |
|
30 | + parent::setUp(); |
|
31 | 31 | |
32 | - $this->registry = $this->createMock(IRegistry::class); |
|
33 | - $this->userManager = $this->createMock(IUserManager::class); |
|
32 | + $this->registry = $this->createMock(IRegistry::class); |
|
33 | + $this->userManager = $this->createMock(IUserManager::class); |
|
34 | 34 | |
35 | - $cmd = new Cleanup($this->registry, $this->userManager); |
|
36 | - $this->cmd = new CommandTester($cmd); |
|
37 | - } |
|
35 | + $cmd = new Cleanup($this->registry, $this->userManager); |
|
36 | + $this->cmd = new CommandTester($cmd); |
|
37 | + } |
|
38 | 38 | |
39 | - public function testCleanup(): void { |
|
40 | - $this->registry->expects($this->once()) |
|
41 | - ->method('cleanUp') |
|
42 | - ->with('u2f'); |
|
39 | + public function testCleanup(): void { |
|
40 | + $this->registry->expects($this->once()) |
|
41 | + ->method('cleanUp') |
|
42 | + ->with('u2f'); |
|
43 | 43 | |
44 | - $rc = $this->cmd->execute([ |
|
45 | - 'provider-id' => 'u2f', |
|
46 | - ]); |
|
44 | + $rc = $this->cmd->execute([ |
|
45 | + 'provider-id' => 'u2f', |
|
46 | + ]); |
|
47 | 47 | |
48 | - $this->assertEquals(0, $rc); |
|
49 | - $output = $this->cmd->getDisplay(); |
|
50 | - $this->assertStringContainsString('All user-provider associations for provider u2f have been removed', $output); |
|
51 | - } |
|
48 | + $this->assertEquals(0, $rc); |
|
49 | + $output = $this->cmd->getDisplay(); |
|
50 | + $this->assertStringContainsString('All user-provider associations for provider u2f have been removed', $output); |
|
51 | + } |
|
52 | 52 | } |
@@ -18,77 +18,77 @@ |
||
18 | 18 | use Test\TestCase; |
19 | 19 | |
20 | 20 | class EnableTest extends TestCase { |
21 | - /** @var ProviderManager|MockObject */ |
|
22 | - private $providerManager; |
|
23 | - |
|
24 | - /** @var IUserManager|MockObject */ |
|
25 | - private $userManager; |
|
26 | - |
|
27 | - /** @var CommandTester */ |
|
28 | - private $command; |
|
29 | - |
|
30 | - protected function setUp(): void { |
|
31 | - parent::setUp(); |
|
32 | - |
|
33 | - $this->providerManager = $this->createMock(ProviderManager::class); |
|
34 | - $this->userManager = $this->createMock(IUserManager::class); |
|
35 | - |
|
36 | - $cmd = new Enable($this->providerManager, $this->userManager); |
|
37 | - $this->command = new CommandTester($cmd); |
|
38 | - } |
|
39 | - |
|
40 | - public function testInvalidUID(): void { |
|
41 | - $this->userManager->expects($this->once()) |
|
42 | - ->method('get') |
|
43 | - ->with('nope') |
|
44 | - ->willReturn(null); |
|
45 | - |
|
46 | - $rc = $this->command->execute([ |
|
47 | - 'uid' => 'nope', |
|
48 | - 'provider_id' => 'nope', |
|
49 | - ]); |
|
50 | - |
|
51 | - $this->assertEquals(1, $rc); |
|
52 | - $this->assertStringContainsString('Invalid UID', $this->command->getDisplay()); |
|
53 | - } |
|
54 | - |
|
55 | - public function testEnableNotSupported(): void { |
|
56 | - $user = $this->createMock(IUser::class); |
|
57 | - $this->userManager->expects($this->once()) |
|
58 | - ->method('get') |
|
59 | - ->with('belle') |
|
60 | - ->willReturn($user); |
|
61 | - $this->providerManager->expects($this->once()) |
|
62 | - ->method('tryEnableProviderFor') |
|
63 | - ->with('totp', $user) |
|
64 | - ->willReturn(false); |
|
65 | - |
|
66 | - $rc = $this->command->execute([ |
|
67 | - 'uid' => 'belle', |
|
68 | - 'provider_id' => 'totp', |
|
69 | - ]); |
|
70 | - |
|
71 | - $this->assertEquals(2, $rc); |
|
72 | - $this->assertStringContainsString('The provider does not support this operation', $this->command->getDisplay()); |
|
73 | - } |
|
74 | - |
|
75 | - public function testEnabled(): void { |
|
76 | - $user = $this->createMock(IUser::class); |
|
77 | - $this->userManager->expects($this->once()) |
|
78 | - ->method('get') |
|
79 | - ->with('belle') |
|
80 | - ->willReturn($user); |
|
81 | - $this->providerManager->expects($this->once()) |
|
82 | - ->method('tryEnableProviderFor') |
|
83 | - ->with('totp', $user) |
|
84 | - ->willReturn(true); |
|
85 | - |
|
86 | - $rc = $this->command->execute([ |
|
87 | - 'uid' => 'belle', |
|
88 | - 'provider_id' => 'totp', |
|
89 | - ]); |
|
90 | - |
|
91 | - $this->assertEquals(0, $rc); |
|
92 | - $this->assertStringContainsString('Two-factor provider totp enabled for user belle', $this->command->getDisplay()); |
|
93 | - } |
|
21 | + /** @var ProviderManager|MockObject */ |
|
22 | + private $providerManager; |
|
23 | + |
|
24 | + /** @var IUserManager|MockObject */ |
|
25 | + private $userManager; |
|
26 | + |
|
27 | + /** @var CommandTester */ |
|
28 | + private $command; |
|
29 | + |
|
30 | + protected function setUp(): void { |
|
31 | + parent::setUp(); |
|
32 | + |
|
33 | + $this->providerManager = $this->createMock(ProviderManager::class); |
|
34 | + $this->userManager = $this->createMock(IUserManager::class); |
|
35 | + |
|
36 | + $cmd = new Enable($this->providerManager, $this->userManager); |
|
37 | + $this->command = new CommandTester($cmd); |
|
38 | + } |
|
39 | + |
|
40 | + public function testInvalidUID(): void { |
|
41 | + $this->userManager->expects($this->once()) |
|
42 | + ->method('get') |
|
43 | + ->with('nope') |
|
44 | + ->willReturn(null); |
|
45 | + |
|
46 | + $rc = $this->command->execute([ |
|
47 | + 'uid' => 'nope', |
|
48 | + 'provider_id' => 'nope', |
|
49 | + ]); |
|
50 | + |
|
51 | + $this->assertEquals(1, $rc); |
|
52 | + $this->assertStringContainsString('Invalid UID', $this->command->getDisplay()); |
|
53 | + } |
|
54 | + |
|
55 | + public function testEnableNotSupported(): void { |
|
56 | + $user = $this->createMock(IUser::class); |
|
57 | + $this->userManager->expects($this->once()) |
|
58 | + ->method('get') |
|
59 | + ->with('belle') |
|
60 | + ->willReturn($user); |
|
61 | + $this->providerManager->expects($this->once()) |
|
62 | + ->method('tryEnableProviderFor') |
|
63 | + ->with('totp', $user) |
|
64 | + ->willReturn(false); |
|
65 | + |
|
66 | + $rc = $this->command->execute([ |
|
67 | + 'uid' => 'belle', |
|
68 | + 'provider_id' => 'totp', |
|
69 | + ]); |
|
70 | + |
|
71 | + $this->assertEquals(2, $rc); |
|
72 | + $this->assertStringContainsString('The provider does not support this operation', $this->command->getDisplay()); |
|
73 | + } |
|
74 | + |
|
75 | + public function testEnabled(): void { |
|
76 | + $user = $this->createMock(IUser::class); |
|
77 | + $this->userManager->expects($this->once()) |
|
78 | + ->method('get') |
|
79 | + ->with('belle') |
|
80 | + ->willReturn($user); |
|
81 | + $this->providerManager->expects($this->once()) |
|
82 | + ->method('tryEnableProviderFor') |
|
83 | + ->with('totp', $user) |
|
84 | + ->willReturn(true); |
|
85 | + |
|
86 | + $rc = $this->command->execute([ |
|
87 | + 'uid' => 'belle', |
|
88 | + 'provider_id' => 'totp', |
|
89 | + ]); |
|
90 | + |
|
91 | + $this->assertEquals(0, $rc); |
|
92 | + $this->assertStringContainsString('Two-factor provider totp enabled for user belle', $this->command->getDisplay()); |
|
93 | + } |
|
94 | 94 | } |
@@ -18,77 +18,77 @@ |
||
18 | 18 | use Test\TestCase; |
19 | 19 | |
20 | 20 | class DisableTest extends TestCase { |
21 | - /** @var ProviderManager|MockObject */ |
|
22 | - private $providerManager; |
|
23 | - |
|
24 | - /** @var IUserManager|MockObject */ |
|
25 | - private $userManager; |
|
26 | - |
|
27 | - /** @var CommandTester */ |
|
28 | - private $command; |
|
29 | - |
|
30 | - protected function setUp(): void { |
|
31 | - parent::setUp(); |
|
32 | - |
|
33 | - $this->providerManager = $this->createMock(ProviderManager::class); |
|
34 | - $this->userManager = $this->createMock(IUserManager::class); |
|
35 | - |
|
36 | - $cmd = new Disable($this->providerManager, $this->userManager); |
|
37 | - $this->command = new CommandTester($cmd); |
|
38 | - } |
|
39 | - |
|
40 | - public function testInvalidUID(): void { |
|
41 | - $this->userManager->expects($this->once()) |
|
42 | - ->method('get') |
|
43 | - ->with('nope') |
|
44 | - ->willReturn(null); |
|
45 | - |
|
46 | - $rc = $this->command->execute([ |
|
47 | - 'uid' => 'nope', |
|
48 | - 'provider_id' => 'nope', |
|
49 | - ]); |
|
50 | - |
|
51 | - $this->assertEquals(1, $rc); |
|
52 | - $this->assertStringContainsString('Invalid UID', $this->command->getDisplay()); |
|
53 | - } |
|
54 | - |
|
55 | - public function testEnableNotSupported(): void { |
|
56 | - $user = $this->createMock(IUser::class); |
|
57 | - $this->userManager->expects($this->once()) |
|
58 | - ->method('get') |
|
59 | - ->with('ricky') |
|
60 | - ->willReturn($user); |
|
61 | - $this->providerManager->expects($this->once()) |
|
62 | - ->method('tryDisableProviderFor') |
|
63 | - ->with('totp', $user) |
|
64 | - ->willReturn(false); |
|
65 | - |
|
66 | - $rc = $this->command->execute([ |
|
67 | - 'uid' => 'ricky', |
|
68 | - 'provider_id' => 'totp', |
|
69 | - ]); |
|
70 | - |
|
71 | - $this->assertEquals(2, $rc); |
|
72 | - $this->assertStringContainsString('The provider does not support this operation', $this->command->getDisplay()); |
|
73 | - } |
|
74 | - |
|
75 | - public function testEnabled(): void { |
|
76 | - $user = $this->createMock(IUser::class); |
|
77 | - $this->userManager->expects($this->once()) |
|
78 | - ->method('get') |
|
79 | - ->with('ricky') |
|
80 | - ->willReturn($user); |
|
81 | - $this->providerManager->expects($this->once()) |
|
82 | - ->method('tryDisableProviderFor') |
|
83 | - ->with('totp', $user) |
|
84 | - ->willReturn(true); |
|
85 | - |
|
86 | - $rc = $this->command->execute([ |
|
87 | - 'uid' => 'ricky', |
|
88 | - 'provider_id' => 'totp', |
|
89 | - ]); |
|
90 | - |
|
91 | - $this->assertEquals(0, $rc); |
|
92 | - $this->assertStringContainsString('Two-factor provider totp disabled for user ricky', $this->command->getDisplay()); |
|
93 | - } |
|
21 | + /** @var ProviderManager|MockObject */ |
|
22 | + private $providerManager; |
|
23 | + |
|
24 | + /** @var IUserManager|MockObject */ |
|
25 | + private $userManager; |
|
26 | + |
|
27 | + /** @var CommandTester */ |
|
28 | + private $command; |
|
29 | + |
|
30 | + protected function setUp(): void { |
|
31 | + parent::setUp(); |
|
32 | + |
|
33 | + $this->providerManager = $this->createMock(ProviderManager::class); |
|
34 | + $this->userManager = $this->createMock(IUserManager::class); |
|
35 | + |
|
36 | + $cmd = new Disable($this->providerManager, $this->userManager); |
|
37 | + $this->command = new CommandTester($cmd); |
|
38 | + } |
|
39 | + |
|
40 | + public function testInvalidUID(): void { |
|
41 | + $this->userManager->expects($this->once()) |
|
42 | + ->method('get') |
|
43 | + ->with('nope') |
|
44 | + ->willReturn(null); |
|
45 | + |
|
46 | + $rc = $this->command->execute([ |
|
47 | + 'uid' => 'nope', |
|
48 | + 'provider_id' => 'nope', |
|
49 | + ]); |
|
50 | + |
|
51 | + $this->assertEquals(1, $rc); |
|
52 | + $this->assertStringContainsString('Invalid UID', $this->command->getDisplay()); |
|
53 | + } |
|
54 | + |
|
55 | + public function testEnableNotSupported(): void { |
|
56 | + $user = $this->createMock(IUser::class); |
|
57 | + $this->userManager->expects($this->once()) |
|
58 | + ->method('get') |
|
59 | + ->with('ricky') |
|
60 | + ->willReturn($user); |
|
61 | + $this->providerManager->expects($this->once()) |
|
62 | + ->method('tryDisableProviderFor') |
|
63 | + ->with('totp', $user) |
|
64 | + ->willReturn(false); |
|
65 | + |
|
66 | + $rc = $this->command->execute([ |
|
67 | + 'uid' => 'ricky', |
|
68 | + 'provider_id' => 'totp', |
|
69 | + ]); |
|
70 | + |
|
71 | + $this->assertEquals(2, $rc); |
|
72 | + $this->assertStringContainsString('The provider does not support this operation', $this->command->getDisplay()); |
|
73 | + } |
|
74 | + |
|
75 | + public function testEnabled(): void { |
|
76 | + $user = $this->createMock(IUser::class); |
|
77 | + $this->userManager->expects($this->once()) |
|
78 | + ->method('get') |
|
79 | + ->with('ricky') |
|
80 | + ->willReturn($user); |
|
81 | + $this->providerManager->expects($this->once()) |
|
82 | + ->method('tryDisableProviderFor') |
|
83 | + ->with('totp', $user) |
|
84 | + ->willReturn(true); |
|
85 | + |
|
86 | + $rc = $this->command->execute([ |
|
87 | + 'uid' => 'ricky', |
|
88 | + 'provider_id' => 'totp', |
|
89 | + ]); |
|
90 | + |
|
91 | + $this->assertEquals(0, $rc); |
|
92 | + $this->assertStringContainsString('Two-factor provider totp disabled for user ricky', $this->command->getDisplay()); |
|
93 | + } |
|
94 | 94 | } |
@@ -14,64 +14,64 @@ |
||
14 | 14 | use Test\TestCase; |
15 | 15 | |
16 | 16 | class EnableTest extends TestCase { |
17 | - /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
18 | - protected $userManager; |
|
19 | - /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
20 | - protected $consoleInput; |
|
21 | - /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
22 | - protected $consoleOutput; |
|
23 | - |
|
24 | - /** @var Disable */ |
|
25 | - protected $command; |
|
26 | - |
|
27 | - protected function setUp(): void { |
|
28 | - parent::setUp(); |
|
29 | - |
|
30 | - $this->userManager = $this->createMock(IUserManager::class); |
|
31 | - $this->consoleInput = $this->createMock(InputInterface::class); |
|
32 | - $this->consoleOutput = $this->createMock(OutputInterface::class); |
|
33 | - |
|
34 | - $this->command = new Enable($this->userManager); |
|
35 | - } |
|
36 | - |
|
37 | - public function testValidUser(): void { |
|
38 | - $user = $this->createMock(IUser::class); |
|
39 | - $user->expects($this->once()) |
|
40 | - ->method('setEnabled') |
|
41 | - ->with(true); |
|
42 | - |
|
43 | - $this->userManager |
|
44 | - ->method('get') |
|
45 | - ->with('user') |
|
46 | - ->willReturn($user); |
|
47 | - |
|
48 | - $this->consoleInput |
|
49 | - ->method('getArgument') |
|
50 | - ->with('uid') |
|
51 | - ->willReturn('user'); |
|
52 | - |
|
53 | - $this->consoleOutput->expects($this->once()) |
|
54 | - ->method('writeln') |
|
55 | - ->with($this->stringContains('The specified user is enabled')); |
|
56 | - |
|
57 | - self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
58 | - } |
|
59 | - |
|
60 | - public function testInvalidUser(): void { |
|
61 | - $this->userManager->expects($this->once()) |
|
62 | - ->method('get') |
|
63 | - ->with('user') |
|
64 | - ->willReturn(null); |
|
65 | - |
|
66 | - $this->consoleInput |
|
67 | - ->method('getArgument') |
|
68 | - ->with('uid') |
|
69 | - ->willReturn('user'); |
|
70 | - |
|
71 | - $this->consoleOutput->expects($this->once()) |
|
72 | - ->method('writeln') |
|
73 | - ->with($this->stringContains('User does not exist')); |
|
74 | - |
|
75 | - self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
76 | - } |
|
17 | + /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
18 | + protected $userManager; |
|
19 | + /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
20 | + protected $consoleInput; |
|
21 | + /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
22 | + protected $consoleOutput; |
|
23 | + |
|
24 | + /** @var Disable */ |
|
25 | + protected $command; |
|
26 | + |
|
27 | + protected function setUp(): void { |
|
28 | + parent::setUp(); |
|
29 | + |
|
30 | + $this->userManager = $this->createMock(IUserManager::class); |
|
31 | + $this->consoleInput = $this->createMock(InputInterface::class); |
|
32 | + $this->consoleOutput = $this->createMock(OutputInterface::class); |
|
33 | + |
|
34 | + $this->command = new Enable($this->userManager); |
|
35 | + } |
|
36 | + |
|
37 | + public function testValidUser(): void { |
|
38 | + $user = $this->createMock(IUser::class); |
|
39 | + $user->expects($this->once()) |
|
40 | + ->method('setEnabled') |
|
41 | + ->with(true); |
|
42 | + |
|
43 | + $this->userManager |
|
44 | + ->method('get') |
|
45 | + ->with('user') |
|
46 | + ->willReturn($user); |
|
47 | + |
|
48 | + $this->consoleInput |
|
49 | + ->method('getArgument') |
|
50 | + ->with('uid') |
|
51 | + ->willReturn('user'); |
|
52 | + |
|
53 | + $this->consoleOutput->expects($this->once()) |
|
54 | + ->method('writeln') |
|
55 | + ->with($this->stringContains('The specified user is enabled')); |
|
56 | + |
|
57 | + self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
58 | + } |
|
59 | + |
|
60 | + public function testInvalidUser(): void { |
|
61 | + $this->userManager->expects($this->once()) |
|
62 | + ->method('get') |
|
63 | + ->with('user') |
|
64 | + ->willReturn(null); |
|
65 | + |
|
66 | + $this->consoleInput |
|
67 | + ->method('getArgument') |
|
68 | + ->with('uid') |
|
69 | + ->willReturn('user'); |
|
70 | + |
|
71 | + $this->consoleOutput->expects($this->once()) |
|
72 | + ->method('writeln') |
|
73 | + ->with($this->stringContains('User does not exist')); |
|
74 | + |
|
75 | + self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
76 | + } |
|
77 | 77 | } |
@@ -14,152 +14,152 @@ |
||
14 | 14 | use Test\TestCase; |
15 | 15 | |
16 | 16 | class DeleteTest extends TestCase { |
17 | - /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
18 | - protected $tokenProvider; |
|
19 | - /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
20 | - protected $consoleInput; |
|
21 | - /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
22 | - protected $consoleOutput; |
|
23 | - |
|
24 | - /** @var \Symfony\Component\Console\Command\Command */ |
|
25 | - protected $command; |
|
26 | - |
|
27 | - protected function setUp(): void { |
|
28 | - parent::setUp(); |
|
29 | - |
|
30 | - $tokenProvider = $this->tokenProvider = $this->getMockBuilder(IProvider::class) |
|
31 | - ->disableOriginalConstructor() |
|
32 | - ->getMock(); |
|
33 | - $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock(); |
|
34 | - $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock(); |
|
35 | - |
|
36 | - /** @var \OC\Authentication\Token\IProvider $tokenProvider */ |
|
37 | - $this->command = new Delete($tokenProvider); |
|
38 | - } |
|
39 | - |
|
40 | - public function testDeleteTokenById(): void { |
|
41 | - $this->consoleInput->expects($this->exactly(2)) |
|
42 | - ->method('getArgument') |
|
43 | - ->willReturnMap([ |
|
44 | - ['uid', 'user'], |
|
45 | - ['id', '42'] |
|
46 | - ]); |
|
47 | - |
|
48 | - $this->consoleInput->expects($this->once()) |
|
49 | - ->method('getOption') |
|
50 | - ->with('last-used-before') |
|
51 | - ->willReturn(null); |
|
52 | - |
|
53 | - $this->tokenProvider->expects($this->once()) |
|
54 | - ->method('invalidateTokenById') |
|
55 | - ->with('user', 42); |
|
56 | - |
|
57 | - $result = self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
58 | - $this->assertSame(Command::SUCCESS, $result); |
|
59 | - } |
|
60 | - |
|
61 | - public function testDeleteTokenByIdRequiresTokenId(): void { |
|
62 | - $this->consoleInput->expects($this->exactly(2)) |
|
63 | - ->method('getArgument') |
|
64 | - ->willReturnMap([ |
|
65 | - ['uid', 'user'], |
|
66 | - ['id', null] |
|
67 | - ]); |
|
68 | - |
|
69 | - $this->consoleInput->expects($this->once()) |
|
70 | - ->method('getOption') |
|
71 | - ->with('last-used-before') |
|
72 | - ->willReturn(null); |
|
73 | - |
|
74 | - $this->expectException(RuntimeException::class); |
|
75 | - |
|
76 | - $this->tokenProvider->expects($this->never())->method('invalidateTokenById'); |
|
77 | - |
|
78 | - $result = self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
79 | - $this->assertSame(Command::FAILURE, $result); |
|
80 | - } |
|
81 | - |
|
82 | - public function testDeleteTokensLastUsedBefore(): void { |
|
83 | - $this->consoleInput->expects($this->exactly(2)) |
|
84 | - ->method('getArgument') |
|
85 | - ->willReturnMap([ |
|
86 | - ['uid', 'user'], |
|
87 | - ['id', null] |
|
88 | - ]); |
|
89 | - |
|
90 | - $this->consoleInput->expects($this->once()) |
|
91 | - ->method('getOption') |
|
92 | - ->with('last-used-before') |
|
93 | - ->willReturn('946684800'); |
|
94 | - |
|
95 | - $this->tokenProvider->expects($this->once()) |
|
96 | - ->method('invalidateLastUsedBefore') |
|
97 | - ->with('user', 946684800); |
|
98 | - |
|
99 | - $result = self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
100 | - $this->assertSame(Command::SUCCESS, $result); |
|
101 | - } |
|
102 | - |
|
103 | - public function testLastUsedBeforeAcceptsIso8601Expanded(): void { |
|
104 | - $this->consoleInput->expects($this->exactly(2)) |
|
105 | - ->method('getArgument') |
|
106 | - ->willReturnMap([ |
|
107 | - ['uid', 'user'], |
|
108 | - ['id', null] |
|
109 | - ]); |
|
110 | - |
|
111 | - $this->consoleInput->expects($this->once()) |
|
112 | - ->method('getOption') |
|
113 | - ->with('last-used-before') |
|
114 | - ->willReturn('2000-01-01T00:00:00Z'); |
|
115 | - |
|
116 | - $this->tokenProvider->expects($this->once()) |
|
117 | - ->method('invalidateLastUsedBefore') |
|
118 | - ->with('user', 946684800); |
|
119 | - |
|
120 | - $result = self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
121 | - $this->assertSame(Command::SUCCESS, $result); |
|
122 | - } |
|
123 | - |
|
124 | - public function testLastUsedBeforeAcceptsYmd(): void { |
|
125 | - $this->consoleInput->expects($this->exactly(2)) |
|
126 | - ->method('getArgument') |
|
127 | - ->willReturnMap([ |
|
128 | - ['uid', 'user'], |
|
129 | - ['id', null] |
|
130 | - ]); |
|
131 | - |
|
132 | - $this->consoleInput->expects($this->once()) |
|
133 | - ->method('getOption') |
|
134 | - ->with('last-used-before') |
|
135 | - ->willReturn('2000-01-01'); |
|
136 | - |
|
137 | - $this->tokenProvider->expects($this->once()) |
|
138 | - ->method('invalidateLastUsedBefore') |
|
139 | - ->with('user', 946684800); |
|
140 | - |
|
141 | - $result = self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
142 | - $this->assertSame(Command::SUCCESS, $result); |
|
143 | - } |
|
144 | - |
|
145 | - public function testIdAndLastUsedBeforeAreMutuallyExclusive(): void { |
|
146 | - $this->consoleInput->expects($this->exactly(2)) |
|
147 | - ->method('getArgument') |
|
148 | - ->willReturnMap([ |
|
149 | - ['uid', 'user'], |
|
150 | - ['id', '42'] |
|
151 | - ]); |
|
152 | - |
|
153 | - $this->consoleInput->expects($this->once()) |
|
154 | - ->method('getOption') |
|
155 | - ->with('last-used-before') |
|
156 | - ->willReturn('946684800'); |
|
157 | - |
|
158 | - $this->expectException(RuntimeException::class); |
|
159 | - |
|
160 | - $this->tokenProvider->expects($this->never())->method('invalidateLastUsedBefore'); |
|
161 | - |
|
162 | - $result = self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
163 | - $this->assertSame(Command::SUCCESS, $result); |
|
164 | - } |
|
17 | + /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
18 | + protected $tokenProvider; |
|
19 | + /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
20 | + protected $consoleInput; |
|
21 | + /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
22 | + protected $consoleOutput; |
|
23 | + |
|
24 | + /** @var \Symfony\Component\Console\Command\Command */ |
|
25 | + protected $command; |
|
26 | + |
|
27 | + protected function setUp(): void { |
|
28 | + parent::setUp(); |
|
29 | + |
|
30 | + $tokenProvider = $this->tokenProvider = $this->getMockBuilder(IProvider::class) |
|
31 | + ->disableOriginalConstructor() |
|
32 | + ->getMock(); |
|
33 | + $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock(); |
|
34 | + $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock(); |
|
35 | + |
|
36 | + /** @var \OC\Authentication\Token\IProvider $tokenProvider */ |
|
37 | + $this->command = new Delete($tokenProvider); |
|
38 | + } |
|
39 | + |
|
40 | + public function testDeleteTokenById(): void { |
|
41 | + $this->consoleInput->expects($this->exactly(2)) |
|
42 | + ->method('getArgument') |
|
43 | + ->willReturnMap([ |
|
44 | + ['uid', 'user'], |
|
45 | + ['id', '42'] |
|
46 | + ]); |
|
47 | + |
|
48 | + $this->consoleInput->expects($this->once()) |
|
49 | + ->method('getOption') |
|
50 | + ->with('last-used-before') |
|
51 | + ->willReturn(null); |
|
52 | + |
|
53 | + $this->tokenProvider->expects($this->once()) |
|
54 | + ->method('invalidateTokenById') |
|
55 | + ->with('user', 42); |
|
56 | + |
|
57 | + $result = self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
58 | + $this->assertSame(Command::SUCCESS, $result); |
|
59 | + } |
|
60 | + |
|
61 | + public function testDeleteTokenByIdRequiresTokenId(): void { |
|
62 | + $this->consoleInput->expects($this->exactly(2)) |
|
63 | + ->method('getArgument') |
|
64 | + ->willReturnMap([ |
|
65 | + ['uid', 'user'], |
|
66 | + ['id', null] |
|
67 | + ]); |
|
68 | + |
|
69 | + $this->consoleInput->expects($this->once()) |
|
70 | + ->method('getOption') |
|
71 | + ->with('last-used-before') |
|
72 | + ->willReturn(null); |
|
73 | + |
|
74 | + $this->expectException(RuntimeException::class); |
|
75 | + |
|
76 | + $this->tokenProvider->expects($this->never())->method('invalidateTokenById'); |
|
77 | + |
|
78 | + $result = self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
79 | + $this->assertSame(Command::FAILURE, $result); |
|
80 | + } |
|
81 | + |
|
82 | + public function testDeleteTokensLastUsedBefore(): void { |
|
83 | + $this->consoleInput->expects($this->exactly(2)) |
|
84 | + ->method('getArgument') |
|
85 | + ->willReturnMap([ |
|
86 | + ['uid', 'user'], |
|
87 | + ['id', null] |
|
88 | + ]); |
|
89 | + |
|
90 | + $this->consoleInput->expects($this->once()) |
|
91 | + ->method('getOption') |
|
92 | + ->with('last-used-before') |
|
93 | + ->willReturn('946684800'); |
|
94 | + |
|
95 | + $this->tokenProvider->expects($this->once()) |
|
96 | + ->method('invalidateLastUsedBefore') |
|
97 | + ->with('user', 946684800); |
|
98 | + |
|
99 | + $result = self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
100 | + $this->assertSame(Command::SUCCESS, $result); |
|
101 | + } |
|
102 | + |
|
103 | + public function testLastUsedBeforeAcceptsIso8601Expanded(): void { |
|
104 | + $this->consoleInput->expects($this->exactly(2)) |
|
105 | + ->method('getArgument') |
|
106 | + ->willReturnMap([ |
|
107 | + ['uid', 'user'], |
|
108 | + ['id', null] |
|
109 | + ]); |
|
110 | + |
|
111 | + $this->consoleInput->expects($this->once()) |
|
112 | + ->method('getOption') |
|
113 | + ->with('last-used-before') |
|
114 | + ->willReturn('2000-01-01T00:00:00Z'); |
|
115 | + |
|
116 | + $this->tokenProvider->expects($this->once()) |
|
117 | + ->method('invalidateLastUsedBefore') |
|
118 | + ->with('user', 946684800); |
|
119 | + |
|
120 | + $result = self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
121 | + $this->assertSame(Command::SUCCESS, $result); |
|
122 | + } |
|
123 | + |
|
124 | + public function testLastUsedBeforeAcceptsYmd(): void { |
|
125 | + $this->consoleInput->expects($this->exactly(2)) |
|
126 | + ->method('getArgument') |
|
127 | + ->willReturnMap([ |
|
128 | + ['uid', 'user'], |
|
129 | + ['id', null] |
|
130 | + ]); |
|
131 | + |
|
132 | + $this->consoleInput->expects($this->once()) |
|
133 | + ->method('getOption') |
|
134 | + ->with('last-used-before') |
|
135 | + ->willReturn('2000-01-01'); |
|
136 | + |
|
137 | + $this->tokenProvider->expects($this->once()) |
|
138 | + ->method('invalidateLastUsedBefore') |
|
139 | + ->with('user', 946684800); |
|
140 | + |
|
141 | + $result = self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
142 | + $this->assertSame(Command::SUCCESS, $result); |
|
143 | + } |
|
144 | + |
|
145 | + public function testIdAndLastUsedBeforeAreMutuallyExclusive(): void { |
|
146 | + $this->consoleInput->expects($this->exactly(2)) |
|
147 | + ->method('getArgument') |
|
148 | + ->willReturnMap([ |
|
149 | + ['uid', 'user'], |
|
150 | + ['id', '42'] |
|
151 | + ]); |
|
152 | + |
|
153 | + $this->consoleInput->expects($this->once()) |
|
154 | + ->method('getOption') |
|
155 | + ->with('last-used-before') |
|
156 | + ->willReturn('946684800'); |
|
157 | + |
|
158 | + $this->expectException(RuntimeException::class); |
|
159 | + |
|
160 | + $this->tokenProvider->expects($this->never())->method('invalidateLastUsedBefore'); |
|
161 | + |
|
162 | + $result = self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
163 | + $this->assertSame(Command::SUCCESS, $result); |
|
164 | + } |
|
165 | 165 | } |
@@ -14,64 +14,64 @@ |
||
14 | 14 | use Test\TestCase; |
15 | 15 | |
16 | 16 | class DisableTest extends TestCase { |
17 | - /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
18 | - protected $userManager; |
|
19 | - /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
20 | - protected $consoleInput; |
|
21 | - /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
22 | - protected $consoleOutput; |
|
23 | - |
|
24 | - /** @var Disable */ |
|
25 | - protected $command; |
|
26 | - |
|
27 | - protected function setUp(): void { |
|
28 | - parent::setUp(); |
|
29 | - |
|
30 | - $this->userManager = $this->createMock(IUserManager::class); |
|
31 | - $this->consoleInput = $this->createMock(InputInterface::class); |
|
32 | - $this->consoleOutput = $this->createMock(OutputInterface::class); |
|
33 | - |
|
34 | - $this->command = new Disable($this->userManager); |
|
35 | - } |
|
36 | - |
|
37 | - public function testValidUser(): void { |
|
38 | - $user = $this->createMock(IUser::class); |
|
39 | - $user->expects($this->once()) |
|
40 | - ->method('setEnabled') |
|
41 | - ->with(false); |
|
42 | - |
|
43 | - $this->userManager |
|
44 | - ->method('get') |
|
45 | - ->with('user') |
|
46 | - ->willReturn($user); |
|
47 | - |
|
48 | - $this->consoleInput |
|
49 | - ->method('getArgument') |
|
50 | - ->with('uid') |
|
51 | - ->willReturn('user'); |
|
52 | - |
|
53 | - $this->consoleOutput->expects($this->once()) |
|
54 | - ->method('writeln') |
|
55 | - ->with($this->stringContains('The specified user is disabled')); |
|
56 | - |
|
57 | - self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
58 | - } |
|
59 | - |
|
60 | - public function testInvalidUser(): void { |
|
61 | - $this->userManager->expects($this->once()) |
|
62 | - ->method('get') |
|
63 | - ->with('user') |
|
64 | - ->willReturn(null); |
|
65 | - |
|
66 | - $this->consoleInput |
|
67 | - ->method('getArgument') |
|
68 | - ->with('uid') |
|
69 | - ->willReturn('user'); |
|
70 | - |
|
71 | - $this->consoleOutput->expects($this->once()) |
|
72 | - ->method('writeln') |
|
73 | - ->with($this->stringContains('User does not exist')); |
|
74 | - |
|
75 | - self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
76 | - } |
|
17 | + /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
18 | + protected $userManager; |
|
19 | + /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
20 | + protected $consoleInput; |
|
21 | + /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
22 | + protected $consoleOutput; |
|
23 | + |
|
24 | + /** @var Disable */ |
|
25 | + protected $command; |
|
26 | + |
|
27 | + protected function setUp(): void { |
|
28 | + parent::setUp(); |
|
29 | + |
|
30 | + $this->userManager = $this->createMock(IUserManager::class); |
|
31 | + $this->consoleInput = $this->createMock(InputInterface::class); |
|
32 | + $this->consoleOutput = $this->createMock(OutputInterface::class); |
|
33 | + |
|
34 | + $this->command = new Disable($this->userManager); |
|
35 | + } |
|
36 | + |
|
37 | + public function testValidUser(): void { |
|
38 | + $user = $this->createMock(IUser::class); |
|
39 | + $user->expects($this->once()) |
|
40 | + ->method('setEnabled') |
|
41 | + ->with(false); |
|
42 | + |
|
43 | + $this->userManager |
|
44 | + ->method('get') |
|
45 | + ->with('user') |
|
46 | + ->willReturn($user); |
|
47 | + |
|
48 | + $this->consoleInput |
|
49 | + ->method('getArgument') |
|
50 | + ->with('uid') |
|
51 | + ->willReturn('user'); |
|
52 | + |
|
53 | + $this->consoleOutput->expects($this->once()) |
|
54 | + ->method('writeln') |
|
55 | + ->with($this->stringContains('The specified user is disabled')); |
|
56 | + |
|
57 | + self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
58 | + } |
|
59 | + |
|
60 | + public function testInvalidUser(): void { |
|
61 | + $this->userManager->expects($this->once()) |
|
62 | + ->method('get') |
|
63 | + ->with('user') |
|
64 | + ->willReturn(null); |
|
65 | + |
|
66 | + $this->consoleInput |
|
67 | + ->method('getArgument') |
|
68 | + ->with('uid') |
|
69 | + ->willReturn('user'); |
|
70 | + |
|
71 | + $this->consoleOutput->expects($this->once()) |
|
72 | + ->method('writeln') |
|
73 | + ->with($this->stringContains('User does not exist')); |
|
74 | + |
|
75 | + self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
76 | + } |
|
77 | 77 | } |
@@ -16,85 +16,85 @@ |
||
16 | 16 | use Test\TestCase; |
17 | 17 | |
18 | 18 | class AddUserTest extends TestCase { |
19 | - /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
20 | - private $groupManager; |
|
21 | - |
|
22 | - /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
23 | - private $userManager; |
|
24 | - |
|
25 | - /** @var AddUser */ |
|
26 | - private $command; |
|
27 | - |
|
28 | - /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
29 | - private $input; |
|
30 | - |
|
31 | - /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
32 | - private $output; |
|
33 | - |
|
34 | - protected function setUp(): void { |
|
35 | - parent::setUp(); |
|
36 | - |
|
37 | - $this->groupManager = $this->createMock(IGroupManager::class); |
|
38 | - $this->userManager = $this->createMock(IUserManager::class); |
|
39 | - $this->command = new AddUser($this->userManager, $this->groupManager); |
|
40 | - |
|
41 | - $this->input = $this->createMock(InputInterface::class); |
|
42 | - $this->input->method('getArgument') |
|
43 | - ->willReturnCallback(function ($arg) { |
|
44 | - if ($arg === 'group') { |
|
45 | - return 'myGroup'; |
|
46 | - } elseif ($arg === 'user') { |
|
47 | - return 'myUser'; |
|
48 | - } |
|
49 | - throw new \Exception(); |
|
50 | - }); |
|
51 | - $this->output = $this->createMock(OutputInterface::class); |
|
52 | - } |
|
53 | - |
|
54 | - public function testNoGroup(): void { |
|
55 | - $this->groupManager->method('get') |
|
56 | - ->with('myGroup') |
|
57 | - ->willReturn(null); |
|
58 | - |
|
59 | - $this->output->expects($this->once()) |
|
60 | - ->method('writeln') |
|
61 | - ->with('<error>group not found</error>'); |
|
62 | - |
|
63 | - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
64 | - } |
|
65 | - |
|
66 | - public function testNoUser(): void { |
|
67 | - $group = $this->createMock(IGroup::class); |
|
68 | - $this->groupManager->method('get') |
|
69 | - ->with('myGroup') |
|
70 | - ->willReturn($group); |
|
71 | - |
|
72 | - $this->userManager->method('get') |
|
73 | - ->with('myUser') |
|
74 | - ->willReturn(null); |
|
75 | - |
|
76 | - $this->output->expects($this->once()) |
|
77 | - ->method('writeln') |
|
78 | - ->with('<error>user not found</error>'); |
|
79 | - |
|
80 | - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
81 | - } |
|
82 | - |
|
83 | - public function testAdd(): void { |
|
84 | - $group = $this->createMock(IGroup::class); |
|
85 | - $this->groupManager->method('get') |
|
86 | - ->with('myGroup') |
|
87 | - ->willReturn($group); |
|
88 | - |
|
89 | - $user = $this->createMock(IUser::class); |
|
90 | - $this->userManager->method('get') |
|
91 | - ->with('myUser') |
|
92 | - ->willReturn($user); |
|
93 | - |
|
94 | - $group->expects($this->once()) |
|
95 | - ->method('addUser') |
|
96 | - ->with($user); |
|
97 | - |
|
98 | - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
99 | - } |
|
19 | + /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
20 | + private $groupManager; |
|
21 | + |
|
22 | + /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
23 | + private $userManager; |
|
24 | + |
|
25 | + /** @var AddUser */ |
|
26 | + private $command; |
|
27 | + |
|
28 | + /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
29 | + private $input; |
|
30 | + |
|
31 | + /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
32 | + private $output; |
|
33 | + |
|
34 | + protected function setUp(): void { |
|
35 | + parent::setUp(); |
|
36 | + |
|
37 | + $this->groupManager = $this->createMock(IGroupManager::class); |
|
38 | + $this->userManager = $this->createMock(IUserManager::class); |
|
39 | + $this->command = new AddUser($this->userManager, $this->groupManager); |
|
40 | + |
|
41 | + $this->input = $this->createMock(InputInterface::class); |
|
42 | + $this->input->method('getArgument') |
|
43 | + ->willReturnCallback(function ($arg) { |
|
44 | + if ($arg === 'group') { |
|
45 | + return 'myGroup'; |
|
46 | + } elseif ($arg === 'user') { |
|
47 | + return 'myUser'; |
|
48 | + } |
|
49 | + throw new \Exception(); |
|
50 | + }); |
|
51 | + $this->output = $this->createMock(OutputInterface::class); |
|
52 | + } |
|
53 | + |
|
54 | + public function testNoGroup(): void { |
|
55 | + $this->groupManager->method('get') |
|
56 | + ->with('myGroup') |
|
57 | + ->willReturn(null); |
|
58 | + |
|
59 | + $this->output->expects($this->once()) |
|
60 | + ->method('writeln') |
|
61 | + ->with('<error>group not found</error>'); |
|
62 | + |
|
63 | + $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
64 | + } |
|
65 | + |
|
66 | + public function testNoUser(): void { |
|
67 | + $group = $this->createMock(IGroup::class); |
|
68 | + $this->groupManager->method('get') |
|
69 | + ->with('myGroup') |
|
70 | + ->willReturn($group); |
|
71 | + |
|
72 | + $this->userManager->method('get') |
|
73 | + ->with('myUser') |
|
74 | + ->willReturn(null); |
|
75 | + |
|
76 | + $this->output->expects($this->once()) |
|
77 | + ->method('writeln') |
|
78 | + ->with('<error>user not found</error>'); |
|
79 | + |
|
80 | + $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
81 | + } |
|
82 | + |
|
83 | + public function testAdd(): void { |
|
84 | + $group = $this->createMock(IGroup::class); |
|
85 | + $this->groupManager->method('get') |
|
86 | + ->with('myGroup') |
|
87 | + ->willReturn($group); |
|
88 | + |
|
89 | + $user = $this->createMock(IUser::class); |
|
90 | + $this->userManager->method('get') |
|
91 | + ->with('myUser') |
|
92 | + ->willReturn($user); |
|
93 | + |
|
94 | + $group->expects($this->once()) |
|
95 | + ->method('addUser') |
|
96 | + ->with($user); |
|
97 | + |
|
98 | + $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
99 | + } |
|
100 | 100 | } |
@@ -16,85 +16,85 @@ |
||
16 | 16 | use Test\TestCase; |
17 | 17 | |
18 | 18 | class RemoveUserTest extends TestCase { |
19 | - /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
20 | - private $groupManager; |
|
21 | - |
|
22 | - /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
23 | - private $userManager; |
|
24 | - |
|
25 | - /** @var RemoveUser */ |
|
26 | - private $command; |
|
27 | - |
|
28 | - /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
29 | - private $input; |
|
30 | - |
|
31 | - /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
32 | - private $output; |
|
33 | - |
|
34 | - protected function setUp(): void { |
|
35 | - parent::setUp(); |
|
36 | - |
|
37 | - $this->groupManager = $this->createMock(IGroupManager::class); |
|
38 | - $this->userManager = $this->createMock(IUserManager::class); |
|
39 | - $this->command = new RemoveUser($this->userManager, $this->groupManager); |
|
40 | - |
|
41 | - $this->input = $this->createMock(InputInterface::class); |
|
42 | - $this->input->method('getArgument') |
|
43 | - ->willReturnCallback(function ($arg) { |
|
44 | - if ($arg === 'group') { |
|
45 | - return 'myGroup'; |
|
46 | - } elseif ($arg === 'user') { |
|
47 | - return 'myUser'; |
|
48 | - } |
|
49 | - throw new \Exception(); |
|
50 | - }); |
|
51 | - $this->output = $this->createMock(OutputInterface::class); |
|
52 | - } |
|
53 | - |
|
54 | - public function testNoGroup(): void { |
|
55 | - $this->groupManager->method('get') |
|
56 | - ->with('myGroup') |
|
57 | - ->willReturn(null); |
|
58 | - |
|
59 | - $this->output->expects($this->once()) |
|
60 | - ->method('writeln') |
|
61 | - ->with('<error>group not found</error>'); |
|
62 | - |
|
63 | - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
64 | - } |
|
65 | - |
|
66 | - public function testNoUser(): void { |
|
67 | - $group = $this->createMock(IGroup::class); |
|
68 | - $this->groupManager->method('get') |
|
69 | - ->with('myGroup') |
|
70 | - ->willReturn($group); |
|
71 | - |
|
72 | - $this->userManager->method('get') |
|
73 | - ->with('myUser') |
|
74 | - ->willReturn(null); |
|
75 | - |
|
76 | - $this->output->expects($this->once()) |
|
77 | - ->method('writeln') |
|
78 | - ->with('<error>user not found</error>'); |
|
79 | - |
|
80 | - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
81 | - } |
|
82 | - |
|
83 | - public function testAdd(): void { |
|
84 | - $group = $this->createMock(IGroup::class); |
|
85 | - $this->groupManager->method('get') |
|
86 | - ->with('myGroup') |
|
87 | - ->willReturn($group); |
|
88 | - |
|
89 | - $user = $this->createMock(IUser::class); |
|
90 | - $this->userManager->method('get') |
|
91 | - ->with('myUser') |
|
92 | - ->willReturn($user); |
|
93 | - |
|
94 | - $group->expects($this->once()) |
|
95 | - ->method('removeUser') |
|
96 | - ->with($user); |
|
97 | - |
|
98 | - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
99 | - } |
|
19 | + /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
20 | + private $groupManager; |
|
21 | + |
|
22 | + /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
23 | + private $userManager; |
|
24 | + |
|
25 | + /** @var RemoveUser */ |
|
26 | + private $command; |
|
27 | + |
|
28 | + /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
29 | + private $input; |
|
30 | + |
|
31 | + /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
32 | + private $output; |
|
33 | + |
|
34 | + protected function setUp(): void { |
|
35 | + parent::setUp(); |
|
36 | + |
|
37 | + $this->groupManager = $this->createMock(IGroupManager::class); |
|
38 | + $this->userManager = $this->createMock(IUserManager::class); |
|
39 | + $this->command = new RemoveUser($this->userManager, $this->groupManager); |
|
40 | + |
|
41 | + $this->input = $this->createMock(InputInterface::class); |
|
42 | + $this->input->method('getArgument') |
|
43 | + ->willReturnCallback(function ($arg) { |
|
44 | + if ($arg === 'group') { |
|
45 | + return 'myGroup'; |
|
46 | + } elseif ($arg === 'user') { |
|
47 | + return 'myUser'; |
|
48 | + } |
|
49 | + throw new \Exception(); |
|
50 | + }); |
|
51 | + $this->output = $this->createMock(OutputInterface::class); |
|
52 | + } |
|
53 | + |
|
54 | + public function testNoGroup(): void { |
|
55 | + $this->groupManager->method('get') |
|
56 | + ->with('myGroup') |
|
57 | + ->willReturn(null); |
|
58 | + |
|
59 | + $this->output->expects($this->once()) |
|
60 | + ->method('writeln') |
|
61 | + ->with('<error>group not found</error>'); |
|
62 | + |
|
63 | + $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
64 | + } |
|
65 | + |
|
66 | + public function testNoUser(): void { |
|
67 | + $group = $this->createMock(IGroup::class); |
|
68 | + $this->groupManager->method('get') |
|
69 | + ->with('myGroup') |
|
70 | + ->willReturn($group); |
|
71 | + |
|
72 | + $this->userManager->method('get') |
|
73 | + ->with('myUser') |
|
74 | + ->willReturn(null); |
|
75 | + |
|
76 | + $this->output->expects($this->once()) |
|
77 | + ->method('writeln') |
|
78 | + ->with('<error>user not found</error>'); |
|
79 | + |
|
80 | + $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
81 | + } |
|
82 | + |
|
83 | + public function testAdd(): void { |
|
84 | + $group = $this->createMock(IGroup::class); |
|
85 | + $this->groupManager->method('get') |
|
86 | + ->with('myGroup') |
|
87 | + ->willReturn($group); |
|
88 | + |
|
89 | + $user = $this->createMock(IUser::class); |
|
90 | + $this->userManager->method('get') |
|
91 | + ->with('myUser') |
|
92 | + ->willReturn($user); |
|
93 | + |
|
94 | + $group->expects($this->once()) |
|
95 | + ->method('removeUser') |
|
96 | + ->with($user); |
|
97 | + |
|
98 | + $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
99 | + } |
|
100 | 100 | } |