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 php 8.3 support in tests #39866

Merged
merged 3 commits into from
Aug 15, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/dav/tests/unit/CalDAV/CalDavBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ public function testGetDenormalizedData($expected, $key, $calData): void {
try {
$actual = $this->backend->getDenormalizedData($calData);
$this->assertEquals($expected, $actual[$key]);
} catch (\ValueError $e) {
} catch (\Throwable $e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} catch (\Throwable $e) {
} catch (\ValueError|\DateRangeError $e) {

Maybe?

if (($e->getMessage() === 'Epoch doesn\'t fit in a PHP integer') && (PHP_INT_SIZE < 8)) {
$this->markTestSkipped('This fail on 32bits because of PHP limitations in DateTime');
}
Expand Down
1 change: 1 addition & 0 deletions apps/files/tests/Controller/ViewControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public function testIndexWithRegularBrowser() {
->willReturnMap([
[$this->user->getUID(), 'files', 'file_sorting', 'name', 'name'],
[$this->user->getUID(), 'files', 'file_sorting_direction', 'asc', 'asc'],
[$this->user->getUID(), 'files', 'files_sorting_configs', '{}', '{}'],
[$this->user->getUID(), 'files', 'show_hidden', false, false],
[$this->user->getUID(), 'files', 'crop_image_previews', true, true],
[$this->user->getUID(), 'files', 'show_grid', true],
Expand Down
5 changes: 5 additions & 0 deletions tests/lib/App/AppManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,11 @@ public function testGetDefaultAppForUser($defaultApps, $expectedApp) {
->with('defaultapp', $this->anything())
->willReturn($defaultApps);

$this->config->expects($this->once())
->method('getUserValue')
->with('user1', 'core', 'defaultapp')
->willReturn('');

$this->assertEquals($expectedApp, $this->manager->getDefaultAppForUser());
}
}
3 changes: 3 additions & 0 deletions tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\Security\ICrypto;
use OCP\Security\IHasher;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase;
Expand All @@ -47,6 +48,8 @@ class PublicKeyTokenProviderTest extends TestCase {
private $tokenProvider;
/** @var PublicKeyTokenMapper|\PHPUnit\Framework\MockObject\MockObject */
private $mapper;
/** @var IHasher|\PHPUnit\Framework\MockObject\MockObject */
private $hasher;
/** @var ICrypto */
private $crypto;
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class LocalTimeProviderTest extends TestCase {
private $actionFactory;
/** @var IL10N|MockObject */
private $l;
/** @var IL10NFactory|MockObject */
private $l10nFactory;
/** @var IURLGenerator|MockObject */
private $urlGenerator;
/** @var IUserManager|MockObject */
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/Files/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1568,10 +1568,10 @@ public function testHookPaths($root, $path, $shouldEmit) {
$defaultRootValue->setAccessible(true);
$oldRoot = $defaultRootValue->getValue();
$defaultView = new View('/foo/files');
$defaultRootValue->setValue($defaultView);
$defaultRootValue->setValue(null, $defaultView);
$view = new View($root);
$result = self::invokePrivate($view, 'shouldEmitHooks', [$path]);
$defaultRootValue->setValue($oldRoot);
$defaultRootValue->setValue(null, $oldRoot);
$this->assertEquals($shouldEmit, $result);
}

Expand Down
1 change: 1 addition & 0 deletions tests/lib/Http/Client/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ClientTest extends \Test\TestCase {
private $config;
/** @var IRemoteHostValidator|MockObject */
private IRemoteHostValidator $remoteHostValidator;
private LoggerInterface $logger;
/** @var array */
private $defaultRequestOptions;

Expand Down
6 changes: 5 additions & 1 deletion tests/lib/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,11 @@ protected static function invokePrivate($object, $methodName, array $parameters
$property->setAccessible(true);

if (!empty($parameters)) {
$property->setValue($object, array_pop($parameters));
if ($property->isStatic()) {
$property->setValue(null, array_pop($parameters));
} else {
$property->setValue($object, array_pop($parameters));
}
}

if (is_object($object)) {
Expand Down
9 changes: 9 additions & 0 deletions tests/lib/TextProcessing/TextProcessingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use OC\TextProcessing\TaskBackgroundJob;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
use OCP\Common\Exception\NotFoundException;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
Expand Down Expand Up @@ -90,6 +91,14 @@ public function getTaskType(): string {
class TextProcessingTest extends \Test\TestCase {
private IManager $manager;
private Coordinator $coordinator;
private array $providers;
private IServerContainer $serverContainer;
private IEventDispatcher $eventDispatcher;
private RegistrationContext $registrationContext;
private \DateTimeImmutable $currentTime;
private TaskMapper $taskMapper;
private array $tasksDb;
private IJobList $jobList;

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