1010
1111use OC \Core \Command \Encryption \DecryptAll ;
1212use OCP \App \IAppManager ;
13- use OCP \Encryption \ IManager ;
13+ use OCP \IAppConfig ;
1414use OCP \IConfig ;
15+ use PHPUnit \Framework \MockObject \MockObject ;
1516use Symfony \Component \Console \Helper \QuestionHelper ;
1617use Symfony \Component \Console \Input \InputInterface ;
1718use Symfony \Component \Console \Output \OutputInterface ;
1819use Test \TestCase ;
1920
2021class DecryptAllTest extends TestCase {
21- /** @var \PHPUnit\Framework\MockObject\MockObject|IConfig */
22- protected $ config ;
23-
24- /** @var \PHPUnit\Framework\MockObject\MockObject | \OCP\Encryption\IManager */
25- protected $ encryptionManager ;
26-
27- /** @var \PHPUnit\Framework\MockObject\MockObject|IAppManager */
28- protected $ appManager ;
29-
30- /** @var \PHPUnit\Framework\MockObject\MockObject | \Symfony\Component\Console\Input\InputInterface */
31- protected $ consoleInput ;
32-
33- /** @var \PHPUnit\Framework\MockObject\MockObject | \Symfony\Component\Console\Output\OutputInterface */
34- protected $ consoleOutput ;
35-
36- /** @var \PHPUnit\Framework\MockObject\MockObject | \Symfony\Component\Console\Helper\QuestionHelper */
37- protected $ questionHelper ;
38-
39- /** @var \PHPUnit\Framework\MockObject\MockObject | \OC\Encryption\DecryptAll */
40- protected $ decryptAll ;
22+ private MockObject &IConfig $ config ;
23+ private MockObject &IAppConfig $ appConfig ;
24+ private MockObject &IAppManager $ appManager ;
25+ private MockObject &InputInterface $ consoleInput ;
26+ private MockObject &OutputInterface $ consoleOutput ;
27+ private MockObject &QuestionHelper $ questionHelper ;
28+ private MockObject &\OC \Encryption \DecryptAll $ decryptAll ;
4129
4230 protected function setUp (): void {
4331 parent ::setUp ();
4432
45- $ this ->config = $ this ->getMockBuilder (IConfig::class)
46- ->disableOriginalConstructor ()
47- ->getMock ();
48- $ this ->encryptionManager = $ this ->getMockBuilder (IManager::class)
49- ->disableOriginalConstructor ()
50- ->getMock ();
51- $ this ->appManager = $ this ->getMockBuilder (IAppManager::class)
52- ->disableOriginalConstructor ()
53- ->getMock ();
54- $ this ->questionHelper = $ this ->getMockBuilder (QuestionHelper::class)
55- ->disableOriginalConstructor ()
56- ->getMock ();
57- $ this ->decryptAll = $ this ->getMockBuilder (\OC \Encryption \DecryptAll::class)
58- ->disableOriginalConstructor ()->getMock ();
33+ $ this ->config = $ this ->createMock (IConfig::class);
34+ $ this ->appConfig = $ this ->createMock (IAppConfig::class);
35+ $ this ->appManager = $ this ->createMock (IAppManager::class);
36+ $ this ->questionHelper = $ this ->createMock (QuestionHelper::class);
37+ $ this ->decryptAll = $ this ->createMock (\OC \Encryption \DecryptAll::class);
38+
5939 $ this ->consoleInput = $ this ->getMockBuilder (InputInterface::class)->getMock ();
6040 $ this ->consoleInput ->expects ($ this ->any ())
6141 ->method ('isInteractive ' )
@@ -92,9 +72,9 @@ public function testMaintenanceAndTrashbin(): void {
9272 ->with ('files_trashbin ' );
9373
9474 $ instance = new DecryptAll (
95- $ this ->encryptionManager ,
9675 $ this ->appManager ,
9776 $ this ->config ,
77+ $ this ->appConfig ,
9878 $ this ->decryptAll ,
9979 $ this ->questionHelper
10080 );
@@ -113,15 +93,16 @@ public function testMaintenanceAndTrashbin(): void {
11393 #[\PHPUnit \Framework \Attributes \DataProvider('dataTestExecute ' )]
11494 public function testExecute ($ encryptionEnabled , $ continue ): void {
11595 $ instance = new DecryptAll (
116- $ this ->encryptionManager ,
11796 $ this ->appManager ,
11897 $ this ->config ,
98+ $ this ->appConfig ,
11999 $ this ->decryptAll ,
120100 $ this ->questionHelper
121101 );
122102
123- $ this ->encryptionManager ->expects ($ this ->once ())
124- ->method ('isEnabled ' )
103+ $ this ->appConfig ->expects ($ this ->once ())
104+ ->method ('getValueBool ' )
105+ ->with ('core ' , 'encryption_enabled ' )
125106 ->willReturn ($ encryptionEnabled );
126107
127108 $ this ->consoleInput ->expects ($ this ->any ())
@@ -131,29 +112,29 @@ public function testExecute($encryptionEnabled, $continue): void {
131112
132113 if ($ encryptionEnabled ) {
133114 $ calls = [
134- ['core ' , 'encryption_enabled ' , ' no ' ],
135- ['core ' , 'encryption_enabled ' , ' yes ' ],
115+ ['core ' , 'encryption_enabled ' , false , false ],
116+ ['core ' , 'encryption_enabled ' , true , false ],
136117 ];
137- $ this ->config ->expects ($ this ->exactly (2 ))
138- ->method ('setAppValue ' )
139- ->willReturnCallback (function () use (&$ calls ): void {
118+ $ this ->appConfig ->expects ($ this ->exactly (count ( $ calls ) ))
119+ ->method ('setValueBool ' )
120+ ->willReturnCallback (function () use (&$ calls ): bool {
140121 $ expected = array_shift ($ calls );
141122 $ this ->assertEquals ($ expected , func_get_args ());
123+ return true ;
142124 });
143- $ this ->questionHelper ->expects ($ this ->once ())
144- ->method ('ask ' )
145- ->willReturn ($ continue );
146- if ($ continue ) {
147- $ this ->decryptAll ->expects ($ this ->once ())
148- ->method ('decryptAll ' )
149- ->with ($ this ->consoleInput , $ this ->consoleOutput , 'user1 ' );
150- } else {
151- $ this ->decryptAll ->expects ($ this ->never ())->method ('decryptAll ' );
152- }
153125 } else {
154- $ this ->config ->expects ($ this ->never ())->method ('setAppValue ' );
126+ $ this ->appConfig ->expects ($ this ->never ())
127+ ->method ('setValueBool ' );
128+ }
129+ $ this ->questionHelper ->expects ($ this ->once ())
130+ ->method ('ask ' )
131+ ->willReturn ($ continue );
132+ if ($ continue ) {
133+ $ this ->decryptAll ->expects ($ this ->once ())
134+ ->method ('decryptAll ' )
135+ ->with ($ this ->consoleInput , $ this ->consoleOutput , 'user1 ' );
136+ } else {
155137 $ this ->decryptAll ->expects ($ this ->never ())->method ('decryptAll ' );
156- $ this ->questionHelper ->expects ($ this ->never ())->method ('ask ' );
157138 }
158139
159140 $ this ->invokePrivate ($ instance , 'execute ' , [$ this ->consoleInput , $ this ->consoleOutput ]);
@@ -173,26 +154,28 @@ public function testExecuteFailure(): void {
173154 $ this ->expectException (\Exception::class);
174155
175156 $ instance = new DecryptAll (
176- $ this ->encryptionManager ,
177157 $ this ->appManager ,
178158 $ this ->config ,
159+ $ this ->appConfig ,
179160 $ this ->decryptAll ,
180161 $ this ->questionHelper
181162 );
182163
183164 // make sure that we enable encryption again after a exception was thrown
184165 $ calls = [
185- ['core ' , 'encryption_enabled ' , ' no ' ],
186- ['core ' , 'encryption_enabled ' , ' yes ' ],
166+ ['core ' , 'encryption_enabled ' , false , false ],
167+ ['core ' , 'encryption_enabled ' , true , false ],
187168 ];
188- $ this ->config ->expects ($ this ->exactly (2 ))
189- ->method ('setAppValue ' )
190- ->willReturnCallback (function () use (&$ calls ): void {
169+ $ this ->appConfig ->expects ($ this ->exactly (2 ))
170+ ->method ('setValuebool ' )
171+ ->willReturnCallback (function () use (&$ calls ): bool {
191172 $ expected = array_shift ($ calls );
192173 $ this ->assertEquals ($ expected , func_get_args ());
174+ return true ;
193175 });
194- $ this ->encryptionManager ->expects ($ this ->once ())
195- ->method ('isEnabled ' )
176+ $ this ->appConfig ->expects ($ this ->once ())
177+ ->method ('getValueBool ' )
178+ ->with ('core ' , 'encryption_enabled ' )
196179 ->willReturn (true );
197180
198181 $ this ->consoleInput ->expects ($ this ->any ())
0 commit comments