Skip to content

Commit

Permalink
adding test to avoid such issues
Browse files Browse the repository at this point in the history
  • Loading branch information
saeedvaziry committed Feb 7, 2025
1 parent bba6843 commit 97dd1de
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions tests/Feature/DatabaseBackupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ class DatabaseBackupTest extends TestCase
{
use RefreshDatabase;

public function test_create_backup(): void
/**
* @dataProvider data
*/
public function test_create_backup(string $db): void
{
SSH::fake();
Http::fake();

$this->setupDatabase($db);

$this->actingAs($this->user);

$database = Database::factory()->create([
Expand Down Expand Up @@ -152,8 +157,13 @@ public function test_update_backup(): void
]);
}

public function test_delete_backup(): void
/**
* @dataProvider data
*/
public function test_delete_backup(string $db): void
{
$this->setupDatabase($db);

$this->actingAs($this->user);

$database = Database::factory()->create([
Expand Down Expand Up @@ -182,11 +192,16 @@ public function test_delete_backup(): void
]);
}

public function test_restore_backup(): void
/**
* @dataProvider data
*/
public function test_restore_backup(string $db): void
{
Http::fake();
SSH::fake();

$this->setupDatabase($db);

$this->actingAs($this->user);

$database = Database::factory()->create([
Expand Down Expand Up @@ -220,4 +235,24 @@ public function test_restore_backup(): void
'status' => BackupFileStatus::RESTORED,
]);
}

private function setupDatabase(string $database): void
{
$this->server->services()->where('type', 'database')->delete();

$this->server->services()->create([
'type' => 'database',
'name' => config('core.databases_name.'.$database),
'version' => config('core.databases_version.'.$database),
]);
}

public static function data(): array
{
return [
[\App\Enums\Database::MYSQL80],
[\App\Enums\Database::MARIADB104],
[\App\Enums\Database::POSTGRESQL16],
];
}
}

0 comments on commit 97dd1de

Please sign in to comment.