Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix more tests for PHP 8.2 #35181

Merged
merged 2 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions apps/settings/tests/Controller/CheckSetupControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ public function testCheck() {
->method('getAppValue')
->willReturnMap([
['files_external', 'user_certificate_scan', '', '["a", "b"]'],
['core', 'cronErrors', ''],
['core', 'cronErrors', '', ''],
]);
$this->config->expects($this->any())
->method('getSystemValue')
Expand Down Expand Up @@ -653,7 +653,7 @@ public function testCheck() {
'OCA\Settings\SetupChecks\SupportedDatabase' => ['pass' => true, 'description' => '', 'severity' => 'info'],
'isFairUseOfFreePushService' => false,
'temporaryDirectoryWritable' => false,
\OCA\Settings\SetupChecks\LdapInvalidUuids::class => ['pass' => true, 'description' => 'Invalid UUIDs of LDAP users or groups have been found. Please review your "Override UUID detection" settings in the Expert part of the LDAP configuration and use "occ ldap:update-uuid" to update them.', 'severity' => 'warning'],
\OCA\Settings\SetupChecks\LdapInvalidUuids::class => ['pass' => true, 'description' => 'Invalid UUIDs of LDAP users or groups have been found. Please review your "Override UUID detection" settings in the Expert part of the LDAP configuration and use "occ ldap:update-uuid" to update them.', 'severity' => 'warning'],
]
);
$this->assertEquals($expected, $this->checkSetupController->check());
Expand Down Expand Up @@ -977,11 +977,11 @@ public function testGetFailedIntegrityCheckFilesWithNoErrorsFound() {
->willReturn([]);

$expected = new DataDisplayResponse(
'No errors have been found.',
Http::STATUS_OK,
[
'Content-Type' => 'text/plain',
]
'No errors have been found.',
Http::STATUS_OK,
[
'Content-Type' => 'text/plain',
]
);
$this->assertEquals($expected, $this->checkSetupController->getFailedIntegrityCheckFiles());
}
Expand All @@ -997,7 +997,7 @@ public function testGetFailedIntegrityCheckFilesWithSomeErrorsFound() {
->willReturn([ 'core' => [ 'EXTRA_FILE' => ['/testfile' => []], 'INVALID_HASH' => [ '/.idea/workspace.xml' => [ 'expected' => 'f1c5e2630d784bc9cb02d5a28f55d6f24d06dae2a0fee685f3c2521b050955d9d452769f61454c9ddfa9c308146ade10546cfa829794448eaffbc9a04a29d216', 'current' => 'ce08bf30bcbb879a18b49239a9bec6b8702f52452f88a9d32142cad8d2494d5735e6bfa0d8642b2762c62ca5be49f9bf4ec231d4a230559d4f3e2c471d3ea094', ], '/lib/private/integritycheck/checker.php' => [ 'expected' => 'c5a03bacae8dedf8b239997901ba1fffd2fe51271d13a00cc4b34b09cca5176397a89fc27381cbb1f72855fa18b69b6f87d7d5685c3b45aee373b09be54742ea', 'current' => '88a3a92c11db91dec1ac3be0e1c87f862c95ba6ffaaaa3f2c3b8f682187c66f07af3a3b557a868342ef4a271218fe1c1e300c478e6c156c5955ed53c40d06585', ], '/settings/controller/checksetupcontroller.php' => [ 'expected' => '3e1de26ce93c7bfe0ede7c19cb6c93cadc010340225b375607a7178812e9de163179b0dc33809f451e01f491d93f6f5aaca7929685d21594cccf8bda732327c4', 'current' => '09563164f9904a837f9ca0b5f626db56c838e5098e0ccc1d8b935f68fa03a25c5ec6f6b2d9e44a868e8b85764dafd1605522b4af8db0ae269d73432e9a01e63a', ], ], ], 'bookmarks' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'dav' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'encryption' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'external' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'federation' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_antivirus' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_drop' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_external' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_pdfviewer' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_sharing' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_trashbin' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_versions' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_videoviewer' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'firstrunwizard' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'gitsmart' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'logreader' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature could not get verified.', ], ], 'password_policy' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'provisioning_api' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'sketch' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'threatblock' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'two_factor_auth' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'user_ldap' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'user_shibboleth' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], ]);

$expected = new DataDisplayResponse(
'Technical information
'Technical information
=====================
The following list covers which files have failed the integrity check. Please read
the previous linked documentation to learn more about the errors and how to fix
Expand Down Expand Up @@ -1389,10 +1389,10 @@ public function testGetFailedIntegrityCheckFilesWithSomeErrorsFound() {

)
',
Http::STATUS_OK,
[
'Content-Type' => 'text/plain',
]
Http::STATUS_OK,
[
'Content-Type' => 'text/plain',
]
);
$this->assertEquals($expected, $this->checkSetupController->getFailedIntegrityCheckFiles());
}
Expand Down
2 changes: 2 additions & 0 deletions apps/settings/tests/Settings/Admin/SharingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public function testGetFormWithoutExcludedGroups(): void {
['core', 'shareapi_default_remote_expire_date', 'no', 'no'],
['core', 'shareapi_remote_expire_after_n_days', '7', '7'],
['core', 'shareapi_enforce_remote_expire_date', 'no', 'no'],
['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
]);
$this->shareManager->method('shareWithGroupMembersOnly')
->willReturn(false);
Expand Down Expand Up @@ -181,6 +182,7 @@ public function testGetFormWithExcludedGroups(): void {
['core', 'shareapi_default_remote_expire_date', 'no', 'no'],
['core', 'shareapi_remote_expire_after_n_days', '7', '7'],
['core', 'shareapi_enforce_remote_expire_date', 'no', 'no'],
['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
]);
$this->shareManager->method('shareWithGroupMembersOnly')
->willReturn(false);
Expand Down
4 changes: 2 additions & 2 deletions apps/theming/tests/Themes/DefaultThemeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
*/
namespace OCA\Theming\Tests\Service;

use OC\App\AppManager;
use OCA\Theming\ImageManager;
use OCA\Theming\ITheme;
use OCA\Theming\Themes\DefaultTheme;
Expand All @@ -37,10 +36,11 @@
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;


class DefaultThemeTest extends TestCase {
/** @var ThemingDefaults|MockObject */
private $themingDefaults;
/** @var IUserSession|MockObject */
private $userSession;
/** @var IURLGenerator|MockObject */
private $urlGenerator;
/** @var ImageManager|MockObject */
Expand Down
54 changes: 38 additions & 16 deletions apps/theming/tests/ThemingDefaultsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,30 +424,24 @@ public function testGetShortFooterInvalidPrivacy($invalidPrivacyUrl) {

public function testGetColorPrimaryWithDefault() {
$this->config
->expects($this->at(0))
->method('getAppValue')
->with('theming', 'color', null)
->willReturn($this->defaults->getColorPrimary());
$this->config
->expects($this->at(1))
->expects($this->exactly(2))
->method('getAppValue')
->with('theming', 'disable-user-theming', 'no')
->willReturn('no');
->willReturnMap([
['theming', 'disable-user-theming', 'no', 'no'],
['theming', 'color', '', $this->defaults->getColorPrimary()],
]);

$this->assertEquals($this->defaults->getColorPrimary(), $this->template->getColorPrimary());
}

public function testGetColorPrimaryWithCustom() {
$this->config
->expects($this->at(0))
->method('getAppValue')
->with('theming', 'color', null)
->willReturn('#fff');
$this->config
->expects($this->at(1))
->expects($this->exactly(2))
->method('getAppValue')
->with('theming', 'disable-user-theming', 'no')
->willReturn('no');
->willReturnMap([
['theming', 'disable-user-theming', 'no', 'no'],
['theming', 'color', '', '#fff'],
]);

$this->assertEquals('#fff', $this->template->getColorPrimary());
}
Expand All @@ -460,6 +454,13 @@ public function testGetColorPrimaryWithDefaultBackground() {
$user->expects($this->any())
->method('getUID')
->willReturn('user');
$this->config
->expects($this->exactly(2))
->method('getAppValue')
->willReturnMap([
['theming', 'disable-user-theming', 'no', 'no'],
['theming', 'color', '', ''],
]);

$this->assertEquals(BackgroundService::DEFAULT_COLOR, $this->template->getColorPrimary());
}
Expand All @@ -480,6 +481,13 @@ public function testGetColorPrimaryWithCustomBackground() {
->method('getUserValue')
->with('user', 'theming', 'background', '')
->willReturn(array_keys(BackgroundService::SHIPPED_BACKGROUNDS)[$backgroundIndex]);
$this->config
->expects($this->exactly(2))
->method('getAppValue')
->willReturnMap([
['theming', 'disable-user-theming', 'no', 'no'],
['theming', 'color', '', ''],
]);

$this->assertEquals($background['primary_color'], $this->template->getColorPrimary());
}
Expand All @@ -498,6 +506,13 @@ public function testGetColorPrimaryWithCustomBackgroundColor() {
->method('getUserValue')
->with('user', 'theming', 'background', '')
->willReturn('#fff');
$this->config
->expects($this->exactly(2))
->method('getAppValue')
->willReturnMap([
['theming', 'disable-user-theming', 'no', 'no'],
['theming', 'color', '', ''],
]);

$this->assertEquals('#fff', $this->template->getColorPrimary());
}
Expand All @@ -516,6 +531,13 @@ public function testGetColorPrimaryWithInvalidCustomBackgroundColor() {
->method('getUserValue')
->with('user', 'theming', 'background', '')
->willReturn('nextcloud');
$this->config
->expects($this->exactly(3))
->method('getAppValue')
->willReturnMap([
['theming', 'disable-user-theming', 'no', 'no'],
['theming', 'color', '', ''],
]);

$this->assertEquals($this->template->getDefaultColorPrimary(), $this->template->getColorPrimary());
}
Expand Down
26 changes: 14 additions & 12 deletions tests/lib/AppFramework/Http/RequestStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,42 @@
* Used to simulate php://input for Request tests
*/
class RequestStream {
protected $position;
protected $varname;
protected int $position = 0;
protected string $varname = '';
/* @var resource */
public $context;

public function stream_open($path, $mode, $options, &$opened_path) {
public function stream_open(string $path, string $mode, int $options, ?string &$opened_path): bool {
$url = parse_url($path);
$this->varname = $url["host"];
$this->varname = $url["host"] ?? '';
$this->position = 0;

return true;
}

public function stream_read($count) {
public function stream_read(int $count): string {
$ret = substr($GLOBALS[$this->varname], $this->position, $count);
$this->position += strlen($ret);
return $ret;
}

public function stream_write($data) {
public function stream_write(string $data): int {
$left = substr($GLOBALS[$this->varname], 0, $this->position);
$right = substr($GLOBALS[$this->varname], $this->position + strlen($data));
$GLOBALS[$this->varname] = $left . $data . $right;
$this->position += strlen($data);
return strlen($data);
}

public function stream_tell() {
public function stream_tell(): int {
return $this->position;
}

public function stream_eof() {
public function stream_eof(): bool {
return $this->position >= strlen($GLOBALS[$this->varname]);
}

public function stream_seek($offset, $whence) {
public function stream_seek(int $offset, int $whence = SEEK_SET): bool {
switch ($whence) {
case SEEK_SET:
if ($offset < strlen($GLOBALS[$this->varname]) && $offset >= 0) {
Expand Down Expand Up @@ -74,7 +76,7 @@ public function stream_seek($offset, $whence) {
}
}

public function stream_stat() {
public function stream_stat(): array {
$size = strlen($GLOBALS[$this->varname]);
$time = time();
$data = [
Expand All @@ -96,10 +98,10 @@ public function stream_stat() {
//return false;
}

public function stream_metadata($path, $option, $var) {
public function stream_metadata(string $path, int $option, $var): bool {
if ($option == STREAM_META_TOUCH) {
$url = parse_url($path);
$varname = $url["host"];
$varname = $url["host"] ?? '';
if (!isset($GLOBALS[$varname])) {
$GLOBALS[$varname] = '';
}
Expand Down