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

[tests-only] Adjust unit tests for Symfony 5 #40797

Merged
merged 2 commits into from
May 19, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/federatedfilesharing/tests/NotificationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,14 +341,14 @@ public function dataTryHttpPostToShareEndpointInException() {
public function testDeclineEvent() {
$dispatcher = \OC::$server->getEventDispatcher();
$event = $dispatcher->dispatch(
DeclineShare::class,
new DeclineShare(
[
'remote_id' => '4354353',
'remote' => 'http://localhost',
'share_token' => 'ohno'
]
)
),
DeclineShare::class
);
$this->assertInstanceOf(DeclineShare::class, $event);
}
Expand Down
6 changes: 6 additions & 0 deletions apps/federation/tests/TrustedServersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ public function setUp(): void {
->disableOriginalConstructor()->getMock();
$this->dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')
->disableOriginalConstructor()->getMock();
$this->dispatcher->expects($this->any())->method('dispatch')
->will(
$this->returnCallback(function ($object) {
return $object;
})
);
$this->httpClientService = $this->createMock('OCP\Http\Client\IClientService');
$this->httpClient = $this->createMock('OCP\Http\Client\IClient');
$this->response = $this->createMock('OCP\Http\Client\IResponse');
Expand Down
6 changes: 6 additions & 0 deletions apps/files/tests/Controller/ViewControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ public function setUp(): void {
$this->l10n = $this->createMock('\OCP\IL10N');
$this->config = $this->createMock('\OCP\IConfig');
$this->eventDispatcher = $this->createMock('\Symfony\Component\EventDispatcher\EventDispatcherInterface');
$this->eventDispatcher->expects($this->any())->method('dispatch')
->will(
$this->returnCallback(function ($object) {
return $object;
})
);
$this->userSession = $this->createMock('\OCP\IUserSession');
$this->appManager = $this->createMock('\OCP\App\IAppManager');
$this->user = $this->createMock('\OCP\IUser');
Expand Down
18 changes: 9 additions & 9 deletions apps/files_sharing/tests/HooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function testPrivateLink() {
'resolvedWebLink' => null,
'resolvedDavLink' => null,
]);
$this->eventDispatcher->dispatch('files.resolvePrivateLink', $event);
$this->eventDispatcher->dispatch($event, 'files.resolvePrivateLink');

$this->assertEquals('/owncloud/index.php/apps/files/?view=sharingin&scrollto=123', $event->getArgument('resolvedWebLink'));
$this->assertNull($event->getArgument('resolvedDavLink'));
Expand All @@ -168,7 +168,7 @@ public function testPrivateLinkNoMatch() {
'resolvedWebLink' => null,
'resolvedDavLink' => null,
]);
$this->eventDispatcher->dispatch('files.resolvePrivateLink', $event);
$this->eventDispatcher->dispatch($event, 'files.resolvePrivateLink');

$this->assertNull($event->getArgument('resolvedWebLink'));
$this->assertNull($event->getArgument('resolvedDavLink'));
Expand All @@ -182,7 +182,7 @@ public function testDeleteGroup() {
$this->sharingAllowlist->expects($this->once())->method('setPublicShareSharersGroupsAllowlist')->with([]);

$event = new GenericEvent($group);
$this->eventDispatcher->dispatch('group.postDelete', $event);
$this->eventDispatcher->dispatch($event, 'group.postDelete');
}

public function testPublishShareNotification() {
Expand All @@ -196,7 +196,7 @@ public function testPublishShareNotification() {
'share' => ['id' => '123'],
'shareObject' => $share,
]);
$this->eventDispatcher->dispatch('share.afterCreate', $event);
$this->eventDispatcher->dispatch($event, 'share.afterCreate');
}

public function testDiscardShareNotification() {
Expand All @@ -210,7 +210,7 @@ public function testDiscardShareNotification() {
'share' => ['id' => '123'],
'shareObject' => $share,
]);
$this->eventDispatcher->dispatch('share.afterDelete', $event);
$this->eventDispatcher->dispatch($event, 'share.afterDelete');
}

public function providesDataForCanGet() {
Expand Down Expand Up @@ -271,7 +271,7 @@ public function testCheckDirectCanBeDownloaded($path, $userFolder, $run) {

// Simulate direct download of file
$event = new GenericEvent(null, [ 'path' => $path ]);
$this->eventDispatcher->dispatch('file.beforeGetDirect', $event);
$this->eventDispatcher->dispatch($event, 'file.beforeGetDirect');

$this->assertEquals($run, !$event->hasArgument('errorMessage'));
}
Expand Down Expand Up @@ -349,7 +349,7 @@ public function testCheckZipCanBeDownloaded($dir, $files, $userFolder, $run) {

// Simulate zip download of folder folder
$event = new GenericEvent(null, ['dir' => $dir, 'files' => $files, 'run' => true]);
$this->eventDispatcher->dispatch('file.beforeCreateZip', $event);
$this->eventDispatcher->dispatch($event, 'file.beforeCreateZip');

$this->assertEquals($run, $event->getArgument('run'));
$this->assertEquals($run, !$event->hasArgument('errorMessage'));
Expand All @@ -360,7 +360,7 @@ public function testCheckFileUserNotFound() {

// Simulate zip download of folder folder
$event = new GenericEvent(null, ['dir' => '/test', 'files' => ['test.txt'], 'run' => true]);
$this->eventDispatcher->dispatch('file.beforeCreateZip', $event);
$this->eventDispatcher->dispatch($event, 'file.beforeCreateZip');

// It should run as this would restrict e.g. share links otherwise
$this->assertTrue($event->getArgument('run'));
Expand Down Expand Up @@ -394,7 +394,7 @@ public function testPublishShareSelfUnshareEvent() {
'shareRecipient' => 'recipient_user',
'shareOwner' => 'owner_user',
]);
$this->eventDispatcher->dispatch('fromself.unshare', $event);
$this->eventDispatcher->dispatch($event, 'fromself.unshare');
}

public function testExtendJsConfig() {
Expand Down
2 changes: 1 addition & 1 deletion apps/files_trashbin/tests/TrashbinTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ public function testPrivateLink() {
'resolvedWebLink' => null,
'resolvedDavLink' => null,
]);
\OC::$server->getEventDispatcher()->dispatch('files.resolvePrivateLink', $event);
\OC::$server->getEventDispatcher()->dispatch($event, 'files.resolvePrivateLink');

$this->assertEquals('/owncloud/index.php/apps/files/?view=trashbin&dir=/test.d1462861890/sub&scrollto=somefile.txt', $event->getArgument('resolvedWebLink'));
$this->assertNull($event->getArgument('resolvedDavLink'));
Expand Down
5 changes: 4 additions & 1 deletion tests/Core/Command/Encryption/ChangeKeyStorageRootTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use OC\Files\View;
use OCP\IConfig;
use OCP\IUserManager;
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -71,7 +72,9 @@ public function setUp(): void {
$this->outputInterface = $this->createMock('Symfony\Component\Console\Output\OutputInterface');
$this->userInterface = $this->createMock('\OCP\UserInterface');

$outputFormatterInterface = $this->createMock('Symfony\Component\Console\Formatter\OutputFormatterInterface');
$outputFormatterInterface = $this->createMock(OutputFormatterInterface::class);
$outputFormatterInterface->expects($this->any())->method('isDecorated')
->willReturn(false);
$this->outputInterface->expects($this->any())->method('getFormatter')
->willReturn($outputFormatterInterface);

Expand Down
1 change: 1 addition & 0 deletions tests/Core/Controller/RolesControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function testGetAvatarNoAvatar() {
'id' => 'test.tester',
'displayName' => 'A tester which tests ....'
]);
return $event;
});

$result = $controller->getRoles();
Expand Down
5 changes: 4 additions & 1 deletion tests/lib/Encryption/DecryptAllTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,11 @@ public function setUp(): void {
$this->userInterface = $this->getMockBuilder(UserInterface::class)
->disableOriginalConstructor()->getMock();

$outputFormatterInterface = $this->createMock(OutputFormatterInterface::class);
$outputFormatterInterface->expects($this->any())->method('isDecorated')
->willReturn(false);
$this->outputInterface->expects($this->any())->method('getFormatter')
->willReturn($this->createMock(OutputFormatterInterface::class));
->willReturn($outputFormatterInterface);

$this->instance = new DecryptAll($this->encryptionManager, $this->userManager, $this->view, $this->logger);

Expand Down
6 changes: 6 additions & 0 deletions tests/lib/Repair/AppsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ protected function setUp(): void {
$this->appManager = $this->createMock(IAppManager::class);
$this->defaults = $this->createMock(\OC_Defaults::class);
$this->eventDispatcher = $this->createMock(EventDispatcherInterface::class);
$this->eventDispatcher->expects($this->any())->method('dispatch')
->will(
$this->returnCallback(function ($object) {
return $object;
})
);
$this->config = $this->createMock(IConfig::class);
$this->repair = new Apps(
$this->appManager,
Expand Down