This commit is contained in:
Saeed Vaziry
2025-06-01 11:31:09 +02:00
parent 41388dafbf
commit 84476db764
23 changed files with 1517 additions and 1776 deletions

View File

@ -6,67 +6,13 @@
use App\Enums\ServiceStatus;
use App\Facades\SSH;
use App\Models\Service;
use App\Web\Pages\Servers\PHP\Index;
use App\Web\Pages\Servers\PHP\Widgets\PHPList;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
use Tests\TestCase;
class PHPTest extends TestCase
{
use RefreshDatabase;
public function test_install_new_php(): void
{
SSH::fake();
$this->actingAs($this->user);
Livewire::test(Index::class, ['server' => $this->server])
->callAction('install', [
'version' => '8.1',
])
->assertSuccessful();
$this->assertDatabaseHas('services', [
'server_id' => $this->server->id,
'type' => 'php',
'version' => '8.1',
'status' => ServiceStatus::READY,
]);
}
public function test_uninstall_php(): void
{
SSH::fake();
$this->actingAs($this->user);
$php = new Service([
'server_id' => $this->server->id,
'type' => 'php',
'type_data' => [
'extensions' => [],
'settings' => config('core.php_settings'),
],
'name' => 'php',
'version' => '8.1',
'status' => ServiceStatus::READY,
'is_default' => true,
]);
$php->save();
Livewire::test(PHPList::class, [
'server' => $this->server,
])
->callTableAction('uninstall', $php->id)
->assertSuccessful();
$this->assertDatabaseMissing('services', [
'id' => $php->id,
]);
}
public function test_change_default_php_cli(): void
{
SSH::fake();
@ -85,11 +31,13 @@ public function test_change_default_php_cli(): void
'is_default' => false,
]);
Livewire::test(PHPList::class, [
$this->post(route('php.default-cli', [
'server' => $this->server,
'service' => $php->id,
]), [
'version' => '8.1',
])
->callTableAction('default-php-cli', $php->id)
->assertSuccessful();
->assertSessionDoesntHaveErrors();
$php->refresh();
@ -102,17 +50,18 @@ public function test_install_extension(): void
$this->actingAs($this->user);
Livewire::test(PHPList::class, [
'server' => $this->server,
])
->callTableAction('install-extension', $this->server->php()->id, [
'extension' => 'gmp',
])
->assertSuccessful();
$php = $this->server->php('8.2');
$this->assertContains('gmp', $php->type_data['extensions']);
$this->post(route('php.install-extension', [
'server' => $this->server,
'service' => $php->id,
]), [
'version' => '8.2',
'extension' => 'gmp',
])
->assertSessionDoesntHaveErrors();
$this->assertContains('gmp', $php->refresh()->type_data['extensions']);
}
/**
@ -124,15 +73,20 @@ public function test_get_php_ini(string $version, string $type): void
$this->actingAs($this->user);
Livewire::test(PHPList::class, [
$php = $this->server->php('8.2');
$this->get(route('php.ini', [
'server' => $this->server,
])
->callTableAction('php-ini-'.$type, $this->server->php()->id, [
'ini' => 'new-ini',
])
->assertSuccessful();
'service' => $php->id,
'version' => '8.2',
'type' => $type,
]))
->assertSessionDoesntHaveErrors();
}
/**
* @return array<array<int, string>>
*/
public static function php_ini_data(): array
{
return [