From 06991d7ad908dba84935b989abce9693ae6e1cf7 Mon Sep 17 00:00:00 2001 From: freek Date: Wed, 12 Jan 2022 21:10:10 +0100 Subject: [PATCH] wip --- composer.json | 3 ++- src/BackupDestination/BackupDestination.php | 8 ++------ tests/BackupDestination/BackupTest.php | 17 ----------------- tests/Commands/BackupCommandTest.php | 2 +- tests/Events/BackupWasSuccessfulTest.php | 3 ++- 5 files changed, 7 insertions(+), 26 deletions(-) diff --git a/composer.json b/composer.json index 70924a19..ef667bca 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,8 @@ "spatie/laravel-signal-aware-command": "^1.2", "spatie/temporary-directory": "^2.0", "symfony/console": "^6.0", - "symfony/finder": "^6.0" + "symfony/finder": "^6.0", + "ext-pcntl": "*" }, "require-dev": { "composer-runtime-api": "^2.0", diff --git a/src/BackupDestination/BackupDestination.php b/src/BackupDestination/BackupDestination.php index 15666f6d..19305e86 100644 --- a/src/BackupDestination/BackupDestination.php +++ b/src/BackupDestination/BackupDestination.php @@ -82,19 +82,15 @@ public function write(string $file): void $handle = fopen($file, 'r+'); - $hasWritten = $this->disk->getDriver()->writeStream( + $this->disk->getDriver()->writeStream( $destination, $handle, - $this->getDiskOptions() + $this->getDiskOptions(), ); if (is_resource($handle)) { fclose($handle); } - - if (! $hasWritten) { - throw InvalidBackupFile::writeError($this->backupName()); - } } public function backupName(): string diff --git a/tests/BackupDestination/BackupTest.php b/tests/BackupDestination/BackupTest.php index 3fc8c3a6..4dd60e9c 100644 --- a/tests/BackupDestination/BackupTest.php +++ b/tests/BackupDestination/BackupTest.php @@ -61,23 +61,6 @@ public function when_its_unable_to_read_the_stream_throws_exception() $backup->stream(); } - /** @test */ - public function when_its_unable_to_write_to_stream_throws_exception() - { - $mock = $this->partialMock(Local::class, function (MockInterface $mock) { - $mock->shouldReceive('writeStream')->once()->andReturn(false); - }); - $adapter = new FilesystemAdapter(new Filesystem($mock)); - - $path = Storage::disk($diskName = 'local')->path( - $this->createFileOnDisk($diskName, $filePath = 'mysite.com/file.zip', now()) - ); - $backupDestination = new BackupDestination($adapter, $backupName = 'mysite', $diskName); - - $this->expectException(InvalidBackupFile::class); - $backupDestination->write($path); - } - /** @test */ public function it_can_delete_itself() { diff --git a/tests/Commands/BackupCommandTest.php b/tests/Commands/BackupCommandTest.php index db720dc3..7700fb67 100644 --- a/tests/Commands/BackupCommandTest.php +++ b/tests/Commands/BackupCommandTest.php @@ -82,7 +82,7 @@ public function it_includes_files_from_the_local_disks_in_the_backup() /** @test */ public function it_excludes_the_backup_destination_from_the_backup() { - config()->set('backup.backup.source.files.include', [$this->getDiskRootPath('local')]); + config()->set('backup.backup.source.files.include', [$this->getFullDiskPath('local','testing-file.txt')]); Storage::disk('local')->put('mysite/testing-file.txt', 'dummy content'); diff --git a/tests/Events/BackupWasSuccessfulTest.php b/tests/Events/BackupWasSuccessfulTest.php index c1d35618..0e1f833f 100644 --- a/tests/Events/BackupWasSuccessfulTest.php +++ b/tests/Events/BackupWasSuccessfulTest.php @@ -3,6 +3,7 @@ namespace Spatie\Backup\Tests\Events; use Illuminate\Support\Facades\Event; +use Spatie\Backup\Commands\BackupCommand; use Spatie\Backup\Events\BackupWasSuccessful; use Spatie\Backup\Tests\TestCase; @@ -13,7 +14,7 @@ public function it_will_fire_an_event_after_a_backup_was_completed_successfully( { Event::fake(); - $this->artisan('backup:run', ['--only-files' => true]); + $this->artisan(BackupCommand::class, ['--only-files' => true]); Event::assertDispatched(BackupWasSuccessful::class); }