Skip to content

Commit a16f89a

Browse files
committed
coverage
1 parent 509ea21 commit a16f89a

File tree

9 files changed

+69
-0
lines changed

9 files changed

+69
-0
lines changed

app/Legacy/Legacy.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,22 @@ private static function translateLegacyID(int $id, string $tableName, Request $r
6060
' instead of new ID ' . $newID .
6161
' from ' . $referer;
6262
if (!Configs::getValueAsBool('legacy_id_redirection')) {
63+
// @codeCoverageIgnoreStart
6364
$msg .= ' (translation disabled by configuration)';
6465
throw new ConfigurationException($msg);
66+
// @codeCoverageIgnoreEnd
6567
}
6668
Log::warning(__METHOD__ . ':' . __LINE__ . $msg);
6769

6870
return $newID;
6971
}
7072

73+
// @codeCoverageIgnoreStart
7174
return null;
7275
} catch (\InvalidArgumentException $e) {
7376
throw new QueryBuilderException($e);
7477
}
78+
// @codeCoverageIgnoreEnd
7579
}
7680

7781
/**

app/Legacy/V1/Middleware/LoginRequiredV1.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class LoginRequiredV1
3939
*
4040
* @throws ConfigurationException
4141
* @throws FrameworkException
42+
*
43+
* @codeCoverageIgnore Legacy stuff we don't care.
4244
*/
4345
public function handle(Request $request, \Closure $next, string $requiredStatus): mixed
4446
{

app/Legacy/V1/Requests/Sharing/DeleteSharingRequest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
use App\Rules\IntegerIDRule;
1515
use Illuminate\Support\Facades\Gate;
1616

17+
/**
18+
* @codeCoverageIgnore Legacy stuff we don't care.
19+
*/
1720
class DeleteSharingRequest extends BaseApiRequest
1821
{
1922
public const SHARE_IDS_ATTRIBUTE = 'shareIDs';

app/Legacy/V1/Requests/Sharing/ListSharingRequest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class ListSharingRequest extends BaseApiRequest implements HasBaseAlbum
5454

5555
/**
5656
* {@inheritDoc}
57+
*
58+
* @codeCoverageIgnore Legacy stuff we don't care.
5759
*/
5860
public function authorize(): bool
5961
{
@@ -96,20 +98,26 @@ public function rules(): array
9698
protected function processValidatedValues(array $values, array $files): void
9799
{
98100
$this->album = key_exists(RequestAttribute::ALBUM_ID_ATTRIBUTE, $values) ?
101+
// @codeCoverageIgnoreStart
99102
$this->albumFactory->findBaseAlbumOrFail($values[RequestAttribute::ALBUM_ID_ATTRIBUTE]) :
103+
// @codeCoverageIgnoreEnd
100104
null;
101105

102106
$this->owner = null;
103107
$this->participant = null;
104108
if (key_exists(self::OWNER_ID_ATTRIBUTE, $values)) {
109+
// @codeCoverageIgnoreStart
105110
/** @var int $ownerID */
106111
$ownerID = $values[self::OWNER_ID_ATTRIBUTE];
107112
$this->owner = User::query()->findOrFail($ownerID);
113+
// @codeCoverageIgnoreEnd
108114
}
109115
if (key_exists(self::PARTICIPANT_ID_ATTRIBUTE, $values)) {
116+
// @codeCoverageIgnoreStart
110117
/** @var int $participantID */
111118
$participantID = $values[self::PARTICIPANT_ID_ATTRIBUTE];
112119
$this->participant = User::query()->findOrFail($participantID);
120+
// @codeCoverageIgnoreEnd
113121
}
114122
}
115123

app/Legacy/V1/Requests/Sharing/SetSharesByAlbumRequest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
* Represents a request for setting the shares of a specific album.
2525
*
2626
* Only the owner (or the admin) of the album can set the shares.
27+
*
28+
* @codeCoverageIgnore Legacy stuff we don't care.
2729
*/
2830
class SetSharesByAlbumRequest extends BaseApiRequest implements HasBaseAlbum, HasUserIDs
2931
{

app/Legacy/V1/Requests/View/GetPhotoViewRequest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
use App\Rules\RandomIDRule;
1717
use Illuminate\Support\Facades\Gate;
1818

19+
/**
20+
* @codeCoverageIgnore
21+
*/
1922
class GetPhotoViewRequest extends BaseApiRequest implements HasPhoto
2023
{
2124
use HasPhotoTrait;

app/Services/Auth/SessionOrTokenGuard.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ public static function createGuard(Application $app, string $name, array $config
128128
/** @disregard P1013 */
129129
$guard->setRequest($app->refresh('request', $guard, 'setRequest'));
130130
if (isset($config['remember'])) {
131+
// @codeCoverageIgnoreStart
131132
$guard->setRememberDuration($config['remember']);
133+
// @codeCoverageIgnoreEnd
132134
}
133135

134136
return $guard;
@@ -194,7 +196,9 @@ public function user(): Authenticatable|null
194196
// new authentication state explicitly.
195197
$this->authState = self::AUTH_STATE_STATELESS;
196198
} elseif ($userByRecaller !== null) {
199+
// @codeCoverageIgnoreStart
197200
$this->login($userByRecaller, true);
201+
// @codeCoverageIgnoreEnd
198202
} else {
199203
// In the other cases, `$this->user` has implicitly been set by
200204
// `parent::setUser` or `$this->login`.
@@ -326,7 +330,9 @@ protected function getUserByToken(): ?Authenticatable
326330

327331
// Skip if token starts with Basic: it is not related to Lychee.
328332
if (Str::startsWith('Basic', $token)) {
333+
// @codeCoverageIgnoreStart
329334
return null;
335+
// @codeCoverageIgnoreEnd
330336
}
331337

332338
// Check if token starts with Bearer
@@ -349,8 +355,10 @@ protected function getUserByToken(): ?Authenticatable
349355

350356
return match (true) {
351357
$authenticable !== null => $authenticable,
358+
// @codeCoverageIgnoreStart
352359
$hasBearer && $configThrow => throw new BadRequestHeaderException('Invalid token'),
353360
$hasBearer => null,
361+
// @codeCoverageIgnoreEnd
354362
default => throw new BadRequestHeaderException('Invalid token'),
355363
};
356364
}

app/SmartAlbums/BaseSmartAlbum.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ protected function __construct(SmartAlbumType $id, \Closure $smartCondition)
6868
/** @var AccessPermission|null $perm */
6969
$perm = AccessPermission::query()->where('base_album_id', '=', $id->value)->first();
7070
$this->publicPermissions = $perm;
71+
// @codeCoverageIgnoreStart
7172
} catch (BindingResolutionException $e) {
7273
throw new FrameworkException('Laravel\'s service container', $e);
7374
}
75+
// @codeCoverageIgnoreEnd
7476
}
7577

7678
/**
@@ -136,7 +138,9 @@ protected function getThumbAttribute(): ?Thumb
136138
* user.
137139
*/
138140
$this->thumb ??= Configs::getValueAsBool('SA_random_thumbs')
141+
// @codeCoverageIgnoreStart
139142
? Thumb::createFromRandomQueryable($this->photos())
143+
// @codeCoverageIgnoreEnd
140144
: $this->thumb = Thumb::createFromQueryable(
141145
$this->photos(),
142146
PhotoSortingCriterion::createDefault()

tests/Unit/CoverageTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
use App\Enum\AspectRatioType;
2626
use App\Enum\MapProviders;
2727
use App\Enum\SmartAlbumType;
28+
use App\Exceptions\Internal\LycheeInvalidArgumentException;
29+
use App\SmartAlbums\UnsortedAlbum;
2830
use Tests\AbstractTestCase;
2931

3032
class CoverageTest extends AbstractTestCase
@@ -100,4 +102,37 @@ public function testImportEventReport(): void
100102
);
101103
self::assertEquals('message', $report->toCLIString());
102104
}
105+
106+
public function testBaseSmartAlbumException(): void
107+
{
108+
self::expectException(LycheeInvalidArgumentException::class);
109+
110+
$album = new UnsortedAlbum();
111+
$album->__get('');
112+
}
113+
114+
public function testBaseSmartAlbumException2(): void
115+
{
116+
self::expectException(LycheeInvalidArgumentException::class);
117+
118+
$album = new UnsortedAlbum();
119+
$album->__get('something');
120+
}
121+
122+
public function testBaseSmartAlbumPhotos(): void
123+
{
124+
$album = new UnsortedAlbum();
125+
$data = $album->__get('Photos');
126+
self::assertEmpty($data);
127+
128+
$data = $album->getPhotos();
129+
self::assertEmpty($data);
130+
131+
$album->setPublic();
132+
$album->setPublic();
133+
$data = $album->getPhotos();
134+
self::assertEmpty($data);
135+
$album->setPrivate();
136+
$album->setPrivate();
137+
}
103138
}

0 commit comments

Comments
 (0)