From 2851b899b889442be25639e4d7de3c778bc9c636 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Sun, 8 Aug 2021 00:37:02 +0000 Subject: [PATCH] [TESTS] Add test annotations to core classes --- src/Core/GSFile.php | 7 +++++-- src/Core/Log.php | 6 ++++++ src/Core/Queue/Queue.php | 1 + src/Util/Form/FormFields.php | 3 +++ src/Util/Nickname.php | 24 +++++++++++++----------- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/Core/GSFile.php b/src/Core/GSFile.php index 4ce5904fd5..0463bd893b 100644 --- a/src/Core/GSFile.php +++ b/src/Core/GSFile.php @@ -25,7 +25,6 @@ use App\Core\DB\DB; use function App\Core\I18n\_m; use App\Entity\Attachment; use App\Util\Common; -use App\Util\Exception\ClientException; use App\Util\Exception\DuplicateFoundException; use App\Util\Exception\NoSuchFileException; use App\Util\Exception\NotFoundException; @@ -161,7 +160,9 @@ class GSFile autoLastModified: true ); if (Common::config('site', 'x_static_delivery')) { + // @codeCoverageIgnoreStart $response->trustXSendfileTypeHeader(); + // @codeCoverageIgnoreEnd } return $response; } else { @@ -184,8 +185,10 @@ class GSFile case 1: return $res[0]; default: + // @codeCoverageIgnoreStart Log::error('Media query returned more than one result for identifier: \"' . $id . '\"'); - throw new ClientException(_m('Internal server error')); + throw new ServerException(_m('Internal server error')); + // @codeCoverageIgnoreEnd } } diff --git a/src/Core/Log.php b/src/Core/Log.php index 1b6a13b3de..4012acff04 100644 --- a/src/Core/Log.php +++ b/src/Core/Log.php @@ -43,6 +43,12 @@ abstract class Log self::$logger = $l; } + /** + * Log a critical error when a really unexpected exception occured. This indicates a bug in the software + * + * @throws ServerException + * @codeCoverageIgnore + */ public static function unexpected_exception(\Exception $e) { $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); diff --git a/src/Core/Queue/Queue.php b/src/Core/Queue/Queue.php index ded1955f68..5f2098711f 100644 --- a/src/Core/Queue/Queue.php +++ b/src/Core/Queue/Queue.php @@ -48,6 +48,7 @@ abstract class Queue * @param string $queue * @param bool $high * @param array $stamps + * @codeCoverageIgnore */ public static function enqueue($message, string $queue, bool $high = false, array $stamps = []) { diff --git a/src/Util/Form/FormFields.php b/src/Util/Form/FormFields.php index 4e2587fa42..8271b8770f 100644 --- a/src/Util/Form/FormFields.php +++ b/src/Util/Form/FormFields.php @@ -35,6 +35,9 @@ abstract class FormFields ]; } + /** + * @codeCoverageIgnore + */ public static function password(array $options = []): array { ['password', PasswordType::class, [ diff --git a/src/Util/Nickname.php b/src/Util/Nickname.php index ac2eba7b4d..f995a9d718 100644 --- a/src/Util/Nickname.php +++ b/src/Util/Nickname.php @@ -146,18 +146,20 @@ class Nickname throw new NicknameReservedException(); } elseif ($check_already_used) { switch ($which) { - case self::CHECK_LOCAL_USER: - $lu = LocalUser::findByNicknameOrEmail($nickname, email: ''); - if ($lu !== null) { - throw new NicknameTakenException($lu->getActor()); + case self::CHECK_LOCAL_USER: + $lu = LocalUser::findByNicknameOrEmail($nickname, email: ''); + if ($lu !== null) { + throw new NicknameTakenException($lu->getActor()); + } + break; + // @codeCoverageIgnoreStart + case self::CHECK_LOCAL_GROUP: + throw new \NotImplementedException(); + break; + default: + throw new \InvalidArgumentException(); + // @codeCoverageIgnoreEnd } - break; - case self::CHECK_LOCAL_GROUP: - throw new \NotImplementedException(); - break; - default: - throw new \InvalidArgumentException(); - } } }