diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index f042660d..66273417 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -4,9 +4,11 @@ on: push: branches: - 2.x + - 3.x pull_request: branches: - 2.x + - 3.x jobs: tests: diff --git a/.github/workflows/code-style.yml b/.github/workflows/code-style.yml index d5657279..c64ba0bf 100644 --- a/.github/workflows/code-style.yml +++ b/.github/workflows/code-style.yml @@ -6,6 +6,7 @@ on: - main - 1.x - 2.x + - 3.x pull_request: jobs: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0f349949..001a3cd3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -6,6 +6,7 @@ on: - main - 1.x - 2.x + - 3.x pull_request: jobs: @@ -16,6 +17,7 @@ jobs: fail-fast: true matrix: php: [ 8.4 ] + node-version: [ "20.x" ] steps: - uses: actions/checkout@v4 @@ -44,5 +46,16 @@ jobs: - name: Set up the .env file run: touch .env + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "20.x" + + - name: Install NPM Dependencies + run: npm install + + - name: Build assets + run: npm run build + - name: Run test suite run: php artisan test diff --git a/.gitignore b/.gitignore index e4855327..01e32378 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ yarn-error.log /.idea /.vscode laradumps.yaml +/public/build diff --git a/app/Http/Controllers/API/RedirectController.php b/app/Http/Controllers/API/RedirectController.php index f2340c7c..7184b401 100644 --- a/app/Http/Controllers/API/RedirectController.php +++ b/app/Http/Controllers/API/RedirectController.php @@ -34,7 +34,7 @@ class RedirectController extends Controller #[ResponseFromApiResource(RedirectResource::class, Redirect::class, collection: true, paginate: 25)] public function index(Project $project, Server $server, Site $site): ResourceCollection { - $this->authorize('view', [Redirect::class, $site, $server]); + $this->authorize('viewAny', [Redirect::class, $site, $server]); $this->validateRoute($project, $server, $site); @@ -53,8 +53,6 @@ public function create(Request $request, Project $project, Server $server, Site $this->validateRoute($project, $server, $site); - $this->validate($request, CreateRedirect::rules($site)); - $redirect = app(CreateRedirect::class)->create($site, $request->all()); return new RedirectResource($redirect); @@ -65,7 +63,7 @@ public function create(Request $request, Project $project, Server $server, Site #[Response(status: 204)] public function delete(Project $project, Server $server, Site $site, Redirect $redirect): HttpResponse { - $this->authorize('delete', [Redirect::class, $site, $server]); + $this->authorize('delete', [$redirect, $site, $server]); $this->validateRoute($project, $server, $site); diff --git a/tests/Feature/API/CronjobTest.php b/tests/Feature/API/CronjobTest.php index d548966c..3bee65d8 100644 --- a/tests/Feature/API/CronjobTest.php +++ b/tests/Feature/API/CronjobTest.php @@ -13,7 +13,7 @@ class CronjobTest extends TestCase { use RefreshDatabase; - public function test_see_cronjobs_list() + public function test_see_cronjobs_list(): void { Sanctum::actingAs($this->user, ['read', 'write']); @@ -33,7 +33,7 @@ public function test_see_cronjobs_list() ]); } - public function test_create_cronjob() + public function test_create_cronjob(): void { SSH::fake(); @@ -56,7 +56,7 @@ public function test_create_cronjob() ]); } - public function test_delete_cronjob() + public function test_delete_cronjob(): void { SSH::fake(); diff --git a/tests/Feature/API/ProjectsTest.php b/tests/Feature/API/ProjectsTest.php index 534d3339..442b280f 100644 --- a/tests/Feature/API/ProjectsTest.php +++ b/tests/Feature/API/ProjectsTest.php @@ -80,7 +80,7 @@ public function test_cannot_delete_last_project(): void Sanctum::actingAs($this->user, ['read', 'write']); $this->json('DELETE', "/api/projects/{$this->user->currentProject->id}") - ->assertJsonValidationErrorFor('project'); + ->assertJsonValidationErrorFor('name'); $this->assertDatabaseHas('projects', [ 'id' => $this->user->currentProject->id, diff --git a/tests/Feature/API/ServerProvidersTest.php b/tests/Feature/API/ServerProvidersTest.php index 7d4ab011..9ab0c63c 100644 --- a/tests/Feature/API/ServerProvidersTest.php +++ b/tests/Feature/API/ServerProvidersTest.php @@ -6,6 +6,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Http; use Laravel\Sanctum\Sanctum; +use PHPUnit\Framework\Attributes\DataProvider; use Tests\TestCase; class ServerProvidersTest extends TestCase @@ -13,8 +14,9 @@ class ServerProvidersTest extends TestCase use RefreshDatabase; /** - * @dataProvider data + * @param array $input */ + #[DataProvider('data')] public function test_connect_provider(string $provider, array $input): void { Sanctum::actingAs($this->user, ['read', 'write']); @@ -40,8 +42,9 @@ public function test_connect_provider(string $provider, array $input): void } /** - * @dataProvider data + * @param array $input */ + #[DataProvider('data')] public function test_cannot_connect_to_provider(string $provider, array $input): void { Sanctum::actingAs($this->user, ['read', 'write']); @@ -82,9 +85,7 @@ public function test_see_providers_list(): void ]); } - /** - * @dataProvider data - */ + #[DataProvider('data')] public function test_delete_provider(string $provider): void { Sanctum::actingAs($this->user, ['read', 'write']); @@ -102,9 +103,7 @@ public function test_delete_provider(string $provider): void ->assertNoContent(); } - /** - * @dataProvider data - */ + #[DataProvider('data')] public function test_cannot_delete_provider(string $provider): void { Sanctum::actingAs($this->user, ['read', 'write']); @@ -128,6 +127,9 @@ public function test_cannot_delete_provider(string $provider): void ]); } + /** + * @return array> + */ public static function data(): array { return [ diff --git a/tests/Feature/API/ServicesTest.php b/tests/Feature/API/ServicesTest.php index a485dcd2..fd7e20e2 100644 --- a/tests/Feature/API/ServicesTest.php +++ b/tests/Feature/API/ServicesTest.php @@ -6,6 +6,7 @@ use App\Facades\SSH; use Illuminate\Foundation\Testing\RefreshDatabase; use Laravel\Sanctum\Sanctum; +use PHPUnit\Framework\Attributes\DataProvider; use Tests\TestCase; class ServicesTest extends TestCase @@ -57,9 +58,7 @@ public function test_show_service(): void ]); } - /** - * @dataProvider data - */ + #[DataProvider('data')] public function test_manage_service(string $action): void { Sanctum::actingAs($this->user, ['read', 'write']); @@ -94,6 +93,10 @@ public function test_uninstall_service(): void ])) ->assertSuccessful() ->assertNoContent(); + + $this->assertDatabaseMissing('services', [ + 'id' => $service->id, + ]); } public function test_cannot_uninstall_service_because_it_is_being_used(): void @@ -112,6 +115,9 @@ public function test_cannot_uninstall_service_because_it_is_being_used(): void ->assertJsonValidationErrorFor('service'); } + /** + * @return array> + */ public static function data(): array { return [ diff --git a/tests/Feature/API/SitesTest.php b/tests/Feature/API/SitesTest.php index 296dbf2f..523118f0 100644 --- a/tests/Feature/API/SitesTest.php +++ b/tests/Feature/API/SitesTest.php @@ -11,6 +11,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Http; use Laravel\Sanctum\Sanctum; +use PHPUnit\Framework\Attributes\DataProvider; use Tests\TestCase; use Tests\Traits\PrepareLoadBalancer; @@ -27,8 +28,9 @@ protected function setUp(): void } /** - * @dataProvider create_data + * @param array $inputs */ + #[DataProvider('create_data')] public function test_create_site(array $inputs): void { SSH::fake(); @@ -383,10 +385,11 @@ public function test_update_env(): void ->assertJsonFragment([ 'domain' => $site->domain, ]); - - SSH::assertExecuted('edit-file'); } + /** + * @return array>> + */ public static function create_data(): array { return \Tests\Feature\SitesTest::create_data(); diff --git a/tests/Feature/API/SourceControlsTest.php b/tests/Feature/API/SourceControlsTest.php index f3f01ea0..766bcb20 100644 --- a/tests/Feature/API/SourceControlsTest.php +++ b/tests/Feature/API/SourceControlsTest.php @@ -6,6 +6,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Http; use Laravel\Sanctum\Sanctum; +use PHPUnit\Framework\Attributes\DataProvider; use Tests\TestCase; class SourceControlsTest extends TestCase @@ -13,8 +14,9 @@ class SourceControlsTest extends TestCase use RefreshDatabase; /** - * @dataProvider data + * @param array $input */ + #[DataProvider('data')] public function test_connect_provider(string $provider, array $input): void { Sanctum::actingAs($this->user, ['read', 'write']); @@ -39,6 +41,7 @@ public function test_connect_provider(string $provider, array $input): void /** * @dataProvider data */ + #[DataProvider('data')] public function test_delete_provider(string $provider): void { Sanctum::actingAs($this->user, ['read', 'write']); @@ -60,6 +63,7 @@ public function test_delete_provider(string $provider): void /** * @dataProvider data */ + #[DataProvider('data')] public function test_cannot_delete_provider(string $provider): void { Sanctum::actingAs($this->user, ['read', 'write']); @@ -90,7 +94,10 @@ public function test_cannot_delete_provider(string $provider): void /** * @dataProvider data + * + * @param array $input */ + #[DataProvider('data')] public function test_edit_source_control(string $provider, array $input): void { Http::fake(); @@ -124,6 +131,9 @@ public function test_edit_source_control(string $provider, array $input): void } } + /** + * @return array> + */ public static function data(): array { return [ diff --git a/tests/Feature/API/StorageProvidersTest.php b/tests/Feature/API/StorageProvidersTest.php index fb282322..cc93102b 100644 --- a/tests/Feature/API/StorageProvidersTest.php +++ b/tests/Feature/API/StorageProvidersTest.php @@ -10,6 +10,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Http; use Laravel\Sanctum\Sanctum; +use PHPUnit\Framework\Attributes\DataProvider; use Tests\TestCase; class StorageProvidersTest extends TestCase @@ -17,8 +18,9 @@ class StorageProvidersTest extends TestCase use RefreshDatabase; /** - * @dataProvider createData + * @param array $input */ + #[DataProvider('createData')] public function test_create(array $input): void { Sanctum::actingAs($this->user, ['read', 'write']); @@ -106,7 +108,7 @@ public function test_cannot_delete_provider(): void } /** - * @TODO: complete FTP tests + * @return array>> */ public static function createData(): array { diff --git a/tests/Feature/ApplicationTest.php b/tests/Feature/ApplicationTest.php index 475e97fe..1fa9bc0e 100644 --- a/tests/Feature/ApplicationTest.php +++ b/tests/Feature/ApplicationTest.php @@ -11,6 +11,7 @@ use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Notification; use Inertia\Testing\AssertableInertia; +use PHPUnit\Framework\Attributes\DataProvider; use Tests\TestCase; class ApplicationTest extends TestCase @@ -153,9 +154,8 @@ public function test_update_env_file(): void /** * @param array $webhook * @param array $payload - * - * @dataProvider hookData */ + #[DataProvider('hookData')] public function test_git_hook_deployment(string $provider, array $webhook, string $url, array $payload, bool $skip): void { SSH::fake(); diff --git a/tests/Feature/CronjobTest.php b/tests/Feature/CronjobTest.php index a6d0628c..a40cd124 100644 --- a/tests/Feature/CronjobTest.php +++ b/tests/Feature/CronjobTest.php @@ -143,7 +143,7 @@ public function test_cannot_create_cronjob_for_user_on_another_server(): void ]); } - public function test_create_custom_cronjob() + public function test_create_custom_cronjob(): void { SSH::fake(); @@ -169,7 +169,7 @@ public function test_create_custom_cronjob() SSH::assertExecutedContains('sudo -u vito crontab -l'); } - public function test_enable_cronjob() + public function test_enable_cronjob(): void { SSH::fake(); diff --git a/tests/Feature/DatabaseBackupTest.php b/tests/Feature/DatabaseBackupTest.php index b47d2bf4..e54f55ae 100644 --- a/tests/Feature/DatabaseBackupTest.php +++ b/tests/Feature/DatabaseBackupTest.php @@ -13,17 +13,14 @@ use Illuminate\Support\Facades\Bus; use Illuminate\Support\Facades\Http; use JsonException; +use PHPUnit\Framework\Attributes\DataProvider; use Tests\TestCase; class DatabaseBackupTest extends TestCase { use RefreshDatabase; - /** - * @dataProvider data - * - * @throws JsonException - */ + #[DataProvider('data')] public function test_create_backup(string $db): void { SSH::fake(); @@ -156,11 +153,7 @@ public function test_update_backup(): void ]); } - /** - * @dataProvider data - * - * @throws JsonException - */ + #[DataProvider('data')] public function test_delete_backup(string $db): void { $this->setupDatabase($db); @@ -190,11 +183,7 @@ public function test_delete_backup(string $db): void ]); } - /** - * @dataProvider data - * - * @throws JsonException - */ + #[DataProvider('data')] public function test_restore_backup(string $db): void { Http::fake(); @@ -247,6 +236,9 @@ private function setupDatabase(string $database): void ]); } + /** + * @return array> + */ public static function data(): array { return [ diff --git a/tests/Feature/PHPTest.php b/tests/Feature/PHPTest.php index 4c8bcabe..b45e673e 100644 --- a/tests/Feature/PHPTest.php +++ b/tests/Feature/PHPTest.php @@ -7,6 +7,7 @@ use App\Facades\SSH; use App\Models\Service; use Illuminate\Foundation\Testing\RefreshDatabase; +use PHPUnit\Framework\Attributes\DataProvider; use Tests\TestCase; class PHPTest extends TestCase @@ -64,9 +65,7 @@ public function test_install_extension(): void $this->assertContains('gmp', $php->refresh()->type_data['extensions']); } - /** - * @dataProvider php_ini_data - */ + #[DataProvider('php_ini_data')] public function test_get_php_ini(string $version, string $type): void { SSH::fake('[PHP ini]'); diff --git a/tests/Feature/ServerProvidersTest.php b/tests/Feature/ServerProvidersTest.php index a0ad7efe..bb40a535 100644 --- a/tests/Feature/ServerProvidersTest.php +++ b/tests/Feature/ServerProvidersTest.php @@ -7,6 +7,7 @@ use Illuminate\Support\Facades\Http; use Inertia\Testing\AssertableInertia; use JsonException; +use PHPUnit\Framework\Attributes\DataProvider; use Tests\TestCase; class ServerProvidersTest extends TestCase @@ -16,10 +17,9 @@ class ServerProvidersTest extends TestCase /** * @param array $input * - * @dataProvider data - * * @throws JsonException */ + #[DataProvider('data')] public function test_connect_provider(string $provider, array $input): void { $this->actingAs($this->user); @@ -45,9 +45,8 @@ public function test_connect_provider(string $provider, array $input): void /** * @param array $input - * - * @dataProvider data */ + #[DataProvider('data')] public function test_cannot_connect_to_provider(string $provider, array $input): void { $this->actingAs($this->user); @@ -86,10 +85,9 @@ public function test_see_providers_list(): void } /** - * @dataProvider data - * * @throws JsonException */ + #[DataProvider('data')] public function test_delete_provider(string $provider): void { $this->actingAs($this->user); @@ -108,9 +106,7 @@ public function test_delete_provider(string $provider): void ]); } - /** - * @dataProvider data - */ + #[DataProvider('data')] public function test_cannot_delete_provider(string $provider): void { $this->actingAs($this->user); diff --git a/tests/Feature/ServicesTest.php b/tests/Feature/ServicesTest.php index 9396eca9..b403d531 100644 --- a/tests/Feature/ServicesTest.php +++ b/tests/Feature/ServicesTest.php @@ -9,6 +9,7 @@ use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Http; use Inertia\Testing\AssertableInertia; +use PHPUnit\Framework\Attributes\DataProvider; use Tests\TestCase; class ServicesTest extends TestCase @@ -26,9 +27,7 @@ public function test_see_services_list(): void ->assertInertia(fn (AssertableInertia $page) => $page->component('services/index')); } - /** - * @dataProvider data - */ + #[DataProvider('data')] public function test_restart_service(string $name): void { $this->actingAs($this->user); @@ -50,9 +49,7 @@ public function test_restart_service(string $name): void $this->assertEquals(ServiceStatus::READY, $service->status); } - /** - * @dataProvider data - */ + #[DataProvider('data')] public function test_failed_to_restart_service(string $name): void { $this->actingAs($this->user); @@ -72,9 +69,7 @@ public function test_failed_to_restart_service(string $name): void $this->assertEquals(ServiceStatus::FAILED, $service->status); } - /** - * @dataProvider data - */ + #[DataProvider('data')] public function test_stop_service(string $name): void { $this->actingAs($this->user); @@ -94,9 +89,7 @@ public function test_stop_service(string $name): void $this->assertEquals(ServiceStatus::STOPPED, $service->status); } - /** - * @dataProvider data - */ + #[DataProvider('data')] public function test_failed_to_stop_service(string $name): void { $this->actingAs($this->user); @@ -116,9 +109,7 @@ public function test_failed_to_stop_service(string $name): void $this->assertEquals(ServiceStatus::FAILED, $service->status); } - /** - * @dataProvider data - */ + #[DataProvider('data')] public function test_start_service(string $name): void { $this->actingAs($this->user); @@ -140,9 +131,7 @@ public function test_start_service(string $name): void $this->assertEquals(ServiceStatus::READY, $service->status); } - /** - * @dataProvider data - */ + #[DataProvider('data')] public function test_failed_to_start_service(string $name): void { $this->actingAs($this->user); @@ -162,9 +151,7 @@ public function test_failed_to_start_service(string $name): void $this->assertEquals(ServiceStatus::FAILED, $service->status); } - /** - * @dataProvider data - */ + #[DataProvider('data')] public function test_enable_service(string $name): void { $this->actingAs($this->user); @@ -186,9 +173,7 @@ public function test_enable_service(string $name): void $this->assertEquals(ServiceStatus::READY, $service->status); } - /** - * @dataProvider data - */ + #[DataProvider('data')] public function test_failed_to_enable_service(string $name): void { $this->actingAs($this->user); @@ -208,9 +193,7 @@ public function test_failed_to_enable_service(string $name): void $this->assertEquals(ServiceStatus::FAILED, $service->status); } - /** - * @dataProvider data - */ + #[DataProvider('data')] public function test_disable_service(string $name): void { $this->actingAs($this->user); @@ -230,9 +213,7 @@ public function test_disable_service(string $name): void $this->assertEquals(ServiceStatus::DISABLED, $service->status); } - /** - * @dataProvider data - */ + #[DataProvider('data')] public function test_failed_to_disable_service(string $name): void { $this->actingAs($this->user); @@ -252,9 +233,7 @@ public function test_failed_to_disable_service(string $name): void $this->assertEquals(ServiceStatus::FAILED, $service->status); } - /** - * @dataProvider installData - */ + #[DataProvider('installData')] public function test_install_service(string $name, string $type, string $version): void { Http::fake([ @@ -357,11 +336,6 @@ public static function installData(): array 'database', '16', ], - [ - 'vito-agent', - 'monitoring', - 'latest', - ], ]; } } diff --git a/tests/Feature/SitesTest.php b/tests/Feature/SitesTest.php index ba4c57a5..fa544c8e 100644 --- a/tests/Feature/SitesTest.php +++ b/tests/Feature/SitesTest.php @@ -11,6 +11,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Http; use Inertia\Testing\AssertableInertia; +use PHPUnit\Framework\Attributes\DataProvider; use Tests\TestCase; class SitesTest extends TestCase @@ -19,9 +20,8 @@ class SitesTest extends TestCase /** * @param array $inputs - * - * @dataProvider create_data */ + #[DataProvider('create_data')] public function test_create_site(array $inputs): void { SSH::fake(); @@ -55,9 +55,8 @@ public function test_create_site(array $inputs): void /** * @param array $inputs - * - * @dataProvider failure_create_data */ + #[DataProvider('failure_create_data')] public function test_isolated_user_failure(array $inputs): void { SSH::fake(); @@ -67,9 +66,7 @@ public function test_isolated_user_failure(array $inputs): void ->assertSessionHasErrors(); } - /** - * @dataProvider create_failure_data - */ + #[DataProvider('create_failure_data')] public function test_create_site_failed_due_to_source_control(int $status): void { $inputs = [ @@ -275,7 +272,7 @@ public function test_change_branch(): void } /** - * @return array> + * @return array> */ public static function failure_create_data(): array { diff --git a/tests/Feature/SourceControlsTest.php b/tests/Feature/SourceControlsTest.php index d81c2910..dfca5642 100644 --- a/tests/Feature/SourceControlsTest.php +++ b/tests/Feature/SourceControlsTest.php @@ -5,6 +5,7 @@ use App\Models\SourceControl; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Http; +use PHPUnit\Framework\Attributes\DataProvider; use Tests\TestCase; class SourceControlsTest extends TestCase @@ -13,9 +14,8 @@ class SourceControlsTest extends TestCase /** * @param array $input - * - * @dataProvider data */ + #[DataProvider('data')] public function test_connect_provider(string $provider, ?string $customUrl, array $input): void { $this->actingAs($this->user); @@ -53,9 +53,7 @@ public function test_connect_provider(string $provider, ?string $customUrl, arra } } - /** - * @dataProvider data - */ + #[DataProvider('data')] public function test_delete_provider(string $provider): void { $this->actingAs($this->user); @@ -75,9 +73,7 @@ public function test_delete_provider(string $provider): void ]); } - /** - * @dataProvider data - */ + #[DataProvider('data')] public function test_cannot_delete_provider(string $provider): void { $this->actingAs($this->user); @@ -104,9 +100,8 @@ public function test_cannot_delete_provider(string $provider): void /** * @param array $input - * - * @dataProvider data */ + #[DataProvider('data')] public function test_edit_source_control(string $provider, ?string $url, array $input): void { Http::fake(); diff --git a/tests/Feature/SshKeysTest.php b/tests/Feature/SshKeysTest.php index 2f1b94b6..fc251e0a 100644 --- a/tests/Feature/SshKeysTest.php +++ b/tests/Feature/SshKeysTest.php @@ -5,6 +5,7 @@ use App\Models\SshKey; use Illuminate\Foundation\Testing\RefreshDatabase; use Inertia\Testing\AssertableInertia; +use PHPUnit\Framework\Attributes\DataProvider; use Tests\TestCase; class SshKeysTest extends TestCase @@ -56,9 +57,8 @@ public function test_delete_key(): void /** * @param array $postBody - * - * @dataProvider ssh_key_data_provider */ + #[DataProvider('ssh_key_data_provider')] public function test_create_ssh_key_handles_invalid_or_partial_keys(array $postBody, bool $expectedToSucceed): void { $this->actingAs($this->user); diff --git a/tests/Feature/StorageProvidersTest.php b/tests/Feature/StorageProvidersTest.php index a81e3b86..8d15ddcf 100644 --- a/tests/Feature/StorageProvidersTest.php +++ b/tests/Feature/StorageProvidersTest.php @@ -10,6 +10,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Http; use Inertia\Testing\AssertableInertia; +use PHPUnit\Framework\Attributes\DataProvider; use Tests\TestCase; class StorageProvidersTest extends TestCase @@ -18,9 +19,8 @@ class StorageProvidersTest extends TestCase /** * @param array $input - * - * @dataProvider createData */ + #[DataProvider('createData')] public function test_create(array $input): void { $this->actingAs($this->user); @@ -104,8 +104,6 @@ public function test_cannot_delete_provider(): void } /** - * @TODO: complete FTP tests - * * @return array */ public static function createData(): array diff --git a/tests/Unit/Actions/Service/InstallTest.php b/tests/Unit/Actions/Service/InstallTest.php index 497f9922..2615a7f1 100644 --- a/tests/Unit/Actions/Service/InstallTest.php +++ b/tests/Unit/Actions/Service/InstallTest.php @@ -21,7 +21,9 @@ public function test_install_vito_agent(): void 'https://api.github.com/repos/vitodeploy/agent/tags' => Http::response([['name' => '0.1.0']]), ]); - $service = app(Install::class)->install($this->server, [ + $this->server->monitoring()->delete(); + + app(Install::class)->install($this->server, [ 'type' => 'monitoring', 'name' => 'vito-agent', 'version' => 'latest', @@ -34,12 +36,11 @@ public function test_install_vito_agent(): void 'version' => '0.1.0', 'status' => ServiceStatus::READY, ]); - - $this->assertNotNull($service->type_data); } public function test_install_vito_agent_failed(): void { + $this->server->monitoring()->delete(); $this->expectExceptionMessage('Failed to fetch tags'); SSH::fake('Active: inactive'); Http::fake([ @@ -58,7 +59,7 @@ public function test_install_nginx(): void SSH::fake('Active: active'); - $service = app(Install::class)->install($this->server, [ + app(Install::class)->install($this->server, [ 'type' => 'webserver', 'name' => 'nginx', 'version' => 'latest', @@ -71,8 +72,6 @@ public function test_install_nginx(): void 'version' => 'latest', 'status' => ServiceStatus::READY, ]); - - $this->assertNotNull($service->type_data); } public function test_install_caddy(): void @@ -81,7 +80,7 @@ public function test_install_caddy(): void SSH::fake('Active: active'); - $service = app(Install::class)->install($this->server, [ + app(Install::class)->install($this->server, [ 'type' => 'webserver', 'name' => 'caddy', 'version' => 'latest', @@ -94,8 +93,6 @@ public function test_install_caddy(): void 'version' => 'latest', 'status' => ServiceStatus::READY, ]); - - $this->assertNotNull($service->type_data); } public function test_install_mysql(): void @@ -104,7 +101,7 @@ public function test_install_mysql(): void SSH::fake('Active: active'); - $service = app(Install::class)->install($this->server, [ + app(Install::class)->install($this->server, [ 'type' => 'database', 'name' => 'mysql', 'version' => '8.0', @@ -117,8 +114,6 @@ public function test_install_mysql(): void 'version' => '8.0', 'status' => ServiceStatus::READY, ]); - - $this->assertNotNull($service->type_data); } public function test_install_mysql_failed(): void @@ -137,7 +132,7 @@ public function test_install_supervisor(): void SSH::fake('Active: active'); - $service = app(Install::class)->install($this->server, [ + app(Install::class)->install($this->server, [ 'type' => 'process_manager', 'name' => 'supervisor', 'version' => 'latest', @@ -150,8 +145,6 @@ public function test_install_supervisor(): void 'version' => 'latest', 'status' => ServiceStatus::READY, ]); - - $this->assertNotNull($service->type_data); } public function test_install_redis(): void @@ -160,7 +153,7 @@ public function test_install_redis(): void SSH::fake('Active: active'); - $service = app(Install::class)->install($this->server, [ + app(Install::class)->install($this->server, [ 'type' => 'memory_database', 'name' => 'redis', 'version' => 'latest', @@ -173,7 +166,5 @@ public function test_install_redis(): void 'version' => 'latest', 'status' => ServiceStatus::READY, ]); - - $this->assertNotNull($service->type_data); } } diff --git a/tests/Unit/Actions/Service/UninstallTest.php b/tests/Unit/Actions/Service/UninstallTest.php index ba59868c..0820cd2c 100644 --- a/tests/Unit/Actions/Service/UninstallTest.php +++ b/tests/Unit/Actions/Service/UninstallTest.php @@ -20,7 +20,9 @@ public function test_uninstall_vito_agent(): void { SSH::fake(); - Service::factory()->create([ + $this->server->monitoring()->delete(); + + $service = Service::factory()->create([ 'server_id' => $this->server->id, 'name' => 'vito-agent', 'type' => 'monitoring', @@ -31,11 +33,7 @@ public function test_uninstall_vito_agent(): void app(Uninstall::class)->uninstall($this->server->monitoring()); $this->assertDatabaseMissing('services', [ - 'server_id' => $this->server->id, - 'name' => 'vito-agent', - 'type' => 'monitoring', - 'version' => 'latest', - 'status' => ServiceStatus::READY, + 'id' => $service->id, ]); } diff --git a/tests/Unit/Helpers/AgentTest.php b/tests/Unit/Helpers/AgentTest.php index 58e0c7cb..26575abf 100644 --- a/tests/Unit/Helpers/AgentTest.php +++ b/tests/Unit/Helpers/AgentTest.php @@ -7,7 +7,10 @@ class AgentTest extends TestCase { - private $operatingSystems = [ + /** + * @var array + */ + private array $operatingSystems = [ 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko' => 'Windows', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.13+ (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2' => 'OS X', 'Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko ) Version/5.1 Mobile/9B176 Safari/7534.48.3' => 'iOS', @@ -18,7 +21,10 @@ class AgentTest extends TestCase 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36' => 'Windows', ]; - private $browsers = [ + /** + * @var array + */ + private array $browsers = [ 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko' => 'IE', 'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25' => 'Safari', 'Mozilla/5.0 (Windows; U; Win 9x 4.90; SG; rv:1.9.2.4) Gecko/20101104 Netscape/9.1.0285' => 'Netscape', @@ -36,7 +42,10 @@ class AgentTest extends TestCase 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) coc_coc_browser/86.0.180 Chrome/80.0.3987.180 Safari/537.36' => 'Coc Coc', ]; - private $mobileDevices = [ + /** + * @var array + */ + private array $mobileDevices = [ 'Mozilla/5.0 (iPhone; U; ru; CPU iPhone OS 4_2_1 like Mac OS X; ru) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148a Safari/6533.18.5', 'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25', 'Mozilla/5.0 (Linux; U; Android 2.3.4; fr-fr; HTC Desire Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1', @@ -45,7 +54,10 @@ class AgentTest extends TestCase 'Mozilla/5.0 (Linux; U; Android 4.0.3; en-us; ASUS Transformer Pad TF300T Build/IML74K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30', ]; - private $desktops = [ + /** + * @var array + */ + private array $desktops = [ 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko', 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0', 'Mozilla/5.0 (Windows; U; Win 9x 4.90; SG; rv:1.9.2.4) Gecko/20101104 Netscape/9.1.0285', @@ -56,7 +68,7 @@ class AgentTest extends TestCase 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.13+ (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2', ]; - public function test_operating_systems() + public function test_operating_systems(): void { $agent = new Agent; @@ -66,7 +78,7 @@ public function test_operating_systems() } } - public function test_browsers() + public function test_browsers(): void { $agent = new Agent; @@ -76,7 +88,7 @@ public function test_browsers() } } - public function test_desktop_devices() + public function test_desktop_devices(): void { $agent = new Agent; @@ -86,7 +98,7 @@ public function test_desktop_devices() } } - public function test_mobile_devices() + public function test_mobile_devices(): void { $agent = new Agent; diff --git a/tests/Unit/Models/ServerModelTest.php b/tests/Unit/Models/ServerModelTest.php index ce33576c..e4a44197 100644 --- a/tests/Unit/Models/ServerModelTest.php +++ b/tests/Unit/Models/ServerModelTest.php @@ -11,7 +11,7 @@ class ServerModelTest extends TestCase { use RefreshDatabase; - public function test_should_have_default_service() + public function test_should_have_default_service(): void { $php = $this->server->defaultService('php'); $php->update(['is_default' => false]); diff --git a/tests/Unit/SSH/Services/Database/GetCharsetsTest.php b/tests/Unit/SSH/Services/Database/GetCharsetsTest.php index faca824d..4b4e1fba 100644 --- a/tests/Unit/SSH/Services/Database/GetCharsetsTest.php +++ b/tests/Unit/SSH/Services/Database/GetCharsetsTest.php @@ -4,10 +4,14 @@ use App\Facades\SSH; use App\SSH\Services\Database\Database; +use PHPUnit\Framework\Attributes\DataProvider; use Tests\TestCase; class GetCharsetsTest extends TestCase { + /** + * @var array>> + */ protected static array $mysqlCharsets = [ 'armscii8' => [ 'default' => 'armscii8_general_ci', @@ -33,8 +37,9 @@ class GetCharsetsTest extends TestCase ]; /** - * @dataProvider data + * @param array> $expected */ + #[DataProvider('data')] public function test_update_charsets(string $name, string $version, string $output, array $expected): void { $database = $this->server->database(); @@ -52,7 +57,7 @@ public function test_update_charsets(string $name, string $version, string $outp } /** - * @return array[] + * @return array> */ public static function data(): array { diff --git a/tests/Unit/SSH/Services/Database/GetDatabasesTest.php b/tests/Unit/SSH/Services/Database/GetDatabasesTest.php index 883d019f..cbe731d2 100644 --- a/tests/Unit/SSH/Services/Database/GetDatabasesTest.php +++ b/tests/Unit/SSH/Services/Database/GetDatabasesTest.php @@ -4,13 +4,12 @@ use App\Facades\SSH; use App\SSH\Services\Database\Database; +use PHPUnit\Framework\Attributes\DataProvider; use Tests\TestCase; class GetDatabasesTest extends TestCase { - /** - * @dataProvider data - */ + #[DataProvider('data')] public function test_get_databases(string $name, string $version, string $output): void { $database = $this->server->database(); @@ -24,12 +23,11 @@ public function test_get_databases(string $name, string $version, string $output $databaseHandler = $database->handler(); $databases = $databaseHandler->getDatabases(); - $this->assertIsArray($databases); $this->assertEquals('vito', $databases[0][0]); } /** - * @return array[] + * @return array> */ public static function data(): array { diff --git a/tests/Unit/SSH/Services/Database/GetUsersTest.php b/tests/Unit/SSH/Services/Database/GetUsersTest.php index 18eefc51..3a35d9a5 100644 --- a/tests/Unit/SSH/Services/Database/GetUsersTest.php +++ b/tests/Unit/SSH/Services/Database/GetUsersTest.php @@ -4,13 +4,12 @@ use App\Facades\SSH; use App\SSH\Services\Database\Database; +use PHPUnit\Framework\Attributes\DataProvider; use Tests\TestCase; class GetUsersTest extends TestCase { - /** - * @dataProvider data - */ + #[DataProvider('data')] public function test_get_users(string $name, string $version, string $output): void { $database = $this->server->database(); @@ -24,12 +23,11 @@ public function test_get_users(string $name, string $version, string $output): v $databaseHandler = $database->handler(); $users = $databaseHandler->getUsers(); - $this->assertIsArray($users); $this->assertEquals('vito', $users[0][0]); } /** - * @return array[] + * @return array> */ public static function data(): array { diff --git a/tests/Unit/SourceControlProviders/GitlabTest.php b/tests/Unit/SourceControlProviders/GitlabTest.php index 3c7a6e73..9248bda8 100644 --- a/tests/Unit/SourceControlProviders/GitlabTest.php +++ b/tests/Unit/SourceControlProviders/GitlabTest.php @@ -5,6 +5,7 @@ use App\Models\SourceControl; use App\SourceControlProviders\Gitlab; use Illuminate\Foundation\Testing\RefreshDatabase; +use PHPUnit\Framework\Attributes\DataProvider; use Tests\TestCase; class GitlabTest extends TestCase @@ -36,9 +37,7 @@ public function test_default_gitlab_repo_url(): void $this->assertSame('git@gitlab.com-TEST_KEY:test/repo.git', $gitlab->fullRepoUrl($repo, $key)); } - /** - * @dataProvider customUrlData - */ + #[DataProvider('customUrlData')] public function test_custom_url(string $url, string $expected): void { $sourceControlModel = SourceControl::factory() @@ -50,9 +49,7 @@ public function test_custom_url(string $url, string $expected): void $this->assertSame($expected, $gitlab->getApiUrl()); } - /** - * @dataProvider customRepoUrlData - */ + #[DataProvider('customRepoUrlData')] public function test_custom_full_repository_url(string $url, string $expected): void { $repo = 'test/repo'; @@ -67,6 +64,9 @@ public function test_custom_full_repository_url(string $url, string $expected): $this->assertSame($expected, $gitlab->fullRepoUrl($repo, $key)); } + /** + * @return array> + */ public static function customRepoUrlData(): array { return [ @@ -76,6 +76,9 @@ public static function customRepoUrlData(): array ]; } + /** + * @return array> + */ public static function customUrlData(): array { return [ diff --git a/tests/Unit/StorageProviders/S3Test.php b/tests/Unit/StorageProviders/S3Test.php index 965f087f..cc5b1b27 100644 --- a/tests/Unit/StorageProviders/S3Test.php +++ b/tests/Unit/StorageProviders/S3Test.php @@ -15,7 +15,7 @@ class S3Test extends TestCase { use RefreshDatabase; - public function test_s3_connect_successful() + public function test_s3_connect_successful(): void { $storageProvider = StorageProviderModel::factory()->create([ 'provider' => StorageProvider::S3, @@ -59,7 +59,7 @@ public function test_s3_connect_successful() $this->assertTrue($s3->connect()); } - public function test_s3_connect_failure() + public function test_s3_connect_failure(): void { $storageProvider = StorageProviderModel::factory()->create([ 'provider' => StorageProvider::S3,