Skip to content

Commit

Permalink
fix(ci): Remove more withConsecutive in apps
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Sep 20, 2024
1 parent 4ba3d4a commit 0e07c31
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 90 deletions.
11 changes: 4 additions & 7 deletions apps/theming/tests/Controller/ThemingControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -715,13 +715,10 @@ public function testGetManifest(): void {
$this->urlGenerator
->expects($this->exactly(2))
->method('linkToRoute')
->withConsecutive(
['theming.Icon.getTouchIcon', ['app' => 'core']],
['theming.Icon.getFavicon', ['app' => 'core']],
)->willReturnOnConsecutiveCalls(
'touchicon',
'favicon',
);
->willReturnMap([
['theming.Icon.getTouchIcon', ['app' => 'core'], 'touchicon'],
['theming.Icon.getFavicon', ['app' => 'core'], 'favicon'],
]);
$response = new Http\JSONResponse([
'name' => 'Nextcloud',
'start_url' => 'localhost',
Expand Down
40 changes: 16 additions & 24 deletions apps/theming/tests/ImageManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,10 @@ public function mockGetImage($key, $file) {
->willReturn(file_get_contents(__DIR__ . '/../../../tests/data/testimage.png'));
$folder->expects($this->exactly(2))
->method('fileExists')
->withConsecutive(
['logo'],
['logo.png'],
)->willReturnOnConsecutiveCalls(
true,
false,
);
->willReturnMap([
['logo', true],
['logo.png', false],
]);
$folder->expects($this->once())
->method('getFile')
->with('logo')
Expand All @@ -119,14 +116,12 @@ public function mockGetImage($key, $file) {

public function testGetImageUrl(): void {
$this->checkImagick();
$file = $this->createMock(ISimpleFile::class);
$this->config->expects($this->exactly(2))
->method('getAppValue')
->withConsecutive(
['theming', 'cachebuster', '0'],
['theming', 'logoMime', '']
)
->willReturn(0);
->willReturnMap([
['theming', 'cachebuster', '0', '0'],
['theming', 'logoMime', '', '0'],
]);
$this->urlGenerator->expects($this->once())
->method('linkToRoute')
->willReturn('url-to-image');
Expand All @@ -136,11 +131,10 @@ public function testGetImageUrl(): void {
public function testGetImageUrlDefault(): void {
$this->config->expects($this->exactly(2))
->method('getAppValue')
->withConsecutive(
['theming', 'cachebuster', '0'],
['theming', 'logoMime', '']
)
->willReturnOnConsecutiveCalls(0, '');
->willReturnMap([
['theming', 'cachebuster', '0', '0'],
['theming', 'logoMime', '', ''],
]);
$this->urlGenerator->expects($this->once())
->method('imagePath')
->with('core', 'logo/logo.png')
Expand All @@ -150,14 +144,12 @@ public function testGetImageUrlDefault(): void {

public function testGetImageUrlAbsolute(): void {
$this->checkImagick();
$file = $this->createMock(ISimpleFile::class);
$this->config->expects($this->exactly(2))
->method('getAppValue')
->withConsecutive(
['theming', 'cachebuster', '0'],
['theming', 'logoMime', '']
)
->willReturnOnConsecutiveCalls(0, 0);
->willReturnMap([
['theming', 'cachebuster', '0', '0'],
['theming', 'logoMime', '', ''],
]);
$this->urlGenerator->expects($this->any())
->method('getAbsoluteUrl')
->willReturn('url-to-image-absolute?v=0');
Expand Down
79 changes: 34 additions & 45 deletions apps/theming/tests/ThemingDefaultsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -500,13 +500,18 @@ public function testGetColorPrimary(bool $disableTheming, string $primaryColor,
}

public function testSet(): void {
$expectedCalls = [
['theming', 'MySetting', 'MyValue'],
['theming', 'cachebuster', 16],
];
$i = 0;
$this->config
->expects($this->exactly(2))
->method('setAppValue')
->withConsecutive(
['theming', 'MySetting', 'MyValue'],
['theming', 'cachebuster', 16],
);
->willReturnCallback(function () use ($expectedCalls, &$i) {
$this->assertEquals($expectedCalls[$i], func_get_args());
$i++;
});
$this->config
->expects($this->once())
->method('getAppValue')
Expand All @@ -515,11 +520,10 @@ public function testSet(): void {
$this->cacheFactory
->expects($this->exactly(2))
->method('createDistributed')
->withConsecutive(
['theming-'],
['imagePath'],
)
->willReturn($this->cache);
->willReturnMap([
['theming-', $this->cache],
['imagePath', $this->cache],
]);
$this->cache
->expects($this->any())
->method('clear')
Expand All @@ -535,13 +539,10 @@ public function testUndoName(): void {
$this->config
->expects($this->exactly(2))
->method('getAppValue')
->withConsecutive(
['theming', 'cachebuster', '0'],
['theming', 'name', 'Nextcloud'],
)->willReturnOnConsecutiveCalls(
'15',
'Nextcloud',
);
->willReturnMap([
['theming', 'cachebuster', '0', '15'],
['theming', 'name', 'Nextcloud', 'Nextcloud'],
]);
$this->config
->expects($this->once())
->method('setAppValue')
Expand All @@ -558,13 +559,10 @@ public function testUndoBaseUrl(): void {
$this->config
->expects($this->exactly(2))
->method('getAppValue')
->withConsecutive(
['theming', 'cachebuster', '0'],
['theming', 'url', $this->defaults->getBaseUrl()],
)->willReturnOnConsecutiveCalls(
'15',
$this->defaults->getBaseUrl(),
);
->willReturnMap([
['theming', 'cachebuster', '0', '15'],
['theming', 'url', $this->defaults->getBaseUrl(), $this->defaults->getBaseUrl()],
]);
$this->config
->expects($this->once())
->method('setAppValue')
Expand All @@ -581,13 +579,10 @@ public function testUndoSlogan(): void {
$this->config
->expects($this->exactly(2))
->method('getAppValue')
->withConsecutive(
['theming', 'cachebuster', '0'],
['theming', 'slogan', $this->defaults->getSlogan()],
)->willReturnOnConsecutiveCalls(
'15',
$this->defaults->getSlogan(),
);
->willReturnMap([
['theming', 'cachebuster', '0', '15'],
['theming', 'slogan', $this->defaults->getSlogan(), $this->defaults->getSlogan()],
]);
$this->config
->expects($this->once())
->method('setAppValue')
Expand Down Expand Up @@ -649,13 +644,10 @@ private function getLogoHelper($withName, $useSvg) {
$this->config
->expects($this->exactly(2))
->method('getAppValue')
->withConsecutive(
['theming', 'logoMime'],
['theming', 'cachebuster', '0'],
)->willReturnOnConsecutiveCalls(
'',
'0'
);
->willReturnMap([
['theming', 'logoMime', '', ''],
['theming', 'cachebuster', '0', '0'],
]);
$this->urlGenerator->expects($this->once())
->method('imagePath')
->with('core', $withName)
Expand All @@ -675,13 +667,10 @@ public function testGetLogoCustom(): void {
$this->config
->expects($this->exactly(2))
->method('getAppValue')
->withConsecutive(
['theming', 'logoMime', false],
['theming', 'cachebuster', '0'],
)->willReturnOnConsecutiveCalls(
'image/svg+xml',
'0',
);
->willReturnMap([
['theming', 'logoMime', '', 'image/svg+xml'],
['theming', 'cachebuster', '0', '0'],
]);
$this->urlGenerator->expects($this->once())
->method('linkToRoute')
->with('theming.Theming.getImage')
Expand Down Expand Up @@ -710,7 +699,7 @@ public function testGetScssVariables(): void {
['theming', 'logoheaderMime', '', 'jpeg'],
['theming', 'faviconMime', '', 'jpeg'],
]);

$this->appConfig
->expects(self::atLeastOnce())
->method('getValueString')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,10 @@ public function testRun(): void {

$this->config->expects($this->exactly(2))
->method('getSystemValueBool')
->withConsecutive(
['has_internet_connection', true],
['debug', false],
)
->willReturnOnConsecutiveCalls(
true,
true,
);
->willReturnMap([
['has_internet_connection', true, true],
['debug', false, true],
]);

self::invokePrivate($job, 'run', [null]);
}
Expand Down Expand Up @@ -224,7 +220,7 @@ public function dataCheckAppUpdates(): array {
['app2', '1.9.2'],
],
[
['app2', '1.9.2'],
['app2', '1.9.2', ''],
],
],
];
Expand All @@ -251,9 +247,14 @@ public function testCheckAppUpdates(array $apps, array $isUpdateAvailable, array
->method('isUpdateAvailable')
->willReturnMap($isUpdateAvailable);

$mockedMethod = $job->expects($this->exactly(\count($notifications)))
->method('createNotifications');
\call_user_func_array([$mockedMethod, 'withConsecutive'], $notifications);
$i = 0;
$job->expects($this->exactly(\count($notifications)))
->method('createNotifications')
->willReturnCallback(function () use ($notifications, &$i) {
$this->assertEquals($notifications[$i], func_get_args());
$i++;
});


self::invokePrivate($job, 'checkAppUpdates');
}
Expand Down Expand Up @@ -331,10 +332,9 @@ public function testCreateNotifications(string $app, string $version, $lastNotif
->willReturnSelf();

if ($userNotifications !== null) {
$mockedMethod = $notification->expects($this->exactly(\count($userNotifications)))
$notification->expects($this->exactly(\count($userNotifications)))
->method('setUser')
->willReturnSelf();
\call_user_func_array([$mockedMethod, 'withConsecutive'], $userNotifications);

$this->notificationManager->expects($this->exactly(\count($userNotifications)))
->method('notify');
Expand Down

0 comments on commit 0e07c31

Please sign in to comment.