Skip to content

Commit 586292c

Browse files
committed
test: Introduce fakes for app config
And use it in some tests Signed-off-by: Louis Chmn <louis@chmn.me>
1 parent 94194e7 commit 586292c

6 files changed

Lines changed: 411 additions & 25 deletions

File tree

apps/appstore/tests/Controller/ApiControllerTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
use OC\Installer;
1717
use OCA\Appstore\Controller\ApiController;
1818
use OCP\AppFramework\Http\DataResponse;
19-
use OCP\IAppConfig;
2019
use OCP\IConfig;
2120
use OCP\IRequest;
2221
use OCP\L10N\IFactory;
2322
use OCP\Support\Subscription\IRegistry;
2423
use PHPUnit\Framework\MockObject\MockObject;
2524
use Psr\Log\LoggerInterface;
25+
use Test\FakeAppConfig;
2626
use Test\TestCase;
2727

2828
#[\PHPUnit\Framework\Attributes\Group(name: 'DB')]
@@ -31,8 +31,6 @@ final class ApiControllerTest extends TestCase {
3131

3232
private IConfig&MockObject $config;
3333

34-
private IAppConfig&MockObject $appConfig;
35-
3634
private AppManager&MockObject $appManager;
3735

3836
private DependencyAnalyzer&MockObject $dependencyAnalyzer;
@@ -59,7 +57,6 @@ protected function setUp(): void {
5957

6058
$this->request = $this->createMock(IRequest::class);
6159
$this->config = $this->createMock(IConfig::class);
62-
$this->appConfig = $this->createMock(IAppConfig::class);
6360
$this->appManager = $this->createMock(AppManager::class);
6461
$this->dependencyAnalyzer = $this->createMock(DependencyAnalyzer::class);
6562
$this->categoryFetcher = $this->createMock(CategoryFetcher::class);
@@ -73,7 +70,7 @@ protected function setUp(): void {
7370
$this->apiController = new ApiController(
7471
$this->request,
7572
$this->config,
76-
$this->appConfig,
73+
new FakeAppConfig(),
7774
$this->appManager,
7875
$this->dependencyAnalyzer,
7976
$this->categoryFetcher,

apps/cloud_federation_api/tests/RequestHandlerControllerTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use OCP\Federation\ICloudFederationFactory;
2121
use OCP\Federation\ICloudFederationProviderManager;
2222
use OCP\Federation\ICloudIdManager;
23-
use OCP\IAppConfig;
2423
use OCP\IGroupManager;
2524
use OCP\IRequest;
2625
use OCP\IURLGenerator;
@@ -29,6 +28,7 @@
2928
use OCP\OCM\IOCMDiscoveryService;
3029
use PHPUnit\Framework\MockObject\MockObject;
3130
use Psr\Log\LoggerInterface;
31+
use Test\FakeAppConfig;
3232
use Test\TestCase;
3333

3434
class RequestHandlerControllerTest extends TestCase {
@@ -41,7 +41,6 @@ class RequestHandlerControllerTest extends TestCase {
4141
private Config&MockObject $config;
4242
private IEventDispatcher&MockObject $eventDispatcher;
4343
private FederatedInviteMapper&MockObject $federatedInviteMapper;
44-
private IAppConfig&MockObject $appConfig;
4544

4645
private ICloudFederationFactory&MockObject $cloudFederationFactory;
4746
private ICloudIdManager&MockObject $cloudIdManager;
@@ -62,7 +61,6 @@ protected function setUp(): void {
6261
$this->config = $this->createMock(Config::class);
6362
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
6463
$this->federatedInviteMapper = $this->createMock(FederatedInviteMapper::class);
65-
$this->appConfig = $this->createMock(IAppConfig::class);
6664
$this->cloudFederationFactory = $this->createMock(ICloudFederationFactory::class);
6765
$this->cloudIdManager = $this->createMock(ICloudIdManager::class);
6866
$this->discoveryService = $this->createMock(IOCMDiscoveryService::class);
@@ -79,7 +77,7 @@ protected function setUp(): void {
7977
$this->config,
8078
$this->eventDispatcher,
8179
$this->federatedInviteMapper,
82-
$this->appConfig,
80+
new FakeAppConfig(),
8381
$this->cloudFederationFactory,
8482
$this->cloudIdManager,
8583
$this->discoveryService,

apps/dashboard/tests/DashboardServiceTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
use OCP\IUserManager;
1919
use PHPUnit\Framework\MockObject\MockObject;
2020
use Test\TestCase;
21+
use Test\FakeAppConfig;
22+
use Test\FakeFrameworkAppConfig;
2123

2224
class DashboardServiceTest extends TestCase {
2325

2426
private IUserConfig&MockObject $userConfig;
25-
private IAppConfig&MockObject $appConfig;
27+
private IAppConfig $appConfig;
2628
private IUserManager&MockObject $userManager;
2729
private IAccountManager&MockObject $accountManager;
2830
private DashboardService $service;
@@ -31,7 +33,7 @@ protected function setUp(): void {
3133
parent::setUp();
3234

3335
$this->userConfig = $this->createMock(IUserConfig::class);
34-
$this->appConfig = $this->createMock(IAppConfig::class);
36+
$this->appConfig = new FakeFrameworkAppConfig('dashboard');
3537
$this->userManager = $this->createMock(IUserManager::class);
3638
$this->accountManager = $this->createMock(IAccountManager::class);
3739

@@ -45,9 +47,6 @@ protected function setUp(): void {
4547
}
4648

4749
public function testGetLayoutRemovesEmptyAndDuplicateEntries(): void {
48-
$this->appConfig->method('getAppValueString')
49-
->with('layout', 'recommendations,spreed,mail,calendar')
50-
->willReturn('recommendations,spreed,mail,calendar');
5150
$this->userConfig->method('getValueString')
5251
->with('alice', 'dashboard', 'layout', 'recommendations,spreed,mail,calendar')
5352
->willReturn('spreed,,mail,mail,calendar,spreed');

apps/dav/tests/unit/CalDAV/Federation/CalendarFederationConfigTest.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,19 @@
1212
use OCA\DAV\CalDAV\Federation\CalendarFederationConfig;
1313
use OCP\AppFramework\Services\IAppConfig;
1414
use PHPUnit\Framework\Attributes\DataProvider;
15-
use PHPUnit\Framework\MockObject\MockObject;
15+
use Test\FakeFrameworkAppConfig;
1616
use Test\TestCase;
1717

1818
class CalendarFederationConfigTest extends TestCase {
1919
private CalendarFederationConfig $config;
2020

21-
private IAppConfig&MockObject $appConfig;
21+
private IAppConfig $appConfig;
2222

2323
protected function setUp(): void {
2424
parent::setUp();
2525

26-
$this->appConfig = $this->createMock(IAppConfig::class);
27-
28-
$this->config = new CalendarFederationConfig(
29-
$this->appConfig,
26+
$this->appConfig = new FakeFrameworkAppConfig('dav');
27+
$this->config = new CalendarFederationConfig($this->appConfig,
3028
);
3129
}
3230

@@ -39,11 +37,7 @@ public static function provideIsFederationEnabledData(): array {
3937

4038
#[DataProvider(methodName: 'provideIsFederationEnabledData')]
4139
public function testIsFederationEnabled(bool $configValue): void {
42-
$this->appConfig->expects(self::once())
43-
->method('getAppValueBool')
44-
->with('enableCalendarFederation', true)
45-
->willReturn($configValue);
46-
40+
$this->appConfig->setAppValueBool('enableCalendarFederation', $configValue);
4741
$this->assertEquals($configValue, $this->config->isFederationEnabled());
4842
}
4943
}

0 commit comments

Comments
 (0)