This commit is contained in:
Saeed Vaziry
2025-06-04 19:04:02 +02:00
parent 35894003f5
commit f8f8d57fe2
31 changed files with 165 additions and 171 deletions

View File

@ -4,9 +4,11 @@ on:
push:
branches:
- 2.x
- 3.x
pull_request:
branches:
- 2.x
- 3.x
jobs:
tests:

View File

@ -6,6 +6,7 @@ on:
- main
- 1.x
- 2.x
- 3.x
pull_request:
jobs:

View File

@ -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

1
.gitignore vendored
View File

@ -22,3 +22,4 @@ yarn-error.log
/.idea
/.vscode
laradumps.yaml
/public/build

View File

@ -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);

View File

@ -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();

View File

@ -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,

View File

@ -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<string, mixed> $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<string, mixed> $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<array<int, mixed>>
*/
public static function data(): array
{
return [

View File

@ -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<array<string>>
*/
public static function data(): array
{
return [

View File

@ -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<string, mixed> $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<array<array<string, mixed>>>
*/
public static function create_data(): array
{
return \Tests\Feature\SitesTest::create_data();

View File

@ -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<string, mixed> $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<string, mixed> $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<array<int, mixed>>
*/
public static function data(): array
{
return [

View File

@ -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<string, mixed> $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<int, array<int, array<string, mixed>>>
*/
public static function createData(): array
{

View File

@ -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<string, mixed> $webhook
* @param array<string, mixed> $payload
*
* @dataProvider hookData
*/
#[DataProvider('hookData')]
public function test_git_hook_deployment(string $provider, array $webhook, string $url, array $payload, bool $skip): void
{
SSH::fake();

View File

@ -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();

View File

@ -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<int, array<int, string>>
*/
public static function data(): array
{
return [

View File

@ -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]');

View File

@ -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<string, mixed> $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<string, mixed> $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);

View File

@ -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',
],
];
}
}

View File

@ -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<string, mixed> $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<string, mixed> $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<array<string, mixed>>
* @return array<array<int, mixed>>
*/
public static function failure_create_data(): array
{

View File

@ -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<string, mixed> $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<string, mixed> $input
*
* @dataProvider data
*/
#[DataProvider('data')]
public function test_edit_source_control(string $provider, ?string $url, array $input): void
{
Http::fake();

View File

@ -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<string, string> $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);

View File

@ -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<string, mixed> $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<int, mixed>
*/
public static function createData(): array

View File

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

View File

@ -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,
]);
}

View File

@ -7,7 +7,10 @@
class AgentTest extends TestCase
{
private $operatingSystems = [
/**
* @var array<string, string>
*/
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<string, string>
*/
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<string>
*/
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<string>
*/
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;

View File

@ -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]);

View File

@ -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<string, array<string, string|array<string>>>
*/
protected static array $mysqlCharsets = [
'armscii8' => [
'default' => 'armscii8_general_ci',
@ -33,8 +37,9 @@ class GetCharsetsTest extends TestCase
];
/**
* @dataProvider data
* @param array<string, string|array<string>> $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<int, array<int, mixed>>
*/
public static function data(): array
{

View File

@ -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<int, array<int, mixed>>
*/
public static function data(): array
{

View File

@ -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<int, array<int, mixed>>
*/
public static function data(): array
{

View File

@ -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<int, array<int, string>>
*/
public static function customRepoUrlData(): array
{
return [
@ -76,6 +76,9 @@ public static function customRepoUrlData(): array
];
}
/**
* @return array<int, array<int, string>>
*/
public static function customUrlData(): array
{
return [

View File

@ -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,