|
4 | 4 |
|
5 | 5 | use Illuminate\Support\Facades\DB; |
6 | 6 | use Illuminate\Support\Facades\Event; |
| 7 | +use Illuminate\Support\Facades\Storage; |
7 | 8 | use Wnx\LaravelBackupRestore\Commands\RestoreCommand; |
8 | 9 | use Wnx\LaravelBackupRestore\Events\DatabaseReset; |
9 | 10 | use Wnx\LaravelBackupRestore\Events\LocalBackupRemoved; |
10 | 11 | use Wnx\LaravelBackupRestore\Exceptions\NoBackupsFound; |
11 | 12 |
|
| 13 | +use function Pest\Laravel\artisan; |
| 14 | + |
12 | 15 | // MySQL |
13 | 16 | it('restores mysql database', function (string $backup, ?string $password = null) { |
14 | 17 | $this->artisan(RestoreCommand::class, [ |
|
76 | 79 |
|
77 | 80 | // pgsql |
78 | 81 | it('restores pgsql database', function (string $backup, ?string $password = null) { |
| 82 | + $connection = config('database.connections.pgsql-restore'); |
| 83 | + |
79 | 84 | $this->artisan(RestoreCommand::class, [ |
80 | 85 | '--disk' => 'remote', |
81 | 86 | '--backup' => $backup, |
82 | 87 | '--connection' => 'pgsql-restore', |
83 | 88 | '--password' => $password, |
84 | 89 | '--no-interaction' => true, |
85 | 90 | ]) |
86 | | - ->expectsQuestion("Proceed to restore \"{$backup}\" using the \"pgsql-restore\" database connection. (Database: laravel_backup_restore, Host: 127.0.0.1, username: root)", true) |
| 91 | + ->expectsQuestion("Proceed to restore \"{$backup}\" using the \"pgsql-restore\" database connection. (Database: laravel_backup_restore, Host: {$connection['host']}, username: {$connection['username']})", true) |
87 | 92 | ->assertSuccessful(); |
88 | 93 |
|
89 | 94 | $result = DB::connection('pgsql')->table('users')->count(); |
|
192 | 197 | ->assertSuccessful(); |
193 | 198 |
|
194 | 199 | Event::assertNotDispatched(LocalBackupRemoved::class); |
195 | | - $files = \Illuminate\Support\Facades\Storage::disk('local')->allFiles('backup-restore-temp'); |
| 200 | + $files = Storage::disk('local')->allFiles('backup-restore-temp'); |
196 | 201 |
|
197 | 202 | expect($files)->not->toBeEmpty(); |
198 | 203 |
|
199 | 204 | })->group('sqlite'); |
| 205 | + |
| 206 | +it('restores pgsql database with binary dump', function (string $backup, ?string $password = null) { |
| 207 | + config([ |
| 208 | + 'backup.backup.database_dump_file_extension' => 'backup', |
| 209 | + ]); |
| 210 | + artisan('db:wipe', [ |
| 211 | + '--database' => 'pgsql-restore', |
| 212 | + ]); |
| 213 | + |
| 214 | + $connection = config('database.connections.pgsql-restore'); |
| 215 | + |
| 216 | + $this->artisan(RestoreCommand::class, [ |
| 217 | + '--disk' => 'remote', |
| 218 | + '--backup' => $backup, |
| 219 | + '--connection' => 'pgsql-restore', |
| 220 | + '--password' => $password, |
| 221 | + '--no-interaction' => true, |
| 222 | + ]) |
| 223 | + ->expectsQuestion("Proceed to restore \"{$backup}\" using the \"pgsql-restore\" database connection. (Database: laravel_backup_restore, Host: {$connection['host']}, username: {$connection['username']})", true) |
| 224 | + ->assertSuccessful(); |
| 225 | + |
| 226 | + $result = DB::connection('pgsql-restore')->table('users')->count(); |
| 227 | + |
| 228 | + expect($result)->toBe(1); |
| 229 | + |
| 230 | + artisan('db:wipe', [ |
| 231 | + '--database' => 'pgsql-restore', |
| 232 | + ]); |
| 233 | +})->with([ |
| 234 | + [ |
| 235 | + 'backup' => 'Laravel/2025-12-26-pgsql-no-compression-custom-extension-binary-dump.zip', |
| 236 | + ], |
| 237 | +])->group('pgsql'); |
0 commit comments