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

feat: php 8.2 #40981

Draft
wants to merge 37 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
e35a18d
feat: php 8.2
DeepDiver1975 Sep 18, 2023
4c628a3
fix: param declarations and deprecations
DeepDiver1975 Sep 19, 2023
5f95ede
chore: move adjustments
DeepDiver1975 Sep 19, 2023
154a39a
chore: Adjust .drone.star format
phil-davis Sep 20, 2023
9d60382
feat: fix phpstan & phan
DeepDiver1975 Sep 25, 2023
3f397a5
fix: style & phan
DeepDiver1975 Sep 25, 2023
371f7b1
fix: add oc version back to DefinitionParameter::jsonSerialize
DeepDiver1975 Sep 25, 2023
afce69c
fix: more php8.x deprecations
DeepDiver1975 Sep 25, 2023
12cd2a6
fix: more php8.x deprecations
DeepDiver1975 Sep 25, 2023
219951f
fix: more deprecations and type errors and related
DeepDiver1975 Sep 26, 2023
6f68ff8
fix: preview generation
DeepDiver1975 Sep 26, 2023
890372f
fix: more fixes ....
DeepDiver1975 Sep 26, 2023
996f455
fix: ShareTest and MemcacheLockingProvider
DeepDiver1975 Sep 27, 2023
9e313ff
fix: drop ext-apc - this is unused for decades
DeepDiver1975 Sep 27, 2023
4b65d4d
fix: cache tests + usage of TestCase::getUniqueID()
DeepDiver1975 Sep 28, 2023
ebb81f9
fix: dynamic properties
DeepDiver1975 Sep 28, 2023
bd1a2f5
feat: move php version check to base.php
DeepDiver1975 Sep 29, 2023
85a6551
fix: installation on MySql
DeepDiver1975 Sep 29, 2023
5d376b5
fix: MigratorTest for MySQL
DeepDiver1975 Sep 29, 2023
e3db05a
chore: write log messagen an exception to error_log in case of except…
DeepDiver1975 Oct 1, 2023
1c9b8f4
fix: Share20OcsController
DeepDiver1975 Oct 2, 2023
24ee8e0
fix: Dispatcher/DispatcherTest
DeepDiver1975 Oct 2, 2023
f1605cc
fix: Http and tests
DeepDiver1975 Oct 2, 2023
142d574
fix: more deprcations ...
DeepDiver1975 Oct 2, 2023
a31e36a
fix: ....
DeepDiver1975 Oct 2, 2023
0626ec3
fix: ....
DeepDiver1975 Oct 2, 2023
090b505
fix: UserControllerTest
DeepDiver1975 Oct 4, 2023
6c29927
fix: owncloud log command tests
DeepDiver1975 Oct 4, 2023
ed603be
fix: more deprecation warnings
DeepDiver1975 Oct 4, 2023
2b50cb5
fix: .....
DeepDiver1975 Oct 4, 2023
21ca946
chore: :zzz:
DeepDiver1975 Oct 4, 2023
63e283c
chore: migrate to symfony/mailer
DeepDiver1975 Jan 20, 2023
384d465
fix: mail logger method signature
DeepDiver1975 Oct 9, 2023
aa040d3
fix: make OC_image::loadFromBase64 public again
DeepDiver1975 Oct 9, 2023
fc143a3
fix: ...
DeepDiver1975 Feb 29, 2024
bd3b18b
fix: ...
DeepDiver1975 Feb 29, 2024
b5fc713
chore: speed up OC_Helper::findBinaryPath()
DeepDiver1975 Feb 29, 2024
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
2 changes: 1 addition & 1 deletion .drone.star
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ SONARSOURCE_SONAR_SCANNER_CLI = "sonarsource/sonar-scanner-cli"
TOOLHIPPIE_CALENS = "toolhippie/calens:latest"
WEBHIPPIE_REDIS = "webhippie/redis:latest"

DEFAULT_PHP_VERSION = "7.4"
DEFAULT_PHP_VERSION = "8.2"
DEFAULT_NODEJS_VERSION = "14"

# minio mc environment variables
Expand Down
23 changes: 5 additions & 18 deletions apps/dav/lib/CalDAV/Schedule/IMipPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,12 @@
* @license http://sabre.io/license/ Modified BSD License
*/
class IMipPlugin extends SabreIMipPlugin {
/** @var IMailer */
private $mailer;

/** @var ILogger */
private $logger;

/** @var IRequest */
private $request;
private IMailer $mailer;
private ILogger $logger;
private IRequest $request;

/**
* Creates the email handler.
*
* @param IMailer $mailer
* @param ILogger $logger
* @param IRequest $request
*/
public function __construct(IMailer $mailer, ILogger $logger, IRequest $request) {
parent::__construct('');
Expand Down Expand Up @@ -123,14 +114,10 @@ public function schedule(ITip\Message $iTipMessage) {
->setFrom([$sender => $senderName])
->setTo([$recipient => $recipientName])
->setSubject($subject)
->setBody($iTipMessage->message->serialize(), $contentType);
->attach($iTipMessage->message->serialize(), "event.ics", $contentType);
try {
$failed = $this->mailer->send($message);
$this->mailer->send($message);
$iTipMessage->scheduleStatus = '1.1; Scheduling message is sent via iMip';
if ($failed) {
$this->logger->error('Unable to deliver message to {failed}', ['app' => 'dav', 'failed' => \implode(', ', $failed)]);
$iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
}
} catch (\Exception $ex) {
$this->logger->logException($ex, ['app' => 'dav']);
$iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
Expand Down
10 changes: 5 additions & 5 deletions apps/dav/lib/Connector/Sabre/Principal.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ public function getPrincipalsByPrefix($prefixPath) {
* getPrincipalsByPrefix.
*
* @param string $path
* @return array
* @return array|null
*/
public function getPrincipalByPath($path) {
list($prefix, $name) = \Sabre\Uri\split($path);
public function getPrincipalByPath($path): ?array {
[$prefix, $name] = \Sabre\Uri\split($path);

if ($prefix === $this->principalPrefix) {
$user = $this->userManager->get($name);
Expand Down Expand Up @@ -219,12 +219,12 @@ public function findByUri($uri, $principalPrefix) {
* @param IUser $user
* @return array
*/
protected function userToPrincipal($user) {
protected function userToPrincipal(IUser $user): array {
$userId = $user->getUID();
$displayName = $user->getDisplayName();
$principal = [
'uri' => $this->principalPrefix . '/' . $userId,
'{DAV:}displayname' => $displayName === null ? $userId : $displayName,
'{DAV:}displayname' => $displayName,
];

$email = $user->getEMailAddress();
Expand Down
1 change: 0 additions & 1 deletion apps/dav/lib/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ public function __construct(IRequest $request, $baseUri) {
$acl->principalCollectionSet = [
'principals/users', 'principals/groups'
];
$acl->defaultUsernamePath = 'principals/users';
$this->server->addPlugin($acl);
}

Expand Down
7 changes: 5 additions & 2 deletions apps/dav/lib/Upload/AssemblyStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,12 @@ public static function wrap(array $nodes) {
'assembly' => [
'nodes' => $nodes]
]);
\stream_wrapper_register('assembly', '\OCA\DAV\Upload\AssemblyStream');
$existed = \in_array("assembly", stream_get_wrappers());
if (!$existed) {
\stream_wrapper_register('assembly', __CLASS__);
}
try {
$wrapped = \fopen('assembly://', 'r', null, $context);
$wrapped = \fopen('assembly://', 'r', false, $context);
} catch (\BadMethodCallException $e) {
\stream_wrapper_unregister('assembly');
throw $e;
Expand Down
4 changes: 2 additions & 2 deletions apps/dav/tests/unit/CalDAV/CalendarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public function setUp(): void {
$this->l10n
->expects($this->any())
->method('t')
->will($this->returnCallback(function ($text, $parameters = []) {
->willReturnCallback(function ($text, $parameters = []) {
return \vsprintf($text, $parameters);
}));
});
}

public function testDelete() {
Expand Down
155 changes: 55 additions & 100 deletions apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,124 +22,78 @@

namespace OCA\DAV\Tests\unit\CalDAV\Schedule;

use Exception;
use OC\Mail\Mailer;
use OCA\DAV\CalDAV\Schedule\IMipPlugin;
use OCP\ILogger;
use OCP\IRequest;
use PHPUnit\Framework\MockObject\MockObject;
use Sabre\VObject\Component\VCalendar;
use Sabre\VObject\ITip\Message;
use Symfony\Component\Mime\Email;
use Test\TestCase;
use OC\Log;

class IMipPluginTest extends TestCase {
public function testDelivery() {
$mailMessage = new \OC\Mail\Message(new \Swift_Message());
/** @var Mailer | \PHPUnit\Framework\MockObject\MockObject $mailer */
$mailer = $this->createMock(Mailer::class);
$mailer->method('createMessage')->willReturn($mailMessage);
$mailer->expects($this->once())->method('send');
/** @var ILogger | \PHPUnit\Framework\MockObject\MockObject $logger */
$logger = $this->createMock(Log::class);
/** @var IRequest| \PHPUnit\Framework\MockObject\MockObject $request */
private \OC\Mail\Message $mailMessage;
/**
* @var Mailer|MockObject
*/
private $mailer;
private IMipPlugin $plugin;
/** @var ILogger|MockObject */
private $logger;

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

$this->mailMessage = new \OC\Mail\Message(new Email());
$this->mailer = $this->createMock(Mailer::class);
$this->mailer->method('createMessage')->willReturn($this->mailMessage);

$this->logger = $this->createMock(Log::class);
/** @var IRequest| MockObject $request */
$request = $this->createMock(IRequest::class);

$plugin = new IMipPlugin($mailer, $logger, $request);
$message = new Message();
$message->method = 'REQUEST';
$message->message = new VCalendar();
$message->message->add('VEVENT', [
'UID' => $message->uid,
'SEQUENCE' => $message->sequence,
'SUMMARY' => 'Fellowship meeting',
]);
$message->sender = 'mailto:[email protected]';
$message->recipient = 'mailto:[email protected]';
$this->plugin = new IMipPlugin($this->mailer, $this->logger, $request);
}

public function testDelivery(): void {
$this->mailer->expects($this->once())->method('send');

$message = $this->buildIMIPMessage('REQUEST');

$plugin->schedule($message);
$this->plugin->schedule($message);
$this->assertEquals('1.1', $message->getScheduleStatus());
$this->assertEquals('Fellowship meeting', $mailMessage->getSubject());
$this->assertEquals(['[email protected]' => null], $mailMessage->getTo());
$this->assertEquals(['[email protected]' => null], $mailMessage->getReplyTo());
$this->assertEquals('text/calendar; charset=UTF-8; method=REQUEST', $mailMessage->getSwiftMessage()->getContentType());
$this->assertEquals('Fellowship meeting', $this->mailMessage->getSubject());
$this->assertEquals(['[email protected]' => null], $this->mailMessage->getTo());
$this->assertEquals(['[email protected]' => null], $this->mailMessage->getReplyTo());
$this->assertStringContainsString('text/calendar; charset=UTF-8; method=REQUEST', $this->mailMessage->getMessage()->getBody()->bodyToString());
}

public function testFailedDeliveryWithException() {
$mailMessage = new \OC\Mail\Message(new \Swift_Message());
/** @var Mailer | \PHPUnit\Framework\MockObject\MockObject $mailer */
$mailer = $this->createMock(Mailer::class);
$mailer->method('createMessage')->willReturn($mailMessage);
$mailer->method('send')->willThrowException(new \Exception());
/** @var ILogger | \PHPUnit\Framework\MockObject\MockObject $logger */
$logger = $this->createMock(Log::class);
/** @var IRequest| \PHPUnit\Framework\MockObject\MockObject $request */
$request = $this->createMock(IRequest::class);
public function testFailedDeliveryWithException(): void {
$ex = new Exception();
$this->mailer->method('send')->willThrowException($ex);
$this->logger->expects(self::once())->method('logException')->with($ex, ['app' => 'dav']);

$plugin = new IMipPlugin($mailer, $logger, $request);
$message = new Message();
$message->method = 'REQUEST';
$message->message = new VCalendar();
$message->message->add('VEVENT', [
'UID' => $message->uid,
'SEQUENCE' => $message->sequence,
'SUMMARY' => 'Fellowship meeting',
]);
$message->sender = 'mailto:[email protected]';
$message->recipient = 'mailto:[email protected]';
$message = $this->buildIMIPMessage('REQUEST');

$plugin->schedule($message);
$this->assertEquals('5.0', $message->getScheduleStatus());
$this->assertEquals('Fellowship meeting', $mailMessage->getSubject());
$this->assertEquals(['[email protected]' => null], $mailMessage->getTo());
$this->assertEquals(['[email protected]' => null], $mailMessage->getReplyTo());
$this->assertEquals('text/calendar; charset=UTF-8; method=REQUEST', $mailMessage->getSwiftMessage()->getContentType());
$this->plugin->schedule($message);
$this->assertIMipState($message, '5.0', 'REQUEST', 'Fellowship meeting');
}

public function testFailedDelivery() {
$mailMessage = new \OC\Mail\Message(new \Swift_Message());
/** @var Mailer | \PHPUnit\Framework\MockObject\MockObject $mailer */
$mailer = $this->createMock(Mailer::class);
$mailer->method('createMessage')->willReturn($mailMessage);
$mailer->method('send')->willReturn(['[email protected]']);
/** @var ILogger | \PHPUnit\Framework\MockObject\MockObject $logger */
$logger = $this->createMock(Log::class);
$logger->expects(self::once())->method('error')->with('Unable to deliver message to {failed}', ['app' => 'dav', 'failed' => '[email protected]']);
/** @var IRequest| \PHPUnit\Framework\MockObject\MockObject $request */
$request = $this->createMock(IRequest::class);
public function testDeliveryOfCancel(): void {
$this->mailer->expects($this->once())->method('send');

$plugin = new IMipPlugin($mailer, $logger, $request);
$message = new Message();
$message->method = 'REQUEST';
$message->message = new VCalendar();
$message->message->add('VEVENT', [
'UID' => $message->uid,
'SEQUENCE' => $message->sequence,
'SUMMARY' => 'Fellowship meeting',
]);
$message->sender = 'mailto:[email protected]';
$message->recipient = 'mailto:[email protected]';
$message = $this->buildIMIPMessage('CANCEL');

$plugin->schedule($message);
$this->assertEquals('5.0', $message->getScheduleStatus());
$this->assertEquals('Fellowship meeting', $mailMessage->getSubject());
$this->assertEquals(['[email protected]' => null], $mailMessage->getTo());
$this->assertEquals(['[email protected]' => null], $mailMessage->getReplyTo());
$this->assertEquals('text/calendar; charset=UTF-8; method=REQUEST', $mailMessage->getSwiftMessage()->getContentType());
$this->plugin->schedule($message);
$this->assertIMipState($message, '1.1', 'CANCEL', 'Cancelled: Fellowship meeting');
}

public function testDeliveryOfCancel() {
$mailMessage = new \OC\Mail\Message(new \Swift_Message());
/** @var Mailer | \PHPUnit\Framework\MockObject\MockObject $mailer */
$mailer = $this->createMock(Mailer::class);
$mailer->method('createMessage')->willReturn($mailMessage);
$mailer->expects($this->once())->method('send');
/** @var ILogger | \PHPUnit\Framework\MockObject\MockObject $logger */
$logger = $this->createMock(Log::class);
/** @var IRequest| \PHPUnit\Framework\MockObject\MockObject $request */
$request = $this->createMock(IRequest::class);

$plugin = new IMipPlugin($mailer, $logger, $request);
private function buildIMIPMessage(string $method): Message {
$message = new Message();
$message->method = 'CANCEL';
$message->method = $method;
$message->message = new VCalendar();
$message->message->add('VEVENT', [
'UID' => $message->uid,
Expand All @@ -148,13 +102,14 @@ public function testDeliveryOfCancel() {
]);
$message->sender = 'mailto:[email protected]';
$message->recipient = 'mailto:[email protected]';
return $message;
}

$plugin->schedule($message);
$this->assertEquals('1.1', $message->getScheduleStatus());
$this->assertEquals('Cancelled: Fellowship meeting', $mailMessage->getSubject());
$this->assertEquals(['[email protected]' => null], $mailMessage->getTo());
$this->assertEquals(['[email protected]' => null], $mailMessage->getReplyTo());
$this->assertEquals('text/calendar; charset=UTF-8; method=CANCEL', $mailMessage->getSwiftMessage()->getContentType());
$this->assertEquals('CANCELLED', $message->message->VEVENT->STATUS->getValue());
private function assertIMipState(Message $message, string $scheduleStatus, string $method, string $mailSubject): void {
$this->assertEquals($scheduleStatus, $message->getScheduleStatus());
$this->assertEquals($mailSubject, $this->mailMessage->getSubject());
$this->assertEquals(['[email protected]' => null], $this->mailMessage->getTo());
$this->assertEquals(['[email protected]' => null], $this->mailMessage->getReplyTo());
$this->assertStringContainsString("text/calendar; charset=UTF-8; method=$method", $this->mailMessage->getMessage()->getBody()->bodyToString());
}
}
25 changes: 12 additions & 13 deletions apps/dav/tests/unit/Connector/Sabre/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,12 @@ public function testFileContentNotAllowedConvertedToForbidden() {
->getMock();
$view->expects($this->atLeastOnce())
->method('resolvePath')
->will(
$this->returnCallback(
function ($path) use ($storage) {
return [$storage, $path];
}
)
->willReturnCallback(
function ($path) use ($storage) {
return [$storage, $path];
}
);
$view->method('getRelativePath')->willReturn('test.txt');

$storage->expects($this->once())
->method('fopen')
Expand Down Expand Up @@ -349,11 +348,11 @@ public function testChunkedPutFails($thrownException, $expectedException, $check
$view = $this->createMock(View::class, ['getRelativePath', 'resolvePath'], []);
$view->expects($this->atLeastOnce())
->method('resolvePath')
->will($this->returnCallback(
function ($path) use ($storage) {
return [$storage, $path];
}
));
->willReturnCallback(function ($path) use ($storage) {
return [$storage, $path];
});
$view->method('getAbsolutePath')->willReturnArgument(0);
$view->method('getRelativePath')->willReturnArgument(0);

if ($thrownException !== null) {
$storage->expects($this->once())
Expand All @@ -362,7 +361,7 @@ function ($path) use ($storage) {
} else {
$storage->expects($this->once())
->method('fopen')
->will($this->returnValue(false));
->willReturn(false);
}

$view->expects($this->any())
Expand Down Expand Up @@ -774,7 +773,7 @@ public function testPutOverwriteFileTriggersHooks() {
* if the passed view was chrooted (can happen with public webdav
* where the root is the share root)
*/
public function testPutSingleFileTriggersHooksDifferentRoot() {
public function testPutSingleFileTriggersHooksDifferentRoot(): void {
$view = Filesystem::getView();
$view->mkdir('noderoot');

Expand Down
4 changes: 4 additions & 0 deletions apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,10 @@ public function testAdditionalHeaders() {
->expects($this->once())
->method('getName')
->willReturn('somefile.xml');
$node
->expects($this->once())
->method('getContentDispositionFileName')
->willReturn('somefile.xml');

$this->tree
->expects($this->once())
Expand Down
Loading