diff --git a/app/Actions/Oauth/Oauth.php b/app/Actions/Oauth/Oauth.php index 854efa12f57..b183a1430c6 100644 --- a/app/Actions/Oauth/Oauth.php +++ b/app/Actions/Oauth/Oauth.php @@ -21,6 +21,10 @@ use Laravel\Socialite\Contracts\User as ContractsUser; use Laravel\Socialite\Facades\Socialite; +/** + * @codeCoverageIgnore + * This code is untestable as it is tightly coupled with the Socialite facade. + */ class Oauth { public const OAUTH_REGISTER = 'register'; diff --git a/app/Assets/BaseSizeVariantNamingStrategy.php b/app/Assets/BaseSizeVariantNamingStrategy.php index 1d97659ea22..afddf861e05 100644 --- a/app/Assets/BaseSizeVariantNamingStrategy.php +++ b/app/Assets/BaseSizeVariantNamingStrategy.php @@ -48,7 +48,9 @@ protected function generateExtension(SizeVariantType $sizeVariant): string } if ($this->extension === '') { + // @codeCoverageIgnoreStart throw new MissingValueException('extension'); + // @codeCoverageIgnoreEnd } return $this->extension; diff --git a/app/Assets/Helpers.php b/app/Assets/Helpers.php index 7d778b9cefd..d73aff0d12e 100644 --- a/app/Assets/Helpers.php +++ b/app/Assets/Helpers.php @@ -135,8 +135,10 @@ public function getSymbolByQuantity(float $bytes): string $exp = intval(floor(log($bytes) / log(1024.0))); if ($exp >= sizeof($symbols)) { + // @codeCoverageIgnoreStart // if the number is too large, we fall back to the largest available symbol $exp = sizeof($symbols) - 1; + // @codeCoverageIgnoreEnd } return sprintf('%.2f %s', ($bytes / pow(1024, $exp)), $symbols[$exp]); diff --git a/app/Http/Controllers/OauthController.php b/app/Http/Controllers/OauthController.php index d4904aec2eb..749b327f38c 100644 --- a/app/Http/Controllers/OauthController.php +++ b/app/Http/Controllers/OauthController.php @@ -39,6 +39,8 @@ public function __construct( * @param string $provider * * @return Redirector|RedirectResponse + * + * @codeCoverageIgnore */ public function redirected(string $provider) { @@ -63,6 +65,8 @@ public function redirected(string $provider) * @param string $provider * * @return HttpFoundationRedirectResponse + * + * @codeCoverageIgnore */ public function authenticate(string $provider) { @@ -81,6 +85,8 @@ public function authenticate(string $provider) * @param string $provider * * @return HttpFoundationRedirectResponse + * + * @codeCoverageIgnore */ public function register(string $provider) { diff --git a/tests/Feature_v2/Oauth/OauthTest.php b/tests/Feature_v2/Oauth/OauthTest.php index b14b6d0ed53..315eeb5eb6a 100644 --- a/tests/Feature_v2/Oauth/OauthTest.php +++ b/tests/Feature_v2/Oauth/OauthTest.php @@ -46,4 +46,8 @@ public function testGetAnonymous(): void $response = $this->actingAs($this->userMayUpload1)->deleteJson('Oauth', ['provider' => 'github']); $this->assertNoContent($response); } + + public function testOauthRegistration(): void + { + } } diff --git a/tests/Unit/CoverageTest.php b/tests/Unit/CoverageTest.php index 25b10b833fd..f5e42b04331 100644 --- a/tests/Unit/CoverageTest.php +++ b/tests/Unit/CoverageTest.php @@ -18,6 +18,9 @@ namespace Tests\Unit; +use App\DTO\BacktraceRecord; +use App\DTO\ImportEventReport; +use App\DTO\ImportProgressReport; use App\Enum\AspectRatioCSSType; use App\Enum\AspectRatioType; use App\Enum\MapProviders; @@ -56,4 +59,45 @@ public function testMapProvidersEnum(): void self::assertEquals(AspectRatioCSSType::aspect2by3, AspectRatioType::aspect2by3->css()); } + + public function testBackTraceReccord(): void + { + $record = new BacktraceRecord( + file: 'file', + line: 1, + class: 'class', + function: 'function', + ); + + self::assertEquals('file', $record->getFile()); + self::assertEquals('function', $record->getFunction()); + self::assertEquals('class', $record->getClass()); + self::assertEquals(['file' => 'file', 'line' => 1, 'method' => 'class::function'], $record->toArray()); + } + + public function testImportProgressReport(): void + { + $report = ImportProgressReport::create( + path: 'path', + progress: 1, + ); + self::assertEquals('path: 1%', $report->toCLIString()); + } + + public function testImportEventReport(): void + { + $report = ImportEventReport::createWarning( + subtype: 'subtype', + path: 'path', + message: 'message', + ); + self::assertEquals('path: message', $report->toCLIString()); + + $report = ImportEventReport::createWarning( + subtype: 'subtype', + path: null, + message: 'message', + ); + self::assertEquals('message', $report->toCLIString()); + } } diff --git a/tests/Unit/HelpersUnitTest.php b/tests/Unit/HelpersUnitTest.php index 4a36bf5d5e8..b68d491aa67 100644 --- a/tests/Unit/HelpersUnitTest.php +++ b/tests/Unit/HelpersUnitTest.php @@ -18,6 +18,7 @@ namespace Tests\Unit; +use App\Exceptions\Internal\ZeroModuloException; use App\Facades\Helpers; use Tests\AbstractTestCase; @@ -32,8 +33,44 @@ class HelpersUnitTest extends AbstractTestCase */ public function testTrancateIf32(): void { - $this->assertEquals('1', Helpers::trancateIf32('10000', 0, 1000)); // check first call => returns 1 - $this->assertEquals('2', Helpers::trancateIf32('10000', 1, 1000)); // check equal => returns +1 - $this->assertEquals('5', Helpers::trancateIf32('50000', 2, 1000)); // check if normal higher => returns higher + self::assertEquals('1', Helpers::trancateIf32('10000', 0, 1000)); // check first call => returns 1 + self::assertEquals('2', Helpers::trancateIf32('10000', 1, 1000)); // check equal => returns +1 + self::assertEquals('5', Helpers::trancateIf32('50000', 2, 1000)); // check if normal higher => returns higher + self::assertEquals('50000', Helpers::trancateIf32('50000', 2, 2147483649)); // check if normal higher => returns higher + } + + public function testHasFullPermissions(): void + { + self::assertEquals(false, Helpers::hasFullPermissions('does-not-exists')); + } + + public function testGcd(): void + { + self::assertEquals(5, Helpers::gcd(10, 5)); + self::assertEquals(1, Helpers::gcd(7, 5)); + } + + public function testGcdException(): void + { + self::expectException(ZeroModuloException::class); + Helpers::gcd(0, 0); + } + + public function testConvertSize(): void + { + self::assertEquals(1, Helpers::convertSize('1')); + self::assertEquals(1024, Helpers::convertSize('1K')); + self::assertEquals(1024 * 1024, Helpers::convertSize('1M')); + self::assertEquals(1024 * 1024 * 1024, Helpers::convertSize('1G')); + } + + public function testDecimalToDegreeMinutesSeconds(): void + { + self::assertEquals('', Helpers::decimalToDegreeMinutesSeconds(190, true)); + self::assertEquals('', Helpers::decimalToDegreeMinutesSeconds(190, false)); + self::assertEquals("90° 0' 0\" N", Helpers::decimalToDegreeMinutesSeconds(90, true)); + self::assertEquals("90° 0' 0\" S", Helpers::decimalToDegreeMinutesSeconds(-90, true)); + self::assertEquals("90° 0' 0\" E", Helpers::decimalToDegreeMinutesSeconds(90, false)); + self::assertEquals("90° 0' 0\" W", Helpers::decimalToDegreeMinutesSeconds(-90, false)); } } \ No newline at end of file