Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria committed Sep 15, 2024
1 parent 360a815 commit e9e5b61
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function do(MaintenanceRequest $request): void
*
* @return int
*/
public function check(): int
public function check(MaintenanceRequest $request): int
{
return SizeVariant::query()
->where('filesize', '=', 0)
Expand Down
24 changes: 24 additions & 0 deletions tests/Feature_v2/LandingTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* We don't care for unhandled exceptions in tests.
* It is the nature of a test to throw an exception.
* Without this suppression we had 100+ Linter warning in this file which
* don't help anything.
*
* @noinspection PhpDocMissingThrowsInspection
* @noinspection PhpUnhandledExceptionInspection
*/

namespace Tests\Feature_v2;

use Tests\Feature_v2\Base\BaseApiV2Test;

class LandingTest extends BaseApiV2Test
{
public function testGet(): void
{
$response = $this->getJson('LandingPage');
$this->assertOk($response);
}
}
11 changes: 11 additions & 0 deletions tests/Feature_v2/Maintenance/CleaningTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,15 @@ public function testAdmin(): void
$response = $this->actingAs($this->admin)->postJson('Maintenance::cleaning', ['path' => 'filesystems.disks.extract-jobs.root']);
$this->assertOk($response);
}

public function testAdminWithFiles(): void
{
touch(storage_path('extract-jobs') . '/delete-me.txt');

Check failure on line 66 in tests/Feature_v2/Maintenance/CleaningTest.php

View workflow job for this annotation

GitHub Actions / 2️⃣ PHP 8.2 - PHPStan

Function touch is unsafe to use. It can return FALSE instead of throwing an exception. Please add 'use function Safe\touch;' at the beginning of the file to use the variant provided by the 'thecodingmachine/safe' library.

Check failure on line 66 in tests/Feature_v2/Maintenance/CleaningTest.php

View workflow job for this annotation

GitHub Actions / 2️⃣ PHP 8.2 - PHPStan

Function touch is unsafe to use. It can return FALSE instead of throwing an exception. Please add 'use function Safe\touch;' at the beginning of the file to use the variant provided by the 'thecodingmachine/safe' library.
$response = $this->actingAs($this->admin)->getJsonWithData('Maintenance::cleaning', ['path' => 'filesystems.disks.extract-jobs.root']);
$this->assertOk($response);

$response = $this->actingAs($this->admin)->postJson('Maintenance::cleaning', ['path' => 'filesystems.disks.extract-jobs.root']);
$this->assertOk($response);
static::assertEquals(false, file_exists(storage_path('extract-jobs') . '/delete-me.txt'));
}
}
10 changes: 10 additions & 0 deletions tests/Feature_v2/Maintenance/JobsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

namespace Tests\Feature_v2\Maintenance;

use App\Enum\JobStatus;
use App\Models\JobHistory;
use Tests\Feature_v2\Base\BaseApiV2Test;

class JobsTest extends BaseApiV2Test
Expand All @@ -36,6 +38,14 @@ public function testUser(): void

public function testAdmin(): void
{
$jobHistory = new JobHistory();
$jobHistory->owner_id = $this->admin->id;
$jobHistory->job = 'Maintenance::jobs';
$jobHistory->status = JobStatus::STARTED;
$jobHistory->created_at = now();
$jobHistory->updated_at = now();
$jobHistory->save();

$response = $this->actingAs($this->admin)->getJsonWithData('Maintenance::jobs');
$this->assertOk($response);

Expand Down
45 changes: 45 additions & 0 deletions tests/Feature_v2/Maintenance/MissingFileSizeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/**
* We don't care for unhandled exceptions in tests.
* It is the nature of a test to throw an exception.
* Without this suppression we had 100+ Linter warning in this file which
* don't help anything.
*
* @noinspection PhpDocMissingThrowsInspection
* @noinspection PhpUnhandledExceptionInspection
*/

namespace Tests\Feature_v2\Maintenance;

use Tests\Feature_v2\Base\BaseApiV2Test;

class MissingFileSizeTest extends BaseApiV2Test
{
public function testGuest(): void
{
$response = $this->getJsonWithData('Maintenance::missingFileSize');
$this->assertUnauthorized($response);

$response = $this->postJson('Maintenance::missingFileSize');
$this->assertUnauthorized($response);
}

public function testUser(): void
{
$response = $this->actingAs($this->userLocked)->getJsonWithData('Maintenance::missingFileSize');
$this->assertForbidden($response);

$response = $this->actingAs($this->userLocked)->postJson('Maintenance::missingFileSize');
$this->assertForbidden($response);
}

public function testAdmin(): void
{
$response = $this->actingAs($this->admin)->getJsonWithData('Maintenance::missingFileSize');
$this->assertOk($response);

$response = $this->actingAs($this->admin)->postJson('Maintenance::missingFileSize');
$this->assertNoContent($response);
}
}
42 changes: 42 additions & 0 deletions tests/Feature_v2/UsersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/**
* We don't care for unhandled exceptions in tests.
* It is the nature of a test to throw an exception.
* Without this suppression we had 100+ Linter warning in this file which
* don't help anything.
*
* @noinspection PhpDocMissingThrowsInspection
* @noinspection PhpUnhandledExceptionInspection
*/

namespace Tests\Feature_v2;

use Tests\Feature_v2\Base\BaseApiV2Test;

class UsersTest extends BaseApiV2Test
{
public function testGetGuest(): void
{
$response = $this->getJson('Users');
$this->assertUnauthorized($response);
}

public function testGet(): void
{
$response = $this->actingAs($this->userMayUpload1)->getJson('Users');
$this->assertOk($response);
}

public function testGetCountGuest(): void
{
$response = $this->getJson('Users::count');
$this->assertUnauthorized($response);
}

public function testGetCount(): void
{
$response = $this->actingAs($this->userMayUpload1)->getJson('Users::count');
$this->assertOk($response);
}
}
24 changes: 24 additions & 0 deletions tests/Feature_v2/VersionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* We don't care for unhandled exceptions in tests.
* It is the nature of a test to throw an exception.
* Without this suppression we had 100+ Linter warning in this file which
* don't help anything.
*
* @noinspection PhpDocMissingThrowsInspection
* @noinspection PhpUnhandledExceptionInspection
*/

namespace Tests\Feature_v2;

use Tests\Feature_v2\Base\BaseApiV2Test;

class VersionTest extends BaseApiV2Test
{
public function testGet(): void
{
$response = $this->getJson('Version');
$this->assertOk($response);
}
}

0 comments on commit e9e5b61

Please sign in to comment.