Skip to content

Commit 7708495

Browse files
Add more tests
1 parent b660313 commit 7708495

File tree

3 files changed

+66
-5
lines changed

3 files changed

+66
-5
lines changed

src/Console/Commands/RestoreCommand.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Itiden\Backup\Console\Commands;
66

77
use Illuminate\Console\Command;
8-
use Illuminate\Contracts\Console\PromptsForMissingInput;
98
use Itiden\Backup\Contracts\Repositories\BackupRepository;
109
use Itiden\Backup\DataTransferObjects\BackupDto;
1110
use Itiden\Backup\Facades\Restorer;
@@ -15,7 +14,7 @@
1514
/**
1615
* Restore content from a directory / backup
1716
*/
18-
class RestoreCommand extends Command implements PromptsForMissingInput
17+
final class RestoreCommand extends Command
1918
{
2019
protected $signature = 'statamic:backup:restore {--path=} {--force}';
2120

@@ -31,15 +30,17 @@ public function handle(BackupRepository $repo)
3130
scroll: 10,
3231
options: $repo->all()->flatMap(
3332
fn (BackupDto $backup) => [$backup->path => $backup->path]
34-
)
33+
),
34+
required: true
3535
)),
3636
};
3737

3838
if (
3939
$this->option('force')
4040
|| confirm(
4141
label: "Are you sure you want to restore your content?",
42-
hint: "This will overwrite your current content with state from {$backup->created_at->format('Y-m-d H:i:s')}"
42+
hint: "This will overwrite your current content with state from {$backup->created_at->format('Y-m-d H:i:s')}",
43+
required: true
4344
)
4445
) {
4546
spin(fn () => Restorer::restore($backup), 'Restoring backup');
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Storage;
4+
use Itiden\Backup\Contracts\Repositories\BackupRepository;
5+
use Itiden\Backup\Facades\Backuper;
6+
7+
use function Pest\Laravel\artisan;
8+
9+
uses()->group('restore-command');
10+
11+
it('shows all available backups', function () {
12+
app(BackupRepository::class)->empty();
13+
14+
Backuper::backup();
15+
16+
$backups = app(BackupRepository::class)->all();
17+
18+
artisan('statamic:backup:restore')
19+
->expectsQuestion(
20+
question: 'Which backup do you want to restore to?',
21+
answer: $backups->first()->path
22+
)
23+
->expectsConfirmation('Are you sure you want to restore your content?')
24+
->assertFailed();
25+
});
26+
27+
it('can restore from a specific path', function () {
28+
app(BackupRepository::class)->empty();
29+
30+
$backup = Backuper::backup();
31+
32+
artisan('statamic:backup:restore', ['--path' => Storage::disk(config('backup.destination.disk'))->path($backup->path)])
33+
->expectsConfirmation('Are you sure you want to restore your content?')
34+
->assertFailed();
35+
});

tests/Unit/PipeTest.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
Assets::class,
4444
]);
4545

46-
test('can skip a pipe', function () {
46+
test('can skip a pipe with users', function () {
4747
/** @var Users::class $pipe */
4848
$pipe = app()->make(Users::class);
4949

@@ -63,3 +63,28 @@
6363

6464
$zipper->close();
6565
});
66+
67+
test('can skip a pipe with content', function () {
68+
/** @var Users::class $pipe */
69+
$pipe = app()->make(Content::class);
70+
71+
$callable = function ($z) {
72+
return $z;
73+
};
74+
75+
File::copyDirectory(config('backup.content_path'), config('backup.content_path') . '_backup');
76+
File::deleteDirectory(config('backup.content_path'));
77+
78+
$zipper = Zipper::open(config('backup.temp_path') . '/backup.zip');
79+
80+
$pipe->backup(zip: $zipper, next: $callable);
81+
82+
83+
expect($zipper->getMeta())->toHaveKey(Content::class);
84+
expect($zipper->getMeta()[Content::class])->toHaveKey('skipped', 'Content directory didn\'t exist, is it configured correctly?');
85+
86+
$zipper->close();
87+
88+
File::copyDirectory(config('backup.content_path') . '_backup', config('backup.content_path'));
89+
File::deleteDirectory(config('backup.content_path') . '_backup');
90+
});

0 commit comments

Comments
 (0)