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 dynamic properties and other problems in tests for PHP 8.2 #35156

Merged
merged 5 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
1 change: 0 additions & 1 deletion apps/dav/lib/RootCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ public function __construct() {
$roomCalendarRoot->disableListing = $disableListing;

$publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config, $logger);
$publicCalendarRoot->disableListing = $disableListing;
tcitworld marked this conversation as resolved.
Show resolved Hide resolved

$systemTagCollection = new SystemTag\SystemTagsByIdCollection(
\OC::$server->getSystemTagManager(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@
use OCA\DAV\BackgroundJob\CleanupInvitationTokenJob;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\DB\QueryBuilder\IQueryFunction;
use OCP\IDBConnection;
use Test\TestCase;

class CleanupInvitationTokenJobTest extends TestCase {

/** @var IDBConnection | \PHPUnit\Framework\MockObject\MockObject */
private $dbConnection;

Expand Down Expand Up @@ -78,7 +76,7 @@ public function testRun() {
[1337, \PDO::PARAM_STR, null, 'namedParameter1337']
]);

$function = $this->createMock(IQueryFunction::class);
$function = 'function1337';
come-nc marked this conversation as resolved.
Show resolved Hide resolved
$expr->expects($this->once())
->method('lt')
->with('expiration', 'namedParameter1337')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@
use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\CardDAV\CardDavBackend;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\DB\Exception;
use OCP\IConfig;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase;

class PruneOutdatedSyncTokensJobTest extends TestCase {
/** @var ITimeFactory | MockObject */
private $timeFactory;
blizzz marked this conversation as resolved.
Show resolved Hide resolved

/** @var CalDavBackend | MockObject */
private $calDavBackend;
Expand Down
5 changes: 3 additions & 2 deletions apps/dav/tests/unit/CalDAV/Reminder/ReminderServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,11 @@
use OCP\IGroupManager;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase;

class ReminderServiceTest extends TestCase {

/** @var Backend|MockObject */
private $backend;

Expand Down Expand Up @@ -74,6 +72,9 @@ class ReminderServiceTest extends TestCase {
/** @var MockObject|LoggerInterface */
private $logger;

/** @var MockObject|Principal */
private $principalConnector;

public const CALENDAR_DATA = <<<EOD
BEGIN:VCALENDAR
PRODID:-//Nextcloud calendar v1.6.4
Expand Down
4 changes: 3 additions & 1 deletion apps/dav/tests/unit/CardDAV/Activity/BackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
use Test\TestCase;

class BackendTest extends TestCase {

/** @var IManager|MockObject */
protected $activityManager;

Expand All @@ -53,6 +52,9 @@ class BackendTest extends TestCase {
/** @var IAppManager|MockObject */
protected $appManager;

/** @var IUserManager|MockObject */
protected $userManager;

protected function setUp(): void {
parent::setUp();
$this->activityManager = $this->createMock(IManager::class);
Expand Down
9 changes: 4 additions & 5 deletions apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
use Test\TestCase;

class PrincipalTest extends TestCase {

/** @var IUserManager | MockObject */
private $userManager;

Expand Down Expand Up @@ -658,12 +657,12 @@ public function testSearchPrincipalWithEnumerationDisabledDisplayname(): void {
$user2->method('getSystemEMailAddress')->willReturn('user2@foo.bar');
$user3 = $this->createMock(IUser::class);
$user3->method('getUID')->willReturn('user3');
$user2->method('getDisplayName')->willReturn('User 22');
$user2->method('getSystemEMailAddress')->willReturn('user2@foo.bar123');
$user3->method('getDisplayName')->willReturn('User 22');
$user3->method('getSystemEMailAddress')->willReturn('user2@foo.bar123');
$user4 = $this->createMock(IUser::class);
$user4->method('getUID')->willReturn('user4');
$user2->method('getDisplayName')->willReturn('User 222');
$user2->method('getSystemEMailAddress')->willReturn('user2@foo.bar456');
$user4->method('getDisplayName')->willReturn('User 222');
$user4->method('getSystemEMailAddress')->willReturn('user2@foo.bar456');

$this->userManager->expects($this->at(0))
->method('searchDisplayName')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@
use OCP\DB\IResult;
use OCP\DB\QueryBuilder\IExpressionBuilder;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\DB\QueryBuilder\IQueryFunction;
use OCP\IDBConnection;
use OCP\IRequest;
use Sabre\VObject\ITip\Message;
use Test\TestCase;

class InvitationResponseControllerTest extends TestCase {

/** @var InvitationResponseController */
private $controller;

Expand Down Expand Up @@ -478,7 +476,7 @@ private function buildQueryExpects($token, $return, $time) {
->with(\PDO::FETCH_ASSOC)
->willReturn($return);

$function = $this->createMock(IQueryFunction::class);
$function = 'functionToken';
$expr->expects($this->once())
->method('eq')
->with('token', 'namedParameterToken')
Expand Down
2 changes: 2 additions & 0 deletions apps/federatedfilesharing/tests/Settings/AdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class AdminTest extends TestCase {
private $federatedShareProvider;
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
private $gsConfig;
/** @var IInitialState|\PHPUnit\Framework\MockObject\MockObject */
private $initialState;

protected function setUp(): void {
parent::setUp();
Expand Down
8 changes: 5 additions & 3 deletions apps/files_sharing/tests/ShareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class ShareTest extends TestCase {

private static $tempStorage;

private string $subsubfolder = '';

protected function setUp(): void {
parent::setUp();

Expand Down Expand Up @@ -176,14 +178,14 @@ public function testShareWithGroupUniqueName() {

$shares = $this->shareManager->getSharedWith(self::TEST_FILES_SHARING_API_USER2, IShare::TYPE_GROUP);
$share = $shares[0];
$this->assertSame('/test.txt' ,$share->getTarget());
$this->assertSame('/test.txt', $share->getTarget());
$this->assertSame(19, $share->getPermissions());

\OC\Files\Filesystem::rename('test.txt', 'new test.txt');

$shares = $this->shareManager->getSharedWith(self::TEST_FILES_SHARING_API_USER2, IShare::TYPE_GROUP);
$share = $shares[0];
$this->assertSame('/new test.txt' ,$share->getTarget());
$this->assertSame('/new test.txt', $share->getTarget());
$this->assertSame(19, $share->getPermissions());

$share->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE);
Expand All @@ -193,7 +195,7 @@ public function testShareWithGroupUniqueName() {
$shares = $this->shareManager->getSharedWith(self::TEST_FILES_SHARING_API_USER2, IShare::TYPE_GROUP);
$share = $shares[0];

$this->assertSame('/new test.txt' ,$share->getTarget());
$this->assertSame('/new test.txt', $share->getTarget());
$this->assertSame(3, $share->getPermissions());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
use Psr\Log\LoggerInterface;

class GroupsControllerTest extends \Test\TestCase {

/** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
protected $request;
/** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
Expand All @@ -57,6 +56,8 @@ class GroupsControllerTest extends \Test\TestCase {
protected $userSession;
/** @var IAccountManager|\PHPUnit\Framework\MockObject\MockObject */
protected $accountManager;
/** @var IFactory|\PHPUnit\Framework\MockObject\MockObject */
protected $l10nFactory;
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
protected $logger;
/** @var SubAdmin|\PHPUnit\Framework\MockObject\MockObject */
Expand Down
14 changes: 11 additions & 3 deletions apps/settings/tests/Mailer/NewUserMailHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class NewUserMailHelperTest extends TestCase {
private $urlGenerator;
/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
private $l10n;
/** @var IFactory|\PHPUnit\Framework\MockObject\MockObject */
private $l10nFactory;
/** @var IMailer|\PHPUnit\Framework\MockObject\MockObject */
private $mailer;
/** @var ISecureRandom|\PHPUnit\Framework\MockObject\MockObject */
Expand Down Expand Up @@ -367,7 +369,9 @@ public function testGenerateTemplateWithPasswordResetToken() {
Install Client: https://nextcloud.com/install/#install-clients


--
EOF;
$expectedTextBody .= "\n-- \n";
$expectedTextBody .= <<<EOF
TestCloud
This is an automatically sent email, please do not reply.
EOF;
Expand Down Expand Up @@ -601,7 +605,9 @@ public function testGenerateTemplateWithoutPasswordResetToken() {
Install Client: https://nextcloud.com/install/#install-clients


--
EOF;
$expectedTextBody .= "\n-- \n";
$expectedTextBody .= <<<EOF
TestCloud
This is an automatically sent email, please do not reply.
EOF;
Expand Down Expand Up @@ -822,7 +828,9 @@ public function testGenerateTemplateWithoutUserId() {
Install Client: https://nextcloud.com/install/#install-clients


--
EOF;
$expectedTextBody .= "\n-- \n";
$expectedTextBody .= <<<EOF
TestCloud
This is an automatically sent email, please do not reply.
EOF;
Expand Down
3 changes: 2 additions & 1 deletion apps/theming/tests/Settings/PersonalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class PersonalTest extends TestCase {
private ThemesService $themesService;
private IInitialState $initialStateService;
private ThemingDefaults $themingDefaults;
private Personal $admin;

/** @var ITheme[] */
private $themes;
Expand Down Expand Up @@ -144,7 +145,7 @@ private function initThemes() {
$themingDefaults->expects($this->any())
->method('getColorPrimary')
->willReturn('#0082c9');

$themingDefaults->expects($this->any())
->method('getDefaultColorPrimary')
->willReturn('#0082c9');
Expand Down
3 changes: 2 additions & 1 deletion apps/theming/tests/Themes/DyslexiaFontTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;


class DyslexiaFontTest extends TestCase {
/** @var ThemingDefaults|MockObject */
private $themingDefaults;
/** @var IUserSession|MockObject */
private $userSession;
/** @var IURLGenerator|MockObject */
private $urlGenerator;
/** @var ImageManager|MockObject */
Expand Down
4 changes: 1 addition & 3 deletions lib/private/User/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
* @package OC\User
*/
class Session implements IUserSession, Emitter {

/** @var Manager $manager */
private $manager;

Expand Down Expand Up @@ -448,7 +447,6 @@ public function logClientIn($user,

// Try to login with this username and password
if (!$this->login($user, $password)) {

// Failed, maybe the user used their email address
if (!filter_var($user, FILTER_VALIDATE_EMAIL)) {
return false;
Expand Down Expand Up @@ -672,7 +670,7 @@ public function createSessionToken(IRequest $request, $uid, $loginName, $passwor
// User does not exist
return false;
}
$name = isset($request->server['HTTP_USER_AGENT']) ? utf8_encode($request->server['HTTP_USER_AGENT']) : 'unknown browser';
$name = isset($request->server['HTTP_USER_AGENT']) ? mb_convert_encoding($request->server['HTTP_USER_AGENT'], 'UTF-8', 'ISO-8859-1') : 'unknown browser';
try {
$sessionId = $this->session->getId();
$pwd = $this->getPassword($password);
Expand Down
4 changes: 3 additions & 1 deletion tests/lib/DB/MigrationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
* @package Test\DB
*/
class MigrationsTest extends \Test\TestCase {

/** @var MigrationService | \PHPUnit\Framework\MockObject\MockObject */
private $migrationService;
/** @var \PHPUnit\Framework\MockObject\MockObject | IDBConnection $db */
Expand Down Expand Up @@ -247,6 +246,9 @@ public function testEnsureOracleConstraintsValid() {
->willReturn(\str_repeat('a', 30));

$primaryKey = $this->createMock(Index::class);
$primaryKey->expects($this->once())
->method('getName')
->willReturn(\str_repeat('a', 30));

$table->expects($this->once())
->method('getColumns')
Expand Down
9 changes: 5 additions & 4 deletions tests/lib/Encryption/Keys/StorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,23 @@
use Test\TestCase;

class StorageTest extends TestCase {

/** @var Storage */
protected $storage;

/** @var \PHPUnit\Framework\MockObject\MockObject */
/** @var MockObject|\OC\Encryption\Util */
protected $util;

/** @var \PHPUnit\Framework\MockObject\MockObject */
/** @var MockObject|View */
protected $view;

/** @var \PHPUnit\Framework\MockObject\MockObject */
/** @var MockObject|IConfig */
protected $config;

/** @var MockObject|ICrypto */
protected $crypto;

private array $mkdirStack = [];

protected function setUp(): void {
parent::setUp();

Expand Down
11 changes: 7 additions & 4 deletions tests/lib/Security/VerificationToken/VerificationTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,21 @@
use OCP\Security\ISecureRandom;
use OCP\Security\VerificationToken\InvalidTokenException;
use Test\TestCase;
use PHPUnit\Framework\MockObject\MockObject;

class VerificationTokenTest extends TestCase {
/** @var VerificationToken */
protected $token;
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
/** @var IConfig|MockObject */
protected $config;
/** @var ISecureRandom|\PHPUnit\Framework\MockObject\MockObject */
/** @var ISecureRandom|MockObject */
protected $secureRandom;
/** @var ICrypto|\PHPUnit\Framework\MockObject\MockObject */
/** @var ICrypto|MockObject */
protected $crypto;
/** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
/** @var ITimeFactory|MockObject */
protected $timeFactory;
/** @var IJobList|MockObject */
protected $jobList;

protected function setUp(): void {
parent::setUp();
Expand Down
Loading