Skip to content

Commit 2841dd5

Browse files
committed
test: remove all remaining ReflectionProperty/Method::setAccessible() calls and stale PHPUnit annotations
setAccessible() is a no-op since PHP 8.1 and removed in PHP 8.5. Removes remaining calls across the three files that still had them: - EncryptionTest.php: collapse 18 setAccessible(true/false) pairs by calling setValue/getValue directly on the ReflectionProperty (no need to open/close access around each call) - ResourceLocatorTest.php: remove the single no-op setAccessible(true) on a ReflectionMethod Also clean up PHPUnit annotation noise in the same pass: - S3SSEKMSTest.php: remove duplicate @dataProvider doc-comment annotations where #[DataProvider] PHP attributes are already present - ManagerTest.php: delete four fully commented-out test methods that used the deprecated @expectedException/@expectedExceptionMessage doc-comment style; all four scenarios are covered by the active equivalents in the same file (testModuleReRegistration, testModuleUnRegistration, testGetEncryptionModuleUnknown, testGetEncryptionModule) Signed-off-by: Anna Larch <anna@nextcloud.com> AI-Assisted-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 0da9913 commit 2841dd5

4 files changed

Lines changed: 9 additions & 107 deletions

File tree

tests/lib/Encryption/ManagerTest.php

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -199,64 +199,6 @@ public function testSetDefaultEncryptionModule(): void {
199199
$this->assertEquals('ID1', $this->manager->getDefaultEncryptionModuleId());
200200
}
201201

202-
// /**
203-
// * @expectedException \OC\Encryption\Exceptions\ModuleAlreadyExistsException
204-
// * @expectedExceptionMessage Id "0" already used by encryption module "TestDummyModule0"
205-
// */
206-
// public function testModuleRegistration() {
207-
// $config = $this->createMock(IConfig::class);
208-
// $config->expects($this->any())->method('getSystemValueBool')->willReturn(true);
209-
// $em = $this->createMock(IEncryptionModule::class);
210-
// $em->expects($this->any())->method('getId')->willReturn(0);
211-
// $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
212-
// $m = new Manager($config);
213-
// $m->registerEncryptionModule($em);
214-
// $this->assertTrue($m->isEnabled());
215-
// $m->registerEncryptionModule($em);
216-
// }
217-
//
218-
// public function testModuleUnRegistration() {
219-
// $config = $this->createMock(IConfig::class);
220-
// $config->expects($this->any())->method('getSystemValueBool')->willReturn(true);
221-
// $em = $this->createMock(IEncryptionModule::class);
222-
// $em->expects($this->any())->method('getId')->willReturn(0);
223-
// $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
224-
// $m = new Manager($config);
225-
// $m->registerEncryptionModule($em);
226-
// $this->assertTrue($m->isEnabled());
227-
// $m->unregisterEncryptionModule($em);
228-
// $this->assertFalse($m->isEnabled());
229-
// }
230-
//
231-
// /**
232-
// * @expectedException \OC\Encryption\Exceptions\ModuleDoesNotExistsException
233-
// * @expectedExceptionMessage Module with ID: unknown does not exist.
234-
// */
235-
// public function testGetEncryptionModuleUnknown() {
236-
// $config = $this->createMock(IConfig::class);
237-
// $config->expects($this->any())->method('getSystemValueBool')->willReturn(true);
238-
// $em = $this->createMock(IEncryptionModule::class);
239-
// $em->expects($this->any())->method('getId')->willReturn(0);
240-
// $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
241-
// $m = new Manager($config);
242-
// $m->registerEncryptionModule($em);
243-
// $this->assertTrue($m->isEnabled());
244-
// $m->getEncryptionModule('unknown');
245-
// }
246-
//
247-
// public function testGetEncryptionModule() {
248-
// $config = $this->createMock(IConfig::class);
249-
// $config->expects($this->any())->method('getSystemValueBool')->willReturn(true);
250-
// $em = $this->createMock(IEncryptionModule::class);
251-
// $em->expects($this->any())->method('getId')->willReturn(0);
252-
// $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
253-
// $m = new Manager($config);
254-
// $m->registerEncryptionModule($em);
255-
// $this->assertTrue($m->isEnabled());
256-
// $en0 = $m->getEncryptionModule(0);
257-
// $this->assertEquals(0, $en0->getId());
258-
// }
259-
260202
protected function addNewEncryptionModule(Manager $manager, $id) {
261203
$encryptionModule = $this->createMock(IEncryptionModule::class);
262204
$encryptionModule->expects($this->any())

tests/lib/Files/ObjectStore/S3SSEKMSTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,6 @@ public static function dataLargeFileSizes(): array {
159159
];
160160
}
161161

162-
/**
163-
* Test various file sizes with SSE-KMS
164-
*
165-
* @dataProvider dataFileSizes
166-
*/
167162
#[\PHPUnit\Framework\Attributes\DataProvider('dataFileSizes')]
168163
public function testFileSizesWithKMS(int $size): void {
169164
$urn = 'kms-test-size-' . ($size / 1024) . 'kb';
@@ -256,11 +251,6 @@ public function testZeroByteFileWithKMS(): void {
256251
'Zero-byte file should still have SSE-KMS encryption');
257252
}
258253

259-
/**
260-
* Test large file sizes with SSE-KMS to verify multipart threshold behavior
261-
*
262-
* @dataProvider dataLargeFileSizes
263-
*/
264254
#[\PHPUnit\Framework\Attributes\DataProvider('dataLargeFileSizes')]
265255
#[\PHPUnit\Framework\Attributes\Group('SLOWDB')]
266256
public function testLargeFileSizesWithKMS(int $size): void {

tests/lib/Files/Stream/EncryptionTest.php

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -147,30 +147,12 @@ public function testStreamOpen(
147147

148148
// set internal properties of the stream wrapper
149149
$stream = new \ReflectionClass(Encryption::class);
150-
$encryptionModule = $stream->getProperty('encryptionModule');
151-
$encryptionModule->setAccessible(true);
152-
$encryptionModule->setValue($streamWrapper, $encryptionModuleMock);
153-
$encryptionModule->setAccessible(false);
154-
$storage = $stream->getProperty('storage');
155-
$storage->setAccessible(true);
156-
$storage->setValue($streamWrapper, $storageMock);
157-
$storage->setAccessible(false);
158-
$file = $stream->getProperty('file');
159-
$file->setAccessible(true);
160-
$file->setValue($streamWrapper, $fileMock);
161-
$file->setAccessible(false);
162-
$util = $stream->getProperty('util');
163-
$util->setAccessible(true);
164-
$util->setValue($streamWrapper, $utilMock);
165-
$util->setAccessible(false);
166-
$fullPathP = $stream->getProperty('fullPath');
167-
$fullPathP->setAccessible(true);
168-
$fullPathP->setValue($streamWrapper, $fullPath);
169-
$fullPathP->setAccessible(false);
170-
$header = $stream->getProperty('header');
171-
$header->setAccessible(true);
172-
$header->setValue($streamWrapper, []);
173-
$header->setAccessible(false);
150+
$stream->getProperty('encryptionModule')->setValue($streamWrapper, $encryptionModuleMock);
151+
$stream->getProperty('storage')->setValue($streamWrapper, $storageMock);
152+
$stream->getProperty('file')->setValue($streamWrapper, $fileMock);
153+
$stream->getProperty('util')->setValue($streamWrapper, $utilMock);
154+
$stream->getProperty('fullPath')->setValue($streamWrapper, $fullPath);
155+
$stream->getProperty('header')->setValue($streamWrapper, []);
174156
$this->invokePrivate($streamWrapper, 'signed', [true]);
175157
$this->invokePrivate($streamWrapper, 'internalPath', [$fullPath]);
176158
$this->invokePrivate($streamWrapper, 'uid', ['test']);
@@ -180,20 +162,9 @@ public function testStreamOpen(
180162
$streamWrapper->stream_open('', $mode, '', $dummyVar);
181163

182164
// check internal properties
183-
$size = $stream->getProperty('size');
184-
$size->setAccessible(true);
185-
$this->assertSame($expectedSize, $size->getValue($streamWrapper));
186-
$size->setAccessible(false);
187-
188-
$unencryptedSize = $stream->getProperty('unencryptedSize');
189-
$unencryptedSize->setAccessible(true);
190-
$this->assertSame($expectedUnencryptedSize, $unencryptedSize->getValue($streamWrapper));
191-
$unencryptedSize->setAccessible(false);
192-
193-
$readOnly = $stream->getProperty('readOnly');
194-
$readOnly->setAccessible(true);
195-
$this->assertSame($expectedReadOnly, $readOnly->getValue($streamWrapper));
196-
$readOnly->setAccessible(false);
165+
$this->assertSame($expectedSize, $stream->getProperty('size')->getValue($streamWrapper));
166+
$this->assertSame($expectedUnencryptedSize, $stream->getProperty('unencryptedSize')->getValue($streamWrapper));
167+
$this->assertSame($expectedReadOnly, $stream->getProperty('readOnly')->getValue($streamWrapper));
197168
}
198169

199170
public static function dataProviderStreamOpen(): array {

tests/lib/Template/ResourceLocatorTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ public function testFindNotFound(): void {
7373
public function testAppendIfExist(): void {
7474
$locator = $this->getResourceLocator('theme');
7575
$method = new \ReflectionMethod($locator, 'appendIfExist');
76-
$method->setAccessible(true);
7776

7877
$method->invoke($locator, __DIR__, basename(__FILE__), 'webroot');
7978
$resource1 = [__DIR__, 'webroot', basename(__FILE__)];

0 commit comments

Comments
 (0)