Skip to content

Commit

Permalink
Adjust PHP unit tests for Symfony 5
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-davis committed May 19, 2023
1 parent 8781afb commit 5877f12
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 12 deletions.
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
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
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

0 comments on commit 5877f12

Please sign in to comment.