Skip to content

Commit

Permalink
fix(tests): Remove deprecated syntax
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Jan 16, 2024
1 parent f7d6a12 commit 6647312
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tests/CurrentUserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
namespace OCA\Activity\Tests;

use OCA\Activity\CurrentUser;
use OCA\Activity\Tests\Mock\Request;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserSession;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IShare;
use PHPUnit\Framework\MockObject\MockObject;
use OCP\IUserSession;
use OCP\Share\IManager;
use PHPUnit\Framework\MockObject\MockObject;

/**
* Class CurrentUserTest
Expand All @@ -48,7 +49,7 @@ class CurrentUserTest extends TestCase {
protected function setUp(): void {
parent::setUp();

$this->request = $this->createMock(IRequest::class);
$this->request = $this->createMock(Request::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->shareManager = $this->createMock(IManager::class);
}
Expand Down Expand Up @@ -183,7 +184,10 @@ public function dataGetCloudIDFromToken(): array {
public function testGetCloudIDFromToken(array $server, $share, ?string $expected): void {
$instance = $this->getInstance();

$this->request->server = $server;
$this->request->method('__get')->willReturnCallback(fn (string $prop) => match ($prop) {
'server' => $server,
default => null,
});

if ($share === null) {
$this->shareManager->expects($this->never())
Expand Down
10 changes: 10 additions & 0 deletions tests/Listener/SetUserDefaultsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ class SetUserDefaultsTest extends TestCase {
*/
private $listener;

/**
* @var IUser|MockObject
*/
private $user;

/**
* @var PostLoginEvent
*/
private $event;

public const UID = 'myuser';

public function setUp(): void {
Expand Down
5 changes: 5 additions & 0 deletions tests/Listener/UserDeletedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ class UserDeletedTest extends TestCase {
*/
private $listener;

/**
* @var IUser|MockObject
*/
private $user;

public const UID = 'myuser';

public function setUp(): void {
Expand Down
13 changes: 13 additions & 0 deletions tests/Mock/Request.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace OCA\Activity\Tests\Mock;

use OCP\IRequest;

// We need this as we need to mock ::$server
// which can not be accessed on PHP 8.2 due to deprecation of dynamic properties.
interface Request extends IRequest {
public function __get(string $prop): mixed;
}

0 comments on commit 6647312

Please sign in to comment.