Skip to content

Commit

Permalink
improve
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria committed Jan 17, 2025
1 parent a8f321f commit 9b3ead7
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 3 deletions.
4 changes: 4 additions & 0 deletions app/Actions/Oauth/Oauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 2 additions & 0 deletions app/Assets/BaseSizeVariantNamingStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ protected function generateExtension(SizeVariantType $sizeVariant): string
}

if ($this->extension === '') {
// @codeCoverageIgnoreStart
throw new MissingValueException('extension');
// @codeCoverageIgnoreEnd
}

return $this->extension;
Expand Down
2 changes: 2 additions & 0 deletions app/Assets/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
6 changes: 6 additions & 0 deletions app/Http/Controllers/OauthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public function __construct(
* @param string $provider
*
* @return Redirector|RedirectResponse
*
* @codeCoverageIgnore
*/
public function redirected(string $provider)
{
Expand All @@ -63,6 +65,8 @@ public function redirected(string $provider)
* @param string $provider
*
* @return HttpFoundationRedirectResponse
*
* @codeCoverageIgnore
*/
public function authenticate(string $provider)
{
Expand All @@ -81,6 +85,8 @@ public function authenticate(string $provider)
* @param string $provider
*
* @return HttpFoundationRedirectResponse
*
* @codeCoverageIgnore
*/
public function register(string $provider)
{
Expand Down
4 changes: 4 additions & 0 deletions tests/Feature_v2/Oauth/OauthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ public function testGetAnonymous(): void
$response = $this->actingAs($this->userMayUpload1)->deleteJson('Oauth', ['provider' => 'github']);
$this->assertNoContent($response);
}

public function testOauthRegistration(): void
{
}
}
44 changes: 44 additions & 0 deletions tests/Unit/CoverageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
43 changes: 40 additions & 3 deletions tests/Unit/HelpersUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

namespace Tests\Unit;

use App\Exceptions\Internal\ZeroModuloException;
use App\Facades\Helpers;
use Tests\AbstractTestCase;

Expand All @@ -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));
}
}

0 comments on commit 9b3ead7

Please sign in to comment.