Skip to content

Commit fc68e71

Browse files
cuppettclaude
andcommitted
fix(tests): Update encryption command tests for IAppConfig changes
Update unit tests for Enable and Disable commands to mock the new IAppConfig dependency that was added in the previous commit. Changes: - tests/Core/Command/Encryption/EnableTest: Add IAppConfig mock - tests/Core/Command/Encryption/DisableTest: Add IAppConfig mock - Update test expectations to use getValueString/setValueString Fixes 7 test failures in the NODB test suite. Co-authored-by: Claude Sonnet 4.5 (1M context) <[email protected]> Signed-off-by: Stephen Cuppett <[email protected]>
1 parent d6c905a commit fc68e71

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

tests/Core/Command/Encryption/DisableTest.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace Tests\Core\Command\Encryption;
1010

1111
use OC\Core\Command\Encryption\Disable;
12+
use OCP\IAppConfig;
1213
use OCP\IConfig;
1314
use Symfony\Component\Console\Input\InputInterface;
1415
use Symfony\Component\Console\Output\OutputInterface;
@@ -18,6 +19,8 @@ class DisableTest extends TestCase {
1819
/** @var \PHPUnit\Framework\MockObject\MockObject */
1920
protected $config;
2021
/** @var \PHPUnit\Framework\MockObject\MockObject */
22+
protected $appConfig;
23+
/** @var \PHPUnit\Framework\MockObject\MockObject */
2124
protected $consoleInput;
2225
/** @var \PHPUnit\Framework\MockObject\MockObject */
2326
protected $consoleOutput;
@@ -31,11 +34,15 @@ protected function setUp(): void {
3134
$config = $this->config = $this->getMockBuilder(IConfig::class)
3235
->disableOriginalConstructor()
3336
->getMock();
37+
$appConfig = $this->appConfig = $this->getMockBuilder(IAppConfig::class)
38+
->disableOriginalConstructor()
39+
->getMock();
3440
$this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
3541
$this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
3642

3743
/** @var IConfig $config */
38-
$this->command = new Disable($config);
44+
/** @var IAppConfig $appConfig */
45+
$this->command = new Disable($config, $appConfig);
3946
}
4047

4148

@@ -54,18 +61,18 @@ public static function dataDisable(): array {
5461
*/
5562
#[\PHPUnit\Framework\Attributes\DataProvider('dataDisable')]
5663
public function testDisable($oldStatus, $isUpdating, $expectedString): void {
57-
$this->config->expects($this->once())
58-
->method('getAppValue')
59-
->with('core', 'encryption_enabled', $this->anything())
64+
$this->appConfig->expects($this->once())
65+
->method('getValueString')
66+
->with('core', 'encryption_enabled', 'no')
6067
->willReturn($oldStatus);
6168

6269
$this->consoleOutput->expects($this->once())
6370
->method('writeln')
6471
->with($this->stringContains($expectedString));
6572

6673
if ($isUpdating) {
67-
$this->config->expects($this->once())
68-
->method('setAppValue')
74+
$this->appConfig->expects($this->once())
75+
->method('setValueString')
6976
->with('core', 'encryption_enabled', 'no');
7077
}
7178

tests/Core/Command/Encryption/EnableTest.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use OC\Core\Command\Encryption\Enable;
1212
use OCP\Encryption\IManager;
13+
use OCP\IAppConfig;
1314
use OCP\IConfig;
1415
use Symfony\Component\Console\Input\InputInterface;
1516
use Symfony\Component\Console\Output\OutputInterface;
@@ -19,6 +20,8 @@ class EnableTest extends TestCase {
1920
/** @var \PHPUnit\Framework\MockObject\MockObject */
2021
protected $config;
2122
/** @var \PHPUnit\Framework\MockObject\MockObject */
23+
protected $appConfig;
24+
/** @var \PHPUnit\Framework\MockObject\MockObject */
2225
protected $manager;
2326
/** @var \PHPUnit\Framework\MockObject\MockObject */
2427
protected $consoleInput;
@@ -34,15 +37,19 @@ protected function setUp(): void {
3437
$config = $this->config = $this->getMockBuilder(IConfig::class)
3538
->disableOriginalConstructor()
3639
->getMock();
40+
$appConfig = $this->appConfig = $this->getMockBuilder(IAppConfig::class)
41+
->disableOriginalConstructor()
42+
->getMock();
3743
$manager = $this->manager = $this->getMockBuilder(IManager::class)
3844
->disableOriginalConstructor()
3945
->getMock();
4046
$this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
4147
$this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
4248

4349
/** @var \OCP\IConfig $config */
50+
/** @var \OCP\IAppConfig $appConfig */
4451
/** @var \OCP\Encryption\IManager $manager */
45-
$this->command = new Enable($config, $manager);
52+
$this->command = new Enable($config, $appConfig, $manager);
4653
}
4754

4855

@@ -59,8 +66,8 @@ public static function dataEnable(): array {
5966
#[\PHPUnit\Framework\Attributes\DataProvider('dataEnable')]
6067
public function testEnable(string $oldStatus, ?string $defaultModule, array $availableModules, bool $isUpdating, string $expectedString, string $expectedDefaultModuleString): void {
6168
if ($isUpdating) {
62-
$this->config->expects($this->once())
63-
->method('setAppValue')
69+
$this->appConfig->expects($this->once())
70+
->method('setValueString')
6471
->with('core', 'encryption_enabled', 'yes');
6572
}
6673

@@ -69,14 +76,14 @@ public function testEnable(string $oldStatus, ?string $defaultModule, array $ava
6976
->willReturn($availableModules);
7077

7178
if (empty($availableModules)) {
72-
$this->config->expects($this->once())
73-
->method('getAppValue')
79+
$this->appConfig->expects($this->once())
80+
->method('getValueString')
7481
->willReturnMap([
7582
['core', 'encryption_enabled', 'no', $oldStatus],
7683
]);
7784
} else {
78-
$this->config->expects($this->exactly(2))
79-
->method('getAppValue')
85+
$this->appConfig->expects($this->exactly(2))
86+
->method('getValueString')
8087
->willReturnMap([
8188
['core', 'encryption_enabled', 'no', $oldStatus],
8289
['core', 'default_encryption_module', '', $defaultModule],

0 commit comments

Comments
 (0)