Skip to content

Commit 3b8fb6f

Browse files
Add better test for restore
1 parent 53e80ff commit 3b8fb6f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/Unit/RestorerTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
use Itiden\Backup\Facades\Restorer;
1010
use Itiden\Backup\Enums\State;
1111
use Itiden\Backup\StateManager;
12+
use Statamic\Facades\Stache;
1213

1314
use function Itiden\Backup\Tests\fixtures_path;
15+
use function Itiden\Backup\Tests\user;
1416

1517
describe('restorer', function (): void {
1618
it('can restore from timestamp', function (): void {
@@ -25,6 +27,32 @@
2527
expect(File::isEmptyDirectory(fixtures_path('content/collections')))->toBeFalse();
2628
});
2729

30+
it('restores correct files', function (): void {
31+
user();
32+
expect(File::allFiles(Stache::store('entries')->directory()))->toHaveCount(2); // 1 entry, 1 collection
33+
expect(File::allFiles(Stache::store('form-submissions')->directory()))->toHaveCount(1);
34+
expect(File::allFiles(Stache::store('users')->directory()))->toHaveCount(1);
35+
36+
// config()->set('backup.stache_stores', [
37+
// 'form-submissions',
38+
// ]);
39+
40+
$backup = Backuper::backup();
41+
42+
File::cleanDirectory(fixtures_path('content')); // Simulate the stache directories doesnt exist anymore by removing the their parent directory
43+
File::cleanDirectory(Stache::store('users')->directory());
44+
45+
expect(file_exists(Stache::store('entries')->directory()))->toBeFalse();
46+
expect(file_exists(Stache::store('form-submissions')->directory()))->toBeFalse();
47+
expect(File::allFiles(Stache::store('users')->directory()))->toHaveCount(0);
48+
49+
Restorer::restore($backup);
50+
51+
expect(File::allFiles(Stache::store('entries')->directory()))->toHaveCount(2); // 1 entry, 1 collection
52+
expect(File::allFiles(Stache::store('form-submissions')->directory()))->toHaveCount(1);
53+
expect(File::allFiles(Stache::store('users')->directory()))->toHaveCount(1);
54+
});
55+
2856
it('throws an exception if the backup path does not exist', function (): void {
2957
Restorer::restore(
3058
new BackupDto(

0 commit comments

Comments
 (0)