Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test: Fix tests/lib/[C-G]*
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed May 15, 2025
commit 3cc4410273f359d7b8acf61925121f7b23c2323d
4 changes: 2 additions & 2 deletions tests/lib/Cache/FileCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected function tearDown(): void {

private function setupMockStorage() {
$mockStorage = $this->getMockBuilder(Local::class)
->setMethods(['filemtime', 'unlink'])
->onlyMethods(['filemtime', 'unlink'])
->setConstructorArgs([['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]])
->getMock();

Expand Down Expand Up @@ -125,7 +125,7 @@ public function testGarbageCollectLeaveRecentKeys(): void {
$this->instance->gc();
}

public function lockExceptionProvider() {
public static function lockExceptionProvider(): array {
return [
[new \OCP\Lock\LockedException('key1')],
[new \OCP\Files\LockNotAcquiredException('key1', 1)],
Expand Down
10 changes: 5 additions & 5 deletions tests/lib/Calendar/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public function testSearchOptions($search1, $search2, $expected): void {
$this->assertEquals($expected, $result);
}

public function searchProvider() {
public static function searchProvider(): array {
$search1 = [
[
'id' => 1,
Expand Down Expand Up @@ -1096,7 +1096,7 @@ public function testHandleImipReply(): void {
$this->userManager,
$this->serverFactory,
])
->setMethods([
->onlyMethods([
'getCalendarsForPrincipal'
])
->getMock();
Expand Down Expand Up @@ -1544,11 +1544,11 @@ public function testHandleImipCancelOrganiserInReplyTo(): void {
$this->userManager,
$this->serverFactory,
])
->setMethods([
->onlyMethods([
'getCalendarsForPrincipal'
])
->getMock();

$principalUri = 'principals/user/pierre';
$sender = '[email protected]';
$recipient = '[email protected]';
Expand Down Expand Up @@ -1588,7 +1588,7 @@ public function testHandleImipCancel(): void {
$this->userManager,
$this->serverFactory,
])
->setMethods([
->onlyMethods([
'getCalendarsForPrincipal'
])
->getMock();
Expand Down
11 changes: 7 additions & 4 deletions tests/lib/Encryption/EncryptionWrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
use OC\Encryption\EncryptionWrapper;
use OC\Encryption\Manager;
use OC\Memcache\ArrayCache;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Storage\IDisableEncryptionStorage;
use OCP\Files\Storage\IStorage;
use Psr\Log\LoggerInterface;
use Test\TestCase;
use OCA\Files_Trashbin\Storage;
use OC\Files\Storage\Wrapper\Encryption;

class EncryptionWrapperTest extends TestCase {
/** @var EncryptionWrapper */
Expand Down Expand Up @@ -55,24 +58,24 @@ public function testWrapStorage($expectedWrapped, $wrappedStorages): void {
]);
}

$mount = $this->getMockBuilder('OCP\Files\Mount\IMountPoint')
$mount = $this->getMockBuilder(IMountPoint::class)
->disableOriginalConstructor()
->getMock();

$returnedStorage = $this->instance->wrapStorage('mountPoint', $storage, $mount);

$this->assertEquals(
$expectedWrapped,
$returnedStorage->instanceOfStorage('OC\Files\Storage\Wrapper\Encryption'),
$returnedStorage->instanceOfStorage(Encryption::class),
'Asserted that the storage is (not) wrapped with encryption'
);
}

public function provideWrapStorage() {
public static function provideWrapStorage(): array {
return [
// Wrap when not wrapped or not wrapped with storage
[true, []],
[true, ['OCA\Files_Trashbin\Storage']],
[true, [Storage::class]],

// Do not wrap shared storages
[false, [IDisableEncryptionStorage::class]],
Expand Down
18 changes: 5 additions & 13 deletions tests/lib/Encryption/UpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,7 @@ public function testUpdate($path, $isDir, $allFiles, $numberOfFiles): void {
$updateMock->update($node);
}

/**
* data provider for testUpdate()
*
* @return array
*/
public function dataTestUpdate() {
public static function dataTestUpdate(): array {
return [
['/user/files/foo', true, ['/user/files/foo/file1.txt', '/user/files/foo/file1.txt'], 2],
['/user/files/test.txt', false, [], 1],
Expand Down Expand Up @@ -152,12 +147,7 @@ public function testPostRename($source, $target): void {
$updateMock->postRename($sourceNode, $targetNode);
}

/**
* test data for testPostRename()
*
* @return array
*/
public function dataTestPostRename() {
public static function dataTestPostRename(): array {
return [
['/test.txt', '/testNew.txt'],
['/folder/test.txt', '/testNew.txt'],
Expand Down Expand Up @@ -193,6 +183,8 @@ protected function getUpdateMock(array $methods): Update&MockObject {
$this->logger,
$this->uid
]
)->setMethods($methods)->getMock();
)
->onlyMethods($methods)
->getMock();
}
}
30 changes: 15 additions & 15 deletions tests/lib/Encryption/UtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class UtilTest extends TestCase {
*
* @see https://bugs.php.net/bug.php?id=21641
*/
protected int $headerSize = 8192;
protected static int $headerSize = 8192;

/** @var \PHPUnit\Framework\MockObject\MockObject */
protected $view;
Expand Down Expand Up @@ -61,7 +61,7 @@ public function testGetEncryptionModuleId($expected, $header): void {
$this->assertEquals($expected, $id);
}

public function providesHeadersForEncryptionModule() {
public static function providesHeadersForEncryptionModule(): array {
return [
['', []],
['', ['1']],
Expand All @@ -80,11 +80,11 @@ public function testCreateHeader($expected, $header, $moduleId): void {
$this->assertEquals($expected, $result);
}

public function providesHeaders() {
public static function providesHeaders(): array {
return [
[str_pad('HBEGIN:oc_encryption_module:0:HEND', $this->headerSize, '-', STR_PAD_RIGHT)
[str_pad('HBEGIN:oc_encryption_module:0:HEND', self::$headerSize, '-', STR_PAD_RIGHT)
, [], '0'],
[str_pad('HBEGIN:oc_encryption_module:0:custom_header:foo:HEND', $this->headerSize, '-', STR_PAD_RIGHT)
[str_pad('HBEGIN:oc_encryption_module:0:custom_header:foo:HEND', self::$headerSize, '-', STR_PAD_RIGHT)
, ['custom_header' => 'foo'], '0'],
];
}
Expand Down Expand Up @@ -120,7 +120,7 @@ public function testIsExcluded($path, $keyStorageRoot, $expected): void {
);
}

public function providePathsForTestIsExcluded() {
public static function providePathsForTestIsExcluded(): array {
return [
['/files_encryption', '', true],
['files_encryption/foo.txt', '', true],
Expand Down Expand Up @@ -152,7 +152,7 @@ public function testIsFile($path, $expected): void {
);
}

public function dataTestIsFile() {
public static function dataTestIsFile(): array {
return [
['/user/files/test.txt', true],
['/user/files', true],
Expand All @@ -175,7 +175,7 @@ public function testStripPartialFileExtension($path, $expected): void {
$this->util->stripPartialFileExtension($path));
}

public function dataTestStripPartialFileExtension() {
public static function dataTestStripPartialFileExtension(): array {
return [
['/foo/test.txt', '/foo/test.txt'],
['/foo/test.txt.part', '/foo/test.txt'],
Expand All @@ -196,17 +196,17 @@ public function testParseRawHeader($rawHeader, $expected): void {
}
}

public function dataTestParseRawHeader() {
public static function dataTestParseRawHeader(): array {
return [
[str_pad('HBEGIN:oc_encryption_module:0:HEND', $this->headerSize, '-', STR_PAD_RIGHT)
[str_pad('HBEGIN:oc_encryption_module:0:HEND', self::$headerSize, '-', STR_PAD_RIGHT)
, [Util::HEADER_ENCRYPTION_MODULE_KEY => '0']],
[str_pad('HBEGIN:oc_encryption_module:0:custom_header:foo:HEND', $this->headerSize, '-', STR_PAD_RIGHT)
[str_pad('HBEGIN:oc_encryption_module:0:custom_header:foo:HEND', self::$headerSize, '-', STR_PAD_RIGHT)
, ['custom_header' => 'foo', Util::HEADER_ENCRYPTION_MODULE_KEY => '0']],
[str_pad('HelloWorld', $this->headerSize, '-', STR_PAD_RIGHT), []],
[str_pad('HelloWorld', self::$headerSize, '-', STR_PAD_RIGHT), []],
['', []],
[str_pad('HBEGIN:oc_encryption_module:0', $this->headerSize, '-', STR_PAD_RIGHT)
[str_pad('HBEGIN:oc_encryption_module:0', self::$headerSize, '-', STR_PAD_RIGHT)
, []],
[str_pad('oc_encryption_module:0:HEND', $this->headerSize, '-', STR_PAD_RIGHT)
[str_pad('oc_encryption_module:0:HEND', self::$headerSize, '-', STR_PAD_RIGHT)
, []],
];
}
Expand Down Expand Up @@ -245,7 +245,7 @@ public function testGetFileKeyDir($isSystemWideMountPoint, $storageRoot, $expect
);
}

public function dataTestGetFileKeyDir() {
public static function dataTestGetFileKeyDir(): array {
return [
[false, '', '/user1/files_encryption/keys/foo/bar.txt/OC_DEFAULT_MODULE/'],
[true, '', '/files_encryption/keys/foo/bar.txt/OC_DEFAULT_MODULE/'],
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/GlobalScale/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function getInstance($mockMethods = []) {
if (!empty($mockMethods)) {
return $this->getMockBuilder(Config::class)
->setConstructorArgs([$this->config])
->setMethods($mockMethods)
->onlyMethods($mockMethods)
->getMock();
}

Expand Down Expand Up @@ -64,7 +64,7 @@ public function testOnlyInternalFederation($gsEnabled, $gsFederation, $expected)
$this->assertSame($expected, $gsConfig->onlyInternalFederation());
}

public function dataTestOnlyInternalFederation() {
public static function dataTestOnlyInternalFederation(): array {
return [
[true, 'global', false],
[true, 'internal', true],
Expand Down
55 changes: 39 additions & 16 deletions tests/lib/Group/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
use OC\User\Manager;
use OC\User\User;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Group\Backend\ABackend;
use OCP\Group\Backend\IAddToGroupBackend;
use OCP\Group\Backend\ICreateGroupBackend;
use OCP\Group\Backend\IGroupDetailsBackend;
use OCP\Group\Backend\IRemoveFromGroupBackend;
use OCP\Group\Backend\ISearchableGroupBackend;
use OCP\GroupInterface;
use OCP\ICacheFactory;
Expand All @@ -21,7 +26,8 @@
use Psr\Log\LoggerInterface;
use Test\TestCase;

interface ISearchableGroupInterface extends ISearchableGroupBackend, GroupInterface {
abstract class TestBackend extends ABackend implements ISearchableGroupBackend, IAddToGroupBackend, ICreateGroupBackend, IGroupDetailsBackend, IRemoveFromGroupBackend, GroupInterface {

}

class ManagerTest extends TestCase {
Expand Down Expand Up @@ -74,9 +80,9 @@ private function getTestBackend($implementedActions = null) {
}
// need to declare it this way due to optional methods
// thanks to the implementsActions logic
$backend = $this->getMockBuilder(ISearchableGroupInterface::class)
$backend = $this->getMockBuilder(TestBackend::class)
->disableOriginalConstructor()
->setMethods([
->onlyMethods([
'getGroupDetails',
'implementsActions',
'getUserGroups',
Expand Down Expand Up @@ -283,9 +289,10 @@ public function testSearch(): void {
->with('1')
->willReturn(['group1']);
$backend->expects($this->once())
->method('groupExists')
->with('group1')
->willReturn(true);
->method('getGroupDetails')
->willReturnMap([
['group1', ['displayName' => 'group1']],
]);

$manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
$manager->addBackend($backend);
Expand All @@ -306,8 +313,11 @@ public function testSearchMultipleBackends(): void {
->with('1')
->willReturn(['group1']);
$backend1->expects($this->any())
->method('groupExists')
->willReturn(true);
->method('getGroupDetails')
->willReturnMap([
['group1', ['displayName' => 'group1']],
['group12', []],
]);

/**
* @var \PHPUnit\Framework\MockObject\MockObject | \OC\Group\Backend $backend2
Expand All @@ -318,8 +328,11 @@ public function testSearchMultipleBackends(): void {
->with('1')
->willReturn(['group12', 'group1']);
$backend2->expects($this->any())
->method('groupExists')
->willReturn(true);
->method('getGroupDetails')
->willReturnMap([
['group12', ['displayName' => 'group12']],
['group1', ['displayName' => 'group1']],
]);

$manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
$manager->addBackend($backend1);
Expand All @@ -335,28 +348,38 @@ public function testSearchMultipleBackends(): void {

public function testSearchMultipleBackendsLimitAndOffset(): void {
/**
* @var \PHPUnit\Framework\MockObject\MockObject | \OC\Group\Backend $backend1
* @var \PHPUnit\Framework\MockObject\MockObject|\OC\Group\Backend $backend1
*/
$backend1 = $this->getTestBackend();
$backend1->expects($this->once())
->method('getGroups')
->with('1', 2, 1)
->willReturn(['group1']);
$backend1->expects($this->any())
->method('groupExists')
->willReturn(true);
->method('getGroupDetails')
->willReturnMap([
[1, []],
[2, []],
['group1', ['displayName' => 'group1']],
['group12', []],
]);

/**
* @var \PHPUnit\Framework\MockObject\MockObject | \OC\Group\Backend $backend2
* @var \PHPUnit\Framework\MockObject\MockObject|\OC\Group\Backend $backend2
*/
$backend2 = $this->getTestBackend();
$backend2->expects($this->once())
->method('getGroups')
->with('1', 2, 1)
->willReturn(['group12']);
$backend2->expects($this->any())
->method('groupExists')
->willReturn(true);
->method('getGroupDetails')
->willReturnMap([
[1, []],
[2, []],
['group1', []],
['group12', ['displayName' => 'group12']],
]);

$manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
$manager->addBackend($backend1);
Expand Down