Skip to content

Commit c944522

Browse files
authored
Merge pull request #1514 from nextcloud/chore/stable27-fix-tests
[stable27] Fix unit tests for PHP 8.2
2 parents 3aaf5fe + 6647312 commit c944522

File tree

5 files changed

+37
-5
lines changed

5 files changed

+37
-5
lines changed

.github/workflows/phpunit-mysql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838

3939
strategy:
4040
matrix:
41-
php-versions: ["8.0", "8.1"]
41+
php-versions: ["8.0", "8.1", "8.2"]
4242
server-versions: ["stable27"]
4343

4444
services:

tests/CurrentUserTest.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@
2222
namespace OCA\Activity\Tests;
2323

2424
use OCA\Activity\CurrentUser;
25+
use OCA\Activity\Tests\Mock\Request;
2526
use OCP\IRequest;
2627
use OCP\IUser;
28+
use OCP\IUserSession;
2729
use OCP\Share\Exceptions\ShareNotFound;
2830
use OCP\Share\IShare;
29-
use PHPUnit\Framework\MockObject\MockObject;
30-
use OCP\IUserSession;
3131
use OCP\Share\IManager;
32+
use PHPUnit\Framework\MockObject\MockObject;
3233

3334
/**
3435
* Class CurrentUserTest
@@ -48,7 +49,7 @@ class CurrentUserTest extends TestCase {
4849
protected function setUp(): void {
4950
parent::setUp();
5051

51-
$this->request = $this->createMock(IRequest::class);
52+
$this->request = $this->createMock(Request::class);
5253
$this->userSession = $this->createMock(IUserSession::class);
5354
$this->shareManager = $this->createMock(IManager::class);
5455
}
@@ -183,7 +184,10 @@ public function dataGetCloudIDFromToken(): array {
183184
public function testGetCloudIDFromToken(array $server, $share, ?string $expected): void {
184185
$instance = $this->getInstance();
185186

186-
$this->request->server = $server;
187+
$this->request->method('__get')->willReturnCallback(fn (string $prop) => match ($prop) {
188+
'server' => $server,
189+
default => null,
190+
});
187191

188192
if ($share === null) {
189193
$this->shareManager->expects($this->never())

tests/Listener/SetUserDefaultsTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ class SetUserDefaultsTest extends TestCase {
4242
*/
4343
private $listener;
4444

45+
/**
46+
* @var IUser|MockObject
47+
*/
48+
private $user;
49+
50+
/**
51+
* @var PostLoginEvent
52+
*/
53+
private $event;
54+
4555
public const UID = 'myuser';
4656

4757
public function setUp(): void {

tests/Listener/UserDeletedTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ class UserDeletedTest extends TestCase {
5353
*/
5454
private $listener;
5555

56+
/**
57+
* @var IUser|MockObject
58+
*/
59+
private $user;
60+
5661
public const UID = 'myuser';
5762

5863
public function setUp(): void {

tests/Mock/Request.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OCA\Activity\Tests\Mock;
6+
7+
use OCP\IRequest;
8+
9+
// We need this as we need to mock ::$server
10+
// which can not be accessed on PHP 8.2 due to deprecation of dynamic properties.
11+
interface Request extends IRequest {
12+
public function __get(string $prop): mixed;
13+
}

0 commit comments

Comments
 (0)