From 6336eac6a51af79dc6eba7fa08f5c4ffef594880 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Tue, 28 Oct 2025 00:53:56 +0100 Subject: [PATCH] chore: setting test metadata in annotations is deprecated (use attributes) Signed-off-by: Ferdinand Thiessen --- .../unit/Listener/OutOfOfficeListenerTest.php | 4 +--- .../SetupChecks/AppDirsWithDifferentOwnerTest.php | 14 +++++--------- tests/lib/Avatar/GuestAvatarTest.php | 6 ++---- tests/lib/Files/SimpleFS/InMemoryFileTest.php | 10 +++------- tests/lib/MemoryInfoTest.php | 12 +++--------- 5 files changed, 14 insertions(+), 32 deletions(-) diff --git a/apps/dav/tests/unit/Listener/OutOfOfficeListenerTest.php b/apps/dav/tests/unit/Listener/OutOfOfficeListenerTest.php index 971d113b742..e30b425dbe8 100644 --- a/apps/dav/tests/unit/Listener/OutOfOfficeListenerTest.php +++ b/apps/dav/tests/unit/Listener/OutOfOfficeListenerTest.php @@ -36,9 +36,7 @@ use Sabre\VObject\Component\VEvent; use Sabre\VObject\Reader; use Test\TestCase; -/** - * @covers \OCA\DAV\Listener\OutOfOfficeListener - */ +#[\PHPUnit\Framework\Attributes\CoversClass(OutOfOfficeListener::class)] class OutOfOfficeListenerTest extends TestCase { private ServerFactory&MockObject $serverFactory; diff --git a/apps/settings/tests/SetupChecks/AppDirsWithDifferentOwnerTest.php b/apps/settings/tests/SetupChecks/AppDirsWithDifferentOwnerTest.php index 423f932dcf5..dcff37a1815 100644 --- a/apps/settings/tests/SetupChecks/AppDirsWithDifferentOwnerTest.php +++ b/apps/settings/tests/SetupChecks/AppDirsWithDifferentOwnerTest.php @@ -10,12 +10,14 @@ namespace OCA\Settings\Tests\SetupChecks; use OCA\Settings\SetupChecks\AppDirsWithDifferentOwner; use OCP\IL10N; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class AppDirsWithDifferentOwnerTest extends TestCase { - private IL10N $l10n; private AppDirsWithDifferentOwner $check; + private IL10N&MockObject $l10n; + /** * Holds a list of directories created during tests. * @@ -42,8 +44,6 @@ class AppDirsWithDifferentOwnerTest extends TestCase { * Then calls the 'getAppDirsWithDifferentOwner' method. * The result is expected to be empty since * there are no directories with different owners than the current user. - * - * @return void */ public function testAppDirectoryOwnersOk(): void { $tempDir = tempnam(sys_get_temp_dir(), 'apps') . 'dir'; @@ -69,8 +69,6 @@ class AppDirsWithDifferentOwnerTest extends TestCase { /** * Calls the check for a none existing app root that is marked as not writable. * It's expected that no error happens since the check shouldn't apply. - * - * @return void */ public function testAppDirectoryOwnersNotWritable(): void { $tempDir = tempnam(sys_get_temp_dir(), 'apps') . 'dir'; @@ -89,11 +87,9 @@ class AppDirsWithDifferentOwnerTest extends TestCase { /** * Removes directories created during tests. - * - * @after - * @return void */ - public function removeTestDirectories() { + #[\PHPUnit\Framework\Attributes\After()] + public function removeTestDirectories(): void { foreach ($this->dirsToRemove as $dirToRemove) { rmdir($dirToRemove); } diff --git a/tests/lib/Avatar/GuestAvatarTest.php b/tests/lib/Avatar/GuestAvatarTest.php index ba14d571e27..aa4c59d9ba7 100644 --- a/tests/lib/Avatar/GuestAvatarTest.php +++ b/tests/lib/Avatar/GuestAvatarTest.php @@ -29,11 +29,9 @@ class GuestAvatarTest extends TestCase { /** * Setups a guest avatar instance for tests. - * - * @before - * @return void */ - public function setupGuestAvatar() { + #[\PHPUnit\Framework\Attributes\Before()] + public function setupGuestAvatar(): void { /* @var MockObject|LoggerInterface $logger */ $logger = $this->createMock(LoggerInterface::class); $config = $this->createMock(IConfig::class); diff --git a/tests/lib/Files/SimpleFS/InMemoryFileTest.php b/tests/lib/Files/SimpleFS/InMemoryFileTest.php index 43587acdce9..62f3c86bb78 100644 --- a/tests/lib/Files/SimpleFS/InMemoryFileTest.php +++ b/tests/lib/Files/SimpleFS/InMemoryFileTest.php @@ -21,18 +21,14 @@ use Test\TestCase; class InMemoryFileTest extends TestCase { /** * Holds a pdf file with know attributes for tests. - * - * @var InMemoryFile */ - private $testPdf; + private InMemoryFile $testPdf; /** * Sets the test file from "./resources/test.pdf". - * - * @before - * @return void */ - public function setupTestPdf() { + #[\PHPUnit\Framework\Attributes\Before()] + public function setupTestPdf(): void { $fileContents = file_get_contents( __DIR__ . '/../../../data/test.pdf' ); diff --git a/tests/lib/MemoryInfoTest.php b/tests/lib/MemoryInfoTest.php index 13e46c96601..707b2149122 100644 --- a/tests/lib/MemoryInfoTest.php +++ b/tests/lib/MemoryInfoTest.php @@ -18,21 +18,15 @@ use PHPUnit\Framework\MockObject\MockObject; class MemoryInfoTest extends TestCase { /** * The "memory_limit" value before tests. - * - * @var string */ - private $iniSettingBeforeTest; + private string $iniSettingBeforeTest; - /** - * @beforeClass - */ + #[\PHPUnit\Framework\Attributes\BeforeClass()] public function backupMemoryInfoIniSetting() { $this->iniSettingBeforeTest = ini_get('memory_limit'); } - /** - * @afterClass - */ + #[\PHPUnit\Framework\Attributes\AfterClass()] public function restoreMemoryInfoIniSetting() { ini_set('memory_limit', $this->iniSettingBeforeTest); }